forked from rapid7/metasploit-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsf_autoload.rb
335 lines (321 loc) · 11.4 KB
/
msf_autoload.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
require 'zeitwerk'
###
# TODO:
# Apply zeitwerk to the rest of framework
# Namespacing wmap/events (when we're able to make potentially breaking changes)
# Correct namespacing to remove the custom inflector (or reduce it's complexity)
# Correct namespacing to cut down on inflector overrides
# Make the necessary changes to reduce/remove the ignored/collapsed files and folders
#
# I don't know why these are needed in `lib/msf/util/dot_net_deserialization/types.rb`
# require 'msf/util/dot_net_deserialization/types/primitives'
# require 'msf/util/dot_net_deserialization/types/general'
# require 'msf/util/dot_net_deserialization/types/record_values'
###
class MsfAutoload
include Singleton
def initialize
@loader = create_loader
configure(@loader)
finalize_loader(@loader)
end
class TempInflector < Zeitwerk::Inflector
def camelize(basename, abspath)
if basename == 'osx' && abspath.end_with?("#{__dir__}/msf/core/payload/osx", "#{__dir__}/msf/core/payload/osx.rb")
'Osx'
elsif basename == 'exe' && abspath.end_with?("#{__dir__}/msf/core/exe", "#{__dir__}/msf/core/exe.rb")
'Exe'
elsif basename == 'json' && abspath.end_with?("#{__dir__}/msf/base/serializer/json.rb")
'Json'
elsif basename == 'powershell' && abspath.end_with?("#{__dir__}/msf/base/sessions/powershell.rb")
'PowerShell'
elsif basename == 'ui' && abspath.end_with?("#{__dir__}/msf/core/module/ui", "#{__dir__}/msf/core/module/ui.rb", "#{__dir__}/rex/post/ui", "#{__dir__}/rex/post/ui.rb", "#{__dir__}/rex/post/meterpreter/extensions/stdapi/ui.rb")
'UI'
elsif basename == 'ssh' && abspath.end_with?("#{__dir__}/rex/proto/ssh")
'Ssh'
elsif basename == 'http' && abspath.end_with?("#{__dir__}/rex/proto/http")
'Http'
elsif basename == 'rftransceiver' && abspath.end_with?("#{__dir__}/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb")
'RFtransceiver'
else
super
end
end
end
private
def ignore_list
[
"#{__dir__}/msf/core/modules/external/go/pkg",
"#{__dir__}/msf/core/constants.rb",
"#{__dir__}/msf/core/cert_provider.rb",
"#{__dir__}/msf/core/rpc/json/",
"#{__dir__}/msf/core/modules/external/ruby/metasploit.rb",
"#{__dir__}/msf/core/rpc/v10/constants.rb",
"#{__dir__}/msf/core.rb",
"#{__dir__}/msf/base.rb",
"#{__dir__}/rex/post/",
"#{__dir__}/rex/post.rb",
"#{__dir__}/rex/proto/ssh/hrr_rb_ssh.rb",
"#{__dir__}/rex/proto/ssh/connection.rb",
"#{__dir__}/rex/proto/kerberos/pac/krb5_pac.rb"
]
end
def collapse_list
[
"#{__dir__}/msf/core",
"#{__dir__}/msf/core/rpc/v10",
"#{__dir__}/msf/core/payload/osx/x64",
"#{__dir__}/msf/core/payload/windows/x64",
"#{__dir__}/msf/core/payload/linux/x64",
"#{__dir__}/msf/core/web_services/servlet",
"#{__dir__}/msf/base",
"#{__dir__}/rex/parser/fs"
]
end
def custom_inflections
{
'uuid' => 'UUID',
'db_manager' => 'DBManager',
'ci' => 'CI',
'fusion_vm' => 'FusionVM',
'gpp' => 'GPP',
'ip360' => 'IP360',
'aspl' => 'ASPL',
'ip_list' => 'IPList',
'mbsa' => 'MBSA',
'xml' => 'XML',
'nbe' => 'NBE',
'open_vas' => 'OpenVAS',
'ip_address' => 'IPAddress',
'wmap' => 'WMAP',
'reflective_dll_loader' => 'ReflectiveDLLLoader',
'ssl' => 'SSL',
'reverse_tcp_double_ssl' => 'ReverseTcpDoubleSSL',
'rpc' => 'RPC',
'db_import_error' => 'DBImportError',
'db_export' => 'DBExport',
'extapi' => 'ExtAPI',
'nonalpha' => 'NonAlpha',
'nonupper' => 'NonUpper',
'natpmp' => 'NATPMP',
'udp_scanner' => 'UDPScanner',
'epmp' => 'EPMP',
'cnpilot' => 'CNPILOT',
'rservices' => 'RServices',
'ntp' => 'NTP',
'mqtt' => 'MQTT',
'iax2' => 'IAX2',
'pii' => 'PII',
'mdns' => 'MDNS',
'crand' => 'CRand',
'llmnr' => 'LLMNR',
'drdos' => 'DRDoS',
'jsp' => 'JSP',
'macho' => 'MachO',
'nodejs' => 'NodeJS',
'jsobfu' => 'JSObfu',
'osx' => 'OSX',
'webrtc' => 'WebRTC',
'json' => 'JSON',
'sip' => 'SIP',
'ntlm' => 'NTLM',
'mssql_commands' => 'MSSQL_COMMANDS',
'mssql' => 'MSSQL',
'pdf' => 'PDF',
'fileformat' => 'FILEFORMAT',
'http' => 'HTTP',
'html' => 'HTML',
'pdf_parse' => 'PDF_Parse',
'vim_soap' => 'VIMSoap',
'ndmp' => 'NDMP',
'ndmp_socket' => 'NDMPSocket',
'dcerpc' => 'DCERPC',
'dcerpc_mgmt' => 'DCERPC_MGMT',
'dcerpc_epm' => 'DCERPC_EPM',
'dcerpc_lsa' => 'DCERPC_LSA',
'wdbrpc_client' => 'WDBRPC_Client',
'sunrpc' => 'SunRPC',
'mysql' => 'MYSQL',
'ldap' => 'LDAP',
'sqli' => 'SQLi',
'dhcp_server' => 'DHCPServer',
'tns' => 'TNS',
'oracle' => 'ORACLE',
'dect_coa' => 'DECT_COA',
'wdbrpc' => 'WDBRPC',
'exe' => 'EXE',
'php_exe' => 'PhpEXE',
'mssql_sqli' => 'MSSQL_SQLI',
'snmp_client' => 'SNMPClient',
'afp' => 'AFP',
'zeromq' => 'ZeroMQ',
'tftp_server' => 'TFTPServer',
'db2' => 'DB2',
'rdp' => 'RDP',
'riff' => 'RIFF',
'dns' => 'DNS',
'smtp_deliver' => 'SMTPDeliver',
'send_uuid' => 'SendUUID',
'exec_x64' => 'Exec_x64',
'reflective_dll_injection' => 'ReflectiveDLLInjection',
'reflective_pe_loader' => 'ReflectivePELoader',
'pe_inject' => 'PEInject',
'payload_db_conf' => 'PayloadDBConf',
'reverse_tcp_x86' => 'ReverseTcp_x86',
'ruby_dl' => 'RubyDL',
'wmic' => 'WMIC',
'net_api' => 'NetAPI',
'rpc_base' => 'RPC_Base',
'rpc_plugin' => 'RPC_Plugin',
'rpc_db' => 'RPC_Db',
'rpc_console' => 'RPC_Console',
'rpc_session' => 'RPC_Session',
'rpc_auth' => 'RPC_Auth',
'rpc_job' => 'RPC_Job',
'rpc_core' => 'RPC_Core',
'rpc_health' => 'RPC_Health',
'rpc_module' => 'RPC_Module',
'cli' => 'CLI',
'sqlitei' => 'SQLitei',
'mysqli' => 'MySQLi',
'postgresqli' => 'PostgreSQLi',
'ssh' => 'SSH',
'winrm' => 'WinRM',
'smb' => 'SMB',
'uris' => 'URIs',
'jboss' => 'JBoss',
'send_uuid_x64' => 'SendUUID_x64',
'reverse_tcp_x64' => 'ReverseTcp_x64',
'block_api_x64' => 'BlockApi_x64',
'exitfunk_x64' => 'Exitfunk_x64',
'reverse_http_x64' => 'ReverseHttp_x64',
'rc4_x64' => 'Rc4_x64',
'bind_tcp_x64' => 'BindTcp_x64',
'reverse_win_http_x64' => 'ReverseWinHttp_x64',
'reflective_dll_inject_x64' => 'ReflectiveDllInject_x64',
'reverse_win_https_x64' => 'ReverseWinHttps_x64',
'reflective_pe_loader_x64' => 'ReflectivePELoader_x64',
'migrate_http_x64' => 'MigrateHttp_x64',
'migrate_common_x64' => 'MigrateCommon_x64',
'migrate_tcp_x64' => 'MigrateTcp_x64',
'migrate_named_pipe_x64' => 'MigrateNamedPipe_x64',
'reverse_named_pipe_x64' => 'ReverseNamedPipe_x64',
'meterpreter_loader_x64' => 'MeterpreterLoader_x64',
'rftransceiver' => 'RFTransceiver',
'dtc' => 'DTC',
'uds' => 'UDS',
'v1_0' => 'V1_0',
'php_include' => 'PHPInclude',
'psexec_ms17_010' => 'Psexec_MS17_010',
'bind_tcp_rc4_x64' => 'BindTcpRc4_x64',
'reverse_tcp_rc4_x64' => 'ReverseTcpRc4_x64',
'reverse_https_x64' => 'ReverseHttps_x64',
'bind_named_pipe_x64' => 'BindNamedPipe_x64',
'addr_loader' => 'AddrLoader_x64',
'db_manager_proxy' => 'DBManagerProxy',
'wmap_scan_ssl' => 'WmapScanSSL',
'http_db_manager_service' => 'HttpDBManagerService',
'vyos' => 'VYOS',
'windows_constants' => 'Windows_Constants',
'tty' => 'TTY',
'meterpreter_java' => 'Meterpreter_Java_Java',
'meterpreter_android' => 'Meterpreter_Java_Android',
'meterpreter_zarch_linux' => 'Meterpreter_zarch_Linux',
'meterpreter_python' => 'Meterpreter_Python_Python',
'meterpreter_ppce500v2_linux' => 'Meterpreter_ppce500v2_Linux',
'meterpreter_x86_osx' => 'Meterpreter_x86_OSX',
'meterpreter_armbe_linux' => 'Meterpreter_armbe_Linux',
'meterpreter_ppc64le_linux' => 'Meterpreter_ppc64le_Linux',
'meterpreter_x64_linux' => 'Meterpreter_x64_Linux',
'meterpreter_armle_linux' => 'Meterpreter_armle_Linux',
'meterpreter_aarch64_linux' => 'Meterpreter_aarch64_Linux',
'meterpreter_x86_win' => 'Meterpreter_x86_Win',
'meterpreter_armle_apple_ios' => 'Meterpreter_armle_Apple_iOS',
'meterpreter_mipsle_linux' => 'Meterpreter_mipsle_Linux',
'meterpreter_x86_bsd' => 'Meterpreter_x86_BSD',
'meterpreter_mips64_linux' => 'Meterpreter_mips64_Linux',
'meterpreter_x86_linux' => 'Meterpreter_x86_Linux',
'meterpreter_mipsbe_linux' => 'Meterpreter_mipsbe_Linux',
'meterpreter_aarch64_apple_ios' => 'Meterpreter_aarch64_Apple_iOS',
'meterpreter_x64_osx' => 'Meterpreter_x64_OSX',
'meterpreter_ppc_linux' => 'Meterpreter_ppc_Linux',
'meterpreter_x64_win' => 'Meterpreter_x64_Win',
'meterpreter_php' => 'Meterpreter_Php_Php',
'meterpreter_multi' => 'Meterpreter_Multi',
'hwbridge' => 'HWBridge',
'vncinject_options' => 'VncInjectOptions',
'vncinject' => 'VncInject',
'json_hash_file' => 'JSONHashFile',
'jwt' => 'JWT',
'ndr' => 'NDR',
'ci_document' => 'CIDocument',
'fusionvm_document' => 'FusionVMDocument',
'group_policy_preferences' => 'GPP',
'ip360_aspl_xml' => 'IP360ASPLXMLStreamParser',
'ip360_xml' => 'IP360XMLStreamParser',
'nessus_xml' => 'NessusXMLStreamParser',
'netsparker_xml' => 'NetSparkerXMLStreamParser',
'nexpose_xml' => 'NexposeXMLStreamParser',
'nmap_xml' => 'NmapXMLStreamParser',
'openvas_document' => 'OpenVASDocument',
'retina_xml' => 'RetinaXMLStreamParser',
'graphml' => 'GraphML',
'apple_backup_manifestdb' => 'AppleBackupManifestDB',
'winscp' => 'WinSCP',
'acpp' => 'ACPP',
'tftp' => 'TFTP',
'ipmi' => 'IPMI',
'channel_auth_reply' => 'Channel_Auth_Reply',
'open_session_reply' => 'Open_Session_Reply',
'rakp2' => 'RAKP2',
'pjl' => 'PJL',
'dhcp' => 'DHCP',
'addp' => 'ADDP',
'rfb' => 'RFB',
'io' => 'IO',
'ntfs' => 'NTFS',
'bitlocker' => 'BITLOCKER',
'adb' => 'ADB',
'drda' => 'DRDA',
'tlv' => 'TLV',
'svcctl' => 'SVCCTL',
'wdscp' => 'WDSCP',
'appapi' => 'AppApi',
'uds_errors' => 'UDSErrors',
'smb_hash_capture' => 'SMBHashCapture',
}
end
def config_paths
[
{ path: "#{__dir__}/msf/", namespace: Msf },
{ path: "#{__dir__}/rex/", namespace: Rex },
]
end
# Enables :prepend to inject existing loader
def create_loader
Zeitwerk::Loader.new
end
# Enables :prepend to override the configuration items pass to the loader
def configure(loader)
config_paths.each do |entry|
if entry[:namespace]
loader.push_dir(entry[:path], namespace: entry[:namespace])
else
loader.push_dir(entry[:path])
end
end
loader.ignore(ignore_list)
loader.collapse(collapse_list)
loader.inflector = TempInflector.new
loader.inflector.inflect(custom_inflections)
end
# Enables :prepend to suppress the loader finalization
def finalize_loader(loader)
loader.setup # ready!
end
end
# global autoload of common gems
autoload :Faker, 'faker'
autoload :BinData, 'bindata'
autoload :RubySMB, 'ruby_smb'
require 'rexml/document'