Merge branch 'bug/redmine-6481-File-open' of https://github.com/jlee-r7/metasploit-framework into jlee-r7-bug/redmine-6481-File-open
commit
e3e566323a
|
@ -290,6 +290,25 @@ class File < Rex::Post::Meterpreter::Extensions::Stdapi::Fs::IO
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# With no associated block, File.open is a synonym for ::new. If the optional
|
||||||
|
# code block is given, it will be passed the opened file as an argument, and
|
||||||
|
# the File object will automatically be closed when the block terminates. In
|
||||||
|
# this instance, File.open returns the value of the block.
|
||||||
|
#
|
||||||
|
# (doc stolen from http://www.ruby-doc.org/core-1.9.3/File.html#method-c-open)
|
||||||
|
#
|
||||||
|
def File.open(name, mode="r", perms=0)
|
||||||
|
f = new(name, mode, perms)
|
||||||
|
if block_given?
|
||||||
|
ret = yield f
|
||||||
|
f.close
|
||||||
|
return ret
|
||||||
|
else
|
||||||
|
return f
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
#
|
#
|
||||||
# Constructor
|
# Constructor
|
||||||
|
|
|
@ -199,16 +199,16 @@ class Metasploit4 < Msf::Post
|
||||||
|
|
||||||
it "should create and remove files" do
|
it "should create and remove files" do
|
||||||
res = true
|
res = true
|
||||||
fd = session.fs.file.new("meterpreter-test", "wb")
|
res &&= session.fs.file.open("meterpreter-test", "wb") { |fd|
|
||||||
fd.write("test")
|
fd.write("test")
|
||||||
fd.close
|
}
|
||||||
|
|
||||||
vprint_status("Wrote to meterpreter-test, checking contents")
|
vprint_status("Wrote to meterpreter-test, checking contents")
|
||||||
fd = session.fs.file.new("meterpreter-test", "rb")
|
res &&= session.fs.file.open("meterpreter-test", "rb") { |fd|
|
||||||
contents = fd.read
|
contents = fd.read
|
||||||
vprint_status("Wrote #{contents}")
|
vprint_status("Wrote #{contents}")
|
||||||
res &&= (contents == "test")
|
(contents == "test")
|
||||||
fd.close
|
}
|
||||||
|
|
||||||
session.fs.file.rm("meterpreter-test")
|
session.fs.file.rm("meterpreter-test")
|
||||||
res &&= !session.fs.dir.entries.include?("meterpreter-test")
|
res &&= !session.fs.dir.entries.include?("meterpreter-test")
|
||||||
|
|
Loading…
Reference in New Issue