CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/test/functional/meterpreter/meterpreter_spec_helper.rb
Views: 11623
1
module MsfTest
2
module MeterpreterSpecHelper
3
def self.included(base)
4
base.class_eval do
5
def generic_failure_strings
6
['fail', 'error', 'exception']
7
end
8
9
def generic_failure_exception_strings
10
['nserror.dll', 'tiki-error.php', 'tiki-error_simple.php', 'tiki-rss_error.php'] # #ugh, this is dependent on the target
11
end
12
13
def hlp_run_command_check_output(name, command, success_strings = [], fail_strings = [], fail_exception_strings = [])
14
fail_strings = fail_strings | generic_failure_strings
15
fail_exception_strings = fail_exception_strings | generic_failure_exception_strings
16
17
temp_command_file = "#{@output_directory}/#{name}"
18
19
command_output = Rex::Ui::Text::Output::File.new(temp_command_file)
20
@session.init_ui(@input, command_output)
21
22
command_output.print_line("meterpreter_functional_test_start")
23
24
if @verbose
25
puts "Running Command: " + command
26
end
27
28
@session.run_cmd(command)
29
command_output.print_line("meterpreter_functional_test_end")
30
data = hlp_file_to_string(temp_command_file)
31
32
data.should contain_a_complete_test
33
data.should contain_all_successes
34
data.should contain_no_failures_except
35
end
36
37
def hlp_file_to_string(filename)
38
data = ""
39
f = File.open(filename, "r")
40
f.each_line do |line|
41
data += line
42
end
43
return data
44
end
45
46
def hlp_string_to_file(string, filepath)
47
# Create a new file and write to it
48
File.open(filepath, 'w') do |f2|
49
f2.puts string
50
end
51
end
52
end
53
end
54
end
55
end
56
57