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
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))
data.update({'successful_logins': 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):
data.update(T1075.get_message_and_status(ScanStatus.SCANNED))
status = ScanStatus.SCANNED
else:
data.update(T1075.get_message_and_status(ScanStatus.UNSCANNED))
status = ScanStatus.UNSCANNED
data.update(T1075.get_message_and_status(status))
return data

View File

@ -35,16 +35,16 @@ class T1110(AttackTechnique):
result['successful_creds'].append(T1110.parse_creds(attempt))
if succeeded:
data = T1110.get_message_and_status(ScanStatus.USED)
status = ScanStatus.USED
elif attempts:
data = T1110.get_message_and_status(ScanStatus.SCANNED)
status = ScanStatus.SCANNED
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
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
@staticmethod

View File

@ -14,15 +14,16 @@ class T1210(AttackTechnique):
@staticmethod
def get_report_data():
data = {'title': T1210.technique_title(T1210.tech_id)}
data = {'title': T1210.technique_title()}
scanned_services = T1210.get_scanned_services()
exploited_services = T1210.get_exploited_services()
if exploited_services:
data.update({'status': ScanStatus.USED.name, 'message': T1210.used_msg})
status = ScanStatus.USED
elif scanned_services:
data.update({'status': ScanStatus.SCANNED.name, 'message': T1210.scanned_msg})
status = ScanStatus.SCANNED
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})
return data

View File

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