CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/tools/modules/solo.rb
Views: 1904
1
#!/usr/bin/env ruby
2
3
module Msf
4
module Modules
5
end
6
end
7
8
msfbase = __FILE__
9
while File.symlink?(msfbase)
10
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
11
end
12
13
$:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib')))
14
15
require 'json'
16
17
module_path = ARGV.shift
18
19
# Usage when we don't have a module name
20
def usage(mod='MODULE_FILE', name='Run a module outside of Metasploit Framework')
21
$stderr.puts "Usage: solo.rb #{mod} [OPTIONS] [ACTION]"
22
$stderr.puts name
23
end
24
25
def log_output(m)
26
message = m.params['message']
27
28
sigil = case m.params['level']
29
when 'error', 'warning'
30
'!'
31
when 'good'
32
'+'
33
else
34
'*'
35
end
36
37
$stderr.puts "[#{sigil}] #{message}"
38
end
39
40
def process_report(m)
41
puts "[+] Found #{m.params['type']}: #{JSON.generate m.params['data']}"
42
end
43
44
if !module_path || module_path[0] == '-'
45
usage
46
else
47
mod = Msf::Modules::External.new module_path
48
args, method = Msf::Modules::External::CLI.parse_options mod
49
50
success = mod.exec(method: method, args: args) do |m|
51
begin
52
case m.method
53
when :message
54
log_output(m)
55
when :report
56
process_report(m)
57
when :reply
58
puts m.params['return']
59
end
60
rescue Interrupt => e
61
abort 'Exiting...'
62
rescue Exception => e
63
abort "Encountered an error: #{e.message}"
64
end
65
end
66
67
abort 'Module exited abnormally' if !success
68
end
69
70