Skip to content

Commit

Permalink
Correct burp for --os
Browse files Browse the repository at this point in the history
  • Loading branch information
n3rada committed May 9, 2024
1 parent c372672 commit da266f4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 43 deletions.
27 changes: 14 additions & 13 deletions toboggan/modules/snippet.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,34 @@

# Buit-in imports
import subprocess
import os
from urllib.parse import quote

# This will be set dynamically based on the user input
BASE_CMD = None


def execute(command: str, timeout: float = None) -> str:
"""
Executes a system command embedded in the BASE_CMD command.
Executes a system command embedded in the BASE_CMD command, with elements of the command URL encoded.
Args:
command (str): The command to be embedded and executed.
command (str): The command to be embedded and executed, elements are URL encoded.
timeout (float, optional): Maximum time in seconds before the command times out. Defaults to None.
Returns:
str: Output of the command.
"""

full_cmd = BASE_CMD.replace("||cmd||", command)
env = os.environ.copy()

if False:
env['http_proxy'] = 'http://127.0.0.1:8080'
env['https_proxy'] = 'http://127.0.0.1:8080'


return subprocess.check_output(
BASE_CMD.replace("||cmd||", quote(command)), stderr=subprocess.STDOUT, shell=True, timeout=timeout, env=env
).decode("utf-8")

try:
# Execute the composed command and wait for it to complete or time out.
output = subprocess.check_output(
full_cmd, stderr=subprocess.STDOUT, shell=True, timeout=timeout
).decode("utf-8")
except subprocess.TimeoutExpired:
return "Error: Command execution timed out."
except subprocess.CalledProcessError as error:
return f"Error executing command: {error.output.decode('utf-8')}"

return output
50 changes: 20 additions & 30 deletions toboggan/src/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,6 @@ def __init__(
# Public methods

# Private methods
def __configure_burp_proxy(self, module_code: str) -> str:
"""
Configures the module code to use a Burp Suite proxy for all requests if the burp_proxy attribute is set to True.
This method searches for a specific placeholder ('# ||BURP||') in the module code and replaces it with the proxy configuration settings. If the burp_proxy attribute is not set or the placeholder is not found in the code, the original module code is returned without modification.
Args:
module_code (str): The original code of the module to be potentially modified to include Burp Suite proxy settings.
Returns:
str: The modified module code with Burp Suite proxy settings included if burp_proxy is True and the placeholder is found; otherwise, the original module code.
"""

if "# ||BURP||" not in module_code:
print("[Toboggan] '# ||BURP||' placeholder not found.")
return module_code

print("[Toboggan] All requests will be transmitted through Burp proxy.")
return module_code.replace(
"# ||BURP||",
'proxies={"http://": "http://127.0.0.1:8080", "https://": "http://127.0.0.1:8080"},',
)

def __configure_webshell_module(self, module_code):
parsed_url = urlparse(self.__url)
query_params = parse_qs(parsed_url.query)
Expand Down Expand Up @@ -120,12 +97,13 @@ def __load_module(self) -> None:
print(f"[Toboggan] Using built-in method {module_name}.")
module_code = built_in_module_path.read_text(encoding="utf-8")

if self.__module_path == "webshell" and self.__url is None:
raise ValueError(
"[Toboggan] No url provided. Cannot handle the webshell."
)
if self.__module_path == "webshell":
if self.__url is None:
raise ValueError(
"[Toboggan] No url provided. Cannot handle the webshell."
)

module_code = self.__configure_webshell_module(module_code)
module_code = self.__configure_webshell_module(module_code)

else:
# Handling external module path
Expand All @@ -144,7 +122,17 @@ def __load_module(self) -> None:

# Apply Burp Proxy configuration
if self.__burp_proxy:
module_code = self.__configure_burp_proxy(module_code)
print("[Toboggan] All requests will be transmitted through Burp proxy.")
if module_name == 'snippet':
module_code = module_code.replace('if False', 'if True')
else:
if "# ||BURP||" not in module_code:
print("[Toboggan] '# ||BURP||' placeholder not found.")
else:
module_code = module_code.replace(
"# ||BURP||",
'proxies={"http://": "http://127.0.0.1:8080", "https://": "http://127.0.0.1:8080"},',
)

# Load the module
module = types.ModuleType(name=module_name)
Expand All @@ -155,10 +143,12 @@ def __load_module(self) -> None:
f"The module {module_name} does not contain a callable 'execute' method."
)

required_params = ["command", "timeout"]

# Check if required parameters are present in the 'execute' method
if not all(
param in inspect.signature(module.execute).parameters
for param in ["command", "timeout"]
for param in required_params
):
raise TypeError(
f"The 'execute' method in {module_name} does not have the expected parameters: {', '.join(required_params)}."
Expand Down

0 comments on commit da266f4

Please sign in to comment.