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