Some PEP8 cleanup

pull/12/head
Thorsten Sick 3 years ago
parent ac482e8b9e
commit 6177532133

@ -7,13 +7,14 @@ import os
import time
from pprint import pprint, pformat
from typing import Optional
import requests
import simplejson
from app.exceptions import CalderaError
from app.interface_sfx import CommandlineColors
from typing import Optional
# TODO: Ability deserves an own class.

@ -2,10 +2,10 @@
""" Configuration loader for PurpleDome """
from typing import Optional
import yaml
from app.exceptions import ConfigurationError
from typing import Optional
# So the config being read is distributed into several files and they will have different formats (yaml, CACAO)

@ -1,6 +1,6 @@
#!/usr/bin/env python3
# A document generator module.
""" Generate human readable document describing the attack based on an attack log """
import json
import os

@ -115,14 +115,14 @@ class Experiment():
self.attack_logger.vprint(f"Connecting to caldera {caldera_url}, running agents are: {running_agents}", 3)
self.attack_logger.vprint(f"Missing agent: {target_1.get_paw()} ...", 3)
target_1.start_caldera_client()
self.attack_logger.vprint(f"Restarted caldera agent: {target_1.get_paw()} ...", )
self.attack_logger.vprint(f"Restarted caldera agent: {target_1.get_paw()} ...", 3)
time.sleep(120) # Was 30, but maybe there are timing issues
running_agents = self.caldera_control.list_paws_of_running_agents()
self.attack_logger.vprint(f"{CommandlineColors.OKGREEN}Caldera agents reached{CommandlineColors.ENDC}", 1)
# Add running machines to log
for t in self.targets:
i = t.get_machine_info()
for target in self.targets:
i = target.get_machine_info()
i["role"] = "target"
self.attack_logger.add_machine_info(i)
@ -217,10 +217,10 @@ class Experiment():
self.attack_logger.post_process()
attack_log_file_path = os.path.join(self.lootdir, "attack.json")
self.attack_logger.write_json(attack_log_file_path)
dg = DocGenerator()
dg.generate(attack_log_file_path)
dg.compile_documentation()
zip_this += dg.get_outfile_paths()
document_generator = DocGenerator()
document_generator.generate(attack_log_file_path)
document_generator.compile_documentation()
zip_this += document_generator.get_outfile_paths()
self.zip_loot(zip_this)
def machine_needs_caldera(self, target, caldera_conf):
@ -237,7 +237,6 @@ class Experiment():
return c_cmdline + c_conffile + c_plugins
def attack(self, target, attack):
""" Pick an attack and run it
@ -293,29 +292,29 @@ class Experiment():
if os.path.exists(a_file):
yield a_file
def __clean_result_files(self, root):
""" Deletes result files
# def __clean_result_files(self, root):
# """ Deletes result files
@param root: Root dir of the machine to collect data from
"""
# @param root: Root dir of the machine to collect data from
# """
# TODO: Properly implement. Get proper root parameter
for a_file in self.__get_results_files(root):
os.remove(a_file)
# for a_file in self.__get_results_files(root):
# os.remove(a_file)
def __collect_loot(self, root):
""" Collect results into loot dir
# def __collect_loot(self, root):
# """ Collect results into loot dir
@param root: Root dir of the machine to collect data from
"""
# @param root: Root dir of the machine to collect data from
# """
try:
os.makedirs(os.path.abspath(self.experiment_config.loot_dir()))
except FileExistsError:
pass
for a_file in self.__get_results_files(root):
self.attack_logger.vprint("Copy {} {}".format(a_file, os.path.abspath(self.experiment_config.loot_dir())), 3)
# try:
# os.makedirs(os.path.abspath(self.experiment_config.loot_dir()))
# except FileExistsError:
# pass
# for a_file in self.__get_results_files(root):
# self.attack_logger.vprint("Copy {} {}".format(a_file, os.path.abspath(self.experiment_config.loot_dir())), 3)
def __start_attacker(self):
""" Start the attacking VM """

@ -3,13 +3,13 @@
from glob import glob
import os
import straight.plugin # type: ignore
from plugins.base.plugin_base import BasePlugin
from plugins.base.attack import AttackPlugin
from plugins.base.machinery import MachineryPlugin
from plugins.base.sensor import SensorPlugin
from plugins.base.vulnerability_plugin import VulnerabilityPlugin
import straight.plugin # type: ignore
from app.interface_sfx import CommandlineColors
from app.attack_log import AttackLog

@ -1,18 +1,18 @@
#!/usr/bin/env python3
# A standalone document generator. Takes an attack log and generates a doc using templates. Functionality will later be merged into PurpleDome
""" Generate human readable document describing the attack based on an attack log """
import argparse
from app.doc_generator import DocGenerator
default_attack_log = "removeme/loot/2021_09_08___07_41_35/attack.json" # FIN 7 first run on environment
DEFAULT_ATTACK_LOG = "removeme/loot/2021_09_08___07_41_35/attack.json" # FIN 7 first run on environment
def create_parser():
""" Creates the parser for the command line arguments"""
parser = argparse.ArgumentParser("Controls an experiment on the configured systems")
parser.add_argument("--attack_log", default=default_attack_log, help="The attack log the document is based on")
parser.add_argument("--attack_log", default=DEFAULT_ATTACK_LOG, help="The attack log the document is based on")
parser.add_argument("--outfile", default="tools/human_readable_documentation/source/contents.rst", help="The default output file")
return parser

@ -1,15 +1,15 @@
#!/usr/bin/env python3
""" Base class for Kali plugins """
from enum import Enum
import os
from plugins.base.plugin_base import BasePlugin
from app.exceptions import PluginError, ConfigurationError, RequirementError
from app.calderacontrol import CalderaControl
# from app.metasploit import MSFVenom, Metasploit
from typing import Optional
from plugins.base.machinery import MachineryPlugin
from app.calderacontrol import CalderaControl
from app.exceptions import PluginError, ConfigurationError, RequirementError
from app.metasploit import MetasploitInstant
from enum import Enum
from plugins.base.machinery import MachineryPlugin
from plugins.base.plugin_base import BasePlugin
class Requirement(Enum):

@ -5,8 +5,8 @@ Special for this plugin class: If there is no plugin matching a specified attack
You only gotta write a plugin if you want some special features
"""
from plugins.base.plugin_base import BasePlugin
from typing import Optional
from plugins.base.plugin_base import BasePlugin
class CalderaPlugin(BasePlugin):

@ -4,10 +4,10 @@
from enum import Enum
import os
from typing import Optional
from app.config import MachineConfig
from app.interface_sfx import CommandlineColors
from plugins.base.plugin_base import BasePlugin
from typing import Optional
class MachineStates(Enum):

@ -2,11 +2,11 @@
""" Base class for all plugin types """
import os
from typing import Optional
import yaml
# from shutil import copy
from app.exceptions import PluginError # type: ignore
import app.exceptions # type: ignore
from typing import Optional
class BasePlugin():

@ -2,8 +2,9 @@
""" A base plugin class for sensors. Anything installed on the target to collect system information and identify the attack """
import os
from plugins.base.plugin_base import BasePlugin
from typing import Optional
from plugins.base.plugin_base import BasePlugin
class SensorPlugin(BasePlugin):

@ -2,8 +2,8 @@
""" This is a specific plugin type that installs a vulnerability into a VM. This can be a vulnerable application or a configuration setting """
from plugins.base.plugin_base import BasePlugin
from typing import Optional
from plugins.base.plugin_base import BasePlugin
class VulnerabilityPlugin(BasePlugin):

@ -5,7 +5,7 @@ import socket
from plugins.base.attack import AttackPlugin, Requirement
from app.interface_sfx import CommandlineColors
from app.metasploit import MSFVenom, MetasploitInstant
from app.metasploit import MSFVenom
import os
import time

@ -3,7 +3,6 @@
# A plugin to nmap targets slow motion, to evade sensors
from plugins.base.attack import AttackPlugin, Requirement
# from app.metasploit import MetasploitInstant
class MetasploitArpPlugin(AttackPlugin):

@ -3,7 +3,6 @@
# A plugin to nmap targets slow motion, to evade sensors
from plugins.base.attack import AttackPlugin, Requirement
from app.metasploit import MetasploitInstant
class MetasploitClearevPlugin(AttackPlugin):

@ -3,7 +3,6 @@
# A plugin to nmap targets slow motion, to evade sensors
from plugins.base.attack import AttackPlugin, Requirement
from app.metasploit import MetasploitInstant
import socket

@ -3,7 +3,6 @@
# A plugin to nmap targets slow motion, to evade sensors
from plugins.base.attack import AttackPlugin, Requirement
from app.metasploit import MetasploitInstant
class MetasploitKeyloggingPlugin(AttackPlugin):
@ -33,12 +32,11 @@ class MetasploitKeyloggingPlugin(AttackPlugin):
payload_name = "babymetal.exe"
target = self.targets[0]
self.metasploit.smart_infect(target,
payload=payload_type,
outfile=payload_name,
format="exe",
architecture="x64")
payload=payload_type,
outfile=payload_name,
format="exe",
architecture="x64")
self.metasploit.migrate(target, name="winlogon.exe")

@ -3,7 +3,6 @@
# A plugin to nmap targets slow motion, to evade sensors
from plugins.base.attack import AttackPlugin, Requirement
from app.metasploit import MetasploitInstant
import socket
@ -35,7 +34,6 @@ class MetasploitKiwiPlugin(AttackPlugin):
payload_name = "babymetal.exe"
target = self.targets[0]
ip = socket.gethostbyname(self.attacker_machine_plugin.get_ip())
self.metasploit.smart_infect(target,

@ -3,7 +3,6 @@
# A plugin to nmap targets slow motion, to evade sensors
from plugins.base.attack import AttackPlugin, Requirement
from app.metasploit import MetasploitInstant
import socket
@ -37,13 +36,13 @@ class MetasploitMigratePlugin(AttackPlugin):
ip = socket.gethostbyname(self.attacker_machine_plugin.get_ip())
self.metasploit.smart_infect(target,
payload=payload_type,
architecture="x64",
platform="windows",
lhost=ip,
format="exe",
outfile=payload_name
)
payload=payload_type,
architecture="x64",
platform="windows",
lhost=ip,
format="exe",
outfile=payload_name
)
self.metasploit.migrate(target, user="NT AUTHORITY\\SYSTEM", name="svchost.exe", arch="x64")

@ -3,7 +3,6 @@
# A plugin to nmap targets slow motion, to evade sensors
from plugins.base.attack import AttackPlugin, Requirement
from app.metasploit import MetasploitInstant
class MetasploitPsPlugin(AttackPlugin):
@ -34,10 +33,10 @@ class MetasploitPsPlugin(AttackPlugin):
target = self.targets[0]
self.metasploit.smart_infect(target,
payload=payload_type,
outfile=payload_name,
format="exe",
architecture="x64")
payload=payload_type,
outfile=payload_name,
format="exe",
architecture="x64")
self.metasploit.ps_process_discovery(target)

@ -3,7 +3,6 @@
# A plugin to nmap targets slow motion, to evade sensors
from plugins.base.attack import AttackPlugin, Requirement
from app.metasploit import MetasploitInstant
class MetasploitScreengrabPlugin(AttackPlugin):

@ -3,7 +3,6 @@
# A plugin to nmap targets slow motion, to evade sensors
from plugins.base.attack import AttackPlugin, Requirement
from app.metasploit import MetasploitInstant
class MetasploitSysinfoPlugin(AttackPlugin):

Loading…
Cancel
Save