Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stripping quotes in get_pwsh_cmd #109

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/multidecoder/decoders/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,10 @@ def get_cmd_command(cmd: bytes) -> bytes:

def get_powershell_command(powershell: bytes) -> bytes:
match = re.match(POWERSHELL_ARGS_RE, powershell)
return powershell[match.end() :] if match else powershell
if not match:
return powershell
command = powershell[match.end() :]
# Strip if the command starts and end with a double quote (34) or single quote (39)
if len(command) > 1 and command[0] in [34, 39] and command[0] == command[-1]:
command = command[1:-1]
return command
9 changes: 9 additions & 0 deletions tests/test_decoders/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,12 @@ def test_get_powershell_command_exe():

def test_get_powershell_command_args():
assert get_powershell_command(b"powershell -arg1 -arg2 command") == b"command"


def test_get_powershell_command_quotes():
assert (
get_powershell_command(
b"powershell.exe -c \"&{'p8ArwZsj8ZO+Zy/dHPeI';$BxQ='<base64content>';$KOKN='<base64content>';$KOKN=$KOKN+$BxQ;$GBUus=$KOKN;$xCyRLo=[System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($GBUus));$GBUus=$xCyRLo;iex($GBUus)}\""
)
== b"&{'p8ArwZsj8ZO+Zy/dHPeI';$BxQ='<base64content>';$KOKN='<base64content>';$KOKN=$KOKN+$BxQ;$GBUus=$KOKN;$xCyRLo=[System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($GBUus));$GBUus=$xCyRLo;iex($GBUus)}"
)