Skip to content

Commit

Permalink
Fixed obfuscation for ironpython and python stagers (BC-SECURITY#712)
Browse files Browse the repository at this point in the history
* fixed obfuscation for ironpython and python stagers

* Fixed obfuscation for ironpython and python stagers
  • Loading branch information
Cx01N authored Oct 17, 2023
1 parent e727917 commit f0e8d06
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Fixed IronPython and Python stagers not getting obfuscation applied (@Cx01n)

## [5.7.2] - 2023-09-28

- Updated Dropbox C2 to use new API endpoints (@Cx01N)
Expand Down
6 changes: 4 additions & 2 deletions empire/server/core/obfuscation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pathlib import Path

import python_obfuscator
from python_obfuscator.techniques import one_liner
from python_obfuscator.techniques import one_liner, variable_renamer
from sqlalchemy.orm import Session

from empire.server.core.config import empire_config
Expand Down Expand Up @@ -247,6 +247,8 @@ def python_obfuscate(self, module_source):
Obfuscate Python scripts using python-obfuscator
"""
obfuscator = python_obfuscator.obfuscator()
obfuscated_code = obfuscator.obfuscate(module_source, [one_liner])
obfuscated_code = obfuscator.obfuscate(
module_source, [one_liner, variable_renamer]
)

return obfuscated_code
8 changes: 8 additions & 0 deletions empire/server/listeners/dbx.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,14 @@ def generate_launcher(
# RC4 decryption
launcherBase += listener_util.python_extract_stager(staging_key)

if obfuscate:
launcherBase = self.mainMenu.obfuscationv2.python_obfuscate(
launcherBase
)
launcherBase = self.mainMenu.obfuscationv2.obfuscate_keywords(
launcherBase
)

if encode:
launchEncoded = base64.b64encode(
launcherBase.encode("UTF-8")
Expand Down
5 changes: 2 additions & 3 deletions empire/server/listeners/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,8 @@ def generate_launcher(
launcherBase += listener_util.python_extract_stager(staging_key)

if obfuscate:
launcherBase = self.mainMenu.obfuscationv2.obfuscate(
launcherBase,
obfuscation_command=obfuscation_command,
launcherBase = self.mainMenu.obfuscationv2.python_obfuscate(
launcherBase
)
launcherBase = self.mainMenu.obfuscationv2.obfuscate_keywords(
launcherBase
Expand Down
5 changes: 2 additions & 3 deletions empire/server/listeners/http_foreign.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,8 @@ def generate_launcher(
launcherBase += listener_util.python_extract_stager(stagingKey)

if obfuscate:
launcherBase = self.mainMenu.obfuscationv2.obfuscate(
launcherBase,
obfuscation_command=obfuscation_command,
launcherBase = self.mainMenu.obfuscationv2.python_obfuscate(
launcherBase
)
launcherBase = self.mainMenu.obfuscationv2.obfuscate_keywords(
launcherBase
Expand Down
5 changes: 2 additions & 3 deletions empire/server/listeners/http_hop.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,8 @@ def generate_launcher(
launcherBase += listener_util.python_extract_stager(staging_key)

if obfuscate:
launcherBase = self.mainMenu.obfuscationv2.obfuscate(
launcherBase,
obfuscation_command=obfuscation_command,
launcherBase = self.mainMenu.obfuscationv2.python_obfuscate(
launcherBase
)
launcherBase = self.mainMenu.obfuscationv2.obfuscate_keywords(
launcherBase
Expand Down
2 changes: 1 addition & 1 deletion empire/server/listeners/port_forward_pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def generate_launcher(

if obfuscate:
launcherBase = self.mainMenu.obfuscationv2.python_obfuscate(
launcherBase, obfuscation_command=obfuscation_command
launcherBase
)
launcherBase = self.mainMenu.obfuscationv2.obfuscate_keywords(
launcherBase
Expand Down
4 changes: 3 additions & 1 deletion empire/server/listeners/smb.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ def generate_launcher(
launcherBase += listener_util.python_extract_stager(stagingKey)

if obfuscate:
launcherBase = self.mainMenu.obfuscationv2.obfuscate(launcherBase)
launcherBase = self.mainMenu.obfuscationv2.python_obfuscate(
launcherBase
)
launcherBase = self.mainMenu.obfuscationv2.obfuscate_keywords(
launcherBase
)
Expand Down
4 changes: 2 additions & 2 deletions empire/server/stagers/windows/csharp_exe.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def generate(self):

if language.lower() == "powershell":
directory = self.mainMenu.stagers.generate_powershell_exe(
launcher, dot_net_version=dot_net_version
launcher, dot_net_version=dot_net_version, obfuscate=obfuscate_script
)
with open(directory, "rb") as f:
code = f.read()
Expand All @@ -162,7 +162,7 @@ def generate(self):

elif language.lower() == "ironpython":
directory = self.mainMenu.stagers.generate_python_exe(
launcher, dot_net_version=dot_net_version
launcher, dot_net_version=dot_net_version, obfuscate=obfuscate_script
)
with open(directory, "rb") as f:
code = f.read()
Expand Down

0 comments on commit f0e8d06

Please sign in to comment.