From 45ff7d105aa8356746638964a5af4022488d1bb4 Mon Sep 17 00:00:00 2001 From: Vincent Rose Date: Sun, 19 Nov 2023 22:26:45 -0700 Subject: [PATCH] Remove usages of deprecated listener and credential functions (#732) * remove usages of deprecated listener function * remove usages of deprecated credential functions * changelog, update imports, add typehinting * remove usages of deprecated agent functions --- CHANGELOG.md | 3 + empire/server/core/credential_service.py | 2 +- .../data/misc/inactive_modules/redirector.py | 18 +-- empire/server/listeners/port_forward_pivot.py | 146 +++++++++--------- empire/server/listeners/smb.py | 26 ++-- .../modules/csharp/Assembly.Covenant.py | 3 +- .../csharp/AssemblyReflect.Covenant.py | 3 +- .../modules/csharp/Inject_BOF.Covenant.py | 3 +- .../csharp/ProcessInjection.Covenant.py | 5 +- .../modules/csharp/Shellcode.Covenant.py | 3 +- .../powershell/code_execution/invoke_ntsd.py | 5 +- .../invoke_reflectivepeinjection.py | 3 +- .../code_execution/invoke_shellcode.py | 3 +- .../code_execution/invoke_shellcodemsil.py | 3 +- .../powershell/collection/SharpChromium.py | 3 +- .../modules/powershell/collection/WireTap.py | 3 +- .../collection/get_sql_column_sample_data.py | 3 +- .../modules/powershell/collection/minidump.py | 3 +- .../powershell/collection/packet_capture.py | 3 +- .../powershell/collection/screenshot.py | 3 +- .../credentials/credential_injection.py | 32 ++-- .../credentials/mimikatz/dcsync_hashdump.py | 3 +- .../credentials/mimikatz/golden_ticket.py | 29 ++-- .../credentials/mimikatz/lsadump.py | 3 +- .../credentials/mimikatz/mimitokens.py | 3 +- .../powershell/credentials/mimikatz/pth.py | 29 ++-- .../credentials/mimikatz/silver_ticket.py | 37 +++-- .../credentials/mimikatz/trust_keys.py | 3 +- .../modules/powershell/credentials/tokens.py | 3 +- .../powershell/exfiltration/PSRansom.py | 3 +- .../exploitation/exploit_eternalblue.py | 3 +- .../lateral_movement/inveigh_relay.py | 5 +- .../lateral_movement/invoke_dcom.py | 8 +- .../lateral_movement/invoke_executemsbuild.py | 29 ++-- .../lateral_movement/invoke_psexec.py | 5 +- .../lateral_movement/invoke_psremoting.py | 22 ++- .../lateral_movement/invoke_smbexec.py | 8 +- .../lateral_movement/invoke_sqloscmd.py | 28 ++-- .../lateral_movement/invoke_sshcommand.py | 20 +-- .../powershell/lateral_movement/invoke_wmi.py | 35 +++-- .../lateral_movement/invoke_wmi_debugger.py | 26 ++-- .../jenkins_script_console.py | 3 +- .../new_gpo_immediate_task.py | 5 +- .../powershell/management/invoke_bypass.py | 3 +- .../powershell/management/invoke_script.py | 3 +- .../modules/powershell/management/logoff.py | 3 +- .../management/mailraider/disable_security.py | 3 +- .../management/mailraider/get_emailitems.py | 3 +- .../modules/powershell/management/psinject.py | 5 +- .../management/reflective_inject.py | 5 +- .../modules/powershell/management/runas.py | 32 ++-- .../modules/powershell/management/shinject.py | 5 +- .../modules/powershell/management/spawn.py | 3 +- .../modules/powershell/management/spawnas.py | 24 +-- .../powershell/management/switch_listener.py | 3 +- .../powershell/management/user_to_sid.py | 3 +- .../persistence/elevated/registry.py | 5 +- .../persistence/elevated/schtasks.py | 5 +- .../powershell/persistence/elevated/wmi.py | 2 +- .../persistence/elevated/wmi_updater.py | 3 +- .../persistence/misc/add_sid_history.py | 3 +- .../powershell/persistence/misc/debugger.py | 5 +- .../persistence/powerbreach/deaduser.py | 5 +- .../persistence/powerbreach/eventlog.py | 5 +- .../persistence/powerbreach/resolver.py | 5 +- .../persistence/userland/backdoor_lnk.py | 7 +- .../persistence/userland/registry.py | 5 +- .../persistence/userland/schtasks.py | 5 +- .../server/modules/powershell/privesc/ask.py | 5 +- .../modules/powershell/privesc/bypassuac.py | 5 +- .../powershell/privesc/bypassuac_env.py | 5 +- .../powershell/privesc/bypassuac_eventvwr.py | 5 +- .../powershell/privesc/bypassuac_fodhelper.py | 5 +- .../privesc/bypassuac_sdctlbypass.py | 5 +- .../privesc/bypassuac_tokenmanipulation.py | 3 +- .../powershell/privesc/bypassuac_wscript.py | 5 +- .../modules/powershell/privesc/ms16-032.py | 3 +- .../modules/powershell/privesc/ms16-135.py | 3 +- .../privesc/powerup/service_exe_stager.py | 3 +- .../privesc/powerup/service_stager.py | 3 +- .../privesc/powerup/write_dllhijacker.py | 3 +- .../powershell/recon/fetch_brute_local.py | 3 +- .../modules/powershell/recon/find_fruit.py | 3 +- .../recon/get_sql_server_login_default_pw.py | 3 +- .../host/computerdetails.py | 3 +- .../network/get_sql_server_info.py | 3 +- .../python/collection/osx/imessage_dump.py | 3 +- .../collection/osx/native_screenshot_mss.py | 3 +- .../modules/python/collection/osx/prompt.py | 3 +- .../python/collection/osx/search_email.py | 3 +- .../modules/python/collection/osx/sniffer.py | 3 +- .../lateral_movement/multi/ssh_launcher.py | 3 +- .../modules/python/management/multi/spawn.py | 3 +- .../management/osx/shellcodeinject64.py | 3 +- .../python/persistence/multi/desktopfile.py | 3 +- .../python/persistence/osx/CreateHijacker.py | 3 +- .../python/persistence/osx/LaunchAgent.py | 3 +- .../osx/LaunchAgentUserLandPersistence.py | 3 +- .../python/persistence/osx/loginhook.py | 3 +- .../modules/python/persistence/osx/mail.py | 3 +- .../python/privesc/multi/CVE-2021-3560.py | 3 +- .../python/privesc/multi/CVE-2021-4034.py | 3 +- .../modules/python/privesc/multi/bashdoor.py | 3 +- .../python/privesc/multi/sudo_spawn.py | 3 +- .../python/privesc/osx/dyld_print_to_file.py | 3 +- .../modules/python/privesc/osx/piggyback.py | 3 +- .../host/osx/situational_awareness.py | 3 +- empire/server/stagers/osx/shellcode.py | 2 +- empire/server/stagers/windows/dll.py | 2 +- empire/server/stagers/windows/shellcode.py | 2 +- .../test/data/modules/test_custom_module.py | 3 +- empire/test/test_modules.py | 6 +- 112 files changed, 509 insertions(+), 373 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bc936ac2..59ad87e76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Upgrade Pydantic to v2 (@Vinnybod) - Update common FastAPI Dependencies to use 'Annotated' types for simpler code (@Vinnybod) - Simplify TestClient setup (@Vinnybod) +- Removed usages of deprecated `Credentials` and `Listeners` functions (@Vinnybod) +- Remove usages of deprecated `Agents` functions (@Vinnybod) +- Add typehinting for `MainMenu` object in modules (@Vinnybod) ### Removed diff --git a/empire/server/core/credential_service.py b/empire/server/core/credential_service.py index 9c7820597..4294b4e53 100644 --- a/empire/server/core/credential_service.py +++ b/empire/server/core/credential_service.py @@ -40,7 +40,7 @@ def get_all( return query.all() @staticmethod - def get_by_id(db: Session, uid: int): + def get_by_id(db: Session, uid: int) -> models.Credential | None: return db.query(models.Credential).filter(models.Credential.id == uid).first() @staticmethod diff --git a/empire/server/data/misc/inactive_modules/redirector.py b/empire/server/data/misc/inactive_modules/redirector.py index c5182e48c..d784d38c9 100644 --- a/empire/server/data/misc/inactive_modules/redirector.py +++ b/empire/server/data/misc/inactive_modules/redirector.py @@ -23,15 +23,15 @@ def __init__(self, mainMenu): 'Background' : False, 'OutputExtension' : None, - + 'NeedsAdmin' : True, 'OpsecSafe' : True, - + 'Language' : 'powershell', 'MinLanguageVersion' : '2', - + 'Comments': [] } @@ -81,7 +81,7 @@ def __init__(self, mainMenu): self.mainMenu = mainMenu def generate(self, obfuscate=False, obfuscation_command=""): - + script = """ function Invoke-Redirector { param($ListenPort, $ConnectHost, [switch]$Reset, [switch]$ShowAll) @@ -111,7 +111,7 @@ def generate(self, obfuscate=False, obfuscation_command=""): else{ $ConnectAddress = "" $ConnectPort = "" - + $parts = $ConnectHost -split(":") if($parts.Length -eq 2){ # if the form is http[s]://HOST or HOST:PORT @@ -135,7 +135,7 @@ def generate(self, obfuscate=False, obfuscation_command=""): $ConnectPort = $parts[2] } if($ConnectPort -ne ""){ - + $out = netsh interface portproxy add v4tov4 listenport=$ListenPort connectaddress=$ConnectAddress connectport=$ConnectPort protocol=tcp if($out){ $out @@ -151,14 +151,14 @@ def generate(self, obfuscate=False, obfuscation_command=""): } } Invoke-Redirector""" - + addAsListener = False listenerName = False for option,values in self.options.items(): if option.lower() == "listener" and values['Value'] != '': # extract out all options from a listener if one is set - if not self.mainMenu.listeners.is_listener_valid(values['Value']): + if not self.mainMenu.listenersv2.get_active_listener_by_name(values['Value']): print(helpers.color("[!] Invalid listener set")) return "" else: @@ -178,7 +178,7 @@ def generate(self, obfuscate=False, obfuscation_command=""): # if we're just adding a switch script += " -" + str(option) else: - script += " -" + str(option) + " " + str(values['Value']) + script += " -" + str(option) + " " + str(values['Value']) if addAsListener: if listenerName: # if we're add this as a pivot listener diff --git a/empire/server/listeners/port_forward_pivot.py b/empire/server/listeners/port_forward_pivot.py index 4b784ee54..abf0ef59f 100755 --- a/empire/server/listeners/port_forward_pivot.py +++ b/empire/server/listeners/port_forward_pivot.py @@ -704,10 +704,10 @@ def start(self, name=""): return False # validate that the Listener does exist - if self.mainMenu.listeners.is_listener_valid(listenerName): + if self.mainMenu.listenersv2.get_active_listener_by_name(listenerName): # check if a listener for the agent already exists - if self.mainMenu.listeners.is_listener_valid( + if self.mainMenu.listenersv2.get_active_listener_by_name( tempOptions["Name"]["Value"] ): log.error( @@ -862,93 +862,91 @@ def shutdown(self, name=""): self.instance_log.info(f"{name}: shutting down...") log.info(f"{name}: shutting down...") - sessionID = self.mainMenu.agents.get_agent_id_db(name) - isElevated = self.mainMenu.agents.is_agent_elevated(sessionID) - if self.mainMenu.agents.is_agent_present(sessionID) and isElevated: - if self.mainMenu.agents.get_language_db(sessionID).startswith("po"): - script = """ - function Invoke-Redirector { - param($FirewallName, $ListenAddress, $ListenPort, $ConnectHost, [switch]$Reset, [switch]$ShowAll) - if($ShowAll){ - $out = netsh interface portproxy show all - if($out){ - $out - } - else{ - "[*] no redirectors currently configured" - } - } - elseif($Reset){ - Netsh.exe advfirewall firewall del rule name="$FirewallName" - $out = netsh interface portproxy reset - if($out){ - $out - } - else{ - "[+] successfully removed all redirectors" + with SessionLocal() as db: + agent = self.mainMenu.agentsv2.get_by_name(db, name) + + if not agent: + log.error("Agent is not present in the cache or not elevated") + return + + if agent.high_integrity: + if agent.language.startswith("po"): + script = """ + function Invoke-Redirector { + param($FirewallName, $ListenAddress, $ListenPort, $ConnectHost, [switch]$Reset, [switch]$ShowAll) + if($ShowAll){ + $out = netsh interface portproxy show all + if($out){ + $out + } + else{ + "[*] no redirectors currently configured" + } } - } - else{ - if((-not $ListenPort)){ - "[!] netsh error: required option not specified" + elseif($Reset){ + Netsh.exe advfirewall firewall del rule name="$FirewallName" + $out = netsh interface portproxy reset + if($out){ + $out + } + else{ + "[+] successfully removed all redirectors" + } } else{ - $ConnectAddress = "" - $ConnectPort = "" - - $parts = $ConnectHost -split(":") - if($parts.Length -eq 2){ - # if the form is http[s]://HOST or HOST:PORT - if($parts[0].StartsWith("http")){ - $ConnectAddress = $parts[1] -replace "//","" - if($parts[0] -eq "https"){ - $ConnectPort = "443" + if((-not $ListenPort)){ + "[!] netsh error: required option not specified" + } + else{ + $ConnectAddress = "" + $ConnectPort = "" + + $parts = $ConnectHost -split(":") + if($parts.Length -eq 2){ + # if the form is http[s]://HOST or HOST:PORT + if($parts[0].StartsWith("http")){ + $ConnectAddress = $parts[1] -replace "//","" + if($parts[0] -eq "https"){ + $ConnectPort = "443" + } + else{ + $ConnectPort = "80" + } } else{ - $ConnectPort = "80" + $ConnectAddress = $parts[0] + $ConnectPort = $parts[1] } } - else{ - $ConnectAddress = $parts[0] - $ConnectPort = $parts[1] + elseif($parts.Length -eq 3){ + # if the form is http[s]://HOST:PORT + $ConnectAddress = $parts[1] -replace "//","" + $ConnectPort = $parts[2] } - } - elseif($parts.Length -eq 3){ - # if the form is http[s]://HOST:PORT - $ConnectAddress = $parts[1] -replace "//","" - $ConnectPort = $parts[2] - } - if($ConnectPort -ne ""){ - Netsh.exe advfirewall firewall add rule name=`"$FirewallName`" dir=in action=allow protocol=TCP localport=$ListenPort enable=yes - $out = netsh interface portproxy add v4tov4 listenaddress=$ListenAddress listenport=$ListenPort connectaddress=$ConnectAddress connectport=$ConnectPort protocol=tcp - if($out){ - $out + if($ConnectPort -ne ""){ + Netsh.exe advfirewall firewall add rule name=`"$FirewallName`" dir=in action=allow protocol=TCP localport=$ListenPort enable=yes + $out = netsh interface portproxy add v4tov4 listenaddress=$ListenAddress listenport=$ListenPort connectaddress=$ConnectAddress connectport=$ConnectPort protocol=tcp + if($out){ + $out + } + else{ + "[+] successfully added redirector on port $ListenPort to $ConnectHost" + } } else{ - "[+] successfully added redirector on port $ListenPort to $ConnectHost" + "[!] netsh error: host not in http[s]://HOST:[PORT] format" } } - else{ - "[!] netsh error: host not in http[s]://HOST:[PORT] format" - } } } - } - Invoke-Redirector""" + Invoke-Redirector""" - script += " -Reset" - script += " -FirewallName %s" % (sessionID) + script += " -Reset" + script += f" -FirewallName {agent.session_id}" - with SessionLocal.begin() as db: - agent = self.mainMenu.agentsv2.get_by_id(db, sessionID) self.mainMenu.agenttasksv2.create_task_shell(db, agent, script) - msg = "Tasked agent to uninstall Pivot listener " - self.mainMenu.agents.save_agent_log(sessionID, msg) - - elif self.mainMenu.agents.get_language_db(sessionID).startswith("py"): - log.error("Shutdown not implemented for python") - - else: - log.error("Agent is not present in the cache or not elevated") + msg = "Tasked agent to uninstall Pivot listener " + self.mainMenu.agents.save_agent_log(agent.session_id, msg) - pass + elif agent.language.startswith("py"): + log.error("Shutdown not implemented for python") diff --git a/empire/server/listeners/smb.py b/empire/server/listeners/smb.py index 261b33126..781b2d5bc 100755 --- a/empire/server/listeners/smb.py +++ b/empire/server/listeners/smb.py @@ -423,20 +423,20 @@ def start(self, name=""): """ try: tempOptions = copy.deepcopy(self.options) - sessionID = self.mainMenu.agents.get_agent_id_db( - self.options["Agent"]["Value"] - ) - if self.mainMenu.agents.is_agent_present(sessionID): - with SessionLocal.begin() as db: - agent = self.mainMenu.agentsv2.get_by_id( - db, self.options["Agent"]["Value"] - ) - self.mainMenu.agenttasksv2.create_task_smb( - db, agent, name + "|" + self.options["PipeName"]["Value"] - ) - self.parent_agent = agent.session_id - parent_listener_name = agent.listener + with SessionLocal() as db: + agent = self.mainMenu.agentsv2.get_by_id( + db, self.options["Agent"]["Value"] + ) + + if not agent: + return + + self.mainMenu.agenttasksv2.create_task_smb( + db, agent, name + "|" + self.options["PipeName"]["Value"] + ) + self.parent_agent = agent.session_id + parent_listener_name = agent.listener log.info( f"{self.options['Agent']['Value']}: SMB pivot server task request send to agent" diff --git a/empire/server/modules/csharp/Assembly.Covenant.py b/empire/server/modules/csharp/Assembly.Covenant.py index 6b982504b..5de5d7e71 100755 --- a/empire/server/modules/csharp/Assembly.Covenant.py +++ b/empire/server/modules/csharp/Assembly.Covenant.py @@ -1,12 +1,13 @@ import yaml +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/csharp/AssemblyReflect.Covenant.py b/empire/server/modules/csharp/AssemblyReflect.Covenant.py index a8cda9c40..a6d85ff24 100755 --- a/empire/server/modules/csharp/AssemblyReflect.Covenant.py +++ b/empire/server/modules/csharp/AssemblyReflect.Covenant.py @@ -1,12 +1,13 @@ import yaml +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/csharp/Inject_BOF.Covenant.py b/empire/server/modules/csharp/Inject_BOF.Covenant.py index 739805737..a0bbf1da9 100644 --- a/empire/server/modules/csharp/Inject_BOF.Covenant.py +++ b/empire/server/modules/csharp/Inject_BOF.Covenant.py @@ -1,12 +1,13 @@ import yaml +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/csharp/ProcessInjection.Covenant.py b/empire/server/modules/csharp/ProcessInjection.Covenant.py index 9e11945a2..2e55ab92d 100644 --- a/empire/server/modules/csharp/ProcessInjection.Covenant.py +++ b/empire/server/modules/csharp/ProcessInjection.Covenant.py @@ -6,6 +6,7 @@ import yaml from empire.server.common import helpers +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -13,7 +14,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -31,7 +32,7 @@ def generate( arch = params["Architecture"] launcher_obfuscation = params["Obfuscate"] - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) diff --git a/empire/server/modules/csharp/Shellcode.Covenant.py b/empire/server/modules/csharp/Shellcode.Covenant.py index 37ea76e0b..ad744266a 100755 --- a/empire/server/modules/csharp/Shellcode.Covenant.py +++ b/empire/server/modules/csharp/Shellcode.Covenant.py @@ -1,12 +1,13 @@ import yaml +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/code_execution/invoke_ntsd.py b/empire/server/modules/powershell/code_execution/invoke_ntsd.py index e293a7aed..269ebfad2 100644 --- a/empire/server/modules/powershell/code_execution/invoke_ntsd.py +++ b/empire/server/modules/powershell/code_execution/invoke_ntsd.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -48,7 +49,7 @@ def generate( return handle_error_message(err) script_end = "" - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: %s" % (listener_name)) else: diff --git a/empire/server/modules/powershell/code_execution/invoke_reflectivepeinjection.py b/empire/server/modules/powershell/code_execution/invoke_reflectivepeinjection.py index 4fd5ff1d0..ee9761860 100644 --- a/empire/server/modules/powershell/code_execution/invoke_reflectivepeinjection.py +++ b/empire/server/modules/powershell/code_execution/invoke_reflectivepeinjection.py @@ -1,6 +1,7 @@ import base64 from empire.server.common import helpers +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -8,7 +9,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/code_execution/invoke_shellcode.py b/empire/server/modules/powershell/code_execution/invoke_shellcode.py index b3854aca8..86d8072f5 100644 --- a/empire/server/modules/powershell/code_execution/invoke_shellcode.py +++ b/empire/server/modules/powershell/code_execution/invoke_shellcode.py @@ -1,12 +1,13 @@ import base64 +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/code_execution/invoke_shellcodemsil.py b/empire/server/modules/powershell/code_execution/invoke_shellcodemsil.py index 3e2af0c2d..71264b052 100644 --- a/empire/server/modules/powershell/code_execution/invoke_shellcodemsil.py +++ b/empire/server/modules/powershell/code_execution/invoke_shellcodemsil.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/collection/SharpChromium.py b/empire/server/modules/powershell/collection/SharpChromium.py index 959a1993a..1c9fdc737 100644 --- a/empire/server/modules/powershell/collection/SharpChromium.py +++ b/empire/server/modules/powershell/collection/SharpChromium.py @@ -1,5 +1,6 @@ import logging +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -9,7 +10,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/collection/WireTap.py b/empire/server/modules/powershell/collection/WireTap.py index ac358be72..e6e33fd99 100644 --- a/empire/server/modules/powershell/collection/WireTap.py +++ b/empire/server/modules/powershell/collection/WireTap.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/collection/get_sql_column_sample_data.py b/empire/server/modules/powershell/collection/get_sql_column_sample_data.py index 344bb8e26..4b8bda46e 100644 --- a/empire/server/modules/powershell/collection/get_sql_column_sample_data.py +++ b/empire/server/modules/powershell/collection/get_sql_column_sample_data.py @@ -1,11 +1,12 @@ from empire.server.common import helpers +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/collection/minidump.py b/empire/server/modules/powershell/collection/minidump.py index 620693b55..0a38e6a2a 100644 --- a/empire/server/modules/powershell/collection/minidump.py +++ b/empire/server/modules/powershell/collection/minidump.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/collection/packet_capture.py b/empire/server/modules/powershell/collection/packet_capture.py index bfdd668a3..fb8b43c9c 100644 --- a/empire/server/modules/powershell/collection/packet_capture.py +++ b/empire/server/modules/powershell/collection/packet_capture.py @@ -1,10 +1,11 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/collection/screenshot.py b/empire/server/modules/powershell/collection/screenshot.py index 145d52a1b..b0dbd719a 100644 --- a/empire/server/modules/powershell/collection/screenshot.py +++ b/empire/server/modules/powershell/collection/screenshot.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/credentials/credential_injection.py b/empire/server/modules/powershell/credentials/credential_injection.py index dfe8d9807..6e0e2cad3 100644 --- a/empire/server/modules/powershell/credentials/credential_injection.py +++ b/empire/server/modules/powershell/credentials/credential_injection.py @@ -1,4 +1,5 @@ -from empire.server.core.db.models import Credential +from empire.server.common.empire import MainMenu +from empire.server.core.db.base import SessionLocal from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -6,7 +7,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -32,22 +33,23 @@ def generate( # if a credential ID is specified, try to parse cred_id = params["CredID"] if cred_id != "": - if not main_menu.credentials.is_credential_valid(cred_id): - return handle_error_message("[!] CredID is invalid!") + with SessionLocal() as db: + cred = main_menu.credentialsv2.get_by_id(db, cred_id) - cred: Credential = main_menu.credentials.get_credentials(cred_id) + if not cred: + return handle_error_message("[!] CredID is invalid!") - if cred.credtype != "plaintext": - return handle_error_message( - "[!] A CredID with a plaintext password must be used!" - ) + if cred.credtype != "plaintext": + return handle_error_message( + "[!] A CredID with a plaintext password must be used!" + ) - if cred.domain != "": - params["DomainName"] = cred.domain - if cred.username != "": - params["UserName"] = cred.username - if cred.password != "": - params["Password"] = cred.password + if cred.domain != "": + params["DomainName"] = cred.domain + if cred.username != "": + params["UserName"] = cred.username + if cred.password != "": + params["Password"] = cred.password if ( params["DomainName"] == "" diff --git a/empire/server/modules/powershell/credentials/mimikatz/dcsync_hashdump.py b/empire/server/modules/powershell/credentials/mimikatz/dcsync_hashdump.py index e15899e65..b3bc8bd0e 100644 --- a/empire/server/modules/powershell/credentials/mimikatz/dcsync_hashdump.py +++ b/empire/server/modules/powershell/credentials/mimikatz/dcsync_hashdump.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/credentials/mimikatz/golden_ticket.py b/empire/server/modules/powershell/credentials/mimikatz/golden_ticket.py index c109d3dd5..c2d5c08e7 100644 --- a/empire/server/modules/powershell/credentials/mimikatz/golden_ticket.py +++ b/empire/server/modules/powershell/credentials/mimikatz/golden_ticket.py @@ -1,6 +1,7 @@ import logging -from empire.server.core.db.models import Credential +from empire.server.common.empire import MainMenu +from empire.server.core.db.base import SessionLocal from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -10,7 +11,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -29,19 +30,21 @@ def generate( # if a credential ID is specified, try to parse cred_id = params["CredID"] if cred_id != "": - if not main_menu.credentials.is_credential_valid(cred_id): - return handle_error_message("[!] CredID is invalid!") + with SessionLocal() as db: + cred = main_menu.credentialsv2.get_by_id(db, cred_id) - cred: Credential = main_menu.credentials.get_credentials(cred_id) - if cred.username != "krbtgt": - return handle_error_message("[!] A krbtgt account must be used") + if not cred: + return handle_error_message("[!] CredID is invalid!") - if cred.domain != "": - params["domain"] = cred.domain - if cred.sid != "": - params["sid"] = cred.sid - if cred.password != "": - params["krbtgt"] = cred.password + if cred.username != "krbtgt": + return handle_error_message("[!] A krbtgt account must be used") + + if cred.domain != "": + params["domain"] = cred.domain + if cred.sid != "": + params["sid"] = cred.sid + if cred.password != "": + params["krbtgt"] = cred.password if params["krbtgt"] == "": log.error("krbtgt hash not specified") diff --git a/empire/server/modules/powershell/credentials/mimikatz/lsadump.py b/empire/server/modules/powershell/credentials/mimikatz/lsadump.py index d2dc51167..1eb2d4365 100644 --- a/empire/server/modules/powershell/credentials/mimikatz/lsadump.py +++ b/empire/server/modules/powershell/credentials/mimikatz/lsadump.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/credentials/mimikatz/mimitokens.py b/empire/server/modules/powershell/credentials/mimikatz/mimitokens.py index 574c5da4d..01bbd01f2 100644 --- a/empire/server/modules/powershell/credentials/mimikatz/mimitokens.py +++ b/empire/server/modules/powershell/credentials/mimikatz/mimitokens.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/credentials/mimikatz/pth.py b/empire/server/modules/powershell/credentials/mimikatz/pth.py index 4e394e2d7..d7fda4c25 100644 --- a/empire/server/modules/powershell/credentials/mimikatz/pth.py +++ b/empire/server/modules/powershell/credentials/mimikatz/pth.py @@ -1,6 +1,7 @@ import logging -from empire.server.core.db.models import Credential +from empire.server.common.empire import MainMenu +from empire.server.core.db.base import SessionLocal from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -10,7 +11,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -29,19 +30,21 @@ def generate( # if a credential ID is specified, try to parse cred_id = params["CredID"] if cred_id != "": - if not main_menu.credentials.is_credential_valid(cred_id): - return handle_error_message("[!] CredID is invalid!") + with SessionLocal() as db: + cred = main_menu.credentialsv2.get_by_id(db, cred_id) - cred: Credential = main_menu.credentials.get_credentials(cred_id) - if cred.credtype != "hash": - return handle_error_message("[!] An NTLM hash must be used!") + if not cred: + return handle_error_message("[!] CredID is invalid!") - if cred.username != "": - params["user"] = cred.username - if cred.domain != "": - params["domain"] = cred.domain - if cred.password != "": - params["ntlm"] = cred.password + if cred.credtype != "hash": + return handle_error_message("[!] An NTLM hash must be used!") + + if cred.username != "": + params["user"] = cred.username + if cred.domain != "": + params["domain"] = cred.domain + if cred.password != "": + params["ntlm"] = cred.password if params["ntlm"] == "": log.error("ntlm hash not specified") diff --git a/empire/server/modules/powershell/credentials/mimikatz/silver_ticket.py b/empire/server/modules/powershell/credentials/mimikatz/silver_ticket.py index 045f2ac00..b28cefe90 100644 --- a/empire/server/modules/powershell/credentials/mimikatz/silver_ticket.py +++ b/empire/server/modules/powershell/credentials/mimikatz/silver_ticket.py @@ -1,5 +1,6 @@ from empire.server.common import helpers -from empire.server.core.db.models import Credential +from empire.server.common.empire import MainMenu +from empire.server.core.db.base import SessionLocal from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -7,7 +8,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -26,22 +27,24 @@ def generate( # if a credential ID is specified, try to parse cred_id = params["CredID"] if cred_id != "": - if not main_menu.credentials.is_credential_valid(cred_id): - return handle_error_message("[!] CredID is invalid!") + with SessionLocal() as db: + cred = main_menu.credentialsv2.get_by_id(db, cred_id) - cred: Credential = main_menu.credentials.get_credentials(cred_id) - if not cred.username.endswith("$"): - return handle_error_message( - "[!] please specify a machine account credential" - ) - if cred.domain != "": - params["domain"] = cred.domain - if cred.host != "": - params["target"] = str(cred.host) + "." + str(cred.domain) - if cred.sid != "": - params["sid"] = cred.sid - if cred.password != "": - params["rc4"] = cred.password + if not cred: + return handle_error_message("[!] CredID is invalid!") + + if not cred.username.endswith("$"): + return handle_error_message( + "[!] please specify a machine account credential" + ) + if cred.domain != "": + params["domain"] = cred.domain + if cred.host != "": + params["target"] = str(cred.host) + "." + str(cred.domain) + if cred.sid != "": + params["sid"] = cred.sid + if cred.password != "": + params["rc4"] = cred.password # error checking if not helpers.validate_ntlm(params["rc4"]): diff --git a/empire/server/modules/powershell/credentials/mimikatz/trust_keys.py b/empire/server/modules/powershell/credentials/mimikatz/trust_keys.py index eaeef9265..a94c47fff 100644 --- a/empire/server/modules/powershell/credentials/mimikatz/trust_keys.py +++ b/empire/server/modules/powershell/credentials/mimikatz/trust_keys.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/credentials/tokens.py b/empire/server/modules/powershell/credentials/tokens.py index 9cc4e505d..82995d5af 100644 --- a/empire/server/modules/powershell/credentials/tokens.py +++ b/empire/server/modules/powershell/credentials/tokens.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/exfiltration/PSRansom.py b/empire/server/modules/powershell/exfiltration/PSRansom.py index 950b40fa2..16fd0cbc0 100644 --- a/empire/server/modules/powershell/exfiltration/PSRansom.py +++ b/empire/server/modules/powershell/exfiltration/PSRansom.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/exploitation/exploit_eternalblue.py b/empire/server/modules/powershell/exploitation/exploit_eternalblue.py index fd6f0db94..ddefe0337 100755 --- a/empire/server/modules/powershell/exploitation/exploit_eternalblue.py +++ b/empire/server/modules/powershell/exploitation/exploit_eternalblue.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/lateral_movement/inveigh_relay.py b/empire/server/modules/powershell/lateral_movement/inveigh_relay.py index b28b682ca..8d1c977fe 100644 --- a/empire/server/modules/powershell/lateral_movement/inveigh_relay.py +++ b/empire/server/modules/powershell/lateral_movement/inveigh_relay.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -34,7 +35,7 @@ def generate( return handle_error_message(err) if command == "": - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) diff --git a/empire/server/modules/powershell/lateral_movement/invoke_dcom.py b/empire/server/modules/powershell/lateral_movement/invoke_dcom.py index 63b1dddf0..4525b29a5 100644 --- a/empire/server/modules/powershell/lateral_movement/invoke_dcom.py +++ b/empire/server/modules/powershell/lateral_movement/invoke_dcom.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -45,7 +46,10 @@ def generate( script_end = "" - if not main_menu.listeners.is_listener_valid(listener_name) and not command: + if ( + not main_menu.listenersv2.get_active_listener_by_name(listener_name) + and not command + ): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) diff --git a/empire/server/modules/powershell/lateral_movement/invoke_executemsbuild.py b/empire/server/modules/powershell/lateral_movement/invoke_executemsbuild.py index a83fe9ccd..af4c09268 100644 --- a/empire/server/modules/powershell/lateral_movement/invoke_executemsbuild.py +++ b/empire/server/modules/powershell/lateral_movement/invoke_executemsbuild.py @@ -1,4 +1,5 @@ -from empire.server.core.db.models import Credential +from empire.server.common.empire import MainMenu +from empire.server.core.db.base import SessionLocal from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -6,7 +7,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -37,17 +38,18 @@ def generate( script_end = "Invoke-ExecuteMSBuild" cred_id = params["CredID"] if cred_id != "": - if not main_menu.credentials.is_credential_valid(cred_id): - return handle_error_message("[!] CredID is invalid!") + with SessionLocal() as db: + cred = main_menu.credentialsv2.get_by_id(db, cred_id) - cred: Credential = main_menu.credentials.get_credentials(cred_id) + if not cred: + return handle_error_message("[!] CredID is invalid!") - if cred.domain != "": - params["UserName"] = str(cred.domain) + "\\" + str(cred.username) - else: - params["UserName"] = str(cred.username) - if cred.password != "": - params["Password"] = cred.password + if cred.domain != "": + params["UserName"] = str(cred.domain) + "\\" + str(cred.username) + else: + params["UserName"] = str(cred.username) + if cred.password != "": + params["Password"] = cred.password # Only "Command" or "Listener" but not both if listener_name == "" and command == "": @@ -57,7 +59,10 @@ def generate( "[!] Cannot use Listener and Command at the same time" ) - if not main_menu.listeners.is_listener_valid(listener_name) and not command: + if ( + not main_menu.listenersv2.get_active_listener_by_name(listener_name) + and not command + ): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) elif listener_name: diff --git a/empire/server/modules/powershell/lateral_movement/invoke_psexec.py b/empire/server/modules/powershell/lateral_movement/invoke_psexec.py index c1e11f912..719a3562c 100644 --- a/empire/server/modules/powershell/lateral_movement/invoke_psexec.py +++ b/empire/server/modules/powershell/lateral_movement/invoke_psexec.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -51,7 +52,7 @@ def generate( script_end += ' -ResultFile "%s"' % (result_file) else: - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) diff --git a/empire/server/modules/powershell/lateral_movement/invoke_psremoting.py b/empire/server/modules/powershell/lateral_movement/invoke_psremoting.py index 0b4f12ecf..7a657cb20 100644 --- a/empire/server/modules/powershell/lateral_movement/invoke_psremoting.py +++ b/empire/server/modules/powershell/lateral_movement/invoke_psremoting.py @@ -1,4 +1,5 @@ -from empire.server.core.db.models import Credential +from empire.server.common.empire import MainMenu +from empire.server.core.db.base import SessionLocal from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -6,7 +7,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -37,14 +38,19 @@ def generate( # if a credential ID is specified, try to parse cred_id = params["CredID"] if cred_id != "": - if not main_menu.credentials.is_credential_valid(cred_id): - return handle_error_message("[!] CredID is invalid!") + with SessionLocal() as db: + cred = main_menu.credentialsv2.get_by_id(db, cred_id) - cred: Credential = main_menu.credentials.get_credentials(cred_id) - params["UserName"] = str(cred.domain) + "\\" + str(cred.username) - params["Password"] = cred.password + if not cred: + return handle_error_message("[!] CredID is invalid!") - if not main_menu.listeners.is_listener_valid(listener_name) and not command: + params["UserName"] = str(cred.domain) + "\\" + str(cred.username) + params["Password"] = cred.password + + if ( + not main_menu.listenersv2.get_active_listener_by_name(listener_name) + and not command + ): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) diff --git a/empire/server/modules/powershell/lateral_movement/invoke_smbexec.py b/empire/server/modules/powershell/lateral_movement/invoke_smbexec.py index c33d549fa..8473cf8f5 100644 --- a/empire/server/modules/powershell/lateral_movement/invoke_smbexec.py +++ b/empire/server/modules/powershell/lateral_movement/invoke_smbexec.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -46,7 +47,10 @@ def generate( if err: return handle_error_message(err) - if not main_menu.listeners.is_listener_valid(listener_name) and not command: + if ( + not main_menu.listenersv2.get_active_listener_by_name(listener_name) + and not command + ): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) diff --git a/empire/server/modules/powershell/lateral_movement/invoke_sqloscmd.py b/empire/server/modules/powershell/lateral_movement/invoke_sqloscmd.py index 19f6cc9c5..6780248bb 100644 --- a/empire/server/modules/powershell/lateral_movement/invoke_sqloscmd.py +++ b/empire/server/modules/powershell/lateral_movement/invoke_sqloscmd.py @@ -1,4 +1,5 @@ -from empire.server.core.db.models import Credential +from empire.server.common.empire import MainMenu +from empire.server.core.db.base import SessionLocal from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -6,7 +7,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -14,15 +15,18 @@ def generate( ): cred_id = params["CredID"] if cred_id != "": - if not main_menu.credentials.is_credential_valid(cred_id): - return handle_error_message("[!] CredID is invalid!") - cred: Credential = main_menu.credentials.get_credentials(cred_id) - if cred.domain != "": - params["UserName"] = str(cred.domain) + "\\" + str(cred.username) - else: - params["UserName"] = str(cred.username) - if cred.password != "": - params["Password"] = cred.password + with SessionLocal() as db: + cred = main_menu.credentialsv2.get_by_id(db, cred_id) + + if not cred: + return handle_error_message("[!] CredID is invalid!") + + if cred.domain != "": + params["UserName"] = str(cred.domain) + "\\" + str(cred.username) + else: + params["UserName"] = str(cred.username) + if cred.password != "": + params["Password"] = cred.password # staging options listener_name = params["Listener"] @@ -50,7 +54,7 @@ def generate( return handle_error_message(err) if command == "": - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): return handle_error_message("[!] Invalid listener: " + listener_name) else: launcher = main_menu.stagers.generate_launcher( diff --git a/empire/server/modules/powershell/lateral_movement/invoke_sshcommand.py b/empire/server/modules/powershell/lateral_movement/invoke_sshcommand.py index 444d2ee2f..8f5ab21b5 100644 --- a/empire/server/modules/powershell/lateral_movement/invoke_sshcommand.py +++ b/empire/server/modules/powershell/lateral_movement/invoke_sshcommand.py @@ -1,4 +1,5 @@ -from empire.server.core.db.models import Credential +from empire.server.common.empire import MainMenu +from empire.server.core.db.base import SessionLocal from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -6,7 +7,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -27,15 +28,16 @@ def generate( # if a credential ID is specified, try to parse cred_id = params["CredID"] if cred_id != "": - if not main_menu.credentials.is_credential_valid(cred_id): - return handle_error_message("[!] CredID is invalid!") + with SessionLocal() as db: + cred = main_menu.credentialsv2.get_by_id(db, cred_id) - cred: Credential = main_menu.credentials.get_credentials(cred_id) + if not cred: + return handle_error_message("[!] CredID is invalid!") - if cred.username != "": - params["Username"] = str(cred.username) - if cred.password != "": - params["Password"] = str(cred.password) + if cred.username != "": + params["Username"] = str(cred.username) + if cred.password != "": + params["Password"] = str(cred.password) if params["Username"] == "": return handle_error_message( diff --git a/empire/server/modules/powershell/lateral_movement/invoke_wmi.py b/empire/server/modules/powershell/lateral_movement/invoke_wmi.py index 97060e9a3..af4fbf3d3 100644 --- a/empire/server/modules/powershell/lateral_movement/invoke_wmi.py +++ b/empire/server/modules/powershell/lateral_movement/invoke_wmi.py @@ -1,4 +1,5 @@ -from empire.server.core.db.models import Credential +from empire.server.common.empire import MainMenu +from empire.server.core.db.base import SessionLocal from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -6,7 +7,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -37,19 +38,23 @@ def generate( # if a credential ID is specified, try to parse cred_id = params["CredID"] if cred_id != "": - if not main_menu.credentials.is_credential_valid(cred_id): - return handle_error_message("[!] CredID is invalid!") - - cred: Credential = main_menu.credentials.get_credentials(cred_id) - - if cred.domain != "": - params["UserName"] = str(cred.domain) + "\\" + str(cred.username) - else: - params["UserName"] = str(cred.username) - if cred.password != "": - params["Password"] = cred.password - - if not main_menu.listeners.is_listener_valid(listener_name) and not command: + with SessionLocal() as db: + cred = main_menu.credentialsv2.get_by_id(db, cred_id) + + if not cred: + return handle_error_message("[!] CredID is invalid!") + + if cred.domain != "": + params["UserName"] = str(cred.domain) + "\\" + str(cred.username) + else: + params["UserName"] = str(cred.username) + if cred.password != "": + params["Password"] = cred.password + + if ( + not main_menu.listenersv2.get_active_listener_by_name(listener_name) + and not command + ): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) diff --git a/empire/server/modules/powershell/lateral_movement/invoke_wmi_debugger.py b/empire/server/modules/powershell/lateral_movement/invoke_wmi_debugger.py index e36526915..e144cbd07 100644 --- a/empire/server/modules/powershell/lateral_movement/invoke_wmi_debugger.py +++ b/empire/server/modules/powershell/lateral_movement/invoke_wmi_debugger.py @@ -1,5 +1,6 @@ from empire.server.common import helpers -from empire.server.core.db.models import Credential +from empire.server.common.empire import MainMenu +from empire.server.core.db.base import SessionLocal from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -7,7 +8,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -35,17 +36,18 @@ def generate( # if a credential ID is specified, try to parse cred_id = params["CredID"] if cred_id != "": - if not main_menu.credentials.is_credential_valid(cred_id): - return handle_error_message("[!] CredID is invalid!") + with SessionLocal() as db: + cred = main_menu.credentialsv2.get_by_id(db, cred_id) - cred: Credential = main_menu.credentials.get_credentials(cred_id) + if not cred: + return handle_error_message("[!] CredID is invalid!") - if cred.domain != "": - params["UserName"] = str(cred.domain) + "\\" + str(cred.username) - else: - params["UserName"] = str(cred.username) - if cred.password != "": - params["Password"] = cred.password + if cred.domain != "": + params["UserName"] = str(cred.domain) + "\\" + str(cred.username) + else: + params["UserName"] = str(cred.username) + if cred.password != "": + params["Password"] = cred.password if cleanup.lower() == "true": # the registry command to disable the debugger for the target binary @@ -58,7 +60,7 @@ def generate( elif listener_name != "": # if there's a listener specified, generate a stager and store it - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) diff --git a/empire/server/modules/powershell/lateral_movement/jenkins_script_console.py b/empire/server/modules/powershell/lateral_movement/jenkins_script_console.py index 80d3f80e0..16aa4db48 100644 --- a/empire/server/modules/powershell/lateral_movement/jenkins_script_console.py +++ b/empire/server/modules/powershell/lateral_movement/jenkins_script_console.py @@ -1,4 +1,5 @@ from empire.server.common import helpers +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -6,7 +7,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/lateral_movement/new_gpo_immediate_task.py b/empire/server/modules/powershell/lateral_movement/new_gpo_immediate_task.py index f515a044e..1a725886e 100644 --- a/empire/server/modules/powershell/lateral_movement/new_gpo_immediate_task.py +++ b/empire/server/modules/powershell/lateral_movement/new_gpo_immediate_task.py @@ -1,4 +1,5 @@ from empire.server.common import helpers +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -6,7 +7,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -24,7 +25,7 @@ def generate( launcher_obfuscate = False launcher_obfuscate_command = params["ObfuscateCommand"] - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) diff --git a/empire/server/modules/powershell/management/invoke_bypass.py b/empire/server/modules/powershell/management/invoke_bypass.py index d6f5dd6ee..f18248418 100644 --- a/empire/server/modules/powershell/management/invoke_bypass.py +++ b/empire/server/modules/powershell/management/invoke_bypass.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.db.base import SessionLocal from empire.server.core.module_models import EmpireModule @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/management/invoke_script.py b/empire/server/modules/powershell/management/invoke_script.py index eeeb721de..9e06d2744 100644 --- a/empire/server/modules/powershell/management/invoke_script.py +++ b/empire/server/modules/powershell/management/invoke_script.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/management/logoff.py b/empire/server/modules/powershell/management/logoff.py index 9e319a923..905b861e2 100644 --- a/empire/server/modules/powershell/management/logoff.py +++ b/empire/server/modules/powershell/management/logoff.py @@ -1,10 +1,11 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/management/mailraider/disable_security.py b/empire/server/modules/powershell/management/mailraider/disable_security.py index c409503ac..65a01a895 100644 --- a/empire/server/modules/powershell/management/mailraider/disable_security.py +++ b/empire/server/modules/powershell/management/mailraider/disable_security.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/management/mailraider/get_emailitems.py b/empire/server/modules/powershell/management/mailraider/get_emailitems.py index 5bd1aa700..951825916 100644 --- a/empire/server/modules/powershell/management/mailraider/get_emailitems.py +++ b/empire/server/modules/powershell/management/mailraider/get_emailitems.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/management/psinject.py b/empire/server/modules/powershell/management/psinject.py index 6e4e76bb5..302e17996 100644 --- a/empire/server/modules/powershell/management/psinject.py +++ b/empire/server/modules/powershell/management/psinject.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -40,7 +41,7 @@ def generate( return handle_error_message(err) script_end = "" - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: %s" % (listener_name)) else: diff --git a/empire/server/modules/powershell/management/reflective_inject.py b/empire/server/modules/powershell/management/reflective_inject.py index 7d5724449..4510b2535 100644 --- a/empire/server/modules/powershell/management/reflective_inject.py +++ b/empire/server/modules/powershell/management/reflective_inject.py @@ -1,6 +1,7 @@ import random import string +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -8,7 +9,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -50,7 +51,7 @@ def rand_text_alphanumeric( return handle_error_message(err) script_end = "" - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: %s" % (listener_name)) else: diff --git a/empire/server/modules/powershell/management/runas.py b/empire/server/modules/powershell/management/runas.py index 67b1b280b..8987a3ce1 100644 --- a/empire/server/modules/powershell/management/runas.py +++ b/empire/server/modules/powershell/management/runas.py @@ -1,4 +1,5 @@ -from empire.server.core.db.models import Credential +from empire.server.common.empire import MainMenu +from empire.server.core.db.base import SessionLocal from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -6,7 +7,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -27,22 +28,23 @@ def generate( # if a credential ID is specified, try to parse cred_id = params["CredID"] if cred_id != "": - if not main_menu.credentials.is_credential_valid(cred_id): - return handle_error_message("[!] CredID is invalid!") + with SessionLocal() as db: + cred = main_menu.credentialsv2.get_by_id(db, cred_id) - cred: Credential = main_menu.credentials.get_credentials(cred_id) + if not cred: + return handle_error_message("[!] CredID is invalid!") - if cred.credtype != "plaintext": - return handle_error_message( - "[!] A CredID with a plaintext password must be used!" - ) + if cred.credtype != "plaintext": + return handle_error_message( + "[!] A CredID with a plaintext password must be used!" + ) - if cred.domain != "": - params["Domain"] = cred.domain - if cred.username != "": - params["UserName"] = cred.username - if cred.password != "": - params["Password"] = "'" + cred.password + "'" + if cred.domain != "": + params["Domain"] = cred.domain + if cred.username != "": + params["UserName"] = cred.username + if cred.password != "": + params["Password"] = "'" + cred.password + "'" if ( params["Domain"] == "" diff --git a/empire/server/modules/powershell/management/shinject.py b/empire/server/modules/powershell/management/shinject.py index bc31bffb8..013323299 100644 --- a/empire/server/modules/powershell/management/shinject.py +++ b/empire/server/modules/powershell/management/shinject.py @@ -1,4 +1,5 @@ from empire.server.common import helpers +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -6,7 +7,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -30,7 +31,7 @@ def generate( if err: return handle_error_message(err) - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message(f"[!] Invalid listener: {listener_name}") else: diff --git a/empire/server/modules/powershell/management/spawn.py b/empire/server/modules/powershell/management/spawn.py index 8e2ab0933..5f3100ed4 100644 --- a/empire/server/modules/powershell/management/spawn.py +++ b/empire/server/modules/powershell/management/spawn.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/management/spawnas.py b/empire/server/modules/powershell/management/spawnas.py index 037d821f9..6e35aba5f 100644 --- a/empire/server/modules/powershell/management/spawnas.py +++ b/empire/server/modules/powershell/management/spawnas.py @@ -1,4 +1,5 @@ -from empire.server.core.db.models import Credential +from empire.server.common.empire import MainMenu +from empire.server.core.db.base import SessionLocal from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -6,7 +7,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -25,17 +26,18 @@ def generate( # if a credential ID is specified, try to parse cred_id = params["CredID"] if cred_id != "": - if not main_menu.credentials.is_credential_valid(cred_id): - return handle_error_message("[!] CredID is invalid!") + with SessionLocal() as db: + cred = main_menu.credentialsv2.get_by_id(db, cred_id) - cred: Credential = main_menu.credentials.get_credentials(cred_id) + if not cred: + return handle_error_message("[!] CredID is invalid!") - if cred.domain != "": - params["Domain"] = cred.domain - if cred.username != "": - params["UserName"] = cred.username - if cred.password != "": - params["Password"] = cred.password + if cred.domain != "": + params["Domain"] = cred.domain + if cred.username != "": + params["UserName"] = cred.username + if cred.password != "": + params["Password"] = cred.password # extract all of our options diff --git a/empire/server/modules/powershell/management/switch_listener.py b/empire/server/modules/powershell/management/switch_listener.py index 325daaa02..89b014eed 100644 --- a/empire/server/modules/powershell/management/switch_listener.py +++ b/empire/server/modules/powershell/management/switch_listener.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/management/user_to_sid.py b/empire/server/modules/powershell/management/user_to_sid.py index f8d69096e..366ebfa13 100644 --- a/empire/server/modules/powershell/management/user_to_sid.py +++ b/empire/server/modules/powershell/management/user_to_sid.py @@ -1,10 +1,11 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/persistence/elevated/registry.py b/empire/server/modules/powershell/persistence/elevated/registry.py index 59e537eae..96b10289b 100644 --- a/empire/server/modules/powershell/persistence/elevated/registry.py +++ b/empire/server/modules/powershell/persistence/elevated/registry.py @@ -1,6 +1,7 @@ import os from empire.server.common import helpers +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -8,7 +9,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -94,7 +95,7 @@ def generate( else: # if an external file isn't specified, use a listener - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) diff --git a/empire/server/modules/powershell/persistence/elevated/schtasks.py b/empire/server/modules/powershell/persistence/elevated/schtasks.py index a5f8da0ef..38496f9da 100644 --- a/empire/server/modules/powershell/persistence/elevated/schtasks.py +++ b/empire/server/modules/powershell/persistence/elevated/schtasks.py @@ -1,6 +1,7 @@ import os from empire.server.common import helpers +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -8,7 +9,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -96,7 +97,7 @@ def generate( else: # if an external file isn't specified, use a listener - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) diff --git a/empire/server/modules/powershell/persistence/elevated/wmi.py b/empire/server/modules/powershell/persistence/elevated/wmi.py index ae9815df1..eea041a0a 100644 --- a/empire/server/modules/powershell/persistence/elevated/wmi.py +++ b/empire/server/modules/powershell/persistence/elevated/wmi.py @@ -107,7 +107,7 @@ def generate( ) # if an external file isn't specified, use a listener - elif not main_menu.listeners.is_listener_valid(listener_name): + elif not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) diff --git a/empire/server/modules/powershell/persistence/elevated/wmi_updater.py b/empire/server/modules/powershell/persistence/elevated/wmi_updater.py index 839c3a8bb..8ab65a8eb 100644 --- a/empire/server/modules/powershell/persistence/elevated/wmi_updater.py +++ b/empire/server/modules/powershell/persistence/elevated/wmi_updater.py @@ -1,6 +1,7 @@ import os from empire.server.common import helpers +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -8,7 +9,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/persistence/misc/add_sid_history.py b/empire/server/modules/powershell/persistence/misc/add_sid_history.py index bdb35d9d8..8cbe41565 100644 --- a/empire/server/modules/powershell/persistence/misc/add_sid_history.py +++ b/empire/server/modules/powershell/persistence/misc/add_sid_history.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/persistence/misc/debugger.py b/empire/server/modules/powershell/persistence/misc/debugger.py index 89a164588..8b99aee8e 100644 --- a/empire/server/modules/powershell/persistence/misc/debugger.py +++ b/empire/server/modules/powershell/persistence/misc/debugger.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -46,7 +47,7 @@ def generate( if listener_name != "": # if there's a listener specified, generate a stager and store it - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) diff --git a/empire/server/modules/powershell/persistence/powerbreach/deaduser.py b/empire/server/modules/powershell/persistence/powerbreach/deaduser.py index 9b7d302fe..377c823ec 100644 --- a/empire/server/modules/powershell/persistence/powerbreach/deaduser.py +++ b/empire/server/modules/powershell/persistence/powerbreach/deaduser.py @@ -1,6 +1,7 @@ import os from empire.server.common import helpers +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -8,7 +9,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -73,7 +74,7 @@ def generate( listener_name = params["Listener"] - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) diff --git a/empire/server/modules/powershell/persistence/powerbreach/eventlog.py b/empire/server/modules/powershell/persistence/powerbreach/eventlog.py index d5d1ba180..a629a6702 100644 --- a/empire/server/modules/powershell/persistence/powerbreach/eventlog.py +++ b/empire/server/modules/powershell/persistence/powerbreach/eventlog.py @@ -1,6 +1,7 @@ import os from empire.server.common import helpers +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -8,7 +9,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -52,7 +53,7 @@ def generate( listener_name = params["Listener"] - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) diff --git a/empire/server/modules/powershell/persistence/powerbreach/resolver.py b/empire/server/modules/powershell/persistence/powerbreach/resolver.py index 82d751cf5..a8b470a27 100644 --- a/empire/server/modules/powershell/persistence/powerbreach/resolver.py +++ b/empire/server/modules/powershell/persistence/powerbreach/resolver.py @@ -1,6 +1,7 @@ import os from empire.server.common import helpers +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -8,7 +9,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -60,7 +61,7 @@ def generate( listener_name = params["Listener"] - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) diff --git a/empire/server/modules/powershell/persistence/userland/backdoor_lnk.py b/empire/server/modules/powershell/persistence/userland/backdoor_lnk.py index 4d7e850be..144c9efa6 100644 --- a/empire/server/modules/powershell/persistence/userland/backdoor_lnk.py +++ b/empire/server/modules/powershell/persistence/userland/backdoor_lnk.py @@ -1,6 +1,7 @@ import os from empire.server.common import helpers +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -8,7 +9,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -35,7 +36,7 @@ def generate( status_msg = "" - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) @@ -91,7 +92,7 @@ def generate( else: # if an external file isn't specified, use a listener - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message( "[!] Invalid listener: " + listener_name diff --git a/empire/server/modules/powershell/persistence/userland/registry.py b/empire/server/modules/powershell/persistence/userland/registry.py index 872940de7..08217b197 100644 --- a/empire/server/modules/powershell/persistence/userland/registry.py +++ b/empire/server/modules/powershell/persistence/userland/registry.py @@ -1,6 +1,7 @@ import os from empire.server.common import helpers +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -8,7 +9,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -95,7 +96,7 @@ def generate( else: # if an external file isn't specified, use a listener - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) diff --git a/empire/server/modules/powershell/persistence/userland/schtasks.py b/empire/server/modules/powershell/persistence/userland/schtasks.py index f3010b2ec..eee63c493 100644 --- a/empire/server/modules/powershell/persistence/userland/schtasks.py +++ b/empire/server/modules/powershell/persistence/userland/schtasks.py @@ -1,6 +1,7 @@ import os from empire.server.common import helpers +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -8,7 +9,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -93,7 +94,7 @@ def generate( else: # if an external file isn't specified, use a listener - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) diff --git a/empire/server/modules/powershell/privesc/ask.py b/empire/server/modules/powershell/privesc/ask.py index 65bd9cd40..327686ea3 100644 --- a/empire/server/modules/powershell/privesc/ask.py +++ b/empire/server/modules/powershell/privesc/ask.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -22,7 +23,7 @@ def generate( launcher_obfuscate = False launcher_obfuscate_command = params["ObfuscateCommand"] - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) else: diff --git a/empire/server/modules/powershell/privesc/bypassuac.py b/empire/server/modules/powershell/privesc/bypassuac.py index 63e84c0b1..15600a1b9 100644 --- a/empire/server/modules/powershell/privesc/bypassuac.py +++ b/empire/server/modules/powershell/privesc/bypassuac.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -32,7 +33,7 @@ def generate( if err: return handle_error_message(err) - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) else: diff --git a/empire/server/modules/powershell/privesc/bypassuac_env.py b/empire/server/modules/powershell/privesc/bypassuac_env.py index 88d9ac864..9e414522f 100644 --- a/empire/server/modules/powershell/privesc/bypassuac_env.py +++ b/empire/server/modules/powershell/privesc/bypassuac_env.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -32,7 +33,7 @@ def generate( if err: return handle_error_message(err) - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) else: diff --git a/empire/server/modules/powershell/privesc/bypassuac_eventvwr.py b/empire/server/modules/powershell/privesc/bypassuac_eventvwr.py index d6d1a863d..4c9c478fe 100644 --- a/empire/server/modules/powershell/privesc/bypassuac_eventvwr.py +++ b/empire/server/modules/powershell/privesc/bypassuac_eventvwr.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -32,7 +33,7 @@ def generate( if err: return handle_error_message(err) - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) else: diff --git a/empire/server/modules/powershell/privesc/bypassuac_fodhelper.py b/empire/server/modules/powershell/privesc/bypassuac_fodhelper.py index b7175b83f..ffd3c02a7 100644 --- a/empire/server/modules/powershell/privesc/bypassuac_fodhelper.py +++ b/empire/server/modules/powershell/privesc/bypassuac_fodhelper.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -32,7 +33,7 @@ def generate( if err: return handle_error_message(err) - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) else: diff --git a/empire/server/modules/powershell/privesc/bypassuac_sdctlbypass.py b/empire/server/modules/powershell/privesc/bypassuac_sdctlbypass.py index 5ad43b4d4..032c02b6a 100644 --- a/empire/server/modules/powershell/privesc/bypassuac_sdctlbypass.py +++ b/empire/server/modules/powershell/privesc/bypassuac_sdctlbypass.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -32,7 +33,7 @@ def generate( if err: return handle_error_message(err) - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) else: diff --git a/empire/server/modules/powershell/privesc/bypassuac_tokenmanipulation.py b/empire/server/modules/powershell/privesc/bypassuac_tokenmanipulation.py index 93f67fedb..1a0d50dd8 100644 --- a/empire/server/modules/powershell/privesc/bypassuac_tokenmanipulation.py +++ b/empire/server/modules/powershell/privesc/bypassuac_tokenmanipulation.py @@ -1,6 +1,7 @@ import base64 import re +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -8,7 +9,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/privesc/bypassuac_wscript.py b/empire/server/modules/powershell/privesc/bypassuac_wscript.py index a746ccf76..506d076c8 100644 --- a/empire/server/modules/powershell/privesc/bypassuac_wscript.py +++ b/empire/server/modules/powershell/privesc/bypassuac_wscript.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, @@ -32,7 +33,7 @@ def generate( if err: return handle_error_message(err) - if not main_menu.listeners.is_listener_valid(listener_name): + if not main_menu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return handle_error_message("[!] Invalid listener: " + listener_name) else: diff --git a/empire/server/modules/powershell/privesc/ms16-032.py b/empire/server/modules/powershell/privesc/ms16-032.py index 8a99470e6..47c7c1dfd 100644 --- a/empire/server/modules/powershell/privesc/ms16-032.py +++ b/empire/server/modules/powershell/privesc/ms16-032.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/privesc/ms16-135.py b/empire/server/modules/powershell/privesc/ms16-135.py index 644d7cd9c..4ecb32746 100644 --- a/empire/server/modules/powershell/privesc/ms16-135.py +++ b/empire/server/modules/powershell/privesc/ms16-135.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/privesc/powerup/service_exe_stager.py b/empire/server/modules/powershell/privesc/powerup/service_exe_stager.py index a814d510b..898a9d20c 100644 --- a/empire/server/modules/powershell/privesc/powerup/service_exe_stager.py +++ b/empire/server/modules/powershell/privesc/powerup/service_exe_stager.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/privesc/powerup/service_stager.py b/empire/server/modules/powershell/privesc/powerup/service_stager.py index 035fbd302..75e848408 100644 --- a/empire/server/modules/powershell/privesc/powerup/service_stager.py +++ b/empire/server/modules/powershell/privesc/powerup/service_stager.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/privesc/powerup/write_dllhijacker.py b/empire/server/modules/powershell/privesc/powerup/write_dllhijacker.py index 71980550a..11438078a 100644 --- a/empire/server/modules/powershell/privesc/powerup/write_dllhijacker.py +++ b/empire/server/modules/powershell/privesc/powerup/write_dllhijacker.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/recon/fetch_brute_local.py b/empire/server/modules/powershell/recon/fetch_brute_local.py index c2b106b60..d50b2c5b9 100644 --- a/empire/server/modules/powershell/recon/fetch_brute_local.py +++ b/empire/server/modules/powershell/recon/fetch_brute_local.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/recon/find_fruit.py b/empire/server/modules/powershell/recon/find_fruit.py index a0e08dd49..e8e412aa6 100644 --- a/empire/server/modules/powershell/recon/find_fruit.py +++ b/empire/server/modules/powershell/recon/find_fruit.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/recon/get_sql_server_login_default_pw.py b/empire/server/modules/powershell/recon/get_sql_server_login_default_pw.py index 5d135dec0..fb4df4c8d 100644 --- a/empire/server/modules/powershell/recon/get_sql_server_login_default_pw.py +++ b/empire/server/modules/powershell/recon/get_sql_server_login_default_pw.py @@ -1,10 +1,11 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/situational_awareness/host/computerdetails.py b/empire/server/modules/powershell/situational_awareness/host/computerdetails.py index 326d3705d..d374a879e 100644 --- a/empire/server/modules/powershell/situational_awareness/host/computerdetails.py +++ b/empire/server/modules/powershell/situational_awareness/host/computerdetails.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/powershell/situational_awareness/network/get_sql_server_info.py b/empire/server/modules/powershell/situational_awareness/network/get_sql_server_info.py index ded23c1e8..e210fb5d8 100644 --- a/empire/server/modules/powershell/situational_awareness/network/get_sql_server_info.py +++ b/empire/server/modules/powershell/situational_awareness/network/get_sql_server_info.py @@ -1,10 +1,11 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/python/collection/osx/imessage_dump.py b/empire/server/modules/python/collection/osx/imessage_dump.py index 27fed2c73..72214b1b4 100644 --- a/empire/server/modules/python/collection/osx/imessage_dump.py +++ b/empire/server/modules/python/collection/osx/imessage_dump.py @@ -1,10 +1,11 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/python/collection/osx/native_screenshot_mss.py b/empire/server/modules/python/collection/osx/native_screenshot_mss.py index 141cdaf85..ec707b75e 100644 --- a/empire/server/modules/python/collection/osx/native_screenshot_mss.py +++ b/empire/server/modules/python/collection/osx/native_screenshot_mss.py @@ -1,12 +1,13 @@ import base64 +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/python/collection/osx/prompt.py b/empire/server/modules/python/collection/osx/prompt.py index 583991fda..9810f309b 100644 --- a/empire/server/modules/python/collection/osx/prompt.py +++ b/empire/server/modules/python/collection/osx/prompt.py @@ -1,10 +1,11 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/python/collection/osx/search_email.py b/empire/server/modules/python/collection/osx/search_email.py index 7d25ce788..f2bf1cca6 100644 --- a/empire/server/modules/python/collection/osx/search_email.py +++ b/empire/server/modules/python/collection/osx/search_email.py @@ -1,10 +1,11 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/python/collection/osx/sniffer.py b/empire/server/modules/python/collection/osx/sniffer.py index f1bf291bb..0762f7fb7 100644 --- a/empire/server/modules/python/collection/osx/sniffer.py +++ b/empire/server/modules/python/collection/osx/sniffer.py @@ -1,10 +1,11 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/python/lateral_movement/multi/ssh_launcher.py b/empire/server/modules/python/lateral_movement/multi/ssh_launcher.py index c798a4124..0423774a7 100644 --- a/empire/server/modules/python/lateral_movement/multi/ssh_launcher.py +++ b/empire/server/modules/python/lateral_movement/multi/ssh_launcher.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/python/management/multi/spawn.py b/empire/server/modules/python/management/multi/spawn.py index 44fcf37dd..0937c4de6 100644 --- a/empire/server/modules/python/management/multi/spawn.py +++ b/empire/server/modules/python/management/multi/spawn.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/python/management/osx/shellcodeinject64.py b/empire/server/modules/python/management/osx/shellcodeinject64.py index 47e60d410..914f76b02 100644 --- a/empire/server/modules/python/management/osx/shellcodeinject64.py +++ b/empire/server/modules/python/management/osx/shellcodeinject64.py @@ -1,6 +1,7 @@ import base64 import os +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -8,7 +9,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/python/persistence/multi/desktopfile.py b/empire/server/modules/python/persistence/multi/desktopfile.py index 47dc2ba5a..5a49dfc12 100644 --- a/empire/server/modules/python/persistence/multi/desktopfile.py +++ b/empire/server/modules/python/persistence/multi/desktopfile.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.string_util import removeprefix, removesuffix @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/python/persistence/osx/CreateHijacker.py b/empire/server/modules/python/persistence/osx/CreateHijacker.py index 9a85833c1..30540e533 100644 --- a/empire/server/modules/python/persistence/osx/CreateHijacker.py +++ b/empire/server/modules/python/persistence/osx/CreateHijacker.py @@ -1,5 +1,6 @@ import base64 +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.string_util import removeprefix, removesuffix @@ -7,7 +8,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/python/persistence/osx/LaunchAgent.py b/empire/server/modules/python/persistence/osx/LaunchAgent.py index e1822a8c7..d72b90140 100644 --- a/empire/server/modules/python/persistence/osx/LaunchAgent.py +++ b/empire/server/modules/python/persistence/osx/LaunchAgent.py @@ -1,5 +1,6 @@ import base64 +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.string_util import removeprefix, removesuffix @@ -7,7 +8,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/python/persistence/osx/LaunchAgentUserLandPersistence.py b/empire/server/modules/python/persistence/osx/LaunchAgentUserLandPersistence.py index fbaf9963c..2695953a3 100644 --- a/empire/server/modules/python/persistence/osx/LaunchAgentUserLandPersistence.py +++ b/empire/server/modules/python/persistence/osx/LaunchAgentUserLandPersistence.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.string_util import removeprefix, removesuffix @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/python/persistence/osx/loginhook.py b/empire/server/modules/python/persistence/osx/loginhook.py index 8ddef1b62..39e30ce69 100644 --- a/empire/server/modules/python/persistence/osx/loginhook.py +++ b/empire/server/modules/python/persistence/osx/loginhook.py @@ -1,10 +1,11 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/python/persistence/osx/mail.py b/empire/server/modules/python/persistence/osx/mail.py index b94795c90..796f0c7c5 100644 --- a/empire/server/modules/python/persistence/osx/mail.py +++ b/empire/server/modules/python/persistence/osx/mail.py @@ -2,13 +2,14 @@ from string import ascii_uppercase from time import time +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/python/privesc/multi/CVE-2021-3560.py b/empire/server/modules/python/privesc/multi/CVE-2021-3560.py index 6c9da845f..31d3b462f 100644 --- a/empire/server/modules/python/privesc/multi/CVE-2021-3560.py +++ b/empire/server/modules/python/privesc/multi/CVE-2021-3560.py @@ -1,5 +1,6 @@ import base64 +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -7,7 +8,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/python/privesc/multi/CVE-2021-4034.py b/empire/server/modules/python/privesc/multi/CVE-2021-4034.py index 28f7b18ba..ec9f2aaaf 100644 --- a/empire/server/modules/python/privesc/multi/CVE-2021-4034.py +++ b/empire/server/modules/python/privesc/multi/CVE-2021-4034.py @@ -1,6 +1,7 @@ import base64 import subprocess +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -8,7 +9,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/python/privesc/multi/bashdoor.py b/empire/server/modules/python/privesc/multi/bashdoor.py index 30ef34310..a4c1816fb 100644 --- a/empire/server/modules/python/privesc/multi/bashdoor.py +++ b/empire/server/modules/python/privesc/multi/bashdoor.py @@ -1,10 +1,11 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/python/privesc/multi/sudo_spawn.py b/empire/server/modules/python/privesc/multi/sudo_spawn.py index a17c21146..f9c253505 100644 --- a/empire/server/modules/python/privesc/multi/sudo_spawn.py +++ b/empire/server/modules/python/privesc/multi/sudo_spawn.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/python/privesc/osx/dyld_print_to_file.py b/empire/server/modules/python/privesc/osx/dyld_print_to_file.py index 51a63af14..7645db5c8 100644 --- a/empire/server/modules/python/privesc/osx/dyld_print_to_file.py +++ b/empire/server/modules/python/privesc/osx/dyld_print_to_file.py @@ -1,5 +1,6 @@ import logging +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule log = logging.getLogger(__name__) @@ -8,7 +9,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/python/privesc/osx/piggyback.py b/empire/server/modules/python/privesc/osx/piggyback.py index acf82165f..df630f8ba 100644 --- a/empire/server/modules/python/privesc/osx/piggyback.py +++ b/empire/server/modules/python/privesc/osx/piggyback.py @@ -1,3 +1,4 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule from empire.server.utils.module_util import handle_error_message @@ -5,7 +6,7 @@ class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/modules/python/situational_awareness/host/osx/situational_awareness.py b/empire/server/modules/python/situational_awareness/host/osx/situational_awareness.py index d7cb1a07b..09ebd34ae 100644 --- a/empire/server/modules/python/situational_awareness/host/osx/situational_awareness.py +++ b/empire/server/modules/python/situational_awareness/host/osx/situational_awareness.py @@ -1,10 +1,11 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/server/stagers/osx/shellcode.py b/empire/server/stagers/osx/shellcode.py index 56abb3795..4bb49efeb 100644 --- a/empire/server/stagers/osx/shellcode.py +++ b/empire/server/stagers/osx/shellcode.py @@ -71,7 +71,7 @@ def generate(self): user_agent = self.options["UserAgent"]["Value"] safe_checks = self.options["SafeChecks"]["Value"] - if not self.mainMenu.listeners.is_listener_valid(listener_name): + if not self.mainMenu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script print(helpers.color("[!] Invalid listener: " + listener_name)) return "" diff --git a/empire/server/stagers/windows/dll.py b/empire/server/stagers/windows/dll.py index 5e074f17c..44a21a895 100644 --- a/empire/server/stagers/windows/dll.py +++ b/empire/server/stagers/windows/dll.py @@ -100,7 +100,7 @@ def generate(self): obfuscate_command = self.options["ObfuscateCommand"]["Value"] bypasses = self.options["Bypasses"]["Value"] - if not self.mainMenu.listeners.is_listener_valid( + if not self.mainMenu.listenersv2.get_active_listener_by_name( listener_name ) and not self.mainMenu.listenersv2.get_by_name(SessionLocal(), listener_name): # not a valid listener, return nothing for the script diff --git a/empire/server/stagers/windows/shellcode.py b/empire/server/stagers/windows/shellcode.py index 80a9c4ff8..643fbc11b 100644 --- a/empire/server/stagers/windows/shellcode.py +++ b/empire/server/stagers/windows/shellcode.py @@ -118,7 +118,7 @@ def generate(self): obfuscate_command = self.options["ObfuscateCommand"]["Value"] arch = self.options["Architecture"]["Value"] - if not self.mainMenu.listeners.is_listener_valid(listener_name): + if not self.mainMenu.listenersv2.get_active_listener_by_name(listener_name): # not a valid listener, return nothing for the script return "[!] Invalid listener: " + listener_name diff --git a/empire/test/data/modules/test_custom_module.py b/empire/test/data/modules/test_custom_module.py index 74ceeb8d7..904b4bbbd 100644 --- a/empire/test/data/modules/test_custom_module.py +++ b/empire/test/data/modules/test_custom_module.py @@ -1,10 +1,11 @@ +from empire.server.common.empire import MainMenu from empire.server.core.module_models import EmpireModule class Module: @staticmethod def generate( - main_menu, + main_menu: MainMenu, module: EmpireModule, params: dict, obfuscate: bool = False, diff --git a/empire/test/test_modules.py b/empire/test/test_modules.py index cc1b5702a..ae6cfadc4 100644 --- a/empire/test/test_modules.py +++ b/empire/test/test_modules.py @@ -119,7 +119,7 @@ def test_execute_custom_generate( db_agent = ( db.query(models.Agent).filter(models.Agent.session_id == agent).first() ) - execute = module_service.execute_module( + execute, err = module_service.execute_module( db, db_agent, "empire_test_data_modules_test_custom_module", @@ -128,5 +128,5 @@ def test_execute_custom_generate( ignore_language_version_check=True, ) - assert execute is not None - assert execute[0]["data"] == "This is the module code." + assert err is None + assert execute["data"] == "This is the module code."