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,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..'))
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'rex/file'
|
7
|
+
|
8
|
+
class Rex::FileUtils::UnitTest < ::Test::Unit::TestCase
|
9
|
+
Klass = Rex::FileUtils
|
10
|
+
|
11
|
+
def test_find_full_path
|
12
|
+
assert_not_nil(Klass.find_full_path("ls"))
|
13
|
+
assert_nil(Klass.find_full_path("cookie monster cake"))
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# $Id: disk.rb 5401 2008-02-09 04:35:21Z ramon $
|
4
|
+
|
5
|
+
require 'rex/image_source/image_source'
|
6
|
+
require 'rex/struct2'
|
7
|
+
|
8
|
+
module Rex
|
9
|
+
module ImageSource
|
10
|
+
class Disk < ImageSource
|
11
|
+
|
12
|
+
attr_accessor :file, :file_offset, :size
|
13
|
+
|
14
|
+
WINDOW_SIZE = 4096
|
15
|
+
WINDOW_OVERLAP = 64
|
16
|
+
|
17
|
+
def initialize(_file, _offset = 0, _len = nil)
|
18
|
+
_len = _file.stat.size if !_len
|
19
|
+
|
20
|
+
self.file = _file
|
21
|
+
self.file_offset = _offset
|
22
|
+
self.size = _len
|
23
|
+
end
|
24
|
+
|
25
|
+
def read(offset, len)
|
26
|
+
if offset < 0 || offset+len > size
|
27
|
+
raise RangeError, "Offset #{offset} outside of image source", caller
|
28
|
+
end
|
29
|
+
|
30
|
+
file.seek(file_offset + offset)
|
31
|
+
file.read(len)
|
32
|
+
end
|
33
|
+
|
34
|
+
def index(search, offset = 0)
|
35
|
+
# do a sliding window search across the disk
|
36
|
+
while offset < size
|
37
|
+
|
38
|
+
# get a full window size if we can, we
|
39
|
+
# don't want to read past our boundaries
|
40
|
+
wsize = size - offset
|
41
|
+
wsize = WINDOW_SIZE if wsize > WINDOW_SIZE
|
42
|
+
|
43
|
+
window = self.read(offset, wsize)
|
44
|
+
res = window.index(search)
|
45
|
+
return res + offset if res
|
46
|
+
offset += WINDOW_SIZE - WINDOW_OVERLAP
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def subsource(offset, len)
|
51
|
+
self.class.new(file, file_offset+offset, len)
|
52
|
+
end
|
53
|
+
|
54
|
+
def close
|
55
|
+
file.close
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# $Id: image_source.rb 5401 2008-02-09 04:35:21Z ramon $
|
4
|
+
|
5
|
+
module Rex
|
6
|
+
module ImageSource
|
7
|
+
class ImageSource
|
8
|
+
|
9
|
+
#
|
10
|
+
# Um, just some abstract class stuff I guess, this is the interface
|
11
|
+
# that any image sources should subscribe to...
|
12
|
+
#
|
13
|
+
|
14
|
+
def subsource(offset, len)
|
15
|
+
raise "do something"
|
16
|
+
end
|
17
|
+
|
18
|
+
def size
|
19
|
+
raise "do something"
|
20
|
+
end
|
21
|
+
|
22
|
+
def file_offset
|
23
|
+
raise "do something"
|
24
|
+
end
|
25
|
+
|
26
|
+
def close
|
27
|
+
raise "do something"
|
28
|
+
end
|
29
|
+
|
30
|
+
def read_asciiz(offset)
|
31
|
+
# FIXME, make me better
|
32
|
+
string = ''
|
33
|
+
loop do
|
34
|
+
char = read(offset, 1)
|
35
|
+
break if char == "\x00"
|
36
|
+
offset += 1
|
37
|
+
string << char
|
38
|
+
end
|
39
|
+
return string
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# $Id: memory.rb 5401 2008-02-09 04:35:21Z ramon $
|
4
|
+
|
5
|
+
require 'rex/image_source/image_source'
|
6
|
+
require 'rex/struct2'
|
7
|
+
|
8
|
+
module Rex
|
9
|
+
module ImageSource
|
10
|
+
class Memory < ImageSource
|
11
|
+
|
12
|
+
attr_accessor :rawdata, :size, :file_offset
|
13
|
+
|
14
|
+
def initialize(_rawdata, _file_offset = 0)
|
15
|
+
self.rawdata = _rawdata
|
16
|
+
self.size = _rawdata.length
|
17
|
+
self.file_offset = _file_offset
|
18
|
+
end
|
19
|
+
|
20
|
+
def read(offset, len)
|
21
|
+
rawdata[offset, len]
|
22
|
+
end
|
23
|
+
|
24
|
+
def subsource(offset, len)
|
25
|
+
self.class.new(rawdata[offset, len], offset + file_offset)
|
26
|
+
end
|
27
|
+
|
28
|
+
def close
|
29
|
+
end
|
30
|
+
|
31
|
+
def index(*args)
|
32
|
+
rawdata.index(*args)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
module Rex
|
2
|
+
module IO
|
3
|
+
|
4
|
+
require 'rex/ui/text/output'
|
5
|
+
require 'rex/ui/text/output/buffer'
|
6
|
+
require 'rex/ui/text/input/buffer'
|
7
|
+
|
8
|
+
class BidirectionalPipe < Rex::Ui::Text::Input
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@subscribers_out = {}
|
12
|
+
@subscribers_ref = {}
|
13
|
+
@subscribers_idx = 0
|
14
|
+
@pipe_input = Rex::Ui::Text::Input::Buffer.new
|
15
|
+
|
16
|
+
# We are the shell, the input, and the output
|
17
|
+
self.output = self
|
18
|
+
self.input = self
|
19
|
+
end
|
20
|
+
|
21
|
+
def pipe_input
|
22
|
+
@pipe_input
|
23
|
+
end
|
24
|
+
|
25
|
+
def close
|
26
|
+
@pipe_input.close
|
27
|
+
end
|
28
|
+
|
29
|
+
def has_subscriber?(id)
|
30
|
+
@subscribers_out.has_key?(id)
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_subscriber(id=nil)
|
34
|
+
id ||= (@subscribers_idx += 1).to_s
|
35
|
+
@subscribers_out[id] = Rex::Ui::Text::Output::Buffer.new
|
36
|
+
return id
|
37
|
+
end
|
38
|
+
|
39
|
+
def create_subscriber_proc(id=nil, &block)
|
40
|
+
id = create_subscriber(id)
|
41
|
+
@subscribers_ref[id] = block
|
42
|
+
end
|
43
|
+
|
44
|
+
def remove_subscriber(id)
|
45
|
+
@subscribers_out.delete(id)
|
46
|
+
@subscribers_ref.delete(id)
|
47
|
+
end
|
48
|
+
|
49
|
+
def write_input(buf)
|
50
|
+
@pipe_input.put(buf)
|
51
|
+
end
|
52
|
+
|
53
|
+
def read_subscriber(id)
|
54
|
+
output = @subscribers_out[id]
|
55
|
+
|
56
|
+
return '' if output.nil?
|
57
|
+
|
58
|
+
buf = output.buf
|
59
|
+
|
60
|
+
output.reset
|
61
|
+
|
62
|
+
buf
|
63
|
+
end
|
64
|
+
|
65
|
+
def print(msg='')
|
66
|
+
@subscribers_out.each_pair { |id, buf|
|
67
|
+
begin
|
68
|
+
@subscribers_ref[id] ? @subscribers_ref[id].call(msg) : buf.print(msg)
|
69
|
+
rescue ::Exception => e
|
70
|
+
# $stderr.puts "Error handling subscriber #{id}: #{e} #{e.backtrace.inspect}"
|
71
|
+
raise e
|
72
|
+
end
|
73
|
+
}
|
74
|
+
msg
|
75
|
+
end
|
76
|
+
|
77
|
+
def print_error(msg='')
|
78
|
+
print_line('[-] ' + msg)
|
79
|
+
end
|
80
|
+
|
81
|
+
def print_line(msg='')
|
82
|
+
print(msg + "\n")
|
83
|
+
end
|
84
|
+
|
85
|
+
def print_good(msg='')
|
86
|
+
print_line('[+] ' + msg)
|
87
|
+
end
|
88
|
+
|
89
|
+
def print_debug(msg='')
|
90
|
+
print_line('[!] ' + msg)
|
91
|
+
end
|
92
|
+
|
93
|
+
def flush
|
94
|
+
end
|
95
|
+
|
96
|
+
def print_status(msg='')
|
97
|
+
print_line('[*] ' + msg)
|
98
|
+
end
|
99
|
+
|
100
|
+
#
|
101
|
+
# Wrappers for the pipe_input methods
|
102
|
+
#
|
103
|
+
|
104
|
+
def close
|
105
|
+
@pipe_input.close
|
106
|
+
end
|
107
|
+
|
108
|
+
def sysread(len = 1)
|
109
|
+
@pipe_input.sysread(len)
|
110
|
+
end
|
111
|
+
|
112
|
+
def put(msg)
|
113
|
+
@pipe_input.put(msg)
|
114
|
+
end
|
115
|
+
|
116
|
+
def gets
|
117
|
+
@pipe_input.gets
|
118
|
+
end
|
119
|
+
|
120
|
+
def eof?
|
121
|
+
@pipe_input.eof?
|
122
|
+
end
|
123
|
+
|
124
|
+
def fd
|
125
|
+
@pipe_input.fd
|
126
|
+
end
|
127
|
+
|
128
|
+
#
|
129
|
+
# Wrappers for shell methods
|
130
|
+
#
|
131
|
+
|
132
|
+
attr_accessor :output, :prompt, :input
|
133
|
+
|
134
|
+
def intrinsic_shell?
|
135
|
+
true
|
136
|
+
end
|
137
|
+
|
138
|
+
def supports_readline
|
139
|
+
false
|
140
|
+
end
|
141
|
+
|
142
|
+
def supports_color?
|
143
|
+
false
|
144
|
+
end
|
145
|
+
|
146
|
+
def pgets
|
147
|
+
gets
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
protected
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'socket'
|
4
|
+
|
5
|
+
module Rex
|
6
|
+
module IO
|
7
|
+
|
8
|
+
###
|
9
|
+
#
|
10
|
+
# This class provides an abstraction to a datagram based
|
11
|
+
# connection through the use of a datagram socketpair.
|
12
|
+
#
|
13
|
+
###
|
14
|
+
module DatagramAbstraction
|
15
|
+
|
16
|
+
#
|
17
|
+
# Creates a streaming socket pair
|
18
|
+
#
|
19
|
+
def initialize_abstraction
|
20
|
+
self.lsock, self.rsock = Rex::Socket.udp_socket_pair()
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
# The left side of the stream (local)
|
25
|
+
attr_reader :lsock
|
26
|
+
# The right side of the stream (remote)
|
27
|
+
attr_reader :rsock
|
28
|
+
|
29
|
+
protected
|
30
|
+
attr_writer :lsock
|
31
|
+
attr_writer :rsock
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end; end
|
@@ -0,0 +1,364 @@
|
|
1
|
+
#
|
2
|
+
# This class implements a ring buffer with "cursors" in the form of sequence numbers.
|
3
|
+
# To use this class, pass in a file descriptor and a ring size, the class will read
|
4
|
+
# data from the file descriptor and store it in the ring. If the ring becomes full,
|
5
|
+
# the oldest item will be overwritten. To emulate a stream interface, call read_data
|
6
|
+
# to grab the last sequence number and any buffered data, call read_data again,
|
7
|
+
# passing in the sequence number and all data newer than that sequence will be
|
8
|
+
# returned, along with a new sequence to read from.
|
9
|
+
#
|
10
|
+
|
11
|
+
require 'rex/socket'
|
12
|
+
|
13
|
+
module Rex
|
14
|
+
module IO
|
15
|
+
|
16
|
+
class RingBuffer
|
17
|
+
|
18
|
+
attr_accessor :queue # The data queue, essentially an array of two-element arrays, containing a sequence and data buffer
|
19
|
+
attr_accessor :seq # The next available sequence number
|
20
|
+
attr_accessor :fd # The associated socket or IO object for this ring buffer
|
21
|
+
attr_accessor :size # The number of available slots in the queue
|
22
|
+
attr_accessor :mutex # The mutex locking access to the queue
|
23
|
+
attr_accessor :beg # The index of the earliest data fragment in the ring
|
24
|
+
attr_accessor :cur # The sequence number of the earliest data fragment in the ring
|
25
|
+
attr_accessor :monitor # The thread handle of the built-in monitor when used
|
26
|
+
attr_accessor :monitor_thread_error # :nodoc: #
|
27
|
+
|
28
|
+
#
|
29
|
+
# Create a new ring buffer
|
30
|
+
#
|
31
|
+
def initialize(socket, opts={})
|
32
|
+
self.size = opts[:size] || (1024 * 4)
|
33
|
+
self.fd = socket
|
34
|
+
self.seq = 0
|
35
|
+
self.beg = 0
|
36
|
+
self.cur = 0
|
37
|
+
self.queue = Array.new( self.size )
|
38
|
+
self.mutex = Mutex.new
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# Start the built-in monitor, not called when used in a larger framework
|
43
|
+
#
|
44
|
+
def start_monitor
|
45
|
+
self.monitor = monitor_thread if not self.monitor
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# Stop the built-in monitor
|
50
|
+
#
|
51
|
+
def stop_monitor
|
52
|
+
self.monitor.kill if self.monitor
|
53
|
+
self.monitor = nil
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# The built-in monitor thread
|
58
|
+
#
|
59
|
+
def monitor_thread
|
60
|
+
Thread.new do
|
61
|
+
begin
|
62
|
+
while self.fd
|
63
|
+
buff = self.fd.get_once(-1, 1.0)
|
64
|
+
next if not buff
|
65
|
+
store_data(buff)
|
66
|
+
end
|
67
|
+
rescue ::Exception => e
|
68
|
+
self.monitor_thread_error = e
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
#
|
74
|
+
# Push data back into the associated stream socket. Logging must occur
|
75
|
+
# elsewhere, this function is simply a passthrough.
|
76
|
+
#
|
77
|
+
def put(data)
|
78
|
+
self.fd.put(data)
|
79
|
+
end
|
80
|
+
|
81
|
+
#
|
82
|
+
# The clear_data method wipes the ring buffer
|
83
|
+
#
|
84
|
+
def clear_data
|
85
|
+
self.mutex.synchronize do
|
86
|
+
self.seq = 0
|
87
|
+
self.beg = 0
|
88
|
+
self.cur = 0
|
89
|
+
self.queue = Array.new( self.size )
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
#
|
94
|
+
# The store_data method is used to insert data into the ring buffer.
|
95
|
+
#
|
96
|
+
def store_data(data)
|
97
|
+
self.mutex.synchronize do
|
98
|
+
# self.cur points to the array index of queue containing the last item
|
99
|
+
# adding data will result in cur + 1 being used to store said data
|
100
|
+
# if cur is larger than size - 1, it will wrap back around. If cur
|
101
|
+
# is *smaller* beg, beg is increemnted to cur + 1 (and wrapped if
|
102
|
+
# necessary
|
103
|
+
|
104
|
+
loc = 0
|
105
|
+
if self.seq > 0
|
106
|
+
loc = ( self.cur + 1 ) % self.size
|
107
|
+
|
108
|
+
if loc <= self.beg
|
109
|
+
self.beg = (self.beg + 1) % self.size
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
self.queue[loc] = [self.seq += 1, data]
|
114
|
+
self.cur = loc
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
# The read_data method returns a two element array with the new reader cursor (a sequence number)
|
120
|
+
# and the returned data buffer (if any). A result of nil/nil indicates that no data is available
|
121
|
+
#
|
122
|
+
def read_data(ptr=nil)
|
123
|
+
self.mutex.synchronize do
|
124
|
+
|
125
|
+
# Verify that there is data in the queue
|
126
|
+
return [nil,nil] if not self.queue[self.beg]
|
127
|
+
|
128
|
+
# Configure the beginning read pointer (sequence number, not index)
|
129
|
+
ptr ||= self.queue[self.beg][0]
|
130
|
+
return [nil,nil] if not ptr
|
131
|
+
|
132
|
+
# If the pointer is below our baseline, we lost some data, so jump forward
|
133
|
+
if ptr < self.queue[self.beg][0]
|
134
|
+
ptr = self.queue[self.beg][0]
|
135
|
+
end
|
136
|
+
|
137
|
+
# Calculate how many blocks exist between the current sequence number
|
138
|
+
# and the requested pointer, this becomes the number of blocks we will
|
139
|
+
# need to read to satisfy the result. Due to the mutex block, we do
|
140
|
+
# not need to scan to find the sequence of the starting block or
|
141
|
+
# check the sequence of the ending block.
|
142
|
+
dis = self.seq - ptr
|
143
|
+
|
144
|
+
# If the requested sequnce number is less than our base pointer, it means
|
145
|
+
# that no new data is available and we should return empty.
|
146
|
+
return [nil,nil] if dis < 0
|
147
|
+
|
148
|
+
# Calculate the beginning block index and number of blocks to read
|
149
|
+
off = ptr - self.queue[self.beg][0]
|
150
|
+
set = (self.beg + off) % self.size
|
151
|
+
|
152
|
+
|
153
|
+
# Build the buffer by reading forward by the number of blocks needed
|
154
|
+
# and return the last read sequence number, plus one, as the new read
|
155
|
+
# pointer.
|
156
|
+
buff = ""
|
157
|
+
cnt = 0
|
158
|
+
lst = ptr
|
159
|
+
ptr.upto(self.seq) do |i|
|
160
|
+
block = self.queue[ (set + cnt) % self.size ]
|
161
|
+
lst,data = block[0],block[1]
|
162
|
+
buff += data
|
163
|
+
cnt += 1
|
164
|
+
end
|
165
|
+
|
166
|
+
return [lst + 1, buff]
|
167
|
+
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
#
|
172
|
+
# The base_sequence method returns the earliest sequence number in the queue. This is zero until
|
173
|
+
# all slots are filled and the ring rotates.
|
174
|
+
#
|
175
|
+
def base_sequence
|
176
|
+
self.mutex.synchronize do
|
177
|
+
return 0 if not self.queue[self.beg]
|
178
|
+
return self.queue[self.beg][0]
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
#
|
183
|
+
# The last_sequence method returns the "next" sequence number where new data will be
|
184
|
+
# available.
|
185
|
+
#
|
186
|
+
def last_sequence
|
187
|
+
self.seq
|
188
|
+
end
|
189
|
+
|
190
|
+
#
|
191
|
+
# The create_steam method assigns a IO::Socket compatible object to the ringer buffer
|
192
|
+
#
|
193
|
+
def create_stream
|
194
|
+
Stream.new(self)
|
195
|
+
end
|
196
|
+
|
197
|
+
#
|
198
|
+
# The select method returns when there is a chance of new data
|
199
|
+
# XXX: This is mostly useless and requires a rewrite to use a
|
200
|
+
# real select or notify mechanism
|
201
|
+
#
|
202
|
+
def select
|
203
|
+
::IO.select([ self.fd ], nil, [ self.fd ], 0.10)
|
204
|
+
end
|
205
|
+
|
206
|
+
#
|
207
|
+
# The wait method blocks until new data is available
|
208
|
+
#
|
209
|
+
def wait(seq)
|
210
|
+
nseq = nil
|
211
|
+
while not nseq
|
212
|
+
nseq,data = read_data(seq)
|
213
|
+
select
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
#
|
218
|
+
# The wait_for method blocks until new data is available or the timeout is reached
|
219
|
+
#
|
220
|
+
def wait_for(seq,timeout=1)
|
221
|
+
begin
|
222
|
+
::Timeout.timeout(timeout) do
|
223
|
+
wait(seq)
|
224
|
+
end
|
225
|
+
rescue ::Timeout::Error
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
#
|
230
|
+
# This class provides a backwards compatible "stream" socket that uses
|
231
|
+
# the parents ring buffer.
|
232
|
+
#
|
233
|
+
class Stream
|
234
|
+
attr_accessor :ring
|
235
|
+
attr_accessor :seq
|
236
|
+
attr_accessor :buff
|
237
|
+
|
238
|
+
def initialize(ring)
|
239
|
+
self.ring = ring
|
240
|
+
self.seq = ring.base_sequence
|
241
|
+
self.buff = ''
|
242
|
+
end
|
243
|
+
|
244
|
+
def read(len=nil)
|
245
|
+
if len and self.buff.length >= len
|
246
|
+
data = self.buff.slice!(0,len)
|
247
|
+
return data
|
248
|
+
end
|
249
|
+
|
250
|
+
while true
|
251
|
+
lseq, data = self.ring.read_data( self.seq )
|
252
|
+
return if not lseq
|
253
|
+
|
254
|
+
self.seq = lseq
|
255
|
+
self.buff << data
|
256
|
+
if len
|
257
|
+
if self.buff.length >= len
|
258
|
+
return self.buff.slice!(0,len)
|
259
|
+
else
|
260
|
+
IO.select(nil, nil, nil, 0.25)
|
261
|
+
next
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
data = self.buff
|
266
|
+
self.buff = ''
|
267
|
+
|
268
|
+
return data
|
269
|
+
|
270
|
+
# Not reached
|
271
|
+
break
|
272
|
+
end
|
273
|
+
|
274
|
+
end
|
275
|
+
|
276
|
+
def write(data)
|
277
|
+
self.ring.write(data)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
end
|
282
|
+
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
=begin
|
287
|
+
|
288
|
+
server = Rex::Socket.create_tcp_server('LocalPort' => 0)
|
289
|
+
lport = server.getsockname[2]
|
290
|
+
client = Rex::Socket.create_tcp('PeerHost' => '127.0.0.1', 'PeerPort' => lport)
|
291
|
+
conn = server.accept
|
292
|
+
|
293
|
+
r = Rex::IO::RingBuffer.new(conn, {:size => 1024*1024})
|
294
|
+
client.put("1")
|
295
|
+
client.put("2")
|
296
|
+
client.put("3")
|
297
|
+
|
298
|
+
s,d = r.read_data
|
299
|
+
|
300
|
+
client.put("4")
|
301
|
+
client.put("5")
|
302
|
+
client.put("6")
|
303
|
+
s,d = r.read_data(s)
|
304
|
+
|
305
|
+
client.put("7")
|
306
|
+
client.put("8")
|
307
|
+
client.put("9")
|
308
|
+
s,d = r.read_data(s)
|
309
|
+
|
310
|
+
client.put("0")
|
311
|
+
s,d = r.read_data(s)
|
312
|
+
|
313
|
+
test_counter = 11
|
314
|
+
1.upto(100) do
|
315
|
+
client.put( "X" )
|
316
|
+
test_counter += 1
|
317
|
+
end
|
318
|
+
|
319
|
+
sleep(1)
|
320
|
+
|
321
|
+
s,d = r.read_data
|
322
|
+
p s
|
323
|
+
p d
|
324
|
+
|
325
|
+
fdata = ''
|
326
|
+
File.open("/bin/ls", "rb") do |fd|
|
327
|
+
fdata = fd.read(fd.stat.size)
|
328
|
+
fdata = fdata * 10
|
329
|
+
client.put(fdata)
|
330
|
+
end
|
331
|
+
|
332
|
+
sleep(1)
|
333
|
+
|
334
|
+
s,vdata = r.read_data(s)
|
335
|
+
|
336
|
+
if vdata != fdata
|
337
|
+
puts "DATA FAILED"
|
338
|
+
else
|
339
|
+
puts "DATA VERIFIED"
|
340
|
+
end
|
341
|
+
|
342
|
+
r.clear_data
|
343
|
+
|
344
|
+
a = r.create_stream
|
345
|
+
b = r.create_stream
|
346
|
+
|
347
|
+
client.put("ABC123")
|
348
|
+
sleep(1)
|
349
|
+
|
350
|
+
p a.read
|
351
|
+
p b.read
|
352
|
+
|
353
|
+
client.put("$$$$$$")
|
354
|
+
sleep(1)
|
355
|
+
|
356
|
+
p a.read
|
357
|
+
p b.read
|
358
|
+
|
359
|
+
c = r.create_stream
|
360
|
+
p c.read
|
361
|
+
|
362
|
+
=end
|
363
|
+
|
364
|
+
|