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/plugins/ffautoregen.rb
Views: 1903
1
module Msf
2
###
3
#
4
# This plugin reloads and re-executes a file-format exploit module once it has changed.
5
#
6
###
7
class Plugin::FFAutoRegen < Msf::Plugin
8
9
###
10
#
11
# This class implements a single edit command.
12
#
13
###
14
class FFAutoRegenCommandDispatcher
15
include Msf::Ui::Console::CommandDispatcher
16
17
#
18
# The dispatcher's name.
19
#
20
def name
21
'FFAutoRegen'
22
end
23
24
#
25
# Returns the hash of commands supported by this dispatcher.
26
#
27
def commands
28
{
29
'ffautoregen' => 'Automatically regenerate the document when the exploit source changes'
30
}
31
end
32
33
#
34
# This method handles the command.
35
#
36
def cmd_ffautoregen(*_args)
37
if !active_module || !(path = active_module.file_path)
38
print_line('Error: No active module selected')
39
return nil
40
end
41
42
last = mt = File.stat(path).mtime
43
44
loop do
45
sleep(1)
46
mt = File.stat(path).mtime
47
48
next unless (mt != last)
49
50
last = mt
51
52
nmod = framework.modules.reload_module(active_module)
53
if !nmod
54
print_line('Error: Failed to reload module, trying again on next change...')
55
next
56
end
57
58
jobify = false
59
payload = nmod.datastore['PAYLOAD']
60
encoder = nmod.datastore['ENCODER']
61
target = nmod.datastore['TARGET']
62
nop = nmod.datastore['NOP']
63
64
nmod.exploit_simple(
65
'Encoder' => encoder,
66
'Payload' => payload,
67
'Target' => target,
68
'Nop' => nop,
69
# 'OptionStr' => opt_str,
70
'LocalInput' => driver.input,
71
'LocalOutput' => driver.output,
72
'RunAsJob' => jobify
73
)
74
end
75
end
76
end
77
78
def initialize(framework, opts)
79
super
80
81
# console dispatcher commands.
82
add_console_dispatcher(FFAutoRegenCommandDispatcher)
83
end
84
85
def cleanup
86
remove_console_dispatcher('FFAutoRegen')
87
end
88
89
def name
90
'ffautoregen'
91
end
92
93
def desc
94
'This plugin reloads and re-executes a file-format exploit module once it has changed'
95
end
96
97
end
98
end
99
100