2008-12-03 01:23:27 +00:00
|
|
|
###
|
|
|
|
|
#
|
|
|
|
|
# This module exposes a simple method to create a file.
|
|
|
|
|
#
|
|
|
|
|
###
|
|
|
|
|
|
|
|
|
|
module Msf
|
2010-09-26 18:28:58 +00:00
|
|
|
module Exploit::FILEFORMAT
|
|
|
|
|
|
2008-12-03 01:23:27 +00:00
|
|
|
def initialize(info = {})
|
|
|
|
|
super
|
|
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
|
[
|
2008-12-03 15:47:10 +00:00
|
|
|
OptString.new('FILENAME', [ true, 'The file name.', 'MSF']),
|
2008-12-03 01:23:27 +00:00
|
|
|
], Msf::Exploit::FILEFORMAT
|
|
|
|
|
)
|
2010-09-26 18:28:58 +00:00
|
|
|
|
|
|
|
|
register_advanced_options(
|
|
|
|
|
[
|
|
|
|
|
OptBool.new('DisablePayloadHandler', [ false, "Disable the handler code for the selected payload", true ])
|
|
|
|
|
], Msf::Exploit::FILEFORMAT
|
|
|
|
|
)
|
2008-12-03 01:23:27 +00:00
|
|
|
end
|
|
|
|
|
|
2010-09-26 18:28:58 +00:00
|
|
|
def file_create(data)
|
2011-06-09 14:21:52 +00:00
|
|
|
fname = datastore['FILENAME']
|
|
|
|
|
slashes = fname.count(::File::SEPARATOR)
|
|
|
|
|
|
|
|
|
|
if slashes == 0
|
|
|
|
|
# use default directory, create the directories if they do not exist already
|
2011-06-16 17:33:13 +00:00
|
|
|
if ::File.directory?(Msf::Config.config_directory)
|
2011-06-09 14:21:52 +00:00
|
|
|
::Dir.mkdir(Msf::Config.config_directory + "/data/", 0755) rescue nil
|
|
|
|
|
::Dir.mkdir(Msf::Config.config_directory + "/data/exploits/", 0755) rescue nil
|
|
|
|
|
end
|
2009-03-14 01:28:59 +00:00
|
|
|
|
2011-06-09 14:21:52 +00:00
|
|
|
path = Msf::Config.config_directory + "/data/exploits/"
|
|
|
|
|
fname = path + fname
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
fd = File.new(fname, 'wb')
|
|
|
|
|
fd.write(data)
|
|
|
|
|
fd.close
|
|
|
|
|
print_status("Generated output file #{fname}")
|
|
|
|
|
rescue Errno::ENOENT
|
|
|
|
|
print_error("Path for #{fname} does not exist. Create this path and try again.")
|
|
|
|
|
end
|
|
|
|
|
end
|
2008-12-03 01:23:27 +00:00
|
|
|
end
|
|
|
|
|
end
|