Skip to content

Commit d329a72

Browse files
committed
Revert "Merge master"
This reverts commit 2056ff6.
1 parent 2056ff6 commit d329a72

File tree

32 files changed

+362
-1066
lines changed

32 files changed

+362
-1066
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 ax, word ptr [edi]
148+
mov rax, [rdi]
149149
add rbx, rax ; buffer += bytes_received
150150

151151
test rax,rax ; optional?

lib/msf/core/exploit/capture.rb

Lines changed: 58 additions & 45 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-
'8.8.8.8']),
45+
'www.metasploit.com']),
4646
OptPort.new('GATEWAY_PROBE_PORT',
4747
[
4848
false,
@@ -143,6 +143,7 @@ def close_pcap
143143
return unless self.capture
144144
self.capture = nil
145145
self.arp_capture = nil
146+
GC.start()
146147
end
147148

148149
def capture_extract_ies(raw)
@@ -162,15 +163,26 @@ def capture_extract_ies(raw)
162163
end
163164

164165
#
165-
# Loop through each packet
166+
# This monstrosity works around a series of bugs in the interrupt
167+
# signal handling of Ruby 1.9
166168
#
167169
def each_packet
168170
return unless capture
169-
@capture_count ||= 0
170-
capture.each do |pkt|
171-
yield(pkt)
172-
@capture_count += 1
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?
173184
end
185+
174186
@capture_count
175187
end
176188

@@ -230,9 +242,10 @@ def inject_pcap(pcap_file, filter=nil, delay = 0, pcap=self.capture)
230242
pcap.inject(pkt)
231243
Rex.sleep((delay * 1.0)/1000)
232244
end
245+
GC.start
233246
end
234247

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

250263
# The return value either be a PacketFu::Packet object, or nil
251264
def inject_reply(proto=:udp, pcap=self.capture)
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
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
261278
end
279+
rescue ::Timeout::Error
262280
end
263-
rescue ::Timeout::Error
264281
end
265-
nil
282+
return reply
266283
end
267284

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

313330
begin
314-
to = ((datastore['TIMEOUT'] || 500).to_f * 8) / 1000.0
331+
to = (datastore['TIMEOUT'] || 1500).to_f / 1000.0
315332
::Timeout.timeout(to) do
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]
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
323341
end
324342
end
325343
rescue ::Timeout::Error
326-
# Well, that didn't work (this is common on networks where there's no gateway, like
344+
# Well, that didn't work (this common on networks where there's no gatway, like
327345
# VMWare network interfaces. We'll need to use a fake source hardware address.
328346
self.arp_cache[Rex::Socket.source_address(addr)] = "00:00:00:00:00:00"
329347
end
@@ -336,31 +354,26 @@ def arp(target_ip=nil)
336354
return self.arp_cache[:gateway] unless should_arp? target_ip
337355
source_ip = Rex::Socket.source_address(target_ip)
338356
raise RuntimeError, "Could not access the capture process." unless self.arp_capture
339-
340357
p = arp_packet(target_ip, source_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
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
356368
self.arp_cache[target_ip] = my_packet.eth_saddr
357369
return self.arp_cache[target_ip]
370+
else
371+
next
358372
end
359373
end
360-
rescue ::Timeout::Error
361374
end
375+
rescue ::Timeout::Error
362376
end
363-
nil
364377
end
365378

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

lib/msf/core/exploit/ipv6.rb

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

7777
return if not @ipv6_icmp6_capture
7878
@ipv6_icmp6_capture = nil
79+
GC.start()
7980
end
8081

8182
#

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-
:proxy_host => datastore['PayloadProxyHost'],
260-
:proxy_port => datastore['PayloadProxyPort'],
261-
:proxy_type => datastore['PayloadProxyType'],
262-
:proxy_user => datastore['PayloadProxyUser'],
263-
:proxy_pass => datastore['PayloadProxyPass']
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']
264264

265265
blob = encode_stage(blob)
266266

lib/msf/core/handler/reverse_http.rb

Lines changed: 21 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,33 @@ 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+
6167
# Determine where to bind the server
6268
#
6369
# @return [String]
6470
def listener_address
65-
if datastore['ReverseListenerBindAddress'].to_s == ""
66-
bindaddr = Rex::Socket.is_ipv6?(datastore['LHOST']) ? '::' : '0.0.0.0'
71+
if datastore['ReverseListenerBindAddress'].to_s.empty?
72+
bindaddr = (ipv6?) ? '::' : '0.0.0.0'
6773
else
6874
bindaddr = datastore['ReverseListenerBindAddress']
6975
end
7076

7177
bindaddr
7278
end
7379

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

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

152160
print_status("Started #{scheme.upcase} reverse handler on #{listener_uri}")
153-
lookup_proxy_settings
154161
end
155162

156163
#
@@ -168,45 +175,6 @@ def stop_handler
168175

169176
protected
170177

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-
210178
#
211179
# Parses the HTTPS request
212180
#
@@ -236,8 +204,8 @@ def on_request(cli, req, obj)
236204
blob.sub!('HTTP_COMMUNICATION_TIMEOUT = 300', "HTTP_COMMUNICATION_TIMEOUT = #{datastore['SessionCommunicationTimeout']}")
237205
blob.sub!('HTTP_USER_AGENT = None', "HTTP_USER_AGENT = '#{var_escape.call(datastore['MeterpreterUserAgent'])}'")
238206

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

@@ -300,11 +268,11 @@ def on_request(cli, req, obj)
300268
:expiration => datastore['SessionExpirationTimeout'],
301269
:comm_timeout => datastore['SessionCommunicationTimeout'],
302270
:ua => datastore['MeterpreterUserAgent'],
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']
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']
308276

309277
resp.body = encode_stage(blob)
310278

0 commit comments

Comments
 (0)