Land #9563: improve memory usage on meterpreter file upload

4.x
Brent Cook 2018-02-15 12:07:19 -06:00 committed by Metasploit
parent 7cde510eb6
commit c5a73bdea3
No known key found for this signature in database
GPG Key ID: CDFB5FA52007B954
2 changed files with 20 additions and 10 deletions

View File

@ -275,17 +275,24 @@ class File < Rex::Post::Meterpreter::Extensions::Stdapi::Fs::IO
# Open the file on the remote side for writing and read # Open the file on the remote side for writing and read
# all of the contents of the local file # all of the contents of the local file
stat.call('uploading', src_file, dest_file) if (stat) stat.call('uploading', src_file, dest_file) if (stat)
dest_fd = client.fs.file.new(dest_file, "wb") dest_fd = nil
src_buf = '' src_fd = nil
buf_size = 8 * 1024 * 1024
::File.open(src_file, 'rb') { |f|
src_buf = f.read(f.stat.size)
}
begin begin
dest_fd.write(src_buf) dest_fd = client.fs.file.new(dest_file, "wb")
src_fd = ::File.open(src_file, "rb")
src_size = src_fd.stat.size
while (buf = src_fd.read(buf_size))
dest_fd.write(buf)
percent = dest_fd.pos.to_f / src_size.to_f * 100.0
msg = "Uploaded #{Filesize.new(dest_fd.pos).pretty} of " \
"#{Filesize.new(src_size).pretty} (#{percent.round(2)}%)"
stat.call(msg, src_file, dest_file)
end
ensure ensure
dest_fd.close src_fd.close unless src_fd.nil?
dest_fd.close unless dest_fd.nil?
end end
stat.call('uploaded', src_file, dest_file) if (stat) stat.call('uploaded', src_file, dest_file) if (stat)
end end

View File

@ -874,9 +874,12 @@ class Packet < GroupTlv
# Xor a set of bytes with a given XOR key. # Xor a set of bytes with a given XOR key.
# #
def xor_bytes(xor_key, bytes) def xor_bytes(xor_key, bytes)
xor_key = xor_key.bytes
result = '' result = ''
bytes.bytes.zip(xor_key.bytes.cycle).each do |b| i = 0
result << (b[0].ord ^ b[1].ord).chr bytes.each_byte do |b|
result << (b ^ xor_key[i % xor_key.length]).chr
i += 1
end end
result result
end end