Readability improvements

This commit is contained in:
VakarisZ 2019-06-19 11:54:58 +03:00
parent 9367e6490b
commit b3c6baf214
4 changed files with 24 additions and 24 deletions

View File

@ -31,13 +31,14 @@ class T1075(AttackTechnique):
@staticmethod @staticmethod
def get_report_data(): def get_report_data():
data = {'title': T1075.technique_title(T1075.tech_id)} data = {'title': T1075.technique_title()}
successful_logins = list(mongo.db.telemetry.aggregate(T1075.query)) successful_logins = list(mongo.db.telemetry.aggregate(T1075.query))
data.update({'successful_logins': successful_logins}) data.update({'successful_logins': successful_logins})
if successful_logins: if successful_logins:
data.update(T1075.get_message_and_status(ScanStatus.USED)) status = ScanStatus.USED
elif mongo.db.telemetry.count_documents(T1075.login_attempt_query): elif mongo.db.telemetry.count_documents(T1075.login_attempt_query):
data.update(T1075.get_message_and_status(ScanStatus.SCANNED)) status = ScanStatus.SCANNED
else: else:
data.update(T1075.get_message_and_status(ScanStatus.UNSCANNED)) status = ScanStatus.UNSCANNED
data.update(T1075.get_message_and_status(status))
return data return data

View File

@ -35,16 +35,16 @@ class T1110(AttackTechnique):
result['successful_creds'].append(T1110.parse_creds(attempt)) result['successful_creds'].append(T1110.parse_creds(attempt))
if succeeded: if succeeded:
data = T1110.get_message_and_status(ScanStatus.USED) status = ScanStatus.USED
elif attempts: elif attempts:
data = T1110.get_message_and_status(ScanStatus.SCANNED) status = ScanStatus.SCANNED
else: else:
data = T1110.get_message_and_status(ScanStatus.UNSCANNED) status = ScanStatus.UNSCANNED
data = T1110.get_message_and_status(status)
# Remove data with no successful brute force attempts # Remove data with no successful brute force attempts
attempts = [attempt for attempt in attempts if attempt['attempts']] attempts = [attempt for attempt in attempts if attempt['attempts']]
data.update({'services': attempts, 'title': T1110.technique_title(T1110.tech_id)}) data.update({'services': attempts, 'title': T1110.technique_title()})
return data return data
@staticmethod @staticmethod

View File

@ -14,15 +14,16 @@ class T1210(AttackTechnique):
@staticmethod @staticmethod
def get_report_data(): def get_report_data():
data = {'title': T1210.technique_title(T1210.tech_id)} data = {'title': T1210.technique_title()}
scanned_services = T1210.get_scanned_services() scanned_services = T1210.get_scanned_services()
exploited_services = T1210.get_exploited_services() exploited_services = T1210.get_exploited_services()
if exploited_services: if exploited_services:
data.update({'status': ScanStatus.USED.name, 'message': T1210.used_msg}) status = ScanStatus.USED
elif scanned_services: elif scanned_services:
data.update({'status': ScanStatus.SCANNED.name, 'message': T1210.scanned_msg}) status = ScanStatus.SCANNED
else: else:
data.update({'status': ScanStatus.UNSCANNED.name, 'message': T1210.unscanned_msg}) status = ScanStatus.UNSCANNED.name
data.update(T1210.get_message_and_status(status))
data.update({'scanned_services': scanned_services, 'exploited_services': exploited_services}) data.update({'scanned_services': scanned_services, 'exploited_services': exploited_services})
return data return data

View File

@ -46,20 +46,19 @@ class AttackTechnique(object):
""" """
pass pass
@staticmethod @classmethod
def technique_status(tech_id): def technique_status(cls):
""" """
Gets the status of a certain attack technique. Gets the status of a certain attack technique.
:param tech_id: ID of attack technique, for e.g. T1110
:return: ScanStatus Enum object :return: ScanStatus Enum object
""" """
if mongo.db.attack_results.find_one({'telem_catagory': 'attack', if mongo.db.attack_results.find_one({'telem_catagory': 'attack',
'status': ScanStatus.USED.value, 'status': ScanStatus.USED.value,
'technique': tech_id}): 'technique': cls.tech_id}):
return ScanStatus.USED return ScanStatus.USED
elif mongo.db.attack_results.find_one({'telem_catagory': 'attack', elif mongo.db.attack_results.find_one({'telem_catagory': 'attack',
'status': ScanStatus.SCANNED.value, 'status': ScanStatus.SCANNED.value,
'technique': tech_id}): 'technique': cls.tech_id}):
return ScanStatus.SCANNED return ScanStatus.SCANNED
else: else:
return ScanStatus.UNSCANNED return ScanStatus.UNSCANNED
@ -87,13 +86,12 @@ class AttackTechnique(object):
else: else:
return cls.used_msg return cls.used_msg
@staticmethod @classmethod
def technique_title(tech_id): def technique_title(cls):
""" """
:param tech_id: Technique's id. E.g. T1110
:return: techniques title. E.g. "T1110 Brute force" :return: techniques title. E.g. "T1110 Brute force"
""" """
return AttackConfig.get_technique(tech_id)['title'] return AttackConfig.get_technique(cls.tech_id)['title']
@classmethod @classmethod
def get_tech_base_data(cls): def get_tech_base_data(cls):
@ -102,8 +100,8 @@ class AttackTechnique(object):
:return: dict E.g. {'message': 'Brute force used', 'status': 'Used', 'title': 'T1110 Brute force'} :return: dict E.g. {'message': 'Brute force used', 'status': 'Used', 'title': 'T1110 Brute force'}
""" """
data = {} data = {}
status = AttackTechnique.technique_status(cls.tech_id) status = cls.technique_status()
title = AttackTechnique.technique_title(cls.tech_id) title = cls.technique_title()
data.update({'status': status.name, data.update({'status': status.name,
'title': title, 'title': title,
'message': cls.get_message_by_status(status)}) 'message': cls.get_message_by_status(status)})