forked from p15670423/monkey
Added more log lines
This commit is contained in:
parent
509558fbb2
commit
ad0d9f4567
|
@ -22,6 +22,7 @@ def load_env_from_file():
|
||||||
try:
|
try:
|
||||||
__env_type = load_env_from_file()
|
__env_type = load_env_from_file()
|
||||||
env = ENV_DICT[__env_type]()
|
env = ENV_DICT[__env_type]()
|
||||||
|
logger.info('Monkey\'s env is: {0}'.format(env))
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error('Failed initializing environment', exc_info=True)
|
logger.error('Failed initializing environment', exc_info=True)
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -19,6 +19,7 @@ class MonkeyConfiguration(flask_restful.Resource):
|
||||||
config_json = json.loads(request.data)
|
config_json = json.loads(request.data)
|
||||||
if 'reset' in config_json:
|
if 'reset' in config_json:
|
||||||
ConfigService.reset_config()
|
ConfigService.reset_config()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
ConfigService.update_config(config_json, should_encrypt=True)
|
ConfigService.update_config(config_json, should_encrypt=True)
|
||||||
return self.get()
|
return self.get()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import logging
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
@ -6,6 +7,8 @@ import flask_restful
|
||||||
|
|
||||||
__author__ = 'Barak'
|
__author__ = 'Barak'
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
MONKEY_DOWNLOADS = [
|
MONKEY_DOWNLOADS = [
|
||||||
{
|
{
|
||||||
|
@ -42,7 +45,10 @@ MONKEY_DOWNLOADS = [
|
||||||
def get_monkey_executable(host_os, machine):
|
def get_monkey_executable(host_os, machine):
|
||||||
for download in MONKEY_DOWNLOADS:
|
for download in MONKEY_DOWNLOADS:
|
||||||
if host_os == download.get('type') and machine == download.get('machine'):
|
if host_os == download.get('type') and machine == download.get('machine'):
|
||||||
|
logger.info('Monkey exec found for os: {0} and machine: {1}'.format(host_os, machine))
|
||||||
return download
|
return download
|
||||||
|
logger.warning('No monkey executables could be found for the host os or machine or both: host_os: {0}, machine: {1}'
|
||||||
|
.format(host_os, machine))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import logging
|
||||||
|
|
||||||
import flask_restful
|
import flask_restful
|
||||||
from flask import request, make_response, jsonify
|
from flask import request, make_response, jsonify
|
||||||
|
@ -12,6 +13,8 @@ from cc.utils import local_ip_addresses
|
||||||
|
|
||||||
__author__ = 'Barak'
|
__author__ = 'Barak'
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Root(flask_restful.Resource):
|
class Root(flask_restful.Resource):
|
||||||
|
|
||||||
|
@ -42,6 +45,7 @@ class Root(flask_restful.Resource):
|
||||||
# We can't drop system collections.
|
# We can't drop system collections.
|
||||||
[mongo.db[x].drop() for x in mongo.db.collection_names() if not x.startswith('system.')]
|
[mongo.db[x].drop() for x in mongo.db.collection_names() if not x.startswith('system.')]
|
||||||
ConfigService.init_config()
|
ConfigService.init_config()
|
||||||
|
logger.info('DB was reset')
|
||||||
return jsonify(status='OK')
|
return jsonify(status='OK')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -50,6 +54,7 @@ class Root(flask_restful.Resource):
|
||||||
mongo.db.monkey.update({'dead': False}, {'$set': {'config.alive': False, 'modifytime': datetime.now()}},
|
mongo.db.monkey.update({'dead': False}, {'$set': {'config.alive': False, 'modifytime': datetime.now()}},
|
||||||
upsert=False,
|
upsert=False,
|
||||||
multi=True)
|
multi=True)
|
||||||
|
logger.info('Kill all monkeys was called')
|
||||||
return jsonify(status='OK')
|
return jsonify(status='OK')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -59,6 +64,7 @@ class Root(flask_restful.Resource):
|
||||||
infection_done = NodeService.is_monkey_finished_running()
|
infection_done = NodeService.is_monkey_finished_running()
|
||||||
if not infection_done:
|
if not infection_done:
|
||||||
report_done = False
|
report_done = False
|
||||||
|
logger.info('Report generation cannot be completed, infection is not done.')
|
||||||
else:
|
else:
|
||||||
report_done = ReportService.is_report_generated()
|
report_done = ReportService.is_report_generated()
|
||||||
return dict(run_server=True, run_monkey=is_any_exists, infection_done=infection_done, report_done=report_done)
|
return dict(run_server=True, run_monkey=is_any_exists, infection_done=infection_done, report_done=report_done)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import copy
|
import copy
|
||||||
import collections
|
import collections
|
||||||
import functools
|
import functools
|
||||||
|
import logging
|
||||||
from jsonschema import Draft4Validator, validators
|
from jsonschema import Draft4Validator, validators
|
||||||
|
|
||||||
from cc.database import mongo
|
from cc.database import mongo
|
||||||
|
@ -10,6 +11,8 @@ from cc.utils import local_ip_addresses
|
||||||
|
|
||||||
__author__ = "itay.mizeretz"
|
__author__ = "itay.mizeretz"
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
WARNING_SIGN = u" \u26A0"
|
WARNING_SIGN = u" \u26A0"
|
||||||
|
|
||||||
SCHEMA = {
|
SCHEMA = {
|
||||||
|
@ -893,6 +896,7 @@ class ConfigService:
|
||||||
if should_encrypt:
|
if should_encrypt:
|
||||||
ConfigService.encrypt_config(config_json)
|
ConfigService.encrypt_config(config_json)
|
||||||
mongo.db.config.update({'name': 'newconfig'}, {"$set": config_json}, upsert=True)
|
mongo.db.config.update({'name': 'newconfig'}, {"$set": config_json}, upsert=True)
|
||||||
|
logger.info('monkey config was updated')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def init_default_config():
|
def init_default_config():
|
||||||
|
@ -908,6 +912,7 @@ class ConfigService:
|
||||||
config = copy.deepcopy(ConfigService.default_config)
|
config = copy.deepcopy(ConfigService.default_config)
|
||||||
if should_encrypt:
|
if should_encrypt:
|
||||||
ConfigService.encrypt_config(config)
|
ConfigService.encrypt_config(config)
|
||||||
|
logger.info("Default config was called")
|
||||||
return config
|
return config
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -921,6 +926,7 @@ class ConfigService:
|
||||||
config = ConfigService.get_default_config(True)
|
config = ConfigService.get_default_config(True)
|
||||||
ConfigService.set_server_ips_in_config(config)
|
ConfigService.set_server_ips_in_config(config)
|
||||||
ConfigService.update_config(config, should_encrypt=False)
|
ConfigService.update_config(config, should_encrypt=False)
|
||||||
|
logger.info('Monkey config reset was called')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def set_server_ips_in_config(config):
|
def set_server_ips_in_config(config):
|
||||||
|
@ -937,6 +943,7 @@ class ConfigService:
|
||||||
initial_config['name'] = 'initial'
|
initial_config['name'] = 'initial'
|
||||||
initial_config.pop('_id')
|
initial_config.pop('_id')
|
||||||
mongo.db.config.insert(initial_config)
|
mongo.db.config.insert(initial_config)
|
||||||
|
logger.info('Monkey config was inserted to mongo and saved')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _extend_config_with_default(validator_class):
|
def _extend_config_with_default(validator_class):
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import ipaddress
|
import ipaddress
|
||||||
|
import logging
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
from cc.database import mongo
|
from cc.database import mongo
|
||||||
|
@ -10,6 +11,9 @@ from cc.utils import local_ip_addresses, get_subnets
|
||||||
__author__ = "itay.mizeretz"
|
__author__ = "itay.mizeretz"
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ReportService:
|
class ReportService:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
@ -77,6 +81,8 @@ class ReportService:
|
||||||
creds = ReportService.get_azure_creds()
|
creds = ReportService.get_azure_creds()
|
||||||
machines = set([instance['origin'] for instance in creds])
|
machines = set([instance['origin'] for instance in creds])
|
||||||
|
|
||||||
|
logger.info('Azure issues generated for reporting')
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
'type': 'azure_password',
|
'type': 'azure_password',
|
||||||
|
@ -103,6 +109,8 @@ class ReportService:
|
||||||
}
|
}
|
||||||
for node in nodes]
|
for node in nodes]
|
||||||
|
|
||||||
|
logger.info('Scanned nodes generated for reporting')
|
||||||
|
|
||||||
return nodes
|
return nodes
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -124,6 +132,8 @@ class ReportService:
|
||||||
}
|
}
|
||||||
for monkey in exploited]
|
for monkey in exploited]
|
||||||
|
|
||||||
|
logger.info('Exploited nodes generated for reporting')
|
||||||
|
|
||||||
return exploited
|
return exploited
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -147,6 +157,7 @@ class ReportService:
|
||||||
'origin': origin
|
'origin': origin
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
logger.info('Stolen creds generated for reporting')
|
||||||
return creds
|
return creds
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -167,6 +178,8 @@ class ReportService:
|
||||||
azure_leaked_users = [{'username': user.replace(',', '.'), 'type': 'Clear Password',
|
azure_leaked_users = [{'username': user.replace(',', '.'), 'type': 'Clear Password',
|
||||||
'origin': origin} for user in azure_users]
|
'origin': origin} for user in azure_users]
|
||||||
creds.extend(azure_leaked_users)
|
creds.extend(azure_leaked_users)
|
||||||
|
|
||||||
|
logger.info('Azure machines creds generated for reporting')
|
||||||
return creds
|
return creds
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -318,6 +331,7 @@ class ReportService:
|
||||||
if machine not in issues_dict:
|
if machine not in issues_dict:
|
||||||
issues_dict[machine] = []
|
issues_dict[machine] = []
|
||||||
issues_dict[machine].append(issue)
|
issues_dict[machine].append(issue)
|
||||||
|
logger.info('Issues generated for reporting')
|
||||||
return issues_dict
|
return issues_dict
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -405,6 +419,7 @@ class ReportService:
|
||||||
{'name': 'generated_report'},
|
{'name': 'generated_report'},
|
||||||
{'$set': {'value': True}},
|
{'$set': {'value': True}},
|
||||||
upsert=True)
|
upsert=True)
|
||||||
|
logger.info("Report marked as generated.")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_report():
|
def get_report():
|
||||||
|
|
Loading…
Reference in New Issue