2018-05-23 22:31:09 +00:00
|
|
|
##
|
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
##
|
|
|
|
|
|
|
|
require 'thread'
|
|
|
|
require 'rex/proto/proxy/socks5'
|
|
|
|
|
|
|
|
class MetasploitModule < Msf::Auxiliary
|
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super(
|
2018-05-30 21:15:53 +00:00
|
|
|
'Name' => 'Socks5 Proxy Server',
|
|
|
|
'Description' => %q{
|
|
|
|
This module provides a socks5 proxy server that uses the builtin
|
|
|
|
Metasploit routing to relay connections.
|
|
|
|
},
|
|
|
|
'Author' => [ 'sf', 'Spencer McIntyre', 'surefire' ],
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Actions' =>
|
2018-05-23 22:31:09 +00:00
|
|
|
[
|
|
|
|
[ 'Proxy' ]
|
|
|
|
],
|
|
|
|
'PassiveActions' =>
|
|
|
|
[
|
|
|
|
'Proxy'
|
|
|
|
],
|
|
|
|
'DefaultAction' => 'Proxy'
|
|
|
|
)
|
|
|
|
|
2018-05-30 21:15:53 +00:00
|
|
|
register_options([
|
|
|
|
OptString.new('USERNAME', [false, 'Proxy username for SOCKS5 listener']),
|
|
|
|
OptString.new('PASSWORD', [false, 'Proxy password for SOCKS5 listener']),
|
|
|
|
OptString.new('SRVHOST', [true, 'The address to listen on', '0.0.0.0']),
|
|
|
|
OptPort.new('SRVPORT', [true, 'The port to listen on', 1080])
|
|
|
|
])
|
2018-05-23 22:31:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
@mutex = ::Mutex.new
|
2018-05-30 21:15:53 +00:00
|
|
|
@socks_proxy = nil
|
2018-05-23 22:31:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def cleanup
|
|
|
|
@mutex.synchronize do
|
2018-05-30 21:15:53 +00:00
|
|
|
if @socks_proxy
|
|
|
|
print_status('Stopping the socks5 proxy server')
|
|
|
|
@socks_proxy.stop
|
|
|
|
@socks_proxy = nil
|
2018-05-23 22:31:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
opts = {
|
2018-05-30 21:15:53 +00:00
|
|
|
'ServerHost' => datastore['SRVHOST'],
|
|
|
|
'ServerPort' => datastore['SRVPORT'],
|
2018-05-23 22:31:09 +00:00
|
|
|
'ServerUsername' => datastore['USERNAME'],
|
|
|
|
'ServerPassword' => datastore['PASSWORD'],
|
2018-05-30 21:15:53 +00:00
|
|
|
'Context' => {'Msf' => framework, 'MsfExploit' => self}
|
2018-05-23 22:31:09 +00:00
|
|
|
}
|
2018-05-30 21:15:53 +00:00
|
|
|
@socks_proxy = Rex::Proto::Proxy::Socks5::Server.new(opts)
|
2018-05-23 22:31:09 +00:00
|
|
|
|
2018-05-30 21:15:53 +00:00
|
|
|
print_status('Starting the socks5 proxy server')
|
|
|
|
@socks_proxy.start
|
|
|
|
@socks_proxy.join
|
2018-05-23 22:31:09 +00:00
|
|
|
end
|
|
|
|
end
|