2010-07-08 23:34:33 +00:00
|
|
|
##
|
2013-10-15 18:50:46 +00:00
|
|
|
# This module requires Metasploit: http//metasploit.com/download
|
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2010-07-08 23:34:33 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex/proto/tftp'
|
2014-03-07 16:41:18 +00:00
|
|
|
require 'tmpdir'
|
2010-07-08 23:34:33 +00:00
|
|
|
|
|
|
|
class Metasploit3 < Msf::Auxiliary
|
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
include Msf::Exploit::Remote::TFTPServer
|
|
|
|
include Msf::Auxiliary::Report
|
2010-07-08 23:34:33 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'TFTP File Server',
|
|
|
|
'Description' => %q{
|
|
|
|
This module provides a TFTP service
|
|
|
|
},
|
2014-03-07 16:41:18 +00:00
|
|
|
'Author' => [ 'jduck', 'todb' ],
|
2013-08-30 21:28:54 +00:00
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Actions' =>
|
|
|
|
[
|
|
|
|
[ 'Service' ]
|
|
|
|
],
|
|
|
|
'PassiveActions' =>
|
|
|
|
[
|
|
|
|
'Service'
|
|
|
|
],
|
|
|
|
'DefaultAction' => 'Service'
|
|
|
|
)
|
2010-07-08 23:34:33 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
register_options(
|
|
|
|
[
|
2014-03-06 22:13:20 +00:00
|
|
|
OptAddress.new('SRVHOST', [ true, "The local host to listen on.", '0.0.0.0' ]),
|
|
|
|
OptPort.new('SRVPORT', [ true, "The local port to listen on.", 69 ]),
|
2014-03-07 16:41:18 +00:00
|
|
|
OptString.new('TFTPROOT', [ true, "The TFTP root directory to serve files from", Dir.tmpdir ]),
|
|
|
|
OptString.new('OUTPUTPATH', [ true, "The directory in which uploaded files will be written.", Dir.tmpdir ])
|
2013-08-30 21:28:54 +00:00
|
|
|
], self.class)
|
|
|
|
end
|
2010-07-08 23:34:33 +00:00
|
|
|
|
2014-03-06 22:13:20 +00:00
|
|
|
def srvhost
|
|
|
|
datastore['SRVHOST'] || '0.0.0.0'
|
|
|
|
end
|
|
|
|
|
|
|
|
def srvport
|
|
|
|
datastore['SRVPORT'] || 69
|
|
|
|
end
|
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def run
|
2014-03-06 22:13:20 +00:00
|
|
|
if datastore['OUTPUTPATH'] and datastore['TFTPROOT']
|
|
|
|
print_status("Starting TFTP server on #{srvhost}:#{srvport}...")
|
|
|
|
else
|
2013-08-30 21:28:54 +00:00
|
|
|
print_error("You must set TFTPROOT and/or OUTPUTPATH to use this module.")
|
|
|
|
return
|
|
|
|
end
|
2010-07-08 23:34:33 +00:00
|
|
|
|
2014-03-06 22:13:20 +00:00
|
|
|
@tftp = Rex::Proto::TFTP::Server.new(
|
|
|
|
srvport,
|
|
|
|
srvhost,
|
|
|
|
{}
|
|
|
|
)
|
2010-07-08 23:34:33 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
if datastore['TFTPROOT']
|
|
|
|
print_status("Files will be served from #{datastore['TFTPROOT']}")
|
|
|
|
@tftp.set_tftproot(datastore['TFTPROOT'])
|
|
|
|
end
|
2010-07-08 23:34:33 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
# register output directory
|
|
|
|
if datastore['OUTPUTPATH']
|
|
|
|
print_status("Uploaded files will be saved in #{datastore['OUTPUTPATH']}")
|
|
|
|
@tftp.set_output_dir(datastore['OUTPUTPATH'])
|
|
|
|
end
|
2010-07-08 23:34:33 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
# Individual virtual files can be served here -
|
|
|
|
#@tftp.register_file("ays", "A" * 2048) # multiple of 512 on purpose
|
2010-07-08 23:34:33 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
@tftp.start
|
|
|
|
add_socket(@tftp.sock)
|
2010-07-08 23:34:33 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
# Wait for finish..
|
|
|
|
while @tftp.thread.alive?
|
|
|
|
select(nil, nil, nil, 2)
|
|
|
|
end
|
2010-07-08 23:34:33 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
vprint_status("Stopping TFTP server")
|
|
|
|
@tftp.stop
|
|
|
|
end
|
2010-07-08 23:34:33 +00:00
|
|
|
|
|
|
|
end
|