From 2b6e2a4586e1fff049717a09d634c245e866af46 Mon Sep 17 00:00:00 2001 From: Thorsten Sick Date: Fri, 16 Jul 2021 08:21:00 +0200 Subject: [PATCH] pylinting round 4 --- app/experimentcontrol.py | 4 ++-- app/pluginmanager.py | 15 +++++++-------- metasploit_control.py | 2 +- plugins/base/attack.py | 20 ++++++++++---------- plugins/base/plugin_base.py | 12 ++++++------ 5 files changed, 26 insertions(+), 27 deletions(-) diff --git a/app/experimentcontrol.py b/app/experimentcontrol.py index dd33a1d..73229fc 100644 --- a/app/experimentcontrol.py +++ b/app/experimentcontrol.py @@ -11,11 +11,11 @@ from datetime import datetime from app.attack_log import AttackLog from app.config import ExperimentConfig from app.interface_sfx import CommandlineColors +from app.exceptions import ServerError +from app.pluginmanager import PluginManager from caldera_control import CalderaControl from machine_control import Machine -from app.exceptions import ServerError from plugins.base.attack import AttackPlugin -from app.pluginmanager import PluginManager # TODO: Multi threading at least when starting machines diff --git a/app/pluginmanager.py b/app/pluginmanager.py index 52b0099..aa9b562 100644 --- a/app/pluginmanager.py +++ b/app/pluginmanager.py @@ -167,14 +167,13 @@ class PluginManager(): # Deep checks - result = self.check(plugin) - - for r in result: - print(f"* Issue: {r}") - if len(result): - for r in result: - issues.append(r) - self.attack_logger.vprint(f"{CommandlineColors.BACKGROUND_RED}{r}{CommandlineColors.ENDC}", 1) + results = self.check(plugin) + + if len(results) > 0: + for result in results: + print(f"* Issue: {result}") + issues.append(result) + self.attack_logger.vprint(f"{CommandlineColors.BACKGROUND_RED}{result}{CommandlineColors.ENDC}", 1) return issues # TODO: Add verify command to verify all plugins (or a specific one) diff --git a/metasploit_control.py b/metasploit_control.py index 4e1f7f6..8978454 100644 --- a/metasploit_control.py +++ b/metasploit_control.py @@ -59,7 +59,7 @@ if __name__ == "__main__": # TODO get meterpreter session # TODO simple command to test - metasploit = Metasploit(PASSWORD, attacker=attacker, username=USER) + metasploit = Metasploit(PASSWORD, attack_logger=attack_logger, attacker=attacker, username=USER) metasploit.start_exploit_stub_for_external_payload(payload=PAYLOAD_TYPE) print(metasploit.meterpreter_execute(["getuid"], 0)) # client = MsfRpcClient('yourpassword', ssl=True) diff --git a/plugins/base/attack.py b/plugins/base/attack.py index a6ed6f8..9dea198 100644 --- a/plugins/base/attack.py +++ b/plugins/base/attack.py @@ -1,11 +1,11 @@ #!/usr/bin/env python3 """ Base class for Kali plugins """ +import os from plugins.base.plugin_base import BasePlugin from app.exceptions import PluginError, ConfigurationError from app.calderacontrol import CalderaControl # from app.metasploit import MSFVenom, Metasploit -import os class AttackPlugin(BasePlugin): @@ -50,7 +50,7 @@ class AttackPlugin(BasePlugin): """ Cleanup afterwards """ pass # pylint: disable=unnecessary-pass - def attacker_run_cmd(self, command, warn=True, disown=False): + def attacker_run_cmd(self, command, disown=False): """ Execute a command on the attacker @param command: Command to execute @@ -65,7 +65,7 @@ class AttackPlugin(BasePlugin): res = self.attacker_machine_plugin.__call_remote_run__(command, disown=disown) return res - def targets_run_cmd(self, command, warn=True, disown=False): + def targets_run_cmd(self, command, disown=False): """ Execute a command on the target @param command: Command to execute @@ -136,7 +136,7 @@ class AttackPlugin(BasePlugin): """ raise NotImplementedError - def install(self): + def install(self): # pylint: disable=no-self-use """ Install and setup requirements for the attack """ @@ -179,12 +179,12 @@ class AttackPlugin(BasePlugin): @returns: the machine """ - for t in self.targets: - if t.get_name() == name: - return t + for target in self.targets: + if target.get_name() == name: + return target - for t in self.targets: - if name in t.get_nicknames(): - return t + for target in self.targets: + if name in target.get_nicknames(): + return target raise ConfigurationError(f"No matching machine in experiment config for {name}") diff --git a/plugins/base/plugin_base.py b/plugins/base/plugin_base.py index 0540530..b18ae32 100644 --- a/plugins/base/plugin_base.py +++ b/plugins/base/plugin_base.py @@ -41,12 +41,12 @@ class BasePlugin(): """ Set the attack logger for this machine """ self.attack_logger = attack_logger - def process_templates(self): + def process_templates(self): # pylint: disable=no-self-use """ A method you can optionally implement to transfer your jinja2 templates into the files yo want to send to the target. See 'required_files' """ return - def copy_to_attacker_and_defender(self): + def copy_to_attacker_and_defender(self): # pylint: disable=no-self-use """ Copy attacker/defender specific files to the machines """ return @@ -71,7 +71,7 @@ class BasePlugin(): self.machine_plugin = machine_plugin - def set_sysconf(self, config): + def set_sysconf(self, config): # pylint:disable=unused-argument """ Set system config @param config: A dict with system configuration relevant for all plugins @@ -104,7 +104,7 @@ class BasePlugin(): """ Get a file from the machine """ self.machine_plugin.get(src, dst) # nosec - def run_cmd(self, command, warn=True, disown=False): + def run_cmd(self, command, disown=False): """ Execute a command on the vm using the connection @param command: Command to execute @@ -137,7 +137,7 @@ class BasePlugin(): for i in self.alternative_names: res.add(i) - if len(res): + if len(res) > 0: return list(res) raise NotImplementedError @@ -190,7 +190,7 @@ class BasePlugin(): return self.get_name() - def main_path(self): + def main_path(self): # pylint:disable=no-self-use """ Returns the main path of the Purple Dome installation """ app_dir = os.path.dirname(app.exceptions.__file__)