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

79 lines
2.0 KiB
Ruby
Raw Normal View History

##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# web site for more information on licensing and terms of use.
# http://metasploit.com/
##
require 'msf/core'
require 'rex/proto/tftp'
class Metasploit3 < Msf::Auxiliary
2013-08-30 21:28:54 +00:00
include Msf::Exploit::Remote::TFTPServer
include Msf::Auxiliary::Report
2013-08-30 21:28:54 +00:00
def initialize
super(
'Name' => 'TFTP File Server',
'Description' => %q{
This module provides a TFTP service
},
'Author' => [ 'jduck' ],
'License' => MSF_LICENSE,
'Actions' =>
[
[ 'Service' ]
],
'PassiveActions' =>
[
'Service'
],
'DefaultAction' => 'Service'
)
2013-08-30 21:28:54 +00:00
register_options(
[
OptString.new('TFTPROOT', [ false, "The TFTP root directory to serve files from" ]),
OptString.new('OUTPUTPATH', [ false, "The directory in which uploaded files will be written." ])
], self.class)
end
2013-08-30 21:28:54 +00:00
def run
if not datastore['OUTPUTPATH'] and not datastore['TFTPROOT']
print_error("You must set TFTPROOT and/or OUTPUTPATH to use this module.")
return
end
2013-08-30 21:28:54 +00:00
@tftp = Rex::Proto::TFTP::Server.new
2013-08-30 21:28:54 +00:00
print_status("Starting TFTP server...")
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
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
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
2013-08-30 21:28:54 +00:00
@tftp.start
add_socket(@tftp.sock)
2013-08-30 21:28:54 +00:00
# Wait for finish..
while @tftp.thread.alive?
select(nil, nil, nil, 2)
end
2013-08-30 21:28:54 +00:00
vprint_status("Stopping TFTP server")
@tftp.stop
end
end