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/lib/msf/ui/console/command_dispatcher/evasion.rb
Views: 11788
1
module Msf
2
module Ui
3
module Console
4
module CommandDispatcher
5
class Evasion
6
7
include Msf::Ui::Console::ModuleCommandDispatcher
8
include Msf::Ui::Console::ModuleOptionTabCompletion
9
10
def commands
11
super.update({
12
'run' => 'Launches the evasion module',
13
'rerun' => 'Reloads and launches the evasion module',
14
'exploit' => 'This is an alias for the run command',
15
'rexploit' => 'This is an alias for the rerun command',
16
'reload' => 'Reloads the auxiliary module',
17
'to_handler' => 'Creates a handler with the specified payload'
18
}).merge(mod ? mod.evasion_commands : {})
19
end
20
21
def name
22
'Evasion'
23
end
24
25
def cmd_run(*args, opts: {})
26
if (args.include?('-r') || args.include?('--reload-libs')) && !opts[:previously_reloaded]
27
driver.run_single('reload_lib -a')
28
end
29
30
module_opts = {
31
'Encoder' => mod.datastore['ENCODER'],
32
'Payload' => mod.datastore['PAYLOAD'],
33
'Nop' => mod.datastore['NOP'],
34
'LocalInput' => driver.input,
35
'LocalOutput' => driver.output
36
}
37
38
begin
39
mod.run_simple(module_opts)
40
rescue ::Interrupt
41
print_error('Evasion interrupted by the console user')
42
rescue ::Exception => e
43
print_error("Evasion failed: #{e.class} #{e}")
44
elog('Evasion Failed', error: e)
45
end
46
end
47
48
alias cmd_exploit cmd_run
49
50
def cmd_rerun(*args)
51
opts = {}
52
if args.include?('-r') || args.include?('--reload-libs')
53
driver.run_single('reload_lib -a')
54
opts[:previously_reloaded] = true
55
end
56
57
if reload(true)
58
cmd_run(*args, opts: opts)
59
end
60
end
61
62
alias cmd_rexploit cmd_rerun
63
64
#
65
# Tab completion for the run command
66
#
67
def cmd_run_tabs(str, words)
68
fmt = {
69
'-e' => [ framework.encoders.module_refnames ],
70
'-f' => [ nil ],
71
'-h' => [ nil ],
72
'-j' => [ nil ],
73
'-J' => [ nil ],
74
'-n' => [ framework.nops.module_refnames ],
75
'-o' => [ true ],
76
'-p' => [ framework.payloads.module_refnames ],
77
'-r' => [ nil ],
78
'-t' => [ true ],
79
'-z' => [ nil ]
80
}
81
flags = tab_complete_generic(fmt, str, words)
82
options = tab_complete_option(active_module, str, words)
83
flags + options
84
end
85
86
#
87
# Tab completion for the exploit command
88
#
89
alias cmd_exploit_tabs cmd_run_tabs
90
91
def cmd_to_handler(*args)
92
if args.include?('-r') || args.include?('--reload-libs')
93
driver.run_single('reload_lib -a')
94
end
95
96
handler = framework.modules.create('exploit/multi/handler')
97
98
handler_opts = {
99
'Payload' => mod.datastore['PAYLOAD'],
100
'LocalInput' => driver.input,
101
'LocalOutput' => driver.output,
102
'RunAsJob' => true,
103
'Options' => {
104
'ExitOnSession' => false,
105
}
106
}
107
108
handler.share_datastore(mod.datastore)
109
110
replicant_handler = nil
111
handler.exploit_simple(handler_opts) do |yielded_replicant_handler|
112
replicant_handler = yielded_replicant_handler
113
end
114
115
if replicant_handler.nil?
116
print_error('Failed to run module')
117
return
118
end
119
120
if replicant_handler.error.nil?
121
job_id = handler.job_id
122
123
print_status "Payload Handler Started as Job #{job_id}"
124
end
125
end
126
end
127
end
128
end
129
end
130
end
131
132