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/lib/msf/ui/console/command_dispatcher/post.rb
Views: 1904
1
# -*- coding: binary -*-
2
module Msf
3
module Ui
4
module Console
5
module CommandDispatcher
6
7
###
8
#
9
# Recon module command dispatcher.
10
#
11
###
12
class Post
13
14
include Msf::Ui::Console::ModuleCommandDispatcher
15
include Msf::Ui::Console::ModuleActionCommands
16
include Msf::Ui::Console::ModuleOptionTabCompletion
17
include Msf::Ui::Console::ModuleArgumentParsing
18
19
#
20
# Returns the hash of commands specific to post modules.
21
#
22
def commands
23
super.merge({
24
"run" => "Launches the post exploitation module",
25
"rerun" => "Reloads and launches the module",
26
"exploit" => "This is an alias for the run command",
27
"rexploit" => "This is an alias for the rerun command",
28
}).merge( (mod ? mod.post_commands : {}) )
29
end
30
31
#
32
#
33
# Returns the command dispatcher name.
34
#
35
def name
36
"Post"
37
end
38
39
#
40
# This is an alias for 'rerun'
41
#
42
def cmd_rexploit(*args)
43
cmd_rerun(*args)
44
end
45
46
#
47
# Reloads a post module and executes it
48
#
49
def cmd_rerun(*args)
50
opts = {}
51
if args.include?('-r') || args.include?('--reload-libs')
52
driver.run_single('reload_lib -a')
53
opts[:previously_reloaded] = true
54
end
55
56
# Stop existing job and reload the module
57
if reload(true)
58
cmd_run(*args, opts: opts)
59
end
60
end
61
62
alias cmd_rexploit cmd_rerun
63
64
def cmd_run_help
65
print_module_run_or_check_usage(
66
command: :run,
67
description: 'Launches a post exploitation module.'
68
)
69
end
70
71
#
72
# Executes a post module
73
#
74
def cmd_run(*args, action: nil, opts: {})
75
if (args.include?('-r') || args.include?('--reload-libs')) && !opts[:previously_reloaded]
76
driver.run_single('reload_lib -a')
77
end
78
79
return false unless (args = parse_run_opts(args, action: action))
80
jobify = args[:jobify]
81
82
# Always run passive modules in the background
83
if (mod.passive)
84
jobify = true
85
end
86
87
begin
88
mod.run_simple(
89
'Action' => args[:action],
90
'Options' => args[:datastore_options],
91
'LocalInput' => driver.input,
92
'LocalOutput' => driver.output,
93
'RunAsJob' => jobify,
94
'Quiet' => args[:quiet]
95
)
96
rescue ::Timeout::Error
97
print_error("Post triggered a timeout exception")
98
rescue ::Interrupt
99
print_error("Post interrupted by the console user")
100
rescue ::Exception => e
101
print_error("Post failed: #{e.class} #{e}")
102
if (e.class.to_s != 'Msf::OptionValidateError')
103
print_error("Call stack:")
104
e.backtrace.each do |line|
105
break if line =~ /lib.msf.base.simple/
106
print_error(" #{line}")
107
end
108
end
109
110
return false
111
end
112
113
if (jobify && mod.job_id)
114
print_status("Post module running as background job #{mod.job_id}.")
115
else
116
print_status("Post module execution completed")
117
end
118
end
119
120
alias cmd_exploit cmd_run
121
122
alias cmd_exploit_tabs cmd_run_tabs
123
124
def cmd_run_help
125
print_line "Usage: run [options]"
126
print_line
127
print_line "Launches a post module."
128
print @@module_opts_with_action_support.usage
129
end
130
131
alias cmd_exploit_help cmd_run_help
132
133
end
134
135
end end end end
136
137
138