Skip to content

Conversation

VakarisZ
Copy link
Contributor

@VakarisZ VakarisZ commented Mar 31, 2021

What does this PR do?

Improves modularity in report issues and improves readability in report UI and back end.
Eases the process of new issue incorporation.

PR Checklist

  • Have you added an explanation of what your changes do and why you'd like to include them?
  • Is the TravisCI build passing?
  • Was the CHANGELOG.md updated to reflect the changes?
  • Was the documentation framework updated to reflect the changes?

Testing Checklist

  • Added relevant unit tests?
  • Have you successfully tested your changes locally? Elaborate:

    Tested zerologon, ssh, tunneling, smb, segmentation, stolen credentials and more.

@VakarisZ VakarisZ requested a review from mssalvatore March 31, 2021 09:25
Comment on lines 9 to 12
class ExploiterReportInfo:
machine: str
ip_address: str
type: str
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some processors extend this class, maybe should define separate dataclasses for each extension

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dataclasses can be inherited freely so why not :)

@VakarisZ VakarisZ requested a review from shreyamalviya March 31, 2021 09:29
@ghost
Copy link

ghost commented Mar 31, 2021

DeepCode failed to analyze this pull request

Something went wrong despite trying multiple times, sorry about that.
Please comment this pull request with "Retry DeepCode" to manually retry, or contact us so that a human can look into the issue.

Comment on lines +20 to +32
SMB = ExploiterDescriptor('SmbExploiter', 'SMB Exploiter', CredExploitProcessor)
WMI = ExploiterDescriptor('WmiExploiter', 'WMI Exploiter', CredExploitProcessor)
SSH = ExploiterDescriptor('SSHExploiter', 'SSH Exploiter', CredExploitProcessor)
SAMBACRY = ExploiterDescriptor('SambaCryExploiter', 'SambaCry Exploiter', CredExploitProcessor)
ELASTIC = ExploiterDescriptor('ElasticGroovyExploiter', 'Elastic Groovy Exploiter', ExploitProcessor)
MS08_067 = ExploiterDescriptor('Ms08_067_Exploiter', 'Conficker Exploiter', ExploitProcessor)
SHELLSHOCK = ExploiterDescriptor('ShellShockExploiter', 'ShellShock Exploiter', ShellShockExploitProcessor)
STRUTS2 = ExploiterDescriptor('Struts2Exploiter', 'Struts2 Exploiter', ExploitProcessor)
WEBLOGIC = ExploiterDescriptor('WebLogicExploiter', 'Oracle WebLogic Exploiter', ExploitProcessor)
HADOOP = ExploiterDescriptor('HadoopExploiter', 'Hadoop/Yarn Exploiter', ExploitProcessor)
MSSQL = ExploiterDescriptor('MSSQLExploiter', 'MSSQL Exploiter', ExploitProcessor)
VSFTPD = ExploiterDescriptor('VSFTPDExploiter', 'VSFTPD Backdoor Exploiter', CredExploitProcessor)
DRUPAL = ExploiterDescriptor('DrupalExploiter', 'Drupal Server Exploiter', ExploitProcessor)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason this isn't an actual link is because you don't want to include Monkey code in Island? Or why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because the island doesn't contain the agent's code.

processor: Type[ExploitProcessor]


class ExploiterDescriptorEnum(Enum):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this an enum? What functionality of enum are you using?

Copy link
Contributor Author

@VakarisZ VakarisZ Apr 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not? What do you think would be a better data structure? I like enums over dicts, because when you want to get a specific value from dict, you need to make sure that your key is correct, because key is a hardcoded string.

Comment on lines 33 to 37
def build_exploiter_descriptor_dict() -> Dict[str, ExploiterDescriptor]:
descriptor_dict = {}
for descriptor in ExploiterDescriptorEnum:
descriptor_dict[descriptor.value.class_name] = descriptor
return descriptor_dict
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be in the enum class file? It's tightly coupled to it

}
for exploited_node in exploited]

logger.info('Exploited nodes generated for reporting')

return exploited

@staticmethod
def get_exploits_used_on_node(node: dict) -> List[str]:
return list(set([exploit['exploiter'] for exploit in node['exploits'] if exploit['result']]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the cast from list to set to list? Do you just want a cleaned up list? Do you really need it to be a list and not Iterable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why it was made this way, but I'd guess to remove duplicates in the list.

@@ -677,8 +489,8 @@ def get_config_exploits():
if exploits == default_exploits:
return ['default']

return [ReportService.EXPLOIT_DISPLAY_DICT[exploit] for exploit in
exploits]
# TODO investigate strange code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

Comment on lines 509 to 511
# TODO check if this actually works, because stolen passwords get added to config
# so any password will be in config. We need to separate stolen passwords from initial
# passwords in config.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires you to not just have a clean "setup" config but also a "pre run" config.

Wouldn't it be better to split the stolen creds from user creds and in the monkey have a property that merges them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Monkey probably registers stolen credentials when they are stolen. I tested and it works

@staticmethod
def _is_weak_credential_issue(issue: dict, config_usernames: List[str], config_passwords: List[str]) -> bool:
# Only credential exploiter issues have 'credential_type'
return 'credential_type' in issue and \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't make more sense to clean this according to the type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What 'type'? You mean have a list of credential_type issues? I think that "if issue has credentials, then it's a credential issue" logic is good enough for this PR

@@ -274,7 +274,7 @@ def get_exploits():
for exploit in mongo.db.telemetry.aggregate(query):
new_exploit = ReportService.process_exploit(exploit)
if new_exploit not in exploits:
exploits.append(new_exploit)
exploits.append(new_exploit.__dict__)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? You have a wrapper function in dataclasses to cast to dict

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK that wrapper only calls factory function, which in our case is dict anyways. I see no reason to use that wrapper

@@ -1,4 +1,5 @@
import React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this entire commit be squashed into the original one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you think that it should?

@mssalvatore mssalvatore mentioned this pull request Apr 5, 2021
4 tasks
@shreyamalviya shreyamalviya merged commit c7a241e into develop Apr 6, 2021
@VakarisZ VakarisZ deleted the report_refactoring branch April 12, 2021 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants