Improve utility of meterpreter file upload command

Rather than assume that the destination argument is a directory, check
first, and then do the same thing that 'cp' would do.

 - If dest exists and is a directory, copy to the directory.
 - If dest exists and is a file, copy over the file.
 - If dest does not exist and is a directory, fail.
 - If dest does not exist and is a file, create the file.
bug/bundler_fix
Brent Cook 2015-01-29 13:45:15 -06:00
parent 9d8d17805d
commit 212aeb9106
2 changed files with 14 additions and 5 deletions

View File

@ -246,9 +246,10 @@ class File < Rex::Post::Meterpreter::Extensions::Stdapi::Fs::IO
#
# Upload a single file.
#
def File.upload_file(dest_file, src_file)
def File.upload_file(dest_file, src_file, &stat)
# Open the file on the remote side for writing and read
# all of the contents of the local file
stat.call('uploading', src_file, dest_file) if (stat)
dest_fd = client.fs.file.new(dest_file, "wb")
src_buf = ''
@ -261,6 +262,7 @@ class File < Rex::Post::Meterpreter::Extensions::Stdapi::Fs::IO
ensure
dest_fd.close
end
stat.call('uploaded', src_file, dest_file) if (stat)
end
#

View File

@ -503,10 +503,17 @@ class Console::CommandDispatcher::Stdapi::Fs
client.framework.events.on_session_upload(client, src, dest) if msf_loaded?
}
elsif (stat.file?)
if client.fs.file.exists?(dest) and client.fs.file.stat(dest).directory?
client.fs.file.upload(dest, src) { |step, src, dst|
print_status("#{step.ljust(11)}: #{src} -> #{dst}")
client.framework.events.on_session_upload(client, src, dest) if msf_loaded?
}
else
client.fs.file.upload_file(dest, src) { |step, src, dst|
print_status("#{step.ljust(11)}: #{src} -> #{dst}")
client.framework.events.on_session_upload(client, src, dest) if msf_loaded?
}
end
end
}