added File.upload and File.download

git-svn-id: file:///home/svn/incoming/trunk@2409 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Matt Miller 2005-04-18 00:39:27 +00:00
parent 4748177332
commit 7da65883d0
2 changed files with 61 additions and 1 deletions

View File

@ -16,16 +16,76 @@ module Fs
class File < Rex::Post::Meterpreter::Extensions::Stdapi::Fs::IO class File < Rex::Post::Meterpreter::Extensions::Stdapi::Fs::IO
SEPARATOR = "\\"
Separator = "\\"
include Rex::Post::File include Rex::Post::File
class <<self class <<self
attr_accessor :client attr_accessor :client
end end
def File.basename(*a)
path = a[0]
sep = "\\" + File::SEPARATOR
# I suck at regex.
path =~ /(.*)#{sep}(.*)$/
return $2
end
def File.stat(name) def File.stat(name)
return client.fs.filestat.new(name) return client.fs.filestat.new(name)
end end
# Upload one or more files to the remote computer the remote
# directory supplied in destination
def File.upload(destination, *src_files)
src_files.each { |src|
dest = destination
if (File.basename(destination) != ::File.basename(src))
dest += File::SEPARATOR + ::File.basename(src)
end
dest_fd = client.fs.file.new(dest, "wb")
src_buf = ::IO.readlines(src).join
dest_fd.write(src_buf)
dest_fd.close
}
end
# Download one or more files from the remote computer to the local
# directory supplied in destination
def File.download(destination, *src_files)
src_files.each { |src|
dest = destination
if (::File.basename(destination) != File.basename(src))
dest += ::File::SEPARATOR + File.basename(src)
end
src_fd = client.fs.file.new(src, "rb")
dst_fd = ::File.new(dest, "wb")
while (!src_fd.eof?)
data = src_fd.read
if (data == nil)
next
end
dst_fd.write(data)
end
src_fd.close
dst_fd.close
}
end
## ##
# #
# Constructor # Constructor

View File

@ -38,7 +38,7 @@ class IO < Rex::Post::IO
# Synonym for syswrite # Synonym for syswrite
def write(buf) def write(buf)
syswrite syswrite(buf)
end end
# Closes the channel # Closes the channel