Revert "Revert "Add Meterpreter sanity tests to CI""

This commit is contained in:
adfoster-r7
2023-08-15 13:24:59 +01:00
committed by GitHub
parent 253290d9c4
commit 68ce65c6c9
24 changed files with 3184 additions and 27 deletions
+6 -1
View File
@@ -239,7 +239,12 @@ class MetasploitModule < Msf::Post
bin = read_file(datastore['BaseFileName'])
rm_f(datastore['BaseFileName'])
bin == "\xde\xad\xbe\xef"
test_string = "\xde\xad\xbe\xef"
vprint_status "expected: #{test_string.bytes} - #{test_string.encoding}"
vprint_status "actual: #{bin.bytes} - #{bin.encoding}"
bin == test_string
end
end
+16 -7
View File
@@ -143,14 +143,15 @@ class MetasploitModule < Msf::Post
it "should return the proper directory separator" do
sysinfo = session.sys.config.sysinfo
vprint_status("received sysinfo #{sysinfo}")
if sysinfo["OS"] =~ /windows/i
sep = session.fs.file.separator
res = (sep == "\\")
expected_sep = "\\"
else
sep = session.fs.file.separator
res = (sep == "/")
expected_sep = "/"
end
sep = session.fs.file.separator
vprint_status("Received separator #{sep.inspect} - expected: #{expected_sep.inspect}")
res = (sep == expected_sep)
res
end
@@ -231,6 +232,9 @@ class MetasploitModule < Msf::Post
(contents == "test")
}
# XXX: On windows this can fail with:
# Rex::Post::Meterpreter::RequestError : stdapi_fs_delete_file: Operation failed: The process cannot access the file because it is being used by another process.
# Presumably the Ruby process still has a handle to the file
session.fs.file.rm(file_name)
res &&= !session.fs.dir.entries.include?(file_name)
@@ -251,8 +255,13 @@ class MetasploitModule < Msf::Post
if res
fd = session.fs.file.new(remote, "rb")
uploaded_contents = fd.read
until (fd.eof?)
uploaded_contents << fd.read
begin
until fd.eof?
uploaded_contents << fd.read
end
rescue EOFError
# An EOF can be raised on `fd.read` in the Java Meterpreter
vprint_status("EOF raised")
end
fd.close
original_contents = ::File.read(local, mode: 'rb')