librex 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rex/LICENSE +29 -0
- data/lib/rex/arch.rb +103 -0
- data/lib/rex/arch/sparc.rb +75 -0
- data/lib/rex/arch/sparc.rb.ut.rb +18 -0
- data/lib/rex/arch/x86.rb +513 -0
- data/lib/rex/arch/x86.rb.ut.rb +93 -0
- data/lib/rex/assembly/nasm.rb +104 -0
- data/lib/rex/assembly/nasm.rb.ut.rb +22 -0
- data/lib/rex/codepage.map +104 -0
- data/lib/rex/compat.rb +311 -0
- data/lib/rex/constants.rb +113 -0
- data/lib/rex/elfparsey.rb +11 -0
- data/lib/rex/elfparsey/elf.rb +123 -0
- data/lib/rex/elfparsey/elfbase.rb +258 -0
- data/lib/rex/elfparsey/exceptions.rb +27 -0
- data/lib/rex/elfscan.rb +12 -0
- data/lib/rex/elfscan/scanner.rb +207 -0
- data/lib/rex/elfscan/search.rb +46 -0
- data/lib/rex/encoder/alpha2.rb +31 -0
- data/lib/rex/encoder/alpha2/alpha_mixed.rb +68 -0
- data/lib/rex/encoder/alpha2/alpha_upper.rb +79 -0
- data/lib/rex/encoder/alpha2/generic.rb +114 -0
- data/lib/rex/encoder/alpha2/unicode_mixed.rb +117 -0
- data/lib/rex/encoder/alpha2/unicode_upper.rb +129 -0
- data/lib/rex/encoder/ndr.rb +89 -0
- data/lib/rex/encoder/ndr.rb.ut.rb +44 -0
- data/lib/rex/encoder/nonalpha.rb +61 -0
- data/lib/rex/encoder/nonupper.rb +64 -0
- data/lib/rex/encoder/xdr.rb +106 -0
- data/lib/rex/encoder/xdr.rb.ut.rb +29 -0
- data/lib/rex/encoder/xor.rb +69 -0
- data/lib/rex/encoder/xor/dword.rb +13 -0
- data/lib/rex/encoder/xor/dword_additive.rb +13 -0
- data/lib/rex/encoders/xor_dword.rb +35 -0
- data/lib/rex/encoders/xor_dword_additive.rb +53 -0
- data/lib/rex/encoders/xor_dword_additive.rb.ut.rb +12 -0
- data/lib/rex/encoding/xor.rb +20 -0
- data/lib/rex/encoding/xor.rb.ts.rb +14 -0
- data/lib/rex/encoding/xor/byte.rb +15 -0
- data/lib/rex/encoding/xor/byte.rb.ut.rb +21 -0
- data/lib/rex/encoding/xor/dword.rb +21 -0
- data/lib/rex/encoding/xor/dword.rb.ut.rb +15 -0
- data/lib/rex/encoding/xor/dword_additive.rb +92 -0
- data/lib/rex/encoding/xor/dword_additive.rb.ut.rb +15 -0
- data/lib/rex/encoding/xor/exceptions.rb +17 -0
- data/lib/rex/encoding/xor/generic.rb +146 -0
- data/lib/rex/encoding/xor/generic.rb.ut.rb +120 -0
- data/lib/rex/encoding/xor/qword.rb +15 -0
- data/lib/rex/encoding/xor/word.rb +21 -0
- data/lib/rex/encoding/xor/word.rb.ut.rb +13 -0
- data/lib/rex/exceptions.rb +275 -0
- data/lib/rex/exceptions.rb.ut.rb +44 -0
- data/lib/rex/exploitation/cmdstager.rb +9 -0
- data/lib/rex/exploitation/cmdstager/base.rb +175 -0
- data/lib/rex/exploitation/cmdstager/debug_asm.rb +142 -0
- data/lib/rex/exploitation/cmdstager/debug_write.rb +136 -0
- data/lib/rex/exploitation/cmdstager/tftp.rb +63 -0
- data/lib/rex/exploitation/cmdstager/vbs.rb +128 -0
- data/lib/rex/exploitation/egghunter.rb +277 -0
- data/lib/rex/exploitation/egghunter.rb.ut.rb +25 -0
- data/lib/rex/exploitation/encryptjs.rb +77 -0
- data/lib/rex/exploitation/heaplib.js.b64 +331 -0
- data/lib/rex/exploitation/heaplib.rb +94 -0
- data/lib/rex/exploitation/javascriptosdetect.rb +897 -0
- data/lib/rex/exploitation/obfuscatejs.rb +335 -0
- data/lib/rex/exploitation/omelet.rb +320 -0
- data/lib/rex/exploitation/omelet.rb.ut.rb +13 -0
- data/lib/rex/exploitation/opcodedb.rb +818 -0
- data/lib/rex/exploitation/opcodedb.rb.ut.rb +279 -0
- data/lib/rex/exploitation/seh.rb +92 -0
- data/lib/rex/exploitation/seh.rb.ut.rb +19 -0
- data/lib/rex/file.rb +112 -0
- data/lib/rex/file.rb.ut.rb +16 -0
- data/lib/rex/image_source.rb +12 -0
- data/lib/rex/image_source/disk.rb +60 -0
- data/lib/rex/image_source/image_source.rb +46 -0
- data/lib/rex/image_source/memory.rb +37 -0
- data/lib/rex/io/bidirectional_pipe.rb +157 -0
- data/lib/rex/io/datagram_abstraction.rb +35 -0
- data/lib/rex/io/ring_buffer.rb +364 -0
- data/lib/rex/io/stream.rb +319 -0
- data/lib/rex/io/stream_abstraction.rb +197 -0
- data/lib/rex/io/stream_server.rb +211 -0
- data/lib/rex/job_container.rb +187 -0
- data/lib/rex/logging.rb +4 -0
- data/lib/rex/logging/log_dispatcher.rb +179 -0
- data/lib/rex/logging/log_sink.rb +42 -0
- data/lib/rex/logging/sinks/flatfile.rb +55 -0
- data/lib/rex/logging/sinks/stderr.rb +43 -0
- data/lib/rex/machparsey.rb +9 -0
- data/lib/rex/machparsey/exceptions.rb +34 -0
- data/lib/rex/machparsey/mach.rb +209 -0
- data/lib/rex/machparsey/machbase.rb +408 -0
- data/lib/rex/machscan.rb +9 -0
- data/lib/rex/machscan/scanner.rb +217 -0
- data/lib/rex/mime.rb +9 -0
- data/lib/rex/mime/header.rb +77 -0
- data/lib/rex/mime/message.rb +144 -0
- data/lib/rex/mime/part.rb +20 -0
- data/lib/rex/nop/opty2.rb +108 -0
- data/lib/rex/nop/opty2.rb.ut.rb +23 -0
- data/lib/rex/nop/opty2_tables.rb +300 -0
- data/lib/rex/ole.rb +205 -0
- data/lib/rex/ole/clsid.rb +47 -0
- data/lib/rex/ole/difat.rb +141 -0
- data/lib/rex/ole/directory.rb +231 -0
- data/lib/rex/ole/direntry.rb +240 -0
- data/lib/rex/ole/docs/dependencies.txt +8 -0
- data/lib/rex/ole/docs/references.txt +1 -0
- data/lib/rex/ole/fat.rb +99 -0
- data/lib/rex/ole/header.rb +204 -0
- data/lib/rex/ole/minifat.rb +77 -0
- data/lib/rex/ole/propset.rb +144 -0
- data/lib/rex/ole/samples/create_ole.rb +27 -0
- data/lib/rex/ole/samples/dir.rb +35 -0
- data/lib/rex/ole/samples/dump_stream.rb +34 -0
- data/lib/rex/ole/samples/ole_info.rb +23 -0
- data/lib/rex/ole/storage.rb +395 -0
- data/lib/rex/ole/stream.rb +53 -0
- data/lib/rex/ole/substorage.rb +49 -0
- data/lib/rex/ole/util.rb +157 -0
- data/lib/rex/parser/arguments.rb +97 -0
- data/lib/rex/parser/arguments.rb.ut.rb +67 -0
- data/lib/rex/parser/ini.rb +185 -0
- data/lib/rex/parser/ini.rb.ut.rb +29 -0
- data/lib/rex/parser/ip360_aspl_xml.rb +102 -0
- data/lib/rex/parser/ip360_xml.rb +97 -0
- data/lib/rex/parser/nessus_xml.rb +118 -0
- data/lib/rex/parser/netsparker_xml.rb +94 -0
- data/lib/rex/parser/nexpose_xml.rb +136 -0
- data/lib/rex/parser/nmap_xml.rb +137 -0
- data/lib/rex/parser/retina_xml.rb +109 -0
- data/lib/rex/payloads.rb +1 -0
- data/lib/rex/payloads/win32.rb +2 -0
- data/lib/rex/payloads/win32/common.rb +26 -0
- data/lib/rex/payloads/win32/kernel.rb +53 -0
- data/lib/rex/payloads/win32/kernel/common.rb +54 -0
- data/lib/rex/payloads/win32/kernel/migration.rb +12 -0
- data/lib/rex/payloads/win32/kernel/recovery.rb +50 -0
- data/lib/rex/payloads/win32/kernel/stager.rb +194 -0
- data/lib/rex/peparsey.rb +12 -0
- data/lib/rex/peparsey/exceptions.rb +32 -0
- data/lib/rex/peparsey/pe.rb +212 -0
- data/lib/rex/peparsey/pe_memdump.rb +63 -0
- data/lib/rex/peparsey/pebase.rb +1680 -0
- data/lib/rex/peparsey/section.rb +136 -0
- data/lib/rex/pescan.rb +13 -0
- data/lib/rex/pescan/analyze.rb +309 -0
- data/lib/rex/pescan/scanner.rb +206 -0
- data/lib/rex/pescan/search.rb +56 -0
- data/lib/rex/platforms.rb +1 -0
- data/lib/rex/platforms/windows.rb +51 -0
- data/lib/rex/poly.rb +132 -0
- data/lib/rex/poly/block.rb +477 -0
- data/lib/rex/poly/register.rb +100 -0
- data/lib/rex/poly/register/x86.rb +40 -0
- data/lib/rex/post.rb +8 -0
- data/lib/rex/post/dir.rb +51 -0
- data/lib/rex/post/file.rb +172 -0
- data/lib/rex/post/file_stat.rb +220 -0
- data/lib/rex/post/gen.pl +13 -0
- data/lib/rex/post/io.rb +182 -0
- data/lib/rex/post/meterpreter.rb +4 -0
- data/lib/rex/post/meterpreter/channel.rb +445 -0
- data/lib/rex/post/meterpreter/channel_container.rb +54 -0
- data/lib/rex/post/meterpreter/channels/pool.rb +160 -0
- data/lib/rex/post/meterpreter/channels/pools/file.rb +62 -0
- data/lib/rex/post/meterpreter/channels/pools/stream_pool.rb +103 -0
- data/lib/rex/post/meterpreter/channels/stream.rb +87 -0
- data/lib/rex/post/meterpreter/client.rb +364 -0
- data/lib/rex/post/meterpreter/client_core.rb +274 -0
- data/lib/rex/post/meterpreter/dependencies.rb +3 -0
- data/lib/rex/post/meterpreter/extension.rb +32 -0
- data/lib/rex/post/meterpreter/extensions/espia/espia.rb +58 -0
- data/lib/rex/post/meterpreter/extensions/espia/tlv.rb +16 -0
- data/lib/rex/post/meterpreter/extensions/incognito/incognito.rb +94 -0
- data/lib/rex/post/meterpreter/extensions/incognito/tlv.rb +21 -0
- data/lib/rex/post/meterpreter/extensions/networkpug/networkpug.rb +57 -0
- data/lib/rex/post/meterpreter/extensions/networkpug/tlv.rb +15 -0
- data/lib/rex/post/meterpreter/extensions/priv/fs.rb +118 -0
- data/lib/rex/post/meterpreter/extensions/priv/passwd.rb +61 -0
- data/lib/rex/post/meterpreter/extensions/priv/priv.rb +111 -0
- data/lib/rex/post/meterpreter/extensions/priv/tlv.rb +28 -0
- data/lib/rex/post/meterpreter/extensions/sniffer/sniffer.rb +101 -0
- data/lib/rex/post/meterpreter/extensions/sniffer/tlv.rb +26 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/constants.rb +333 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/fs/dir.rb +282 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb +266 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/fs/file_stat.rb +103 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/fs/io.rb +48 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/net/config.rb +144 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/net/interface.rb +73 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/net/route.rb +56 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/net/socket.rb +137 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/net/socket_subsystem/tcp_client_channel.rb +180 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/net/socket_subsystem/tcp_server_channel.rb +167 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/net/socket_subsystem/udp_channel.rb +208 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun.rb.ts.rb +6 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/api_constants.rb +38106 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/api_constants.rb.ut.rb +31 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/buffer_item.rb +47 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/buffer_item.rb.ut.rb +36 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_advapi32.rb +1818 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_iphlpapi.rb +96 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_kernel32.rb +3848 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_netapi32.rb +26 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_ntdll.rb +153 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_shell32.rb +21 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_user32.rb +3169 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_ws2_32.rb +599 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/dll.rb +318 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/dll_function.rb +100 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/dll_function.rb.ut.rb +42 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/dll_helper.rb +148 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/dll_helper.rb.ut.rb +127 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/multicall.rb +309 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/railgun.rb +204 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/tlv.rb +51 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/util.rb +630 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb +75 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb.ut.rb +103 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/stdapi.rb +149 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/config.rb +97 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/event_log.rb +192 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/event_log_subsystem/event_record.rb +41 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/power.rb +61 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/process.rb +370 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/image.rb +129 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/io.rb +55 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/memory.rb +336 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/thread.rb +141 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry.rb +279 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb +193 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_value.rb +102 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/thread.rb +180 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/tlv.rb +211 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/ui.rb +227 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb +63 -0
- data/lib/rex/post/meterpreter/inbound_packet_handler.rb +30 -0
- data/lib/rex/post/meterpreter/object_aliases.rb +83 -0
- data/lib/rex/post/meterpreter/packet.rb +688 -0
- data/lib/rex/post/meterpreter/packet_dispatcher.rb +431 -0
- data/lib/rex/post/meterpreter/packet_parser.rb +94 -0
- data/lib/rex/post/meterpreter/packet_response_waiter.rb +83 -0
- data/lib/rex/post/meterpreter/ui/console.rb +137 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher.rb +62 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb +730 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/espia.rb +108 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/incognito.rb +241 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/networkpug.rb +231 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv.rb +61 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/elevate.rb +98 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/passwd.rb +51 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/timestomp.rb +132 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/sniffer.rb +187 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi.rb +65 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb +442 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/net.rb +298 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb +486 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb +315 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb +157 -0
- data/lib/rex/post/meterpreter/ui/console/interactive_channel.rb +95 -0
- data/lib/rex/post/permission.rb +26 -0
- data/lib/rex/post/process.rb +57 -0
- data/lib/rex/post/thread.rb +57 -0
- data/lib/rex/post/ui.rb +52 -0
- data/lib/rex/proto.rb +13 -0
- data/lib/rex/proto.rb.ts.rb +8 -0
- data/lib/rex/proto/dcerpc.rb +6 -0
- data/lib/rex/proto/dcerpc.rb.ts.rb +9 -0
- data/lib/rex/proto/dcerpc/client.rb +361 -0
- data/lib/rex/proto/dcerpc/client.rb.ut.rb +491 -0
- data/lib/rex/proto/dcerpc/exceptions.rb +150 -0
- data/lib/rex/proto/dcerpc/handle.rb +47 -0
- data/lib/rex/proto/dcerpc/handle.rb.ut.rb +85 -0
- data/lib/rex/proto/dcerpc/ndr.rb +72 -0
- data/lib/rex/proto/dcerpc/ndr.rb.ut.rb +41 -0
- data/lib/rex/proto/dcerpc/packet.rb +253 -0
- data/lib/rex/proto/dcerpc/packet.rb.ut.rb +56 -0
- data/lib/rex/proto/dcerpc/response.rb +187 -0
- data/lib/rex/proto/dcerpc/response.rb.ut.rb +15 -0
- data/lib/rex/proto/dcerpc/uuid.rb +84 -0
- data/lib/rex/proto/dcerpc/uuid.rb.ut.rb +46 -0
- data/lib/rex/proto/dhcp.rb +7 -0
- data/lib/rex/proto/dhcp/constants.rb +33 -0
- data/lib/rex/proto/dhcp/server.rb +292 -0
- data/lib/rex/proto/drda.rb +5 -0
- data/lib/rex/proto/drda.rb.ts.rb +17 -0
- data/lib/rex/proto/drda/constants.rb +49 -0
- data/lib/rex/proto/drda/constants.rb.ut.rb +23 -0
- data/lib/rex/proto/drda/packet.rb +252 -0
- data/lib/rex/proto/drda/packet.rb.ut.rb +109 -0
- data/lib/rex/proto/drda/utils.rb +123 -0
- data/lib/rex/proto/drda/utils.rb.ut.rb +84 -0
- data/lib/rex/proto/http.rb +5 -0
- data/lib/rex/proto/http.rb.ts.rb +12 -0
- data/lib/rex/proto/http/client.rb +821 -0
- data/lib/rex/proto/http/client.rb.ut.rb +95 -0
- data/lib/rex/proto/http/handler.rb +46 -0
- data/lib/rex/proto/http/handler/erb.rb +128 -0
- data/lib/rex/proto/http/handler/erb.rb.ut.rb +21 -0
- data/lib/rex/proto/http/handler/erb.rb.ut.rb.rhtml +1 -0
- data/lib/rex/proto/http/handler/proc.rb +60 -0
- data/lib/rex/proto/http/handler/proc.rb.ut.rb +24 -0
- data/lib/rex/proto/http/header.rb +161 -0
- data/lib/rex/proto/http/header.rb.ut.rb +46 -0
- data/lib/rex/proto/http/packet.rb +407 -0
- data/lib/rex/proto/http/packet.rb.ut.rb +165 -0
- data/lib/rex/proto/http/request.rb +356 -0
- data/lib/rex/proto/http/request.rb.ut.rb +214 -0
- data/lib/rex/proto/http/response.rb +90 -0
- data/lib/rex/proto/http/response.rb.ut.rb +149 -0
- data/lib/rex/proto/http/server.rb +369 -0
- data/lib/rex/proto/http/server.rb.ut.rb +79 -0
- data/lib/rex/proto/ntlm.rb +7 -0
- data/lib/rex/proto/ntlm.rb.ut.rb +177 -0
- data/lib/rex/proto/ntlm/base.rb +326 -0
- data/lib/rex/proto/ntlm/constants.rb +74 -0
- data/lib/rex/proto/ntlm/crypt.rb +415 -0
- data/lib/rex/proto/ntlm/exceptions.rb +16 -0
- data/lib/rex/proto/ntlm/message.rb +536 -0
- data/lib/rex/proto/ntlm/utils.rb +764 -0
- data/lib/rex/proto/proxy/socks4a.rb +440 -0
- data/lib/rex/proto/rfb.rb +19 -0
- data/lib/rex/proto/rfb.rb.ut.rb +37 -0
- data/lib/rex/proto/rfb/cipher.rb +84 -0
- data/lib/rex/proto/rfb/client.rb +207 -0
- data/lib/rex/proto/rfb/constants.rb +52 -0
- data/lib/rex/proto/smb.rb +7 -0
- data/lib/rex/proto/smb.rb.ts.rb +8 -0
- data/lib/rex/proto/smb/client.rb +1952 -0
- data/lib/rex/proto/smb/client.rb.ut.rb +223 -0
- data/lib/rex/proto/smb/constants.rb +1047 -0
- data/lib/rex/proto/smb/constants.rb.ut.rb +18 -0
- data/lib/rex/proto/smb/crypt.rb +36 -0
- data/lib/rex/proto/smb/evasions.rb +66 -0
- data/lib/rex/proto/smb/exceptions.rb +858 -0
- data/lib/rex/proto/smb/simpleclient.rb +306 -0
- data/lib/rex/proto/smb/simpleclient.rb.ut.rb +128 -0
- data/lib/rex/proto/smb/utils.rb +103 -0
- data/lib/rex/proto/smb/utils.rb.ut.rb +20 -0
- data/lib/rex/proto/sunrpc.rb +1 -0
- data/lib/rex/proto/sunrpc/client.rb +195 -0
- data/lib/rex/proto/tftp.rb +12 -0
- data/lib/rex/proto/tftp/constants.rb +39 -0
- data/lib/rex/proto/tftp/server.rb +497 -0
- data/lib/rex/proto/tftp/server.rb.ut.rb +28 -0
- data/lib/rex/script.rb +42 -0
- data/lib/rex/script/base.rb +59 -0
- data/lib/rex/script/meterpreter.rb +15 -0
- data/lib/rex/script/shell.rb +9 -0
- data/lib/rex/service.rb +48 -0
- data/lib/rex/service_manager.rb +141 -0
- data/lib/rex/service_manager.rb.ut.rb +32 -0
- data/lib/rex/services/local_relay.rb +423 -0
- data/lib/rex/socket.rb +684 -0
- data/lib/rex/socket.rb.ut.rb +107 -0
- data/lib/rex/socket/comm.rb +119 -0
- data/lib/rex/socket/comm/local.rb +412 -0
- data/lib/rex/socket/comm/local.rb.ut.rb +75 -0
- data/lib/rex/socket/ip.rb +130 -0
- data/lib/rex/socket/parameters.rb +345 -0
- data/lib/rex/socket/parameters.rb.ut.rb +51 -0
- data/lib/rex/socket/range_walker.rb +346 -0
- data/lib/rex/socket/range_walker.rb.ut.rb +55 -0
- data/lib/rex/socket/ssl_tcp.rb +184 -0
- data/lib/rex/socket/ssl_tcp.rb.ut.rb +39 -0
- data/lib/rex/socket/ssl_tcp_server.rb +122 -0
- data/lib/rex/socket/ssl_tcp_server.rb.ut.rb +61 -0
- data/lib/rex/socket/subnet_walker.rb +75 -0
- data/lib/rex/socket/subnet_walker.rb.ut.rb +28 -0
- data/lib/rex/socket/switch_board.rb +278 -0
- data/lib/rex/socket/switch_board.rb.ut.rb +52 -0
- data/lib/rex/socket/tcp.rb +76 -0
- data/lib/rex/socket/tcp.rb.ut.rb +64 -0
- data/lib/rex/socket/tcp_server.rb +66 -0
- data/lib/rex/socket/tcp_server.rb.ut.rb +44 -0
- data/lib/rex/socket/udp.rb +164 -0
- data/lib/rex/socket/udp.rb.ut.rb +44 -0
- data/lib/rex/struct2.rb +5 -0
- data/lib/rex/struct2/c_struct.rb +181 -0
- data/lib/rex/struct2/c_struct_template.rb +39 -0
- data/lib/rex/struct2/constant.rb +26 -0
- data/lib/rex/struct2/element.rb +44 -0
- data/lib/rex/struct2/generic.rb +73 -0
- data/lib/rex/struct2/restraint.rb +54 -0
- data/lib/rex/struct2/s_string.rb +72 -0
- data/lib/rex/struct2/s_struct.rb +111 -0
- data/lib/rex/sync.rb +6 -0
- data/lib/rex/sync/event.rb +94 -0
- data/lib/rex/sync/read_write_lock.rb +176 -0
- data/lib/rex/sync/ref.rb +57 -0
- data/lib/rex/sync/thread_safe.rb +82 -0
- data/lib/rex/test.rb +35 -0
- data/lib/rex/text.rb +1163 -0
- data/lib/rex/text.rb.ut.rb +190 -0
- data/lib/rex/thread_factory.rb +42 -0
- data/lib/rex/time.rb +65 -0
- data/lib/rex/transformer.rb +115 -0
- data/lib/rex/transformer.rb.ut.rb +38 -0
- data/lib/rex/ui.rb +21 -0
- data/lib/rex/ui/interactive.rb +298 -0
- data/lib/rex/ui/output.rb +78 -0
- data/lib/rex/ui/output/none.rb +18 -0
- data/lib/rex/ui/progress_tracker.rb +96 -0
- data/lib/rex/ui/subscriber.rb +149 -0
- data/lib/rex/ui/text/color.rb +97 -0
- data/lib/rex/ui/text/color.rb.ut.rb +18 -0
- data/lib/rex/ui/text/dispatcher_shell.rb +467 -0
- data/lib/rex/ui/text/input.rb +117 -0
- data/lib/rex/ui/text/input/buffer.rb +75 -0
- data/lib/rex/ui/text/input/readline.rb +129 -0
- data/lib/rex/ui/text/input/socket.rb +95 -0
- data/lib/rex/ui/text/input/stdio.rb +45 -0
- data/lib/rex/ui/text/irb_shell.rb +57 -0
- data/lib/rex/ui/text/output.rb +80 -0
- data/lib/rex/ui/text/output/buffer.rb +61 -0
- data/lib/rex/ui/text/output/file.rb +43 -0
- data/lib/rex/ui/text/output/socket.rb +43 -0
- data/lib/rex/ui/text/output/stdio.rb +40 -0
- data/lib/rex/ui/text/progress_tracker.rb +56 -0
- data/lib/rex/ui/text/progress_tracker.rb.ut.rb +34 -0
- data/lib/rex/ui/text/shell.rb +328 -0
- data/lib/rex/ui/text/table.rb +279 -0
- data/lib/rex/ui/text/table.rb.ut.rb +55 -0
- data/lib/rex/zip.rb +93 -0
- data/lib/rex/zip/archive.rb +184 -0
- data/lib/rex/zip/blocks.rb +182 -0
- data/lib/rex/zip/entry.rb +104 -0
- data/lib/rex/zip/samples/comment.rb +32 -0
- data/lib/rex/zip/samples/mkwar.rb +138 -0
- data/lib/rex/zip/samples/mkzip.rb +19 -0
- data/lib/rex/zip/samples/recursive.rb +58 -0
- metadata +434 -1
@@ -0,0 +1,227 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rex/post/ui'
|
4
|
+
|
5
|
+
module Rex
|
6
|
+
module Post
|
7
|
+
module Meterpreter
|
8
|
+
module Extensions
|
9
|
+
module Stdapi
|
10
|
+
|
11
|
+
###
|
12
|
+
#
|
13
|
+
# Allows for interacting with the user interface on the remote machine,
|
14
|
+
# such as by disabling the keyboard and mouse.
|
15
|
+
#
|
16
|
+
# WARNING:
|
17
|
+
#
|
18
|
+
# Using keyboard and mouse enabling/disabling features will result in
|
19
|
+
# a DLL file being written to disk.
|
20
|
+
#
|
21
|
+
###
|
22
|
+
class UI < Rex::Post::UI
|
23
|
+
|
24
|
+
include Rex::Post::Meterpreter::ObjectAliasesContainer
|
25
|
+
|
26
|
+
##
|
27
|
+
#
|
28
|
+
# Constructor
|
29
|
+
#
|
30
|
+
##
|
31
|
+
|
32
|
+
#
|
33
|
+
# Initializes the post-exploitation user-interface manipulation subsystem.
|
34
|
+
#
|
35
|
+
def initialize(client)
|
36
|
+
self.client = client
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
#
|
41
|
+
# Device enabling/disabling
|
42
|
+
#
|
43
|
+
##
|
44
|
+
|
45
|
+
#
|
46
|
+
# Disable keyboard input on the remote machine.
|
47
|
+
#
|
48
|
+
def disable_keyboard
|
49
|
+
return enable_keyboard(false)
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# Enable keyboard input on the remote machine.
|
54
|
+
#
|
55
|
+
def enable_keyboard(enable = true)
|
56
|
+
request = Packet.create_request('stdapi_ui_enable_keyboard')
|
57
|
+
|
58
|
+
request.add_tlv(TLV_TYPE_BOOL, enable)
|
59
|
+
|
60
|
+
response = client.send_request(request)
|
61
|
+
|
62
|
+
return true
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# Disable mouse input on the remote machine.
|
67
|
+
#
|
68
|
+
def disable_mouse
|
69
|
+
return enable_mouse(false)
|
70
|
+
end
|
71
|
+
|
72
|
+
#
|
73
|
+
# Enable mouse input on the remote machine.
|
74
|
+
#
|
75
|
+
def enable_mouse(enable = true)
|
76
|
+
request = Packet.create_request('stdapi_ui_enable_mouse')
|
77
|
+
|
78
|
+
request.add_tlv(TLV_TYPE_BOOL, enable)
|
79
|
+
|
80
|
+
response = client.send_request(request)
|
81
|
+
|
82
|
+
return true
|
83
|
+
end
|
84
|
+
|
85
|
+
#
|
86
|
+
# Returns the number of seconds the remote machine has been idle
|
87
|
+
# from user input.
|
88
|
+
#
|
89
|
+
def idle_time
|
90
|
+
request = Packet.create_request('stdapi_ui_get_idle_time')
|
91
|
+
|
92
|
+
response = client.send_request(request)
|
93
|
+
|
94
|
+
return response.get_tlv_value(TLV_TYPE_IDLE_TIME);
|
95
|
+
end
|
96
|
+
|
97
|
+
#
|
98
|
+
# Enumerate desktops.
|
99
|
+
#
|
100
|
+
def enum_desktops
|
101
|
+
request = Packet.create_request('stdapi_ui_desktop_enum')
|
102
|
+
response = client.send_request(request)
|
103
|
+
desktopz = []
|
104
|
+
if( response.result == 0 )
|
105
|
+
response.each( TLV_TYPE_DESKTOP ) { | desktop |
|
106
|
+
desktopz << {
|
107
|
+
'session' => desktop.get_tlv_value( TLV_TYPE_DESKTOP_SESSION ),
|
108
|
+
'station' => desktop.get_tlv_value( TLV_TYPE_DESKTOP_STATION ),
|
109
|
+
'name' => desktop.get_tlv_value( TLV_TYPE_DESKTOP_NAME )
|
110
|
+
}
|
111
|
+
}
|
112
|
+
end
|
113
|
+
return desktopz
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# Get the current desktop meterpreter is using.
|
118
|
+
#
|
119
|
+
def get_desktop
|
120
|
+
request = Packet.create_request( 'stdapi_ui_desktop_get' )
|
121
|
+
response = client.send_request( request )
|
122
|
+
desktop = {}
|
123
|
+
if( response.result == 0 )
|
124
|
+
desktop = {
|
125
|
+
'session' => response.get_tlv_value( TLV_TYPE_DESKTOP_SESSION ),
|
126
|
+
'station' => response.get_tlv_value( TLV_TYPE_DESKTOP_STATION ),
|
127
|
+
'name' => response.get_tlv_value( TLV_TYPE_DESKTOP_NAME )
|
128
|
+
}
|
129
|
+
end
|
130
|
+
return desktop
|
131
|
+
end
|
132
|
+
|
133
|
+
#
|
134
|
+
# Change the meterpreters current desktop. The switch param sets this
|
135
|
+
# new desktop as the interactive one (The local users visible desktop
|
136
|
+
# with screen/keyboard/mouse control).
|
137
|
+
#
|
138
|
+
def set_desktop( session=-1, station='WinSta0', name='Default', switch=false )
|
139
|
+
request = Packet.create_request( 'stdapi_ui_desktop_set' )
|
140
|
+
request.add_tlv( TLV_TYPE_DESKTOP_SESSION, session )
|
141
|
+
request.add_tlv( TLV_TYPE_DESKTOP_STATION, station )
|
142
|
+
request.add_tlv( TLV_TYPE_DESKTOP_NAME, name )
|
143
|
+
request.add_tlv( TLV_TYPE_DESKTOP_SWITCH, switch )
|
144
|
+
response = client.send_request( request )
|
145
|
+
if( response.result == 0 )
|
146
|
+
return true
|
147
|
+
end
|
148
|
+
return false
|
149
|
+
end
|
150
|
+
|
151
|
+
#
|
152
|
+
# Grab a screenshot of the interactive desktop
|
153
|
+
#
|
154
|
+
def screenshot( quality=50 )
|
155
|
+
request = Packet.create_request( 'stdapi_ui_desktop_screenshot' )
|
156
|
+
request.add_tlv( TLV_TYPE_DESKTOP_SCREENSHOT_QUALITY, quality )
|
157
|
+
# include the x64 screenshot dll if the host OS is x64
|
158
|
+
if( client.sys.config.sysinfo['Architecture'] =~ /^\S*x64\S*/ )
|
159
|
+
screenshot_path = ::File.join( Msf::Config.install_root, 'data', 'meterpreter', 'screenshot.x64.dll' )
|
160
|
+
screenshot_path = ::File.expand_path( screenshot_path )
|
161
|
+
screenshot_dll = ''
|
162
|
+
::File.open( screenshot_path, 'rb' ) do |f|
|
163
|
+
screenshot_dll += f.read( f.stat.size )
|
164
|
+
end
|
165
|
+
request.add_tlv( TLV_TYPE_DESKTOP_SCREENSHOT_PE64DLL_BUFFER, screenshot_dll, false, true )
|
166
|
+
request.add_tlv( TLV_TYPE_DESKTOP_SCREENSHOT_PE64DLL_LENGTH, screenshot_dll.length )
|
167
|
+
end
|
168
|
+
# but allways include the x86 screenshot dll as we can use it for wow64 processes if we are on x64
|
169
|
+
screenshot_path = ::File.join( Msf::Config.install_root, 'data', 'meterpreter', 'screenshot.dll' )
|
170
|
+
screenshot_path = ::File.expand_path( screenshot_path )
|
171
|
+
screenshot_dll = ''
|
172
|
+
::File.open( screenshot_path, 'rb' ) do |f|
|
173
|
+
screenshot_dll += f.read( f.stat.size )
|
174
|
+
end
|
175
|
+
request.add_tlv( TLV_TYPE_DESKTOP_SCREENSHOT_PE32DLL_BUFFER, screenshot_dll, false, true )
|
176
|
+
request.add_tlv( TLV_TYPE_DESKTOP_SCREENSHOT_PE32DLL_LENGTH, screenshot_dll.length )
|
177
|
+
# send the request and return the jpeg image if successfull.
|
178
|
+
response = client.send_request( request )
|
179
|
+
if( response.result == 0 )
|
180
|
+
return response.get_tlv_value( TLV_TYPE_DESKTOP_SCREENSHOT )
|
181
|
+
end
|
182
|
+
return nil
|
183
|
+
end
|
184
|
+
|
185
|
+
#
|
186
|
+
# Unlock or lock the desktop
|
187
|
+
#
|
188
|
+
def unlock_desktop(unlock=true)
|
189
|
+
request = Packet.create_request('stdapi_ui_unlock_desktop')
|
190
|
+
request.add_tlv(TLV_TYPE_BOOL, unlock)
|
191
|
+
response = client.send_request(request)
|
192
|
+
return true
|
193
|
+
end
|
194
|
+
|
195
|
+
#
|
196
|
+
# Start the keyboard sniffer
|
197
|
+
#
|
198
|
+
def keyscan_start
|
199
|
+
request = Packet.create_request('stdapi_ui_start_keyscan')
|
200
|
+
response = client.send_request(request)
|
201
|
+
return true
|
202
|
+
end
|
203
|
+
|
204
|
+
#
|
205
|
+
# Stop the keyboard sniffer
|
206
|
+
#
|
207
|
+
def keyscan_stop
|
208
|
+
request = Packet.create_request('stdapi_ui_stop_keyscan')
|
209
|
+
response = client.send_request(request)
|
210
|
+
return true
|
211
|
+
end
|
212
|
+
|
213
|
+
#
|
214
|
+
# Dump the keystroke buffer
|
215
|
+
#
|
216
|
+
def keyscan_dump
|
217
|
+
request = Packet.create_request('stdapi_ui_get_keys')
|
218
|
+
response = client.send_request(request)
|
219
|
+
return response.get_tlv_value(TLV_TYPE_KEYS_DUMP);
|
220
|
+
end
|
221
|
+
|
222
|
+
protected
|
223
|
+
attr_accessor :client # :nodoc:
|
224
|
+
|
225
|
+
end
|
226
|
+
|
227
|
+
end; end; end; end; end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
module Rex
|
4
|
+
module Post
|
5
|
+
module Meterpreter
|
6
|
+
module Extensions
|
7
|
+
module Stdapi
|
8
|
+
module Webcam
|
9
|
+
|
10
|
+
###
|
11
|
+
#
|
12
|
+
# This meterpreter extension can list and capture from webcams and/or microphone
|
13
|
+
#
|
14
|
+
###
|
15
|
+
class Webcam
|
16
|
+
|
17
|
+
def initialize(client)
|
18
|
+
@client = client
|
19
|
+
end
|
20
|
+
|
21
|
+
def webcam_list
|
22
|
+
response = client.send_request(Packet.create_request('webcam_list'))
|
23
|
+
names = []
|
24
|
+
response.get_tlvs( TLV_TYPE_WEBCAM_NAME ).each{ |tlv|
|
25
|
+
names << tlv.value
|
26
|
+
}
|
27
|
+
names
|
28
|
+
end
|
29
|
+
|
30
|
+
# Starts recording video from video source of index #{cam}
|
31
|
+
def webcam_start(cam)
|
32
|
+
request = Packet.create_request('webcam_start')
|
33
|
+
request.add_tlv(TLV_TYPE_WEBCAM_INTERFACE_ID, cam)
|
34
|
+
client.send_request(request)
|
35
|
+
true
|
36
|
+
end
|
37
|
+
|
38
|
+
def webcam_get_frame(quality)
|
39
|
+
request = Packet.create_request('webcam_get_frame')
|
40
|
+
request.add_tlv(TLV_TYPE_WEBCAM_QUALITY, quality)
|
41
|
+
response = client.send_request(request)
|
42
|
+
response.get_tlv( TLV_TYPE_WEBCAM_IMAGE ).value
|
43
|
+
end
|
44
|
+
|
45
|
+
def webcam_stop
|
46
|
+
client.send_request( Packet.create_request( 'webcam_stop' ) )
|
47
|
+
true
|
48
|
+
end
|
49
|
+
|
50
|
+
# Record from default audio source for #{duration} seconds;
|
51
|
+
# returns a low-quality wav file
|
52
|
+
def record_mic(duration)
|
53
|
+
request = Packet.create_request('webcam_audio_record')
|
54
|
+
request.add_tlv(TLV_TYPE_AUDIO_DURATION, duration)
|
55
|
+
response = client.send_request(request)
|
56
|
+
response.get_tlv( TLV_TYPE_AUDIO_DATA ).value
|
57
|
+
end
|
58
|
+
|
59
|
+
attr_accessor :client
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end; end; end; end; end; end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
module Rex
|
4
|
+
module Post
|
5
|
+
module Meterpreter
|
6
|
+
|
7
|
+
###
|
8
|
+
#
|
9
|
+
# Mixin that provides stubs for handling inbound packets
|
10
|
+
#
|
11
|
+
###
|
12
|
+
module InboundPacketHandler
|
13
|
+
|
14
|
+
#
|
15
|
+
# Stub request handler that returns false by default.
|
16
|
+
#
|
17
|
+
def request_handler(client, packet)
|
18
|
+
return false
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# Stub response handler that returns false by default.
|
23
|
+
#
|
24
|
+
def response_handler(client, packet)
|
25
|
+
return false
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end; end; end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
module Rex
|
4
|
+
module Post
|
5
|
+
module Meterpreter
|
6
|
+
|
7
|
+
###
|
8
|
+
#
|
9
|
+
# Mixin for classes that wish to have object aliases but do not
|
10
|
+
# really need to inherit from the ObjectAliases class.
|
11
|
+
#
|
12
|
+
###
|
13
|
+
module ObjectAliasesContainer
|
14
|
+
|
15
|
+
#
|
16
|
+
# Initialize the instance's aliases.
|
17
|
+
#
|
18
|
+
def initialize_aliases(aliases = {})
|
19
|
+
self.aliases = aliases
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# Pass-thru aliases.
|
24
|
+
#
|
25
|
+
def method_missing(symbol, *args)
|
26
|
+
self.aliases[symbol.to_s]
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Recursively dumps all of the aliases registered with a class that
|
31
|
+
# is kind_of? ObjectAliases.
|
32
|
+
#
|
33
|
+
def dump_alias_tree(parent_path, current = nil)
|
34
|
+
items = []
|
35
|
+
|
36
|
+
if (current == nil)
|
37
|
+
current = self
|
38
|
+
end
|
39
|
+
|
40
|
+
# If the current object may have object aliases...
|
41
|
+
if (current.kind_of?(Rex::Post::Meterpreter::ObjectAliases))
|
42
|
+
current.aliases.each_key { |x|
|
43
|
+
current_path = parent_path + '.' + x
|
44
|
+
|
45
|
+
items << current_path
|
46
|
+
|
47
|
+
items.concat(dump_alias_tree(current_path,
|
48
|
+
current.aliases[x]))
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
return items
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# The hash of aliases.
|
57
|
+
#
|
58
|
+
attr_accessor :aliases
|
59
|
+
end
|
60
|
+
|
61
|
+
###
|
62
|
+
#
|
63
|
+
# Generic object aliases from a class instance referenced symbol to an
|
64
|
+
# associated object of an arbitrary type
|
65
|
+
#
|
66
|
+
###
|
67
|
+
class ObjectAliases
|
68
|
+
include Rex::Post::Meterpreter::ObjectAliasesContainer
|
69
|
+
|
70
|
+
##
|
71
|
+
#
|
72
|
+
# Constructor
|
73
|
+
#
|
74
|
+
##
|
75
|
+
|
76
|
+
# An instance
|
77
|
+
def initialize(aliases = {})
|
78
|
+
initialize_aliases(aliases)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
end; end; end
|
@@ -0,0 +1,688 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
module Rex
|
4
|
+
module Post
|
5
|
+
module Meterpreter
|
6
|
+
|
7
|
+
#
|
8
|
+
# Constants
|
9
|
+
#
|
10
|
+
PACKET_TYPE_REQUEST = 0
|
11
|
+
PACKET_TYPE_RESPONSE = 1
|
12
|
+
PACKET_TYPE_PLAIN_REQUEST = 10
|
13
|
+
PACKET_TYPE_PLAIN_RESPONSE = 11
|
14
|
+
|
15
|
+
#
|
16
|
+
# TLV Meta Types
|
17
|
+
#
|
18
|
+
TLV_META_TYPE_NONE = 0
|
19
|
+
TLV_META_TYPE_STRING = (1 << 16)
|
20
|
+
TLV_META_TYPE_UINT = (1 << 17)
|
21
|
+
TLV_META_TYPE_RAW = (1 << 18)
|
22
|
+
TLV_META_TYPE_BOOL = (1 << 19)
|
23
|
+
TLV_META_TYPE_QWORD = (1 << 20)
|
24
|
+
TLV_META_TYPE_COMPRESSED = (1 << 29)
|
25
|
+
TLV_META_TYPE_GROUP = (1 << 30)
|
26
|
+
TLV_META_TYPE_COMPLEX = (1 << 31)
|
27
|
+
|
28
|
+
# Exclude compressed from the mask since other meta types (e.g. RAW) can also
|
29
|
+
# be compressed
|
30
|
+
TLV_META_MASK = (
|
31
|
+
TLV_META_TYPE_STRING |
|
32
|
+
TLV_META_TYPE_UINT |
|
33
|
+
TLV_META_TYPE_RAW |
|
34
|
+
TLV_META_TYPE_BOOL |
|
35
|
+
TLV_META_TYPE_QWORD |
|
36
|
+
TLV_META_TYPE_GROUP |
|
37
|
+
TLV_META_TYPE_COMPLEX
|
38
|
+
)
|
39
|
+
|
40
|
+
#
|
41
|
+
# TLV base starting points
|
42
|
+
#
|
43
|
+
TLV_RESERVED = 0
|
44
|
+
TLV_EXTENSIONS = 20000
|
45
|
+
TLV_USER = 40000
|
46
|
+
TLV_TEMP = 60000
|
47
|
+
|
48
|
+
#
|
49
|
+
# TLV Specific Types
|
50
|
+
#
|
51
|
+
TLV_TYPE_ANY = TLV_META_TYPE_NONE | 0
|
52
|
+
TLV_TYPE_METHOD = TLV_META_TYPE_STRING | 1
|
53
|
+
TLV_TYPE_REQUEST_ID = TLV_META_TYPE_STRING | 2
|
54
|
+
TLV_TYPE_EXCEPTION = TLV_META_TYPE_GROUP | 3
|
55
|
+
TLV_TYPE_RESULT = TLV_META_TYPE_UINT | 4
|
56
|
+
|
57
|
+
TLV_TYPE_STRING = TLV_META_TYPE_STRING | 10
|
58
|
+
TLV_TYPE_UINT = TLV_META_TYPE_UINT | 11
|
59
|
+
TLV_TYPE_BOOL = TLV_META_TYPE_BOOL | 12
|
60
|
+
|
61
|
+
TLV_TYPE_LENGTH = TLV_META_TYPE_UINT | 25
|
62
|
+
TLV_TYPE_DATA = TLV_META_TYPE_RAW | 26
|
63
|
+
TLV_TYPE_FLAGS = TLV_META_TYPE_UINT | 27
|
64
|
+
|
65
|
+
TLV_TYPE_CHANNEL_ID = TLV_META_TYPE_UINT | 50
|
66
|
+
TLV_TYPE_CHANNEL_TYPE = TLV_META_TYPE_STRING | 51
|
67
|
+
TLV_TYPE_CHANNEL_DATA = TLV_META_TYPE_RAW | 52
|
68
|
+
TLV_TYPE_CHANNEL_DATA_GROUP = TLV_META_TYPE_GROUP | 53
|
69
|
+
TLV_TYPE_CHANNEL_CLASS = TLV_META_TYPE_UINT | 54
|
70
|
+
TLV_TYPE_CHANNEL_PARENTID = TLV_META_TYPE_UINT | 55
|
71
|
+
|
72
|
+
TLV_TYPE_SEEK_WHENCE = TLV_META_TYPE_UINT | 70
|
73
|
+
TLV_TYPE_SEEK_OFFSET = TLV_META_TYPE_UINT | 71
|
74
|
+
TLV_TYPE_SEEK_POS = TLV_META_TYPE_UINT | 72
|
75
|
+
|
76
|
+
TLV_TYPE_EXCEPTION_CODE = TLV_META_TYPE_UINT | 300
|
77
|
+
TLV_TYPE_EXCEPTION_STRING = TLV_META_TYPE_STRING | 301
|
78
|
+
|
79
|
+
TLV_TYPE_LIBRARY_PATH = TLV_META_TYPE_STRING | 400
|
80
|
+
TLV_TYPE_TARGET_PATH = TLV_META_TYPE_STRING | 401
|
81
|
+
TLV_TYPE_MIGRATE_PID = TLV_META_TYPE_UINT | 402
|
82
|
+
TLV_TYPE_MIGRATE_LEN = TLV_META_TYPE_UINT | 403
|
83
|
+
TLV_TYPE_MIGRATE_PAYLOAD = TLV_META_TYPE_STRING | 404
|
84
|
+
TLV_TYPE_MIGRATE_ARCH = TLV_META_TYPE_UINT | 405
|
85
|
+
|
86
|
+
TLV_TYPE_CIPHER_NAME = TLV_META_TYPE_STRING | 500
|
87
|
+
TLV_TYPE_CIPHER_PARAMETERS = TLV_META_TYPE_GROUP | 501
|
88
|
+
|
89
|
+
#
|
90
|
+
# Core flags
|
91
|
+
#
|
92
|
+
LOAD_LIBRARY_FLAG_ON_DISK = (1 << 0)
|
93
|
+
LOAD_LIBRARY_FLAG_EXTENSION = (1 << 1)
|
94
|
+
LOAD_LIBRARY_FLAG_LOCAL = (1 << 2)
|
95
|
+
|
96
|
+
###
|
97
|
+
#
|
98
|
+
# Base TLV (Type-Length-Value) class
|
99
|
+
#
|
100
|
+
###
|
101
|
+
class Tlv
|
102
|
+
attr_accessor :type, :value, :compress
|
103
|
+
|
104
|
+
##
|
105
|
+
#
|
106
|
+
# Constructor
|
107
|
+
#
|
108
|
+
##
|
109
|
+
|
110
|
+
#
|
111
|
+
# Returns an instance of a TLV.
|
112
|
+
#
|
113
|
+
def initialize(type, value = nil, compress=false)
|
114
|
+
@type = type
|
115
|
+
@compress = compress
|
116
|
+
|
117
|
+
if (value != nil)
|
118
|
+
if (type & TLV_META_TYPE_STRING == TLV_META_TYPE_STRING)
|
119
|
+
if (value.kind_of?(Fixnum))
|
120
|
+
@value = value.to_s
|
121
|
+
else
|
122
|
+
@value = value.dup
|
123
|
+
end
|
124
|
+
else
|
125
|
+
@value = value
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def inspect
|
131
|
+
utype = type ^ TLV_META_TYPE_COMPRESSED
|
132
|
+
meta = case (utype & TLV_META_MASK)
|
133
|
+
when TLV_META_TYPE_STRING; "STRING"
|
134
|
+
when TLV_META_TYPE_UINT; "INT"
|
135
|
+
when TLV_META_TYPE_RAW; "RAW"
|
136
|
+
when TLV_META_TYPE_BOOL; "BOOL"
|
137
|
+
when TLV_META_TYPE_QWORD; "QWORD"
|
138
|
+
when TLV_META_TYPE_GROUP; "GROUP"
|
139
|
+
when TLV_META_TYPE_COMPLEX; "COMPLEX"
|
140
|
+
else; 'unknown-meta-type'
|
141
|
+
end
|
142
|
+
stype = case type
|
143
|
+
when PACKET_TYPE_REQUEST; "Request"
|
144
|
+
when PACKET_TYPE_RESPONSE; "Response"
|
145
|
+
when TLV_TYPE_REQUEST_ID; "REQUEST-ID"
|
146
|
+
when TLV_TYPE_METHOD; "METHOD"
|
147
|
+
when TLV_TYPE_RESULT; "RESULT"
|
148
|
+
when TLV_TYPE_EXCEPTION; "EXCEPTION"
|
149
|
+
when TLV_TYPE_STRING; "STRING"
|
150
|
+
when TLV_TYPE_UINT; "UINT"
|
151
|
+
when TLV_TYPE_BOOL; "BOOL"
|
152
|
+
|
153
|
+
when TLV_TYPE_LENGTH; "LENGTH"
|
154
|
+
when TLV_TYPE_DATA; "DATA"
|
155
|
+
when TLV_TYPE_FLAGS; "FLAGS"
|
156
|
+
|
157
|
+
when TLV_TYPE_CHANNEL_ID; "CHANNEL-ID"
|
158
|
+
when TLV_TYPE_CHANNEL_TYPE; "CHANNEL-TYPE"
|
159
|
+
when TLV_TYPE_CHANNEL_DATA; "CHANNEL-DATA"
|
160
|
+
when TLV_TYPE_CHANNEL_DATA_GROUP; "CHANNEL-DATA-GROUP"
|
161
|
+
when TLV_TYPE_CHANNEL_CLASS; "CHANNEL-CLASS"
|
162
|
+
when TLV_TYPE_CHANNEL_PARENTID; "CHANNEL-PARENTID"
|
163
|
+
|
164
|
+
when TLV_TYPE_SEEK_WHENCE; "SEEK-WHENCE"
|
165
|
+
when TLV_TYPE_SEEK_OFFSET; "SEEK-OFFSET"
|
166
|
+
when TLV_TYPE_SEEK_POS; "SEEK-POS"
|
167
|
+
|
168
|
+
when TLV_TYPE_EXCEPTION_CODE; "EXCEPTION-CODE"
|
169
|
+
when TLV_TYPE_EXCEPTION_STRING; "EXCEPTION-STRING"
|
170
|
+
|
171
|
+
when TLV_TYPE_LIBRARY_PATH; "LIBRARY-PATH"
|
172
|
+
when TLV_TYPE_TARGET_PATH; "TARGET-PATH"
|
173
|
+
when TLV_TYPE_MIGRATE_PID; "MIGRATE-PID"
|
174
|
+
when TLV_TYPE_MIGRATE_LEN; "MIGRATE-LEN"
|
175
|
+
when TLV_TYPE_MIGRATE_PAYLOAD; "MIGRATE-PAYLOAD"
|
176
|
+
when TLV_TYPE_MIGRATE_ARCH; "MIGRATE-ARCH"
|
177
|
+
|
178
|
+
# Extension classes don't exist yet, so can't use their constants
|
179
|
+
# here.
|
180
|
+
#when Extensions::Stdapi::TLV_TYPE_IP; 'ip-address'
|
181
|
+
else; "unknown-#{type}"
|
182
|
+
end
|
183
|
+
val = value.inspect
|
184
|
+
if val.length > 50
|
185
|
+
val = val[0,50] + ' ..."'
|
186
|
+
end
|
187
|
+
"#<#{self.class} type=#{stype} #{self.class.to_s =~ /Packet/ ? "tlvs=#{@tlvs.inspect}" : "meta=#{meta} value=#{val}"} >"
|
188
|
+
end
|
189
|
+
|
190
|
+
##
|
191
|
+
#
|
192
|
+
# Conditionals
|
193
|
+
#
|
194
|
+
##
|
195
|
+
|
196
|
+
#
|
197
|
+
# Checks to see if a TLVs meta type is equivalent to the meta type passed.
|
198
|
+
#
|
199
|
+
def meta_type?(meta)
|
200
|
+
return (self.type & meta == meta)
|
201
|
+
end
|
202
|
+
|
203
|
+
#
|
204
|
+
# Checks to see if the TLVs type is equivalent to the type passed.
|
205
|
+
#
|
206
|
+
def type?(type)
|
207
|
+
return self.type == type
|
208
|
+
end
|
209
|
+
|
210
|
+
#
|
211
|
+
# Checks to see if the TLVs value is equivalent to the value passed.
|
212
|
+
#
|
213
|
+
def value?(value)
|
214
|
+
return self.value == value
|
215
|
+
end
|
216
|
+
|
217
|
+
##
|
218
|
+
#
|
219
|
+
# Serializers
|
220
|
+
#
|
221
|
+
##
|
222
|
+
|
223
|
+
#
|
224
|
+
# Converts the TLV to raw.
|
225
|
+
#
|
226
|
+
def to_r
|
227
|
+
raw = value.to_s;
|
228
|
+
|
229
|
+
if (self.type & TLV_META_TYPE_STRING == TLV_META_TYPE_STRING)
|
230
|
+
raw += "\x00"
|
231
|
+
elsif (self.type & TLV_META_TYPE_UINT == TLV_META_TYPE_UINT)
|
232
|
+
raw = [value].pack("N")
|
233
|
+
elsif (self.type & TLV_META_TYPE_QWORD == TLV_META_TYPE_QWORD)
|
234
|
+
raw = [ self.htonq( value.to_i ) ].pack("Q")
|
235
|
+
elsif (self.type & TLV_META_TYPE_BOOL == TLV_META_TYPE_BOOL)
|
236
|
+
if (value == true)
|
237
|
+
raw = [1].pack("c")
|
238
|
+
else
|
239
|
+
raw = [0].pack("c")
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
# check if the tlv is to be compressed...
|
244
|
+
if( @compress )
|
245
|
+
raw_uncompressed = raw
|
246
|
+
# compress the raw data
|
247
|
+
raw_compressed = Rex::Text.zlib_deflate( raw_uncompressed )
|
248
|
+
# check we have actually made the raw data smaller...
|
249
|
+
# (small blobs often compress slightly larger then the origional)
|
250
|
+
# if the compressed data is not smaller, we dont use the compressed data
|
251
|
+
if( raw_compressed.length < raw_uncompressed.length )
|
252
|
+
# if so, set the TLV's type to indicate compression is used
|
253
|
+
self.type = self.type | TLV_META_TYPE_COMPRESSED
|
254
|
+
# update the raw data with the uncompressed data length + compressed data
|
255
|
+
# (we include the uncompressed data length as the C side will need to know this for decompression)
|
256
|
+
raw = [ raw_uncompressed.length ].pack("N") + raw_compressed
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
return [raw.length + 8, self.type].pack("NN") + raw
|
261
|
+
end
|
262
|
+
|
263
|
+
#
|
264
|
+
# Translates the raw format of the TLV into a sanitize version.
|
265
|
+
#
|
266
|
+
def from_r(raw)
|
267
|
+
self.value = nil
|
268
|
+
|
269
|
+
length, self.type = raw.unpack("NN");
|
270
|
+
|
271
|
+
# check if the tlv value has been compressed...
|
272
|
+
if( self.type & TLV_META_TYPE_COMPRESSED == TLV_META_TYPE_COMPRESSED )
|
273
|
+
# set this TLV as using compression
|
274
|
+
@compress = true
|
275
|
+
# remove the TLV_META_TYPE_COMPRESSED flag from the tlv type to restore the
|
276
|
+
# tlv type to its origional, allowing for transparent data compression.
|
277
|
+
self.type = self.type ^ TLV_META_TYPE_COMPRESSED
|
278
|
+
# decompress the compressed data (skipping the length and type DWORD's)
|
279
|
+
raw_decompressed = Rex::Text.zlib_inflate( raw[8..length-1] )
|
280
|
+
# update the length to reflect the decompressed data length (+8 for the length and type DWORD's)
|
281
|
+
length = raw_decompressed.length + 8
|
282
|
+
# update the raw buffer with the new length, decompressed data and updated type.
|
283
|
+
raw = [length, self.type].pack("NN") + raw_decompressed
|
284
|
+
end
|
285
|
+
|
286
|
+
if (self.type & TLV_META_TYPE_STRING == TLV_META_TYPE_STRING)
|
287
|
+
if (raw.length > 0)
|
288
|
+
self.value = raw[8..length-2]
|
289
|
+
else
|
290
|
+
self.value = nil
|
291
|
+
end
|
292
|
+
elsif (self.type & TLV_META_TYPE_UINT == TLV_META_TYPE_UINT)
|
293
|
+
self.value = raw.unpack("NNN")[2]
|
294
|
+
elsif (self.type & TLV_META_TYPE_QWORD == TLV_META_TYPE_QWORD)
|
295
|
+
self.value = raw.unpack("NNQ")[2]
|
296
|
+
self.value = self.ntohq( self.value )
|
297
|
+
elsif (self.type & TLV_META_TYPE_BOOL == TLV_META_TYPE_BOOL)
|
298
|
+
self.value = raw.unpack("NNc")[2]
|
299
|
+
|
300
|
+
if (self.value == 1)
|
301
|
+
self.value = true
|
302
|
+
else
|
303
|
+
self.value = false
|
304
|
+
end
|
305
|
+
else
|
306
|
+
self.value = raw[8..length-1]
|
307
|
+
end
|
308
|
+
|
309
|
+
return length;
|
310
|
+
end
|
311
|
+
|
312
|
+
protected
|
313
|
+
|
314
|
+
def htonq( value )
|
315
|
+
if( [1].pack( 's' ) == [1].pack( 'n' ) )
|
316
|
+
return value
|
317
|
+
end
|
318
|
+
return [ value ].pack( 'Q' ).reverse.unpack( 'Q' ).first
|
319
|
+
end
|
320
|
+
|
321
|
+
def ntohq( value )
|
322
|
+
return htonq( value )
|
323
|
+
end
|
324
|
+
|
325
|
+
end
|
326
|
+
|
327
|
+
###
|
328
|
+
#
|
329
|
+
# Group TLVs contain zero or more TLVs
|
330
|
+
#
|
331
|
+
###
|
332
|
+
class GroupTlv < Tlv
|
333
|
+
attr_accessor :tlvs
|
334
|
+
|
335
|
+
##
|
336
|
+
#
|
337
|
+
# Constructor
|
338
|
+
#
|
339
|
+
##
|
340
|
+
|
341
|
+
#
|
342
|
+
# Initializes the group TLV container to the supplied type
|
343
|
+
# and creates an empty TLV array.
|
344
|
+
#
|
345
|
+
def initialize(type)
|
346
|
+
super(type)
|
347
|
+
|
348
|
+
self.tlvs = [ ]
|
349
|
+
end
|
350
|
+
|
351
|
+
##
|
352
|
+
#
|
353
|
+
# Group-based TLV accessors
|
354
|
+
#
|
355
|
+
##
|
356
|
+
|
357
|
+
#
|
358
|
+
# Enumerates TLVs of the supplied type.
|
359
|
+
#
|
360
|
+
def each(type = TLV_TYPE_ANY, &block)
|
361
|
+
get_tlvs(type).each(&block)
|
362
|
+
end
|
363
|
+
|
364
|
+
#
|
365
|
+
# Synonym for each.
|
366
|
+
#
|
367
|
+
def each_tlv(type = TLV_TYPE_ANY, &block)
|
368
|
+
each(type, block)
|
369
|
+
end
|
370
|
+
|
371
|
+
#
|
372
|
+
# Enumerates TLVs of a supplied type with indexes.
|
373
|
+
#
|
374
|
+
def each_with_index(type = TLV_TYPE_ANY, &block)
|
375
|
+
get_tlvs(type).each_with_index(&block)
|
376
|
+
end
|
377
|
+
|
378
|
+
#
|
379
|
+
# Synonym for each_with_index.
|
380
|
+
#
|
381
|
+
def each_tlv_with_index(type = TLV_TYPE_ANY, &block)
|
382
|
+
each_with_index(type, block)
|
383
|
+
end
|
384
|
+
|
385
|
+
#
|
386
|
+
# Returns an array of TLVs for the given type.
|
387
|
+
#
|
388
|
+
def get_tlvs(type)
|
389
|
+
if (type == TLV_TYPE_ANY)
|
390
|
+
return self.tlvs
|
391
|
+
else
|
392
|
+
type_tlvs = []
|
393
|
+
|
394
|
+
self.tlvs.each() { |tlv|
|
395
|
+
if (tlv.type?(type))
|
396
|
+
type_tlvs << tlv
|
397
|
+
end
|
398
|
+
}
|
399
|
+
|
400
|
+
return type_tlvs
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
##
|
405
|
+
#
|
406
|
+
# TLV management
|
407
|
+
#
|
408
|
+
##
|
409
|
+
|
410
|
+
#
|
411
|
+
# Adds a TLV of a given type and value.
|
412
|
+
#
|
413
|
+
def add_tlv(type, value = nil, replace = false, compress=false)
|
414
|
+
|
415
|
+
# If we should replace any TLVs with the same type...remove them first
|
416
|
+
if (replace)
|
417
|
+
each(type) { |tlv|
|
418
|
+
if (tlv.type == type)
|
419
|
+
self.tlvs.delete(tlv)
|
420
|
+
end
|
421
|
+
}
|
422
|
+
end
|
423
|
+
|
424
|
+
if (type & TLV_META_TYPE_GROUP == TLV_META_TYPE_GROUP)
|
425
|
+
tlv = GroupTlv.new(type)
|
426
|
+
else
|
427
|
+
tlv = Tlv.new(type, value, compress)
|
428
|
+
end
|
429
|
+
|
430
|
+
self.tlvs << tlv
|
431
|
+
|
432
|
+
return tlv
|
433
|
+
end
|
434
|
+
|
435
|
+
#
|
436
|
+
# Adds zero or more TLVs to the packet.
|
437
|
+
#
|
438
|
+
def add_tlvs(tlvs)
|
439
|
+
if (tlvs != nil)
|
440
|
+
tlvs.each { |tlv|
|
441
|
+
add_tlv(tlv['type'], tlv['value'])
|
442
|
+
}
|
443
|
+
end
|
444
|
+
end
|
445
|
+
|
446
|
+
#
|
447
|
+
# Gets the first TLV of a given type.
|
448
|
+
#
|
449
|
+
def get_tlv(type, index = 0)
|
450
|
+
type_tlvs = get_tlvs(type)
|
451
|
+
|
452
|
+
if (type_tlvs.length > index)
|
453
|
+
return type_tlvs[index]
|
454
|
+
end
|
455
|
+
|
456
|
+
return nil
|
457
|
+
end
|
458
|
+
|
459
|
+
#
|
460
|
+
# Returns the value of a TLV if it exists, otherwise nil.
|
461
|
+
#
|
462
|
+
def get_tlv_value(type, index = 0)
|
463
|
+
tlv = get_tlv(type, index)
|
464
|
+
|
465
|
+
return (tlv != nil) ? tlv.value : nil
|
466
|
+
end
|
467
|
+
|
468
|
+
#
|
469
|
+
# Returns an array of values for all tlvs of type type.
|
470
|
+
#
|
471
|
+
def get_tlv_values(type)
|
472
|
+
get_tlvs(type).collect { |a| a.value }
|
473
|
+
end
|
474
|
+
|
475
|
+
#
|
476
|
+
# Checks to see if the container has a TLV of a given type.
|
477
|
+
#
|
478
|
+
def has_tlv?(type)
|
479
|
+
return get_tlv(type) != nil
|
480
|
+
end
|
481
|
+
|
482
|
+
#
|
483
|
+
# Zeros out the array of TLVs.
|
484
|
+
#
|
485
|
+
def reset
|
486
|
+
self.tlvs = []
|
487
|
+
end
|
488
|
+
|
489
|
+
##
|
490
|
+
#
|
491
|
+
# Serializers
|
492
|
+
#
|
493
|
+
##
|
494
|
+
|
495
|
+
#
|
496
|
+
# Converts all of the TLVs in the TLV array to raw and prefixes them
|
497
|
+
# with a container TLV of this instance's TLV type.
|
498
|
+
#
|
499
|
+
def to_r
|
500
|
+
raw = ''
|
501
|
+
|
502
|
+
self.each() { |tlv|
|
503
|
+
raw << tlv.to_r
|
504
|
+
}
|
505
|
+
|
506
|
+
return [raw.length + 8, self.type].pack("NN") + raw
|
507
|
+
end
|
508
|
+
|
509
|
+
#
|
510
|
+
# Converts the TLV group container from raw to all of the individual
|
511
|
+
# TLVs.
|
512
|
+
#
|
513
|
+
def from_r(raw)
|
514
|
+
offset = 8
|
515
|
+
|
516
|
+
# Reset the TLVs array
|
517
|
+
self.tlvs = []
|
518
|
+
self.type = raw.unpack("NN")[1]
|
519
|
+
|
520
|
+
# Enumerate all of the TLVs
|
521
|
+
while (offset < raw.length-1)
|
522
|
+
|
523
|
+
tlv = nil
|
524
|
+
|
525
|
+
# Get the length and type
|
526
|
+
length, type = raw[offset..offset+8].unpack("NN")
|
527
|
+
|
528
|
+
if (type & TLV_META_TYPE_GROUP == TLV_META_TYPE_GROUP)
|
529
|
+
tlv = GroupTlv.new(type)
|
530
|
+
else
|
531
|
+
tlv = Tlv.new(type)
|
532
|
+
end
|
533
|
+
|
534
|
+
tlv.from_r(raw[offset..offset+length])
|
535
|
+
|
536
|
+
# Insert it into the list of TLVs
|
537
|
+
tlvs << tlv
|
538
|
+
|
539
|
+
# Move up
|
540
|
+
offset += length
|
541
|
+
end
|
542
|
+
end
|
543
|
+
|
544
|
+
end
|
545
|
+
|
546
|
+
###
|
547
|
+
#
|
548
|
+
# The logical meterpreter packet class
|
549
|
+
#
|
550
|
+
###
|
551
|
+
class Packet < GroupTlv
|
552
|
+
attr_accessor :created_at
|
553
|
+
|
554
|
+
##
|
555
|
+
#
|
556
|
+
# Factory
|
557
|
+
#
|
558
|
+
##
|
559
|
+
|
560
|
+
#
|
561
|
+
# Creates a request with the supplied method.
|
562
|
+
#
|
563
|
+
def Packet.create_request(method = nil)
|
564
|
+
return Packet.new(PACKET_TYPE_REQUEST, method)
|
565
|
+
end
|
566
|
+
|
567
|
+
#
|
568
|
+
# Creates a response to a request if one is provided.
|
569
|
+
#
|
570
|
+
def Packet.create_response(request = nil)
|
571
|
+
response_type = PACKET_TYPE_RESPONSE
|
572
|
+
method = nil
|
573
|
+
|
574
|
+
if (request)
|
575
|
+
if (request.type?(PACKET_TYPE_PLAIN_REQUEST))
|
576
|
+
response_type = PACKET_TYPE_PLAIN_RESPONSE
|
577
|
+
end
|
578
|
+
|
579
|
+
method = request.method
|
580
|
+
end
|
581
|
+
|
582
|
+
return Packet.new(response_type, method)
|
583
|
+
end
|
584
|
+
|
585
|
+
##
|
586
|
+
#
|
587
|
+
# Constructor
|
588
|
+
#
|
589
|
+
##
|
590
|
+
|
591
|
+
#
|
592
|
+
# Initializes the packet to the supplied packet type and method,
|
593
|
+
# if any. If the packet is a request, a request identifier is
|
594
|
+
# created.
|
595
|
+
#
|
596
|
+
def initialize(type = nil, method = nil)
|
597
|
+
super(type)
|
598
|
+
|
599
|
+
if (method)
|
600
|
+
self.method = method
|
601
|
+
end
|
602
|
+
|
603
|
+
self.created_at = ::Time.now
|
604
|
+
|
605
|
+
# If it's a request, generate a random request identifier
|
606
|
+
if ((type == PACKET_TYPE_REQUEST) ||
|
607
|
+
(type == PACKET_TYPE_PLAIN_REQUEST))
|
608
|
+
rid = ''
|
609
|
+
|
610
|
+
32.times { |val| rid << rand(10).to_s }
|
611
|
+
|
612
|
+
add_tlv(TLV_TYPE_REQUEST_ID, rid)
|
613
|
+
end
|
614
|
+
end
|
615
|
+
|
616
|
+
##
|
617
|
+
#
|
618
|
+
# Conditionals
|
619
|
+
#
|
620
|
+
##
|
621
|
+
|
622
|
+
#
|
623
|
+
# Checks to see if the packet is a response.
|
624
|
+
#
|
625
|
+
def response?
|
626
|
+
return ((self.type == PACKET_TYPE_RESPONSE) ||
|
627
|
+
(self.type == PACKET_TYPE_PLAIN_RESPONSE))
|
628
|
+
end
|
629
|
+
|
630
|
+
##
|
631
|
+
#
|
632
|
+
# Accessors
|
633
|
+
#
|
634
|
+
##
|
635
|
+
|
636
|
+
#
|
637
|
+
# Checks to see if the packet's method is equal to the supplied method.
|
638
|
+
#
|
639
|
+
def method?(method)
|
640
|
+
return (get_tlv_value(TLV_TYPE_METHOD) == method)
|
641
|
+
end
|
642
|
+
|
643
|
+
#
|
644
|
+
# Sets the packet's method TLV to the method supplied.
|
645
|
+
#
|
646
|
+
def method=(method)
|
647
|
+
add_tlv(TLV_TYPE_METHOD, method, true)
|
648
|
+
end
|
649
|
+
|
650
|
+
#
|
651
|
+
# Returns the value of the packet's method TLV.
|
652
|
+
#
|
653
|
+
def method
|
654
|
+
return get_tlv_value(TLV_TYPE_METHOD)
|
655
|
+
end
|
656
|
+
|
657
|
+
#
|
658
|
+
# Checks to see if the packet's result value is equal to the supplied
|
659
|
+
# result.
|
660
|
+
#
|
661
|
+
def result?(result)
|
662
|
+
return (get_tlv_value(TLV_TYPE_RESULT) == result)
|
663
|
+
end
|
664
|
+
|
665
|
+
#
|
666
|
+
# Sets the packet's result TLV.
|
667
|
+
#
|
668
|
+
def result=(result)
|
669
|
+
add_tlv(TLV_TYPE_RESULT, result, true)
|
670
|
+
end
|
671
|
+
|
672
|
+
#
|
673
|
+
# Gets the value of the packet's result TLV.
|
674
|
+
#
|
675
|
+
def result
|
676
|
+
return get_tlv_value(TLV_TYPE_RESULT)
|
677
|
+
end
|
678
|
+
|
679
|
+
#
|
680
|
+
# Gets the value of the packet's request identifier TLV.
|
681
|
+
#
|
682
|
+
def rid
|
683
|
+
return get_tlv_value(TLV_TYPE_REQUEST_ID)
|
684
|
+
end
|
685
|
+
end
|
686
|
+
|
687
|
+
end; end; end
|
688
|
+
|