librex 0.0.20 → 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- 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,190 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..'))
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'rex/text'
|
7
|
+
require 'rex/exceptions'
|
8
|
+
class Rex::Text::UnitTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def test_pattern_create
|
11
|
+
set1 = %w{AB ab 12}
|
12
|
+
assert_equal 'Aa1Aa2', Rex::Text.pattern_create(6,set1)
|
13
|
+
set2 = %w{ABC abc 123}
|
14
|
+
assert_equal 'Aa1Aa2Aa3Ab1Ab2Ab3', Rex::Text.pattern_create(18,set2)
|
15
|
+
assert_equal 'Zz8Zz9', Rex::Text.pattern_create(20280)[-6,6] # Bug #2952
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_pattern_create_silly
|
19
|
+
assert_equal "", Rex::Text.pattern_create(nil)
|
20
|
+
assert_equal "", Rex::Text.pattern_create(0)
|
21
|
+
assert_equal 'AAAAAAAAA', Rex::Text.pattern_create(9,['A'])
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_uri_encode
|
25
|
+
srand(0)
|
26
|
+
assert_equal('A1%21', Rex::Text.uri_encode('A1!'), 'uri encode')
|
27
|
+
assert_equal('A1!', Rex::Text.uri_encode('A1!', 'none'), 'uri encode: none')
|
28
|
+
assert_equal('A1%21', Rex::Text.uri_encode('A1!', 'hex-normal'), 'uri encode: hex-normal')
|
29
|
+
assert_equal('%41%31%21', Rex::Text.uri_encode('A1!', 'hex-all'), 'uri encode: hex-all')
|
30
|
+
assert_equal('A1%u01c3', Rex::Text.uri_encode('A1!', 'u-normal'), 'uri encode: u-normal')
|
31
|
+
assert_equal('%uff21%u2081%uff01', Rex::Text.uri_encode('A1!', 'u-all'), 'uri encode: u-all')
|
32
|
+
srand(0)
|
33
|
+
assert_equal("%uff2d%uff49%uff43%uff52%uff4f%uff53%uff4f%uff46%uff54%u2004%uff45%uff4e%uff43%uff4f%uff44%uff49%uff4e%uff47%u3000%uff44%uff52%uff49%uff56%uff45%uff53%u2005%uff4d%uff45%u2000%uff43%uff52%uff41%uff5a%uff59%uff01", Rex::Text.uri_encode('Microsoft encoding drives me crazy!', 'u-half'))
|
34
|
+
|
35
|
+
assert_raises(TypeError) {
|
36
|
+
Rex::Text.uri_encode('a', 'umpa lumpa')
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_html_encode
|
41
|
+
assert_equal('A', Rex::Text.html_encode('A'), 'html_encode default')
|
42
|
+
assert_equal('A', Rex::Text.html_encode('A','hex'), 'html_encode hex')
|
43
|
+
assert_equal('A', Rex::Text.html_encode('A','int'), 'html_encode int')
|
44
|
+
assert_equal('A', Rex::Text.html_encode('A','int-wide'), 'html_encode int-wide')
|
45
|
+
|
46
|
+
assert_raises(TypeError) {
|
47
|
+
Rex::Text.html_encode('a', 'umpa lumpa')
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_rand_text
|
52
|
+
srand(0)
|
53
|
+
assert_equal("\254/u\300C\373\303g\t\323", Rex::Text.rand_text(10), 'rand text 1')
|
54
|
+
assert_equal("\025\362$WF\330X\214:\301", Rex::Text.rand_text(10), 'rand text 2')
|
55
|
+
assert_equal("\346'W\256XQ\245\031MH", Rex::Text.rand_text(10), 'rand text 3')
|
56
|
+
assert_equal('bababbabba', Rex::Text.rand_text(10, nil, 'ab'), 'rand text with specified "good"')
|
57
|
+
assert_equal('MA', Rex::Text.rand_state(), 'rand state')
|
58
|
+
assert_equal('xzdttongb.5gfk0xjly3.aak.fmo0rp.com', Rex::Text.rand_hostname(), 'rand hostname')
|
59
|
+
assert_equal('9aaf811799', Rex::Text.rand_text_hex(10), 'rand hex')
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def test_unicode
|
64
|
+
assert_equal("a\x00b\x00c\x00", Rex::Text.to_unicode('abc'), 'unicode, default = little endian')
|
65
|
+
assert_equal("a\x00b\x00c\x00", Rex::Text.to_unicode('abc', 'utf-16le'), 'utf-16le')
|
66
|
+
assert_equal("\x00a\x00b\x00c", Rex::Text.to_unicode('abc', 'utf-16be'), 'utf-16be')
|
67
|
+
assert_equal("a\x00\x00\x00b\x00\x00\x00c\x00\x00\x00", Rex::Text.to_unicode('abc', 'utf-32le'), 'utf-32le')
|
68
|
+
assert_equal("\x00\x00\x00a\x00\x00\x00b\x00\x00\x00c", Rex::Text.to_unicode('abc', 'utf-32be'), 'utf-32be')
|
69
|
+
assert_equal("abc+-abc-+AAA-", Rex::Text.to_unicode("abc+abc-\x00", 'utf-7'), 'utf-7')
|
70
|
+
assert_equal("+AGE-+AGI-+AGM-+ACs-+AGE-+AGI-+AGM-+AC0-+AAA-", Rex::Text.to_unicode("abc+abc-\x00", 'utf-7', 'all'), 'utf-7-all')
|
71
|
+
|
72
|
+
assert_equal("a\303\272", Rex::Text.to_unicode("a\xFA", 'utf-8'))
|
73
|
+
assert_equal("\xC1\xA1", Rex::Text.to_unicode('a', 'utf-8', 'overlong', 2), 'utf-8 overlong')
|
74
|
+
assert_equal("\xE0\x81\xA1", Rex::Text.to_unicode('a', 'utf-8', 'overlong', 3), 'utf-8 overlong')
|
75
|
+
assert_equal("\xF0\x80\x81\xA1", Rex::Text.to_unicode('a', 'utf-8', 'overlong', 4), 'utf-8 overlong')
|
76
|
+
assert_equal("\xF8\x80\x80\x81\xA1", Rex::Text.to_unicode('a', 'utf-8', 'overlong', 5), 'utf-8 overlong')
|
77
|
+
assert_equal("\xFC\x80\x80\x80\x81\xA1", Rex::Text.to_unicode('a', 'utf-8', 'overlong', 6), 'utf-8 overlong')
|
78
|
+
assert_equal("\xFE\x80\x80\x80\x80\x81\xA1", Rex::Text.to_unicode('a', 'utf-8', 'overlong', 7), 'utf-8 overlong')
|
79
|
+
100.times {
|
80
|
+
assert(["\xC1\x21","\xC1\x61","\xC1\xE1"].include?(Rex::Text.to_unicode('a', 'utf-8', 'invalid')), 'utf-8 invalid')
|
81
|
+
assert(["\xE0\x01\x21","\xE0\x01\x61","\xE0\x01\xA1","\xE0\x01\xE1","\xE0\x41\x21","\xE0\x41\x61","\xE0\x41\xA1","\xE0\x41\xE1","\xE0\x81\x21","\xE0\x81\x61","\xE0\x81\xA1","\xE0\x81\xE1","\xE0\xC1\x21","\xE0\xC1\x61","\xE0\xC1\xA1","\xE0\xC1\xE1"].include?(Rex::Text.to_unicode('a', 'utf-8', 'invalid', 3)), 'utf-8 invalid 3 byte')
|
82
|
+
}
|
83
|
+
|
84
|
+
a = ["\xC1\x21","\xC1\x61","\xC1\xE1"]
|
85
|
+
10.times {
|
86
|
+
encoded = Rex::Text.to_unicode('a', 'utf-8', 'invalid')
|
87
|
+
if a.include?(encoded)
|
88
|
+
a.delete(encoded)
|
89
|
+
end
|
90
|
+
}
|
91
|
+
assert_equal([], a, 'all possible values')
|
92
|
+
|
93
|
+
assert_raises(TypeError) {
|
94
|
+
Rex::Text.to_unicode('a', 'utf-8', '', 8)
|
95
|
+
}
|
96
|
+
assert_raises(TypeError) {
|
97
|
+
Rex::Text.to_unicode('a', 'utf-8', 'foo', 6)
|
98
|
+
}
|
99
|
+
|
100
|
+
assert_raises(TypeError) {
|
101
|
+
Rex::Text.to_unicode('a', 'uhwtfms', -1)
|
102
|
+
}
|
103
|
+
|
104
|
+
100.times {
|
105
|
+
assert(["\x01\x00","\x01\x02","\x01\x04","\x01\xcd","\x01\xde","\xff\x21"].include?(Rex::Text.to_unicode('A', 'uhwtfms')), 'uhwtfms')
|
106
|
+
assert(["\x00\xc0","\x00\xc1","\x00\xc2","\x00\xc3","\x00\xc4","\x00\xc5"].include?(Rex::Text.to_unicode('A', 'uhwtfms', 949)), 'uhwtfms codepage 949')
|
107
|
+
}
|
108
|
+
|
109
|
+
a = ["\x01\x00","\x01\x02","\x01\x04","\x01\xcd","\x01\xde","\xff\x21"]
|
110
|
+
20.times {
|
111
|
+
encoded = Rex::Text.to_unicode('A', 'uhwtfms')
|
112
|
+
if a.include?(encoded)
|
113
|
+
a.delete(encoded)
|
114
|
+
end
|
115
|
+
}
|
116
|
+
assert_equal([], a, 'all possible values uhwtfms')
|
117
|
+
|
118
|
+
assert_raises(TypeError) {
|
119
|
+
Rex::Text.to_unicode('a', 'uhwtfms-half', 1)
|
120
|
+
}
|
121
|
+
|
122
|
+
assert_equal("\xFF\x01", Rex::Text.to_unicode('!', 'uhwtfms-half'))
|
123
|
+
srand(0)
|
124
|
+
assert_equal("\xff\x2d\xff\x49\xff\x43\xff\x52\xff\x4f\xff\x53\xff\x4f\xff\x46\xff\x54\x20\x04\xff\x45\xff\x4e\xff\x43\xff\x4f\xff\x44\xff\x49\xff\x4e\xff\x47\x30\x00\xff\x44\xff\x52\xff\x49\xff\x56\xff\x45\xff\x53\x20\x05\xff\x4d\xff\x45\x20\x00\xff\x43\xff\x52\xff\x41\xff\x5a\xff\x59\xff\x01", Rex::Text.to_unicode('Microsoft encoding drives me crazy!', 'uhwtfms-half'))
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_zlib
|
128
|
+
assert_equal("x\332\313\310T\310\315\317\005\000\a\225\002;", Rex::Text.zlib_deflate('hi mom'), 'compress')
|
129
|
+
assert_equal('hi mom', Rex::Text.zlib_inflate("x\234\313\310T\310\315\317\005\000\a\225\002;"), 'decompress')
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_gzip
|
133
|
+
string = Rex::Text.gzip('hi mom')
|
134
|
+
assert_equal("\x1f\x8b\x08\x00", string.slice!(0,4), 'gzip headers')
|
135
|
+
|
136
|
+
# skip the next 6 bytes as it is host & time specific (zlib's example gun does, so why not us too?)
|
137
|
+
string.slice!(0,6)
|
138
|
+
|
139
|
+
assert_equal("\xcb\xc8\x54\xc8\xcd\xcf\x05\x00\x68\xa4\x1c\xf0\x06\x00\x00\x00", string, 'gzip data')
|
140
|
+
|
141
|
+
assert_equal('hi mom', Rex::Text.ungzip("\037\213\010\000|\261\275C\002\003\313\310T\310\315\317\005\000h\244\034\360\006\000\000\000"), 'ungzip')
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_badchar_index
|
145
|
+
assert_equal(nil, Rex::Text.badchar_index('abcdef', 'gzk'))
|
146
|
+
assert_equal(2, Rex::Text.badchar_index('123avd', 'ly3'))
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_hexify
|
150
|
+
str = "\x01\x02\xff\x00"
|
151
|
+
|
152
|
+
assert_equal("\\x01\\x02\\xff\\x00", Rex::Text.to_hex(str), 'to_hex')
|
153
|
+
assert_equal("ABC01ABC02ABCffABC00", Rex::Text.to_hex(str, 'ABC'), 'to_hex with prefix')
|
154
|
+
assert_equal('%u0102%uff00', Rex::Text.to_hex(str, '%u', 2), 'to_hex with chunk size of 2')
|
155
|
+
|
156
|
+
# to_hex, without providing enouigh data to chunk on a given size
|
157
|
+
assert_raises(RuntimeError){ Rex::Text.to_hex('a', '', 2) }
|
158
|
+
|
159
|
+
assert_equal("buf = \n\"\\x01\\x02\\xff\\x00\"\n", Rex::Text.to_ruby(str), 'to_ruby')
|
160
|
+
assert_equal("my $buf = \n\"\\x01\\x02\\xff\\x00\";\n", Rex::Text.to_perl(str), 'to_perl')
|
161
|
+
assert_equal("unsigned char buf[] = \n\"\\x01\\x02\\xff\\x00\";\n", Rex::Text.to_c(str), 'to_c')
|
162
|
+
|
163
|
+
# 0 -> 20
|
164
|
+
str = "\000\001\002\003\004\005\006\a\010\t\n\v\f\r\016\017\020\021\022\023"
|
165
|
+
|
166
|
+
assert_equal("buf = \n\"\\x00\\x01\\x02\\x03\" +\n\"\\x04\\x05\\x06\\x07\" +\n\"\\x08\\x09\\x0a\\x0b\" +\n\"\\x0c\\x0d\\x0e\\x0f\" +\n\"\\x10\\x11\\x12\\x13\"\n", Rex::Text.to_ruby(str, 20), 'to_ruby with wrap')
|
167
|
+
assert_equal("my $buf = \n\"\\x00\\x01\\x02\\x03\" .\n\"\\x04\\x05\\x06\\x07\" .\n\"\\x08\\x09\\x0a\\x0b\" .\n\"\\x0c\\x0d\\x0e\\x0f\" .\n\"\\x10\\x11\\x12\\x13\";\n", Rex::Text.to_perl(str, 20), 'to_perl with wrap')
|
168
|
+
assert_equal("unsigned char buf[] = \n\"\\x00\\x01\\x02\\x03\\x04\"\n\"\\x05\\x06\\x07\\x08\\x09\"\n\"\\x0a\\x0b\\x0c\\x0d\\x0e\"\n\"\\x0f\\x10\\x11\\x12\\x13\";\n", Rex::Text.to_c(str, 20, "buf"), 'to_c with wrap')
|
169
|
+
assert_equal("\\x0a", Rex::Text.to_hex("\n"), 'to_hex newline')
|
170
|
+
|
171
|
+
str = "\x05Hello\x06World!\x03\x41\x42\x43"
|
172
|
+
assert_equal("\\x05Hello\\x06World!\\x03ABC", Rex::Text.to_hex_ascii(str))
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_xml_char_encode
|
176
|
+
str = "\x05hello\x06world"
|
177
|
+
assert_equal("helloworld", Rex::Text.xml_char_encode(str))
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_wordwrap
|
181
|
+
txt = "this is a test of the word wrap features"
|
182
|
+
|
183
|
+
assert_equal("this is a \ntest of \nthe word \nwrap \nfeatures\n", Rex::Text.wordwrap(txt, 0, 10))
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_transforms
|
187
|
+
assert_equal("acbd18db4cc2f85cedef654fccc4a4d8", Rex::Text.md5('foo'))
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Rex
|
2
|
+
|
3
|
+
###
|
4
|
+
#
|
5
|
+
# This class provides a wrapper around Thread.new that can provide
|
6
|
+
# additional features if a corresponding thread provider is set.
|
7
|
+
#
|
8
|
+
###
|
9
|
+
|
10
|
+
class ThreadFactory
|
11
|
+
|
12
|
+
@@provider = nil
|
13
|
+
|
14
|
+
def self.provider=(val)
|
15
|
+
@@provider = val
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.spawn(name, crit, *args, &block)
|
19
|
+
if @@provider
|
20
|
+
if block
|
21
|
+
return @@provider.spawn(name, crit, *args){ |*args_copy| block.call(*args_copy) }
|
22
|
+
else
|
23
|
+
return @@provider.spawn(name, crit, *args)
|
24
|
+
end
|
25
|
+
else
|
26
|
+
t = nil
|
27
|
+
if block
|
28
|
+
t = ::Thread.new(*args){ |*args_copy| block.call(*args_copy) }
|
29
|
+
else
|
30
|
+
t = ::Thread.new(*args)
|
31
|
+
end
|
32
|
+
t[:tm_name] = name
|
33
|
+
t[:tm_crit] = crit
|
34
|
+
t[:tm_time] = Time.now
|
35
|
+
t[:tm_call] = caller
|
36
|
+
return t
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/lib/rex/time.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
module Rex
|
2
|
+
|
3
|
+
###
|
4
|
+
#
|
5
|
+
# Extended time related functions.
|
6
|
+
#
|
7
|
+
###
|
8
|
+
module ExtTime
|
9
|
+
|
10
|
+
#
|
11
|
+
# Convert seconds to a string that is broken down into years, days, hours,
|
12
|
+
# minutes, and second.
|
13
|
+
#
|
14
|
+
def self.sec_to_s(seconds)
|
15
|
+
parts = [ 31536000, 86400, 3600, 60, 1 ].map { |d|
|
16
|
+
if ((c = seconds / d) > 0)
|
17
|
+
seconds -= c.truncate * d
|
18
|
+
c.truncate
|
19
|
+
else
|
20
|
+
0
|
21
|
+
end
|
22
|
+
}.reverse
|
23
|
+
|
24
|
+
str = ''
|
25
|
+
|
26
|
+
[ "sec", "min", "hour", "day", "year" ].each_with_index { |name, idx|
|
27
|
+
next if (!parts[idx] or parts[idx] == 0)
|
28
|
+
|
29
|
+
str = "#{parts[idx]} #{name + ((parts[idx] != 1) ? 's' :'')} " + str
|
30
|
+
}
|
31
|
+
|
32
|
+
str.empty? ? "0 secs" : str.strip
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Converts a string in the form n years g days x hours y mins z secs.
|
37
|
+
#
|
38
|
+
def self.str_to_sec(str)
|
39
|
+
fields = str.split(/ /)
|
40
|
+
secs = 0
|
41
|
+
|
42
|
+
fields.each_with_index { |f, idx|
|
43
|
+
val = 0
|
44
|
+
case f
|
45
|
+
when /^year/
|
46
|
+
val = 31536000
|
47
|
+
when /^day/
|
48
|
+
val = 86400
|
49
|
+
when /^hour/
|
50
|
+
val = 3600
|
51
|
+
when /^min/
|
52
|
+
val = 60
|
53
|
+
when /^sec/
|
54
|
+
val = 1
|
55
|
+
end
|
56
|
+
|
57
|
+
secs += val * fields[idx-1].to_i
|
58
|
+
}
|
59
|
+
|
60
|
+
secs
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
module Rex
|
2
|
+
|
3
|
+
###
|
4
|
+
#
|
5
|
+
# Transformer - more than meets the eye!
|
6
|
+
#
|
7
|
+
# This class, aside from having a kickass name, is responsible for translating
|
8
|
+
# object instances of one or more types into a single list instance of one or
|
9
|
+
# more types. This is useful for translating object instances that be can
|
10
|
+
# either strings or an array of strings into an array of strings, for
|
11
|
+
# instance. It lets you make things take a uniform structure in an abstract
|
12
|
+
# manner.
|
13
|
+
#
|
14
|
+
###
|
15
|
+
class Transformer
|
16
|
+
|
17
|
+
#
|
18
|
+
# Translates the object instance supplied in src_instance to an instance of
|
19
|
+
# dst_class. The dst_class parameter's instance must support the <<
|
20
|
+
# operator. An example call to this method looks something like:
|
21
|
+
#
|
22
|
+
# Transformer.transform(string, Array, [ String ], target)
|
23
|
+
#
|
24
|
+
def Transformer.transform(src_instance, dst_class, supported_classes,
|
25
|
+
target = nil)
|
26
|
+
dst_instance = dst_class.new
|
27
|
+
|
28
|
+
if (src_instance.kind_of?(Array))
|
29
|
+
src_instance.each { |src_inst|
|
30
|
+
Transformer.transform_single(src_inst, dst_instance,
|
31
|
+
supported_classes, target)
|
32
|
+
}
|
33
|
+
elsif (!src_instance.kind_of?(NilClass))
|
34
|
+
Transformer.transform_single(src_instance, dst_instance,
|
35
|
+
supported_classes, target)
|
36
|
+
end
|
37
|
+
|
38
|
+
return dst_instance
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
#
|
44
|
+
# Transform a single source instance.
|
45
|
+
#
|
46
|
+
def Transformer.transform_single(src_instance, dst_instance,
|
47
|
+
supported_classes, target)
|
48
|
+
# If the src instance's class is supported, just add it to the dst
|
49
|
+
# instance
|
50
|
+
if (supported_classes.include?(src_instance.class))
|
51
|
+
dst_instance << src_instance
|
52
|
+
# If the src instance's class is an array, then we should check to see
|
53
|
+
# if any of the supporting classes support from_a.
|
54
|
+
elsif (src_instance.kind_of?(Array))
|
55
|
+
new_src_instance = nil
|
56
|
+
|
57
|
+
# Walk each supported class calling from_a if exported
|
58
|
+
supported_classes.each { |sup_class|
|
59
|
+
next if (sup_class.respond_to?('from_a') == false)
|
60
|
+
|
61
|
+
new_src_instance = sup_class.from_a(src_instance)
|
62
|
+
|
63
|
+
if (new_src_instance != nil)
|
64
|
+
dst_instance << new_src_instance
|
65
|
+
break
|
66
|
+
end
|
67
|
+
}
|
68
|
+
|
69
|
+
# If we don't have a valid new src instance, then we suck
|
70
|
+
if (new_src_instance == nil)
|
71
|
+
bomb_translation(src_instance, target)
|
72
|
+
end
|
73
|
+
|
74
|
+
# If the source instance is a string, query each of the supported
|
75
|
+
# classes to see if they can serialize it to their particular data
|
76
|
+
# type.
|
77
|
+
elsif (src_instance.kind_of?(String))
|
78
|
+
new_src_instance = nil
|
79
|
+
|
80
|
+
# Walk each supported class calling from_s if exported
|
81
|
+
supported_classes.each { |sup_class|
|
82
|
+
next if (sup_class.respond_to?('from_s') == false)
|
83
|
+
|
84
|
+
new_src_instance = sup_class.from_s(src_instance)
|
85
|
+
|
86
|
+
if (new_src_instance != nil)
|
87
|
+
dst_instance << new_src_instance
|
88
|
+
break
|
89
|
+
end
|
90
|
+
}
|
91
|
+
|
92
|
+
# If we don't have a valid new src instance, then we suck
|
93
|
+
if (new_src_instance == nil)
|
94
|
+
bomb_translation(src_instance, target)
|
95
|
+
end
|
96
|
+
# Otherwise, bomb translation
|
97
|
+
else
|
98
|
+
bomb_translation(src_instance, target)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def Transformer.bomb_translation(src_instance, target) # :nodoc:
|
103
|
+
error = "Invalid source class (#{src_instance.class})"
|
104
|
+
|
105
|
+
if (target != nil)
|
106
|
+
error += " for #{target}"
|
107
|
+
end
|
108
|
+
|
109
|
+
raise ArgumentError, error, caller
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..'))
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'rex/exceptions'
|
7
|
+
require 'rex/transformer'
|
8
|
+
|
9
|
+
class Rex::Transformer::UnitTest < Test::Unit::TestCase
|
10
|
+
class Pizza
|
11
|
+
def Pizza.from_s(str)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class ArrayTester
|
16
|
+
def self.from_a(a)
|
17
|
+
a[0] + a[1]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_transformer
|
22
|
+
a = Rex::Transformer.transform([ 'yo', 'ho' ], Array, [ String ], 'Jones')
|
23
|
+
|
24
|
+
assert_equal(2, a.length, "invalid array length")
|
25
|
+
assert_equal('yo', a[0], "invalid first element")
|
26
|
+
assert_equal('ho', a[1], "invalid second element")
|
27
|
+
|
28
|
+
assert_raise(Rex::ArgumentError, "invalid transform") {
|
29
|
+
Rex::Transformer.transform('dog', Array, [ Pizza ], 'bob')
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_from_a
|
34
|
+
a = Rex::Transformer.transform([ [ 'one', 'two' ] ], Array, [ ArrayTester ], 'Jimmy')
|
35
|
+
|
36
|
+
assert_equal('onetwo', a[0], "invalid from_a conversion")
|
37
|
+
end
|
38
|
+
end
|