librex 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +4 -0
- data/lib/rex.rb +101 -0
- data/lib/rex.rb.ts.rb +70 -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 +100 -0
- data/lib/rex/assembly/nasm.rb.ut.rb +22 -0
- data/lib/rex/codepage.map +104 -0
- data/lib/rex/compat.rb +281 -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 +260 -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 +113 -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 +133 -0
- data/lib/rex/exploitation/egghunter.rb +143 -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 +735 -0
- data/lib/rex/exploitation/obfuscatejs.rb +335 -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 +84 -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/stream.rb +313 -0
- data/lib/rex/io/stream_abstraction.rb +186 -0
- data/lib/rex/io/stream_server.rb +211 -0
- data/lib/rex/job_container.rb +202 -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 +75 -0
- data/lib/rex/mime/message.rb +112 -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 +128 -0
- data/lib/rex/ole/clsid.rb +47 -0
- data/lib/rex/ole/difat.rb +141 -0
- data/lib/rex/ole/directory.rb +230 -0
- data/lib/rex/ole/direntry.rb +240 -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/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/nmap_xml.rb +111 -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 +171 -0
- data/lib/rex/peparsey.rb +12 -0
- data/lib/rex/peparsey/exceptions.rb +32 -0
- data/lib/rex/peparsey/pe.rb +188 -0
- data/lib/rex/peparsey/pe_memdump.rb +63 -0
- data/lib/rex/peparsey/pebase.rb +1655 -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 +468 -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 +438 -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 +335 -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/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 +104 -0
- data/lib/rex/post/meterpreter/extensions/priv/tlv.rb +28 -0
- data/lib/rex/post/meterpreter/extensions/sniffer/sniffer.rb +100 -0
- data/lib/rex/post/meterpreter/extensions/sniffer/tlv.rb +24 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/constants.rb +333 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/fs/dir.rb +273 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb +235 -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 +167 -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 +192 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/stdapi.rb +139 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/config.rb +97 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/event_log.rb +184 -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 +361 -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 +182 -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 +174 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/tlv.rb +185 -0
- data/lib/rex/post/meterpreter/extensions/stdapi/ui.rb +227 -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 +596 -0
- data/lib/rex/post/meterpreter/packet_dispatcher.rb +409 -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 +135 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher.rb +62 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb +595 -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/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 +63 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb +376 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/net.rb +270 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb +484 -0
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb +315 -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 +12 -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 +358 -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 +186 -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/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 +817 -0
- data/lib/rex/proto/http/client.rb.ut.rb +93 -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 +54 -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 +394 -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 +85 -0
- data/lib/rex/proto/http/response.rb.ut.rb +149 -0
- data/lib/rex/proto/http/server.rb +367 -0
- data/lib/rex/proto/http/server.rb.ut.rb +79 -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 +1733 -0
- data/lib/rex/proto/smb/client.rb.ut.rb +223 -0
- data/lib/rex/proto/smb/constants.rb +1062 -0
- data/lib/rex/proto/smb/constants.rb.ut.rb +18 -0
- data/lib/rex/proto/smb/crypt.rb +95 -0
- data/lib/rex/proto/smb/crypt.rb.ut.rb +20 -0
- data/lib/rex/proto/smb/evasions.rb +65 -0
- data/lib/rex/proto/smb/exceptions.rb +846 -0
- data/lib/rex/proto/smb/simpleclient.rb +292 -0
- data/lib/rex/proto/smb/simpleclient.rb.ut.rb +128 -0
- data/lib/rex/proto/smb/utils.rb +514 -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/script.rb +42 -0
- data/lib/rex/script/base.rb +59 -0
- data/lib/rex/script/meterpreter.rb +9 -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 +586 -0
- data/lib/rex/socket.rb.ut.rb +86 -0
- data/lib/rex/socket/comm.rb +119 -0
- data/lib/rex/socket/comm/local.rb +409 -0
- data/lib/rex/socket/comm/local.rb.ut.rb +75 -0
- data/lib/rex/socket/ip.rb +129 -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 +295 -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 +51 -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 +272 -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 +67 -0
- data/lib/rex/socket/tcp_server.rb.ut.rb +44 -0
- data/lib/rex/socket/udp.rb +157 -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 +1029 -0
- data/lib/rex/text.rb.ut.rb +168 -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 +252 -0
- data/lib/rex/ui/output.rb +80 -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 +382 -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 +55 -0
- data/lib/rex/ui/text/output.rb +80 -0
- data/lib/rex/ui/text/output/buffer.rb +65 -0
- data/lib/rex/ui/text/output/file.rb +37 -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 +321 -0
- data/lib/rex/ui/text/table.rb +254 -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 +91 -0
- data/lib/rex/zip/blocks.rb +182 -0
- data/lib/rex/zip/entry.rb +95 -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 +435 -0
@@ -0,0 +1,86 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..'))
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'rex/socket'
|
7
|
+
require 'rex/socket/tcp'
|
8
|
+
|
9
|
+
class Rex::Socket::UnitTest < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def test_ip
|
12
|
+
assert_equal(true,Rex::Socket.dotted_ip?('0.0.0.0'), 'valid IP min')
|
13
|
+
assert_equal(true,Rex::Socket.dotted_ip?('255.255.255.255'), 'valid IP max')
|
14
|
+
assert_equal(false,Rex::Socket.dotted_ip?('0.0.0.0.0'), 'too many sections')
|
15
|
+
assert_equal(false,Rex::Socket.dotted_ip?('0..0.0.0'), 'too many dots')
|
16
|
+
assert_equal(false,Rex::Socket.dotted_ip?('00.0.0'), 'not enough dots')
|
17
|
+
assert_equal(false,Rex::Socket.dotted_ip?('256.256.256.256'), 'numbers too big')
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_create
|
21
|
+
port = 64442
|
22
|
+
serv = TCPServer.new('127.0.0.1', port)
|
23
|
+
|
24
|
+
sock = nil
|
25
|
+
assert_nothing_raised {
|
26
|
+
sock = Rex::Socket.create(
|
27
|
+
'PeerHost' => '127.0.0.1',
|
28
|
+
'PeerPort' => port,
|
29
|
+
'Proto' => 'tcp')
|
30
|
+
}
|
31
|
+
assert_kind_of(Rex::Socket::Tcp, sock, "socket factory creation")
|
32
|
+
|
33
|
+
sock = nil
|
34
|
+
assert_nothing_raised {
|
35
|
+
sock = Rex::Socket.create_tcp(
|
36
|
+
'PeerHost' => '127.0.0.1',
|
37
|
+
'PeerPort' => port)
|
38
|
+
}
|
39
|
+
assert_kind_of(Rex::Socket::Tcp, sock, "tcp socket factory creation")
|
40
|
+
|
41
|
+
serv.close
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_to_sockaddr
|
45
|
+
assert_equal("\x00" * 16, Rex::Socket.to_sockaddr(nil, 0, 0), "null sockaddr")
|
46
|
+
assert_equal([2].pack('s') + "\x00\x16" + "\x00" * 12, Rex::Socket.to_sockaddr(nil, 22), "default addr, port 22 sockaddr")
|
47
|
+
assert_equal([2].pack('s') + "\x00\x16\x01\x02\x03\x04" + "\x00" * 8, Rex::Socket.to_sockaddr("1.2.3.4", 22), "1.2.3.4 addr, port 22 sockaddr")
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_from_sockaddr
|
51
|
+
af, host, port = Rex::Socket.from_sockaddr("\x00" * 16)
|
52
|
+
assert_equal(0, af, "zero af")
|
53
|
+
assert_equal('0.0.0.0', host, "zero host")
|
54
|
+
assert_equal(0, port, "zero port")
|
55
|
+
|
56
|
+
af, host, port = Rex::Socket.from_sockaddr([2].pack('s') + "\x00\x16" + "\x00" * 12)
|
57
|
+
assert_equal(2, af, "af = 2")
|
58
|
+
assert_equal('0.0.0.0', host, "zero host")
|
59
|
+
assert_equal(22, port, "port = 22")
|
60
|
+
|
61
|
+
af, host, port = Rex::Socket.from_sockaddr([2].pack('s') + "\x00\x16\x01\x02\x03\x04" + "\x00" * 8)
|
62
|
+
assert_equal(2, af, "af = 2")
|
63
|
+
assert_equal('1.2.3.4', host, "zero host")
|
64
|
+
assert_equal(22, port, "port = 22")
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_resolv_nbo
|
68
|
+
assert_equal("\x04\x03\x02\x01", Rex::Socket.resolv_nbo("4.3.2.1"))
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_net2bitmask
|
72
|
+
assert_equal(32, Rex::Socket.net2bitmask('255.255.255.255'))
|
73
|
+
assert_equal(28, Rex::Socket.net2bitmask('255.255.255.240'))
|
74
|
+
assert_equal(24, Rex::Socket.net2bitmask('255.255.255.0'))
|
75
|
+
assert_equal(16, Rex::Socket.net2bitmask('255.255.0.0'))
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_bit2netmask
|
79
|
+
assert_equal("255.255.255.255", Rex::Socket.bit2netmask(32))
|
80
|
+
assert_equal("255.255.255.254", Rex::Socket.bit2netmask(31))
|
81
|
+
assert_equal("255.255.255.240", Rex::Socket.bit2netmask(28))
|
82
|
+
assert_equal("255.255.255.0", Rex::Socket.bit2netmask(24))
|
83
|
+
assert_equal("255.255.0.0", Rex::Socket.bit2netmask(16))
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'rex/socket'
|
2
|
+
|
3
|
+
module Rex
|
4
|
+
module Socket
|
5
|
+
|
6
|
+
###
|
7
|
+
#
|
8
|
+
# This mixin provides the basic interface that a derived class must implement
|
9
|
+
# in order to be a compatible comm class. The base comm class also supports
|
10
|
+
# registering event handlers that can be notified when sockets are being
|
11
|
+
# created and have been created. This allows code to extend sockets on
|
12
|
+
# creation from the single point that they are created.
|
13
|
+
#
|
14
|
+
###
|
15
|
+
module Comm
|
16
|
+
|
17
|
+
###
|
18
|
+
#
|
19
|
+
# This mixin provides stubs for event notification handlers that can be
|
20
|
+
# registered with a Comm factory to be called when various events occur,
|
21
|
+
# such as socket instantiation.
|
22
|
+
#
|
23
|
+
###
|
24
|
+
module Events
|
25
|
+
|
26
|
+
#
|
27
|
+
# This callback is notified when a socket is being created and is passed
|
28
|
+
# the parameters that will be used to create it.
|
29
|
+
#
|
30
|
+
def on_before_socket_create(comm, param)
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# This callback is notified when a new socket is created and the
|
35
|
+
# parameters that were used to create it. This provides the callback
|
36
|
+
# with a chance to extend or otherwise modify the socket before it's
|
37
|
+
# passed on to the actual requestor.
|
38
|
+
#
|
39
|
+
def on_socket_created(comm, sock, param)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# Creates a compatible socket based on the supplied uniform parameters.
|
46
|
+
#
|
47
|
+
def self.create(param)
|
48
|
+
raise NotImplementedError
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# Indicates whether or not this comm can be chained with other chainable
|
53
|
+
# comms. This is particularly important for things like Proxy Comms that
|
54
|
+
# can be proxied through one another. The semantics of this are currently
|
55
|
+
# undefined and will probably need some more thought.
|
56
|
+
#
|
57
|
+
def chainable?
|
58
|
+
false
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# Registers an event handler that implements the Rex::Socket::Comm::Event
|
63
|
+
# interface in at least some fashion. Event handlers are notified when
|
64
|
+
# sockets are created through the Comm instance that they register against.
|
65
|
+
#
|
66
|
+
def register_event_handler(handler)
|
67
|
+
if (handlers == nil)
|
68
|
+
self.handlers = []
|
69
|
+
end
|
70
|
+
|
71
|
+
self.handlers << handler
|
72
|
+
end
|
73
|
+
|
74
|
+
#
|
75
|
+
# Deregisters a previously registered event handler.
|
76
|
+
#
|
77
|
+
def deregister_event_handler(handler)
|
78
|
+
if (handlers)
|
79
|
+
handlers.delete(handler)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# Enumerates each registered event handler so that they can be notified of
|
85
|
+
# an event.
|
86
|
+
#
|
87
|
+
def each_event_handler(&block)
|
88
|
+
if (handlers)
|
89
|
+
handlers.each(&block)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
#
|
94
|
+
# Notifies handlers of the before socket create event.
|
95
|
+
#
|
96
|
+
def notify_before_socket_create(comm, param)
|
97
|
+
each_event_handler() { |handler|
|
98
|
+
handler.on_before_socket_create(comm, param)
|
99
|
+
}
|
100
|
+
end
|
101
|
+
|
102
|
+
#
|
103
|
+
# Notifies handlers of the socket created event.
|
104
|
+
#
|
105
|
+
def notify_socket_created(comm, sock, param)
|
106
|
+
each_event_handler() { |handler|
|
107
|
+
handler.on_socket_created(comm, sock, param)
|
108
|
+
}
|
109
|
+
end
|
110
|
+
|
111
|
+
protected
|
112
|
+
|
113
|
+
attr_accessor :handlers # :nodoc:
|
114
|
+
attr_accessor :handlers_rwlock # :nodoc:
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,409 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'rex/socket'
|
3
|
+
require 'rex/socket/tcp'
|
4
|
+
require 'rex/socket/ssl_tcp'
|
5
|
+
require 'rex/socket/ssl_tcp_server'
|
6
|
+
require 'rex/socket/udp'
|
7
|
+
require 'rex/socket/ip'
|
8
|
+
require 'timeout'
|
9
|
+
|
10
|
+
###
|
11
|
+
#
|
12
|
+
# Local communication class factory.
|
13
|
+
#
|
14
|
+
###
|
15
|
+
class Rex::Socket::Comm::Local
|
16
|
+
|
17
|
+
include Singleton
|
18
|
+
include Rex::Socket::Comm
|
19
|
+
|
20
|
+
#
|
21
|
+
# Creates an instance of a socket using the supplied parameters.
|
22
|
+
#
|
23
|
+
def self.create(param)
|
24
|
+
|
25
|
+
# Work around jRuby socket implementation issues
|
26
|
+
if(RUBY_PLATFORM == 'java')
|
27
|
+
return self.create_jruby(param)
|
28
|
+
end
|
29
|
+
|
30
|
+
case param.proto
|
31
|
+
when 'tcp'
|
32
|
+
return create_by_type(param, ::Socket::SOCK_STREAM, ::Socket::IPPROTO_TCP)
|
33
|
+
when 'udp'
|
34
|
+
return create_by_type(param, ::Socket::SOCK_DGRAM, ::Socket::IPPROTO_UDP)
|
35
|
+
when 'ip'
|
36
|
+
return create_ip(param)
|
37
|
+
else
|
38
|
+
raise Rex::UnsupportedProtocol.new(param.proto), caller
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Creates an instance of a socket using the supplied parameters.
|
44
|
+
# Use various hacks to make this work with jRuby
|
45
|
+
#
|
46
|
+
def self.create_jruby(param)
|
47
|
+
sock = nil
|
48
|
+
|
49
|
+
# Notify handlers of the before socket create event.
|
50
|
+
self.instance.notify_before_socket_create(self, param)
|
51
|
+
|
52
|
+
case param.proto
|
53
|
+
when 'tcp'
|
54
|
+
if (param.server?)
|
55
|
+
sock = TCPServer.new(param.localport, param.localhost)
|
56
|
+
klass = Rex::Socket::TcpServer
|
57
|
+
if (param.ssl)
|
58
|
+
klass = Rex::Socket::SslTcpServer
|
59
|
+
end
|
60
|
+
sock.extend(klass)
|
61
|
+
|
62
|
+
else
|
63
|
+
sock = TCPSocket.new(param.peerhost, param.peerport)
|
64
|
+
klass = Rex::Socket::Tcp
|
65
|
+
if (param.ssl)
|
66
|
+
klass = Rex::Socket::SslTcp
|
67
|
+
end
|
68
|
+
sock.extend(klass)
|
69
|
+
end
|
70
|
+
when 'udp'
|
71
|
+
if (param.server?)
|
72
|
+
sock = UDPServer.new(param.localport, param.localhost)
|
73
|
+
klass = Rex::Socket::UdpServer
|
74
|
+
sock.extend(klass)
|
75
|
+
else
|
76
|
+
sock = UDPSocket.new(param.peerhost, param.peerport)
|
77
|
+
klass = Rex::Socket::Udp
|
78
|
+
sock.extend(klass)
|
79
|
+
end
|
80
|
+
else
|
81
|
+
raise Rex::UnsupportedProtocol.new(param.proto), caller
|
82
|
+
end
|
83
|
+
|
84
|
+
sock.initsock(param)
|
85
|
+
self.instance.notify_socket_created(self, sock, param)
|
86
|
+
return sock
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
#
|
91
|
+
# Creates a raw IP socket using the supplied Parameter instance.
|
92
|
+
# Special-cased because of how different it is from UDP/TCP
|
93
|
+
#
|
94
|
+
def self.create_ip(param)
|
95
|
+
self.instance.notify_before_socket_create(self, param)
|
96
|
+
|
97
|
+
sock = ::Socket.open(::Socket::PF_INET, ::Socket::SOCK_RAW, ::Socket::IPPROTO_RAW)
|
98
|
+
sock.setsockopt(::Socket::IPPROTO_IP, ::Socket::IP_HDRINCL, 1)
|
99
|
+
|
100
|
+
# Configure broadcast support
|
101
|
+
sock.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_BROADCAST, true)
|
102
|
+
|
103
|
+
if (param.bare? == false)
|
104
|
+
sock.extend(::Rex::Socket::Ip)
|
105
|
+
sock.initsock(param)
|
106
|
+
end
|
107
|
+
|
108
|
+
self.instance.notify_socket_created(self, sock, param)
|
109
|
+
|
110
|
+
sock
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
#
|
115
|
+
# Creates a socket using the supplied Parameter instance.
|
116
|
+
#
|
117
|
+
def self.create_by_type(param, type, proto = 0)
|
118
|
+
|
119
|
+
# Whether to use IPv6 addressing
|
120
|
+
usev6 = false
|
121
|
+
|
122
|
+
# Detect IPv6 addresses and enable IPv6 accordingly
|
123
|
+
if ( Rex::Socket.support_ipv6?())
|
124
|
+
|
125
|
+
# Allow the caller to force IPv6
|
126
|
+
if (param.v6)
|
127
|
+
usev6 = true
|
128
|
+
end
|
129
|
+
|
130
|
+
# Force IPv6 mode for non-connected UDP sockets
|
131
|
+
if (type == ::Socket::SOCK_DGRAM and not param.peerhost)
|
132
|
+
# FreeBSD allows IPv6 socket creation, but throws an error on sendto()
|
133
|
+
|
134
|
+
if (not Rex::Compat.is_freebsd())
|
135
|
+
usev6 = true
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
local = Rex::Socket.resolv_nbo(param.localhost) if param.localhost
|
140
|
+
peer = Rex::Socket.resolv_nbo(param.peerhost) if param.peerhost
|
141
|
+
|
142
|
+
if (local and local.length == 16)
|
143
|
+
usev6 = true
|
144
|
+
end
|
145
|
+
|
146
|
+
if (peer and peer.length == 16)
|
147
|
+
usev6 = true
|
148
|
+
end
|
149
|
+
|
150
|
+
if (usev6)
|
151
|
+
if (local and local.length == 4)
|
152
|
+
if (local == "\x00\x00\x00\x00")
|
153
|
+
param.localhost = '::'
|
154
|
+
elsif (local == "\x7f\x00\x00\x01")
|
155
|
+
param.localhost = '::1'
|
156
|
+
else
|
157
|
+
param.localhost = '::ffff:' + Rex::Socket.getaddress(param.localhost)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
if (peer and peer.length == 4)
|
162
|
+
if (peer == "\x00\x00\x00\x00")
|
163
|
+
param.peerhost = '::'
|
164
|
+
elsif (peer == "\x7f\x00\x00\x01")
|
165
|
+
param.peerhost = '::1'
|
166
|
+
else
|
167
|
+
param.peerhost = '::ffff:' + Rex::Socket.getaddress(param.peerhost)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
param.v6 = true
|
172
|
+
end
|
173
|
+
else
|
174
|
+
# No IPv6 support
|
175
|
+
param.v6 = false
|
176
|
+
end
|
177
|
+
|
178
|
+
# Notify handlers of the before socket create event.
|
179
|
+
self.instance.notify_before_socket_create(self, param)
|
180
|
+
|
181
|
+
# Create the socket
|
182
|
+
sock = nil
|
183
|
+
if (param.v6)
|
184
|
+
sock = ::Socket.new(::Socket::AF_INET6, type, proto)
|
185
|
+
else
|
186
|
+
sock = ::Socket.new(::Socket::AF_INET, type, proto)
|
187
|
+
end
|
188
|
+
|
189
|
+
# Bind to a given local address and/or port if they are supplied
|
190
|
+
if (param.localhost || param.localport)
|
191
|
+
begin
|
192
|
+
sock.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEADDR, true)
|
193
|
+
|
194
|
+
sock.bind(Rex::Socket.to_sockaddr(param.localhost, param.localport))
|
195
|
+
|
196
|
+
rescue Errno::EADDRINUSE
|
197
|
+
sock.close
|
198
|
+
raise Rex::AddressInUse.new(param.localhost, param.localport), caller
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
# Configure broadcast support for all datagram sockets
|
203
|
+
if (type == ::Socket::SOCK_DGRAM)
|
204
|
+
sock.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_BROADCAST, true)
|
205
|
+
end
|
206
|
+
|
207
|
+
# If a server TCP instance is being created...
|
208
|
+
if (param.server?)
|
209
|
+
sock.listen(32)
|
210
|
+
|
211
|
+
if (param.bare? == false)
|
212
|
+
klass = Rex::Socket::TcpServer
|
213
|
+
if (param.ssl)
|
214
|
+
klass = Rex::Socket::SslTcpServer
|
215
|
+
end
|
216
|
+
sock.extend(klass)
|
217
|
+
|
218
|
+
sock.initsock(param)
|
219
|
+
end
|
220
|
+
# Otherwise, if we're creating a client...
|
221
|
+
else
|
222
|
+
chain = []
|
223
|
+
|
224
|
+
# If we were supplied with host information
|
225
|
+
if (param.peerhost)
|
226
|
+
begin
|
227
|
+
ip = param.peerhost
|
228
|
+
port = param.peerport
|
229
|
+
|
230
|
+
if param.proxies
|
231
|
+
chain = param.proxies.dup
|
232
|
+
chain.push(['host',param.peerhost,param.peerport])
|
233
|
+
ip = chain[0][1]
|
234
|
+
port = chain[0][2].to_i
|
235
|
+
end
|
236
|
+
|
237
|
+
begin
|
238
|
+
Timeout.timeout(param.timeout) do
|
239
|
+
sock.connect(Rex::Socket.to_sockaddr(ip, port))
|
240
|
+
end
|
241
|
+
rescue ::Timeout::Error
|
242
|
+
raise ::Errno::ETIMEDOUT
|
243
|
+
end
|
244
|
+
|
245
|
+
rescue ::Errno::EHOSTUNREACH,::Errno::ENETDOWN,::Errno::ENETUNREACH,::Errno::ENETRESET,::Errno::EHOSTDOWN,::Errno::EACCES,::Errno::EINVAL,::Errno::EADDRNOTAVAIL
|
246
|
+
sock.close
|
247
|
+
raise Rex::HostUnreachable.new(param.peerhost, param.peerport), caller
|
248
|
+
|
249
|
+
rescue Errno::ETIMEDOUT
|
250
|
+
sock.close
|
251
|
+
raise Rex::ConnectionTimeout.new(param.peerhost, param.peerport), caller
|
252
|
+
|
253
|
+
rescue ::Errno::ECONNRESET,::Errno::ECONNREFUSED,::Errno::ENOTCONN,::Errno::ECONNABORTED
|
254
|
+
sock.close
|
255
|
+
raise Rex::ConnectionRefused.new(param.peerhost, param.peerport), caller
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
if (param.bare? == false)
|
260
|
+
case param.proto
|
261
|
+
when 'tcp'
|
262
|
+
klass = Rex::Socket::Tcp
|
263
|
+
sock.extend(klass)
|
264
|
+
sock.initsock(param)
|
265
|
+
when 'udp'
|
266
|
+
sock.extend(Rex::Socket::Udp)
|
267
|
+
sock.initsock(param)
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
if chain.size > 1
|
272
|
+
chain.each_with_index {
|
273
|
+
|proxy, i|
|
274
|
+
next_hop = chain[i + 1]
|
275
|
+
if next_hop
|
276
|
+
proxy(sock, proxy[0], next_hop[1], next_hop[2])
|
277
|
+
end
|
278
|
+
}
|
279
|
+
end
|
280
|
+
|
281
|
+
# Now extend the socket with SSL and perform the handshake
|
282
|
+
if(param.bare? == false and param.ssl)
|
283
|
+
klass = Rex::Socket::SslTcp
|
284
|
+
sock.extend(klass)
|
285
|
+
sock.initsock(param)
|
286
|
+
end
|
287
|
+
|
288
|
+
|
289
|
+
end
|
290
|
+
|
291
|
+
# Notify handlers that a socket has been created.
|
292
|
+
self.instance.notify_socket_created(self, sock, param)
|
293
|
+
|
294
|
+
sock
|
295
|
+
end
|
296
|
+
|
297
|
+
def self.proxy(sock, type, host, port)
|
298
|
+
|
299
|
+
#$stdout.print("PROXY\n")
|
300
|
+
case type.downcase
|
301
|
+
when 'http'
|
302
|
+
setup = "CONNECT #{host}:#{port} HTTP/1.0\r\n\r\n"
|
303
|
+
size = sock.put(setup)
|
304
|
+
if (size != setup.length)
|
305
|
+
raise Rex::ConnectionProxyError.new(host, port, type, "Failed to send the entire request to the proxy"), caller
|
306
|
+
end
|
307
|
+
|
308
|
+
begin
|
309
|
+
ret = sock.get_once(39,30)
|
310
|
+
rescue IOError
|
311
|
+
raise Rex::ConnectionProxyError.new(host, port, type, "Failed to receive a response from the proxy"), caller
|
312
|
+
end
|
313
|
+
|
314
|
+
if ret.nil?
|
315
|
+
raise Rex::ConnectionProxyError.new(host, port, type, "Failed to receive a response from the proxy"), caller
|
316
|
+
end
|
317
|
+
|
318
|
+
resp = Rex::Proto::Http::Response.new
|
319
|
+
resp.update_cmd_parts(ret.split(/\r?\n/)[0])
|
320
|
+
|
321
|
+
if resp.code != 200
|
322
|
+
raise Rex::ConnectionProxyError.new(host, port, type, "The proxy returned a non-OK response"), caller
|
323
|
+
end
|
324
|
+
when 'socks4'
|
325
|
+
setup = [4,1,port.to_i].pack('CCn') + Socket.gethostbyname(host)[3] + Rex::Text.rand_text_alpha(rand(8)+1) + "\x00"
|
326
|
+
size = sock.put(setup)
|
327
|
+
if (size != setup.length)
|
328
|
+
raise Rex::ConnectionProxyError.new(host, port, type, "Failed to send the entire request to the proxy"), caller
|
329
|
+
end
|
330
|
+
|
331
|
+
begin
|
332
|
+
ret = sock.get_once(8, 30)
|
333
|
+
rescue IOError
|
334
|
+
raise Rex::ConnectionProxyError.new(host, port, type, "Failed to receive a response from the proxy"), caller
|
335
|
+
end
|
336
|
+
|
337
|
+
if (ret.nil? or ret.length < 8)
|
338
|
+
raise Rex::ConnectionProxyError.new(host, port, type, "Failed to receive a complete response from the proxy"), caller
|
339
|
+
end
|
340
|
+
if ret[1,1] != "\x5a"
|
341
|
+
raise Rex::ConnectionProxyError.new(host, port, type, "Proxy responded with error code #{ret[0,1].unpack("C")[0]}"), caller
|
342
|
+
end
|
343
|
+
when 'socks5'
|
344
|
+
auth_methods = [5,1,0].pack('CCC')
|
345
|
+
size = sock.put(auth_methods)
|
346
|
+
if (size != auth_methods.length)
|
347
|
+
raise Rex::ConnectionProxyError.new(host, port, type, "Failed to send the entire request to the proxy"), caller
|
348
|
+
end
|
349
|
+
ret = sock.get_once(2,30)
|
350
|
+
if (ret[1,1] == "\xff")
|
351
|
+
raise Rex::ConnectionProxyError.new(host, port, type, "The proxy requires authentication"), caller
|
352
|
+
end
|
353
|
+
|
354
|
+
if (Rex::Socket.is_ipv4?(host))
|
355
|
+
addr = Rex::Socket.gethostbyname(host)[3]
|
356
|
+
setup = [5,1,0,1].pack('C4') + addr + [port.to_i].pack('n')
|
357
|
+
elsif (Rex::Socket.support_ipv6? and Rex::Socket.is_ipv6?(host))
|
358
|
+
# IPv6 stuff all untested
|
359
|
+
addr = Rex::Socket.gethostbyname(host)[3]
|
360
|
+
setup = [5,1,0,4].pack('C4') + addr + [port.to_i].pack('n')
|
361
|
+
else
|
362
|
+
# Then it must be a domain name.
|
363
|
+
# Unfortunately, it looks like the host has always been
|
364
|
+
# resolved by the time it gets here, so this code never runs.
|
365
|
+
setup = [5,1,0,3].pack('C4') + [host.length].pack('C') + host + [port.to_i].pack('n')
|
366
|
+
end
|
367
|
+
|
368
|
+
size = sock.put(setup)
|
369
|
+
if (size != setup.length)
|
370
|
+
raise Rex::ConnectionProxyError.new(host, port, type, "Failed to send the entire request to the proxy"), caller
|
371
|
+
end
|
372
|
+
|
373
|
+
begin
|
374
|
+
response = sock.get_once(10, 30)
|
375
|
+
rescue IOError
|
376
|
+
raise Rex::ConnectionProxyError.new(host, port, type, "Failed to receive a response from the proxy"), caller
|
377
|
+
end
|
378
|
+
|
379
|
+
if (response.nil? or response.length < 10)
|
380
|
+
raise Rex::ConnectionProxyError.new(host, port, type, "Failed to receive a complete response from the proxy"), caller
|
381
|
+
end
|
382
|
+
if response[1,1] != "\x00"
|
383
|
+
raise Rex::ConnectionProxyError.new(host, port, type, "Proxy responded with error code #{response[1,1].unpack("C")[0]}"), caller
|
384
|
+
end
|
385
|
+
else
|
386
|
+
raise RuntimeError, "The proxy type specified is not valid", caller
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
##
|
391
|
+
#
|
392
|
+
# Registration
|
393
|
+
#
|
394
|
+
##
|
395
|
+
|
396
|
+
def self.register_event_handler(handler) # :nodoc:
|
397
|
+
self.instance.register_event_handler(handler)
|
398
|
+
end
|
399
|
+
|
400
|
+
def self.deregister_event_handler(handler) # :nodoc:
|
401
|
+
self.instance.deregister_event_handler(handler)
|
402
|
+
end
|
403
|
+
|
404
|
+
def self.each_event_handler(handler) # :nodoc:
|
405
|
+
self.instance.each_event_handler(handler)
|
406
|
+
end
|
407
|
+
|
408
|
+
end
|
409
|
+
|