Skip to content

Commit 38ded90

Browse files
committed
Merge branch 'master' into staging/rails-4.0
2 parents d329a72 + 1dcad7c commit 38ded90

File tree

32 files changed

+1066
-362
lines changed

32 files changed

+1066
-362
lines changed

data/exploits/CVE-2014-0980.pui

16.7 KB
Binary file not shown.
192 Bytes
Binary file not shown.
160 Bytes
Binary file not shown.
120 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

external/source/shellcode/windows/x64/src/block/block_reverse_https.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ download_more:
145145
test eax,eax ; download failed? (optional?)
146146
jz failure
147147

148-
mov rax, [rdi]
148+
mov ax, word ptr [edi]
149149
add rbx, rax ; buffer += bytes_received
150150

151151
test rax,rax ; optional?

lib/msf/core/exploit/capture.rb

Lines changed: 45 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def initialize(info = {})
4242
[
4343
true,
4444
'Send a TTL=1 random UDP datagram to this host to discover the default gateway\'s MAC',
45-
'www.metasploit.com']),
45+
'8.8.8.8']),
4646
OptPort.new('GATEWAY_PROBE_PORT',
4747
[
4848
false,
@@ -143,7 +143,6 @@ def close_pcap
143143
return unless self.capture
144144
self.capture = nil
145145
self.arp_capture = nil
146-
GC.start()
147146
end
148147

149148
def capture_extract_ies(raw)
@@ -163,26 +162,15 @@ def capture_extract_ies(raw)
163162
end
164163

165164
#
166-
# This monstrosity works around a series of bugs in the interrupt
167-
# signal handling of Ruby 1.9
165+
# Loop through each packet
168166
#
169167
def each_packet
170168
return unless capture
171-
begin
172-
@capture_count = 0
173-
reader = framework.threads.spawn("PcapReceiver", false) do
174-
capture.each do |pkt|
175-
yield(pkt)
176-
@capture_count += 1
177-
end
178-
end
179-
reader.join
180-
rescue ::Exception
181-
raise $!
182-
ensure
183-
reader.kill if reader.alive?
169+
@capture_count ||= 0
170+
capture.each do |pkt|
171+
yield(pkt)
172+
@capture_count += 1
184173
end
185-
186174
@capture_count
187175
end
188176

@@ -242,10 +230,9 @@ def inject_pcap(pcap_file, filter=nil, delay = 0, pcap=self.capture)
242230
pcap.inject(pkt)
243231
Rex.sleep((delay * 1.0)/1000)
244232
end
245-
GC.start
246233
end
247234

248-
# Capture_sendto is intended to replace the old Rex::Socket::Ip.sendto method. It requires
235+
# capture_sendto is intended to replace the old Rex::Socket::Ip.sendto method. It requires
249236
# a payload and a destination address. To send to the broadcast address, set bcast
250237
# to true (this will guarantee that packets will be sent even if ARP doesn't work
251238
# out).
@@ -262,24 +249,20 @@ def capture_sendto(payload="", dhost=nil, bcast=false, dev=nil)
262249

263250
# The return value either be a PacketFu::Packet object, or nil
264251
def inject_reply(proto=:udp, pcap=self.capture)
265-
reply = nil
266-
to = (datastore['TIMEOUT'] || 500).to_f / 1000.0
267-
if not pcap
268-
raise RuntimeError, "Could not access the capture process (remember to open_pcap first!)"
269-
else
270-
begin
271-
::Timeout.timeout(to) do
272-
pcap.each do |r|
273-
packet = PacketFu::Packet.parse(r)
274-
next unless packet.proto.map { |x| x.downcase.to_sym }.include? proto
275-
reply = packet
276-
break
277-
end
252+
# Defaults to ~2 seconds
253+
to = (datastore['TIMEOUT'] * 4) / 1000.0
254+
raise RuntimeError, "Could not access the capture process (remember to open_pcap first!)" if not pcap
255+
begin
256+
::Timeout.timeout(to) do
257+
pcap.each do |r|
258+
packet = PacketFu::Packet.parse(r)
259+
next unless packet.proto.map { |x| x.downcase.to_sym }.include? proto
260+
return packet
278261
end
279-
rescue ::Timeout::Error
280262
end
263+
rescue ::Timeout::Error
281264
end
282-
return reply
265+
nil
283266
end
284267

285268
# This ascertains the correct Ethernet addresses one should use to
@@ -328,20 +311,19 @@ def probe_gateway(addr)
328311
end
329312

330313
begin
331-
to = (datastore['TIMEOUT'] || 1500).to_f / 1000.0
314+
to = ((datastore['TIMEOUT'] || 500).to_f * 8) / 1000.0
332315
::Timeout.timeout(to) do
333-
while (my_packet = inject_reply(:udp, self.arp_capture))
334-
if my_packet.payload == secret
335-
dst_mac = self.arp_cache[:gateway] = my_packet.eth_daddr
336-
src_mac = self.arp_cache[Rex::Socket.source_address(addr)] = my_packet.eth_saddr
337-
return [dst_mac, src_mac]
338-
else
339-
next
340-
end
316+
loop do
317+
my_packet = inject_reply(:udp, self.arp_capture)
318+
next unless my_packet
319+
next unless my_packet.payload == secret
320+
dst_mac = self.arp_cache[:gateway] = my_packet.eth_daddr
321+
src_mac = self.arp_cache[Rex::Socket.source_address(addr)] = my_packet.eth_saddr
322+
return [dst_mac, src_mac]
341323
end
342324
end
343325
rescue ::Timeout::Error
344-
# Well, that didn't work (this common on networks where there's no gatway, like
326+
# Well, that didn't work (this is common on networks where there's no gateway, like
345327
# VMWare network interfaces. We'll need to use a fake source hardware address.
346328
self.arp_cache[Rex::Socket.source_address(addr)] = "00:00:00:00:00:00"
347329
end
@@ -354,26 +336,31 @@ def arp(target_ip=nil)
354336
return self.arp_cache[:gateway] unless should_arp? target_ip
355337
source_ip = Rex::Socket.source_address(target_ip)
356338
raise RuntimeError, "Could not access the capture process." unless self.arp_capture
339+
357340
p = arp_packet(target_ip, source_ip)
358-
inject_eth(:eth_type => 0x0806,
359-
:payload => p,
360-
:pcap => self.arp_capture,
361-
:eth_saddr => self.arp_cache[Rex::Socket.source_address(target_ip)]
362-
)
363-
begin
364-
to = (datastore['TIMEOUT'] || 500).to_f / 1000.0
365-
::Timeout.timeout(to) do
366-
while (my_packet = inject_reply(:arp, self.arp_capture))
367-
if my_packet.arp_saddr_ip == target_ip
341+
342+
# Try up to 3 times to get an ARP response
343+
1.upto(3) do
344+
inject_eth(:eth_type => 0x0806,
345+
:payload => p,
346+
:pcap => self.arp_capture,
347+
:eth_saddr => self.arp_cache[Rex::Socket.source_address(target_ip)]
348+
)
349+
begin
350+
to = ((datastore['TIMEOUT'] || 500).to_f * 8) / 1000.0
351+
::Timeout.timeout(to) do
352+
loop do
353+
my_packet = inject_reply(:arp, self.arp_capture)
354+
next unless my_packet
355+
next unless my_packet.arp_saddr_ip == target_ip
368356
self.arp_cache[target_ip] = my_packet.eth_saddr
369357
return self.arp_cache[target_ip]
370-
else
371-
next
372358
end
373359
end
360+
rescue ::Timeout::Error
374361
end
375-
rescue ::Timeout::Error
376362
end
363+
nil
377364
end
378365

379366
# Creates a full ARP packet, mainly for use with inject_eth()

lib/msf/core/exploit/ipv6.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ def close_icmp_pcap()
7676

7777
return if not @ipv6_icmp6_capture
7878
@ipv6_icmp6_capture = nil
79-
GC.start()
8079
end
8180

8281
#

lib/msf/core/handler/reverse_hop_http.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,11 @@ def send_new_stage
256256
:expiration => datastore['SessionExpirationTimeout'],
257257
:comm_timeout => datastore['SessionCommunicationTimeout'],
258258
:ua => datastore['MeterpreterUserAgent'],
259-
:proxyhost => datastore['PROXYHOST'],
260-
:proxyport => datastore['PROXYPORT'],
261-
:proxy_type => datastore['PROXY_TYPE'],
262-
:proxy_username => datastore['PROXY_USERNAME'],
263-
:proxy_password => datastore['PROXY_PASSWORD']
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']
264264

265265
blob = encode_stage(blob)
266266

lib/msf/core/handler/reverse_http.rb

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,33 +58,25 @@ def initialize(info = {})
5858
], Msf::Handler::ReverseHttp)
5959
end
6060

61-
# Toggle for IPv4 vs IPv6 mode
62-
#
63-
def ipv6?
64-
Rex::Socket.is_ipv6?(datastore['LHOST'])
65-
end
66-
6761
# Determine where to bind the server
6862
#
6963
# @return [String]
7064
def listener_address
71-
if datastore['ReverseListenerBindAddress'].to_s.empty?
72-
bindaddr = (ipv6?) ? '::' : '0.0.0.0'
65+
if datastore['ReverseListenerBindAddress'].to_s == ""
66+
bindaddr = Rex::Socket.is_ipv6?(datastore['LHOST']) ? '::' : '0.0.0.0'
7367
else
7468
bindaddr = datastore['ReverseListenerBindAddress']
7569
end
7670

7771
bindaddr
7872
end
7973

74+
# Return a URI suitable for placing in a payload
75+
#
8076
# @return [String] A URI of the form +scheme://host:port/+
8177
def listener_uri
82-
if ipv6?
83-
listen_host = "[#{listener_address}]"
84-
else
85-
listen_host = listener_address
86-
end
87-
"#{scheme}://#{listen_host}:#{datastore['LPORT']}/"
78+
uri_host = Rex::Socket.is_ipv6?(listener_address) ? "[#{listener_address}]" : listener_address
79+
"#{scheme}://#{uri_host}:#{datastore['LPORT']}/"
8880
end
8981

9082
# Return a URI suitable for placing in a payload.
@@ -158,6 +150,7 @@ def setup_handler
158150
'VirtualDirectory' => true)
159151

160152
print_status("Started #{scheme.upcase} reverse handler on #{listener_uri}")
153+
lookup_proxy_settings
161154
end
162155

163156
#
@@ -175,6 +168,45 @@ def stop_handler
175168

176169
protected
177170

171+
#
172+
# Parses the proxy settings and returns a hash
173+
#
174+
def lookup_proxy_settings
175+
info = {}
176+
return @proxy_settings if @proxy_settings
177+
178+
if datastore['PayloadProxyHost'].to_s == ""
179+
@proxy_settings = info
180+
return @proxy_settings
181+
end
182+
183+
info[:host] = datastore['PayloadProxyHost'].to_s
184+
info[:port] = (datastore['PayloadProxyPort'] || 8080).to_i
185+
info[:type] = datastore['PayloadProxyType'].to_s
186+
187+
uri_host = info[:host]
188+
189+
if Rex::Socket.is_ipv6?(uri_host)
190+
uri_host = "[#{info[:host]}]"
191+
end
192+
193+
info[:info] = "#{uri_host}:#{info[:port]}"
194+
195+
if info[:type] == "SOCKS"
196+
info[:info] = "socks=#{info[:info]}"
197+
else
198+
info[:info] = "http://#{info[:info]}"
199+
if datastore['PayloadProxyUser'].to_s != ""
200+
info[:username] = datastore['PayloadProxyUser'].to_s
201+
end
202+
if datastore['PayloadProxyPass'].to_s != ""
203+
info[:password] = datastore['PayloadProxyPass'].to_s
204+
end
205+
end
206+
207+
@proxy_settings = info
208+
end
209+
178210
#
179211
# Parses the HTTPS request
180212
#
@@ -204,8 +236,8 @@ def on_request(cli, req, obj)
204236
blob.sub!('HTTP_COMMUNICATION_TIMEOUT = 300', "HTTP_COMMUNICATION_TIMEOUT = #{datastore['SessionCommunicationTimeout']}")
205237
blob.sub!('HTTP_USER_AGENT = None', "HTTP_USER_AGENT = '#{var_escape.call(datastore['MeterpreterUserAgent'])}'")
206238

207-
unless datastore['PROXYHOST'].blank?
208-
proxy_url = "http://#{datastore['PROXYHOST']}:#{datastore['PROXYPORT']}"
239+
unless datastore['PayloadProxyHost'].blank?
240+
proxy_url = "http://#{datastore['PayloadProxyHost']||datastore['PROXYHOST']}:#{datastore['PayloadProxyPort']||datastore['PROXYPORT']}"
209241
blob.sub!('HTTP_PROXY = None', "HTTP_PROXY = '#{var_escape.call(proxy_url)}'")
210242
end
211243

@@ -268,11 +300,11 @@ def on_request(cli, req, obj)
268300
:expiration => datastore['SessionExpirationTimeout'],
269301
:comm_timeout => datastore['SessionCommunicationTimeout'],
270302
:ua => datastore['MeterpreterUserAgent'],
271-
:proxyhost => datastore['PROXYHOST'],
272-
:proxyport => datastore['PROXYPORT'],
273-
:proxy_type => datastore['PROXY_TYPE'],
274-
:proxy_username => datastore['PROXY_USERNAME'],
275-
:proxy_password => datastore['PROXY_PASSWORD']
303+
:proxy_host => datastore['PayloadProxyHost'],
304+
:proxy_port => datastore['PayloadProxyPort'],
305+
:proxy_type => datastore['PayloadProxyType'],
306+
:proxy_user => datastore['PayloadProxyUser'],
307+
:proxy_pass => datastore['PayloadProxyPass']
276308

277309
resp.body = encode_stage(blob)
278310

0 commit comments

Comments
 (0)