Report generation algorithm

This commit is contained in:
VakarisZ 2019-04-05 10:06:12 +03:00
parent 5ff7eba12f
commit c3d717a6bf
3 changed files with 30 additions and 2 deletions

View File

@ -10,6 +10,7 @@ from monkey_island.cc.services.config import ConfigService
from monkey_island.cc.services.attack.attack_config import reset_config as reset_attack_config
from monkey_island.cc.services.node import NodeService
from monkey_island.cc.services.report import ReportService
from cc.services.attack.attack_report import AttackReportService
from monkey_island.cc.utils import local_ip_addresses
from monkey_island.cc.services.post_breach_files import remove_PBA_files
@ -71,5 +72,7 @@ class Root(flask_restful.Resource):
else:
if is_any_exists:
ReportService.get_report()
AttackReportService.get_report()
report_done = ReportService.is_report_generated()
attack_report_done = AttackReportService.is_report_generated()
return dict(run_server=True, run_monkey=is_any_exists, infection_done=infection_done, report_done=report_done)

View File

@ -1,18 +1,37 @@
import logging
from cc.services.attack.technique_reports import T1210
from cc.services.attack.attack_telem import get_latest_telem
from cc.database import mongo
__author__ = "VakarisZ"
logger = logging.getLogger(__name__)
TECHNIQUES = {'T1210': T1210}
class AttackReportService:
def __init__(self):
pass
@staticmethod
def get_report():
report = {}
def generate_new_report():
report = {'techniques': {}, 'meta': {get_latest_telem()}}
for tech_id, value in
report.update({'T1210': T1210.get_report_data()})
report.update({''})
return report
@staticmethod
def get_latest_report():
if AttackReportService.is_report_generated():
telem_time = get_latest_telem_time()
lates_report = mongo.db.attack_report.find_one({'name': 'new_report'})
if telem_time == lates_report['telem_time']:
return lates_report
return AttackReportService.generate_new_report()
@staticmethod
def is_report_generated():
generated_report = mongo.db.attack_report.find_one({})
return generated_report is not None

View File

@ -3,6 +3,7 @@ File that contains ATT&CK telemetry storing/retrieving logic
"""
import logging
from monkey_island.cc.database import mongo
from time import time
__author__ = "VakarisZ"
@ -17,3 +18,8 @@ def set_results(technique, data):
"""
data.update({'technique': technique})
mongo.db.attack_results.insert(data)
mongo.db.attack_results.update({'name': 'latest'}, {'name': 'latest', 'timestamp': time()}, upsert=True)
def get_latest_telem():
return mongo.db.attack_results.find({'name': 'latest'})