Reworked how the Fileformat mixin works for exploits, a single filename will use a default path, users can set a full path as well if they want to place the files somewhere else instead of using OUTPUTPATH

git-svn-id: file:///home/svn/framework3/trunk@12889 4d416f70-5f16-0410-b530-b9f4589650da
unstable
David Rude 2011-06-09 14:21:52 +00:00
parent 13f0c5197d
commit 05fe96cf37
1 changed files with 22 additions and 7 deletions

View File

@ -13,7 +13,6 @@ module Exploit::FILEFORMAT
register_options(
[
OptString.new('FILENAME', [ true, 'The file name.', 'MSF']),
OptString.new('OUTPUTPATH', [ true, 'The location of the file.', File.join(Msf::Config.install_root, 'data', 'exploits')]),
], Msf::Exploit::FILEFORMAT
)
@ -25,12 +24,28 @@ module Exploit::FILEFORMAT
end
def file_create(data)
out = File.expand_path(File.join(datastore['OUTPUTPATH'], datastore['FILENAME']))
fd = File.new(out,"wb")
fd.write(data)
fd.close
print_status("Generated output file #{out}")
end
fname = datastore['FILENAME']
slashes = fname.count(::File::SEPARATOR)
if slashes == 0
# use default directory, create the directories if they do not exist already
if ::Dir.exists?(Msf::Config.config_directory)
::Dir.mkdir(Msf::Config.config_directory + "/data/", 0755) rescue nil
::Dir.mkdir(Msf::Config.config_directory + "/data/exploits/", 0755) rescue nil
end
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
end
end