librex 0.0.13 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +1 -1
- data/Rakefile +1 -0
- metadata +3 -435
- data/lib/rex/LICENSE +0 -29
- data/lib/rex/arch.rb +0 -103
- data/lib/rex/arch/sparc.rb +0 -75
- data/lib/rex/arch/sparc.rb.ut.rb +0 -18
- data/lib/rex/arch/x86.rb +0 -513
- data/lib/rex/arch/x86.rb.ut.rb +0 -93
- data/lib/rex/assembly/nasm.rb +0 -104
- data/lib/rex/assembly/nasm.rb.ut.rb +0 -22
- data/lib/rex/codepage.map +0 -104
- data/lib/rex/compat.rb +0 -311
- data/lib/rex/constants.rb +0 -113
- data/lib/rex/elfparsey.rb +0 -11
- data/lib/rex/elfparsey/elf.rb +0 -123
- data/lib/rex/elfparsey/elfbase.rb +0 -258
- data/lib/rex/elfparsey/exceptions.rb +0 -27
- data/lib/rex/elfscan.rb +0 -12
- data/lib/rex/elfscan/scanner.rb +0 -207
- data/lib/rex/elfscan/search.rb +0 -46
- data/lib/rex/encoder/alpha2.rb +0 -31
- data/lib/rex/encoder/alpha2/alpha_mixed.rb +0 -68
- data/lib/rex/encoder/alpha2/alpha_upper.rb +0 -79
- data/lib/rex/encoder/alpha2/generic.rb +0 -114
- data/lib/rex/encoder/alpha2/unicode_mixed.rb +0 -117
- data/lib/rex/encoder/alpha2/unicode_upper.rb +0 -129
- data/lib/rex/encoder/ndr.rb +0 -89
- data/lib/rex/encoder/ndr.rb.ut.rb +0 -44
- data/lib/rex/encoder/nonalpha.rb +0 -61
- data/lib/rex/encoder/nonupper.rb +0 -64
- data/lib/rex/encoder/xdr.rb +0 -106
- data/lib/rex/encoder/xdr.rb.ut.rb +0 -29
- data/lib/rex/encoder/xor.rb +0 -69
- data/lib/rex/encoder/xor/dword.rb +0 -13
- data/lib/rex/encoder/xor/dword_additive.rb +0 -13
- data/lib/rex/encoders/xor_dword.rb +0 -35
- data/lib/rex/encoders/xor_dword_additive.rb +0 -53
- data/lib/rex/encoders/xor_dword_additive.rb.ut.rb +0 -12
- data/lib/rex/encoding/xor.rb +0 -20
- data/lib/rex/encoding/xor.rb.ts.rb +0 -14
- data/lib/rex/encoding/xor/byte.rb +0 -15
- data/lib/rex/encoding/xor/byte.rb.ut.rb +0 -21
- data/lib/rex/encoding/xor/dword.rb +0 -21
- data/lib/rex/encoding/xor/dword.rb.ut.rb +0 -15
- data/lib/rex/encoding/xor/dword_additive.rb +0 -92
- data/lib/rex/encoding/xor/dword_additive.rb.ut.rb +0 -15
- data/lib/rex/encoding/xor/exceptions.rb +0 -17
- data/lib/rex/encoding/xor/generic.rb +0 -146
- data/lib/rex/encoding/xor/generic.rb.ut.rb +0 -120
- data/lib/rex/encoding/xor/qword.rb +0 -15
- data/lib/rex/encoding/xor/word.rb +0 -21
- data/lib/rex/encoding/xor/word.rb.ut.rb +0 -13
- data/lib/rex/exceptions.rb +0 -275
- data/lib/rex/exceptions.rb.ut.rb +0 -44
- data/lib/rex/exploitation/cmdstager.rb +0 -9
- data/lib/rex/exploitation/cmdstager/base.rb +0 -175
- data/lib/rex/exploitation/cmdstager/debug_asm.rb +0 -142
- data/lib/rex/exploitation/cmdstager/debug_write.rb +0 -136
- data/lib/rex/exploitation/cmdstager/tftp.rb +0 -63
- data/lib/rex/exploitation/cmdstager/vbs.rb +0 -128
- data/lib/rex/exploitation/egghunter.rb +0 -277
- data/lib/rex/exploitation/egghunter.rb.ut.rb +0 -25
- data/lib/rex/exploitation/encryptjs.rb +0 -77
- data/lib/rex/exploitation/heaplib.js.b64 +0 -331
- data/lib/rex/exploitation/heaplib.rb +0 -94
- data/lib/rex/exploitation/javascriptosdetect.rb +0 -897
- data/lib/rex/exploitation/obfuscatejs.rb +0 -335
- data/lib/rex/exploitation/omelet.rb +0 -320
- data/lib/rex/exploitation/omelet.rb.ut.rb +0 -13
- data/lib/rex/exploitation/opcodedb.rb +0 -818
- data/lib/rex/exploitation/opcodedb.rb.ut.rb +0 -279
- data/lib/rex/exploitation/seh.rb +0 -92
- data/lib/rex/exploitation/seh.rb.ut.rb +0 -19
- data/lib/rex/file.rb +0 -112
- data/lib/rex/file.rb.ut.rb +0 -16
- data/lib/rex/image_source.rb +0 -12
- data/lib/rex/image_source/disk.rb +0 -60
- data/lib/rex/image_source/image_source.rb +0 -46
- data/lib/rex/image_source/memory.rb +0 -37
- data/lib/rex/io/bidirectional_pipe.rb +0 -157
- data/lib/rex/io/datagram_abstraction.rb +0 -35
- data/lib/rex/io/stream.rb +0 -319
- data/lib/rex/io/stream_abstraction.rb +0 -197
- data/lib/rex/io/stream_server.rb +0 -211
- data/lib/rex/job_container.rb +0 -187
- data/lib/rex/logging.rb +0 -4
- data/lib/rex/logging/log_dispatcher.rb +0 -179
- data/lib/rex/logging/log_sink.rb +0 -42
- data/lib/rex/logging/sinks/flatfile.rb +0 -55
- data/lib/rex/logging/sinks/stderr.rb +0 -43
- data/lib/rex/machparsey.rb +0 -9
- data/lib/rex/machparsey/exceptions.rb +0 -34
- data/lib/rex/machparsey/mach.rb +0 -209
- data/lib/rex/machparsey/machbase.rb +0 -408
- data/lib/rex/machscan.rb +0 -9
- data/lib/rex/machscan/scanner.rb +0 -217
- data/lib/rex/mime.rb +0 -9
- data/lib/rex/mime/header.rb +0 -77
- data/lib/rex/mime/message.rb +0 -144
- data/lib/rex/mime/part.rb +0 -20
- data/lib/rex/nop/opty2.rb +0 -108
- data/lib/rex/nop/opty2.rb.ut.rb +0 -23
- data/lib/rex/nop/opty2_tables.rb +0 -300
- data/lib/rex/ole.rb +0 -205
- data/lib/rex/ole/clsid.rb +0 -47
- data/lib/rex/ole/difat.rb +0 -141
- data/lib/rex/ole/directory.rb +0 -231
- data/lib/rex/ole/direntry.rb +0 -240
- data/lib/rex/ole/docs/dependencies.txt +0 -8
- data/lib/rex/ole/docs/references.txt +0 -1
- data/lib/rex/ole/fat.rb +0 -99
- data/lib/rex/ole/header.rb +0 -204
- data/lib/rex/ole/minifat.rb +0 -77
- data/lib/rex/ole/propset.rb +0 -144
- data/lib/rex/ole/samples/create_ole.rb +0 -27
- data/lib/rex/ole/samples/dir.rb +0 -35
- data/lib/rex/ole/samples/dump_stream.rb +0 -34
- data/lib/rex/ole/samples/ole_info.rb +0 -23
- data/lib/rex/ole/storage.rb +0 -395
- data/lib/rex/ole/stream.rb +0 -53
- data/lib/rex/ole/substorage.rb +0 -49
- data/lib/rex/ole/util.rb +0 -157
- data/lib/rex/parser/arguments.rb +0 -97
- data/lib/rex/parser/arguments.rb.ut.rb +0 -67
- data/lib/rex/parser/ini.rb +0 -185
- data/lib/rex/parser/ini.rb.ut.rb +0 -29
- data/lib/rex/parser/ip360_aspl_xml.rb +0 -102
- data/lib/rex/parser/ip360_xml.rb +0 -93
- data/lib/rex/parser/nessus_xml.rb +0 -118
- data/lib/rex/parser/netsparker_xml.rb +0 -94
- data/lib/rex/parser/nexpose_xml.rb +0 -131
- data/lib/rex/parser/nmap_xml.rb +0 -121
- data/lib/rex/parser/retina_xml.rb +0 -109
- data/lib/rex/payloads.rb +0 -1
- data/lib/rex/payloads/win32.rb +0 -2
- data/lib/rex/payloads/win32/common.rb +0 -26
- data/lib/rex/payloads/win32/kernel.rb +0 -53
- data/lib/rex/payloads/win32/kernel/common.rb +0 -54
- data/lib/rex/payloads/win32/kernel/migration.rb +0 -12
- data/lib/rex/payloads/win32/kernel/recovery.rb +0 -50
- data/lib/rex/payloads/win32/kernel/stager.rb +0 -194
- data/lib/rex/peparsey.rb +0 -12
- data/lib/rex/peparsey/exceptions.rb +0 -32
- data/lib/rex/peparsey/pe.rb +0 -212
- data/lib/rex/peparsey/pe_memdump.rb +0 -63
- data/lib/rex/peparsey/pebase.rb +0 -1680
- data/lib/rex/peparsey/section.rb +0 -136
- data/lib/rex/pescan.rb +0 -13
- data/lib/rex/pescan/analyze.rb +0 -309
- data/lib/rex/pescan/scanner.rb +0 -206
- data/lib/rex/pescan/search.rb +0 -56
- data/lib/rex/platforms.rb +0 -1
- data/lib/rex/platforms/windows.rb +0 -51
- data/lib/rex/poly.rb +0 -132
- data/lib/rex/poly/block.rb +0 -477
- data/lib/rex/poly/register.rb +0 -100
- data/lib/rex/poly/register/x86.rb +0 -40
- data/lib/rex/post.rb +0 -8
- data/lib/rex/post/dir.rb +0 -51
- data/lib/rex/post/file.rb +0 -172
- data/lib/rex/post/file_stat.rb +0 -220
- data/lib/rex/post/gen.pl +0 -13
- data/lib/rex/post/io.rb +0 -182
- data/lib/rex/post/meterpreter.rb +0 -4
- data/lib/rex/post/meterpreter/channel.rb +0 -445
- data/lib/rex/post/meterpreter/channel_container.rb +0 -54
- data/lib/rex/post/meterpreter/channels/pool.rb +0 -160
- data/lib/rex/post/meterpreter/channels/pools/file.rb +0 -62
- data/lib/rex/post/meterpreter/channels/pools/stream_pool.rb +0 -103
- data/lib/rex/post/meterpreter/channels/stream.rb +0 -87
- data/lib/rex/post/meterpreter/client.rb +0 -364
- data/lib/rex/post/meterpreter/client_core.rb +0 -274
- data/lib/rex/post/meterpreter/dependencies.rb +0 -3
- data/lib/rex/post/meterpreter/extension.rb +0 -32
- data/lib/rex/post/meterpreter/extensions/espia/espia.rb +0 -58
- data/lib/rex/post/meterpreter/extensions/espia/tlv.rb +0 -16
- data/lib/rex/post/meterpreter/extensions/incognito/incognito.rb +0 -94
- data/lib/rex/post/meterpreter/extensions/incognito/tlv.rb +0 -21
- data/lib/rex/post/meterpreter/extensions/networkpug/networkpug.rb +0 -57
- data/lib/rex/post/meterpreter/extensions/networkpug/tlv.rb +0 -15
- data/lib/rex/post/meterpreter/extensions/priv/fs.rb +0 -118
- data/lib/rex/post/meterpreter/extensions/priv/passwd.rb +0 -61
- data/lib/rex/post/meterpreter/extensions/priv/priv.rb +0 -111
- data/lib/rex/post/meterpreter/extensions/priv/tlv.rb +0 -28
- data/lib/rex/post/meterpreter/extensions/sniffer/sniffer.rb +0 -101
- data/lib/rex/post/meterpreter/extensions/sniffer/tlv.rb +0 -26
- data/lib/rex/post/meterpreter/extensions/stdapi/constants.rb +0 -333
- data/lib/rex/post/meterpreter/extensions/stdapi/fs/dir.rb +0 -282
- data/lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb +0 -266
- data/lib/rex/post/meterpreter/extensions/stdapi/fs/file_stat.rb +0 -103
- data/lib/rex/post/meterpreter/extensions/stdapi/fs/io.rb +0 -48
- data/lib/rex/post/meterpreter/extensions/stdapi/net/config.rb +0 -144
- data/lib/rex/post/meterpreter/extensions/stdapi/net/interface.rb +0 -73
- data/lib/rex/post/meterpreter/extensions/stdapi/net/route.rb +0 -56
- data/lib/rex/post/meterpreter/extensions/stdapi/net/socket.rb +0 -137
- data/lib/rex/post/meterpreter/extensions/stdapi/net/socket_subsystem/tcp_client_channel.rb +0 -180
- data/lib/rex/post/meterpreter/extensions/stdapi/net/socket_subsystem/tcp_server_channel.rb +0 -167
- data/lib/rex/post/meterpreter/extensions/stdapi/net/socket_subsystem/udp_channel.rb +0 -208
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun.rb.ts.rb +0 -6
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/api_constants.rb +0 -38106
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/api_constants.rb.ut.rb +0 -31
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/buffer_item.rb +0 -47
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/buffer_item.rb.ut.rb +0 -36
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_advapi32.rb +0 -1818
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_iphlpapi.rb +0 -96
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_kernel32.rb +0 -3848
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_netapi32.rb +0 -26
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_ntdll.rb +0 -153
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_shell32.rb +0 -21
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_user32.rb +0 -3169
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_ws2_32.rb +0 -599
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/dll.rb +0 -318
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/dll_function.rb +0 -100
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/dll_function.rb.ut.rb +0 -42
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/dll_helper.rb +0 -148
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/dll_helper.rb.ut.rb +0 -127
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/multicall.rb +0 -309
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/railgun.rb +0 -204
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/tlv.rb +0 -51
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/util.rb +0 -630
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb +0 -75
- data/lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb.ut.rb +0 -103
- data/lib/rex/post/meterpreter/extensions/stdapi/stdapi.rb +0 -149
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/config.rb +0 -97
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/event_log.rb +0 -192
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/event_log_subsystem/event_record.rb +0 -41
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/power.rb +0 -61
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/process.rb +0 -370
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/image.rb +0 -129
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/io.rb +0 -55
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/memory.rb +0 -336
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/thread.rb +0 -141
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry.rb +0 -279
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb +0 -193
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_value.rb +0 -102
- data/lib/rex/post/meterpreter/extensions/stdapi/sys/thread.rb +0 -180
- data/lib/rex/post/meterpreter/extensions/stdapi/tlv.rb +0 -211
- data/lib/rex/post/meterpreter/extensions/stdapi/ui.rb +0 -227
- data/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb +0 -63
- data/lib/rex/post/meterpreter/inbound_packet_handler.rb +0 -30
- data/lib/rex/post/meterpreter/object_aliases.rb +0 -83
- data/lib/rex/post/meterpreter/packet.rb +0 -688
- data/lib/rex/post/meterpreter/packet_dispatcher.rb +0 -431
- data/lib/rex/post/meterpreter/packet_parser.rb +0 -94
- data/lib/rex/post/meterpreter/packet_response_waiter.rb +0 -83
- data/lib/rex/post/meterpreter/ui/console.rb +0 -137
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher.rb +0 -62
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb +0 -730
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/espia.rb +0 -108
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/incognito.rb +0 -241
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/networkpug.rb +0 -231
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv.rb +0 -61
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/elevate.rb +0 -98
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/passwd.rb +0 -51
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/timestomp.rb +0 -132
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/sniffer.rb +0 -187
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi.rb +0 -65
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb +0 -442
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/net.rb +0 -298
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb +0 -486
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb +0 -315
- data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb +0 -157
- data/lib/rex/post/meterpreter/ui/console/interactive_channel.rb +0 -95
- data/lib/rex/post/permission.rb +0 -26
- data/lib/rex/post/process.rb +0 -57
- data/lib/rex/post/thread.rb +0 -57
- data/lib/rex/post/ui.rb +0 -52
- data/lib/rex/proto.rb +0 -13
- data/lib/rex/proto.rb.ts.rb +0 -8
- data/lib/rex/proto/dcerpc.rb +0 -6
- data/lib/rex/proto/dcerpc.rb.ts.rb +0 -9
- data/lib/rex/proto/dcerpc/client.rb +0 -361
- data/lib/rex/proto/dcerpc/client.rb.ut.rb +0 -491
- data/lib/rex/proto/dcerpc/exceptions.rb +0 -150
- data/lib/rex/proto/dcerpc/handle.rb +0 -47
- data/lib/rex/proto/dcerpc/handle.rb.ut.rb +0 -85
- data/lib/rex/proto/dcerpc/ndr.rb +0 -72
- data/lib/rex/proto/dcerpc/ndr.rb.ut.rb +0 -41
- data/lib/rex/proto/dcerpc/packet.rb +0 -253
- data/lib/rex/proto/dcerpc/packet.rb.ut.rb +0 -56
- data/lib/rex/proto/dcerpc/response.rb +0 -187
- data/lib/rex/proto/dcerpc/response.rb.ut.rb +0 -15
- data/lib/rex/proto/dcerpc/uuid.rb +0 -84
- data/lib/rex/proto/dcerpc/uuid.rb.ut.rb +0 -46
- data/lib/rex/proto/dhcp.rb +0 -7
- data/lib/rex/proto/dhcp/constants.rb +0 -33
- data/lib/rex/proto/dhcp/server.rb +0 -292
- data/lib/rex/proto/drda.rb +0 -5
- data/lib/rex/proto/drda.rb.ts.rb +0 -17
- data/lib/rex/proto/drda/constants.rb +0 -49
- data/lib/rex/proto/drda/constants.rb.ut.rb +0 -23
- data/lib/rex/proto/drda/packet.rb +0 -252
- data/lib/rex/proto/drda/packet.rb.ut.rb +0 -109
- data/lib/rex/proto/drda/utils.rb +0 -123
- data/lib/rex/proto/drda/utils.rb.ut.rb +0 -84
- data/lib/rex/proto/http.rb +0 -5
- data/lib/rex/proto/http.rb.ts.rb +0 -12
- data/lib/rex/proto/http/client.rb +0 -821
- data/lib/rex/proto/http/client.rb.ut.rb +0 -95
- data/lib/rex/proto/http/handler.rb +0 -46
- data/lib/rex/proto/http/handler/erb.rb +0 -128
- data/lib/rex/proto/http/handler/erb.rb.ut.rb +0 -21
- data/lib/rex/proto/http/handler/erb.rb.ut.rb.rhtml +0 -1
- data/lib/rex/proto/http/handler/proc.rb +0 -60
- data/lib/rex/proto/http/handler/proc.rb.ut.rb +0 -24
- data/lib/rex/proto/http/header.rb +0 -161
- data/lib/rex/proto/http/header.rb.ut.rb +0 -46
- data/lib/rex/proto/http/packet.rb +0 -407
- data/lib/rex/proto/http/packet.rb.ut.rb +0 -165
- data/lib/rex/proto/http/request.rb +0 -356
- data/lib/rex/proto/http/request.rb.ut.rb +0 -214
- data/lib/rex/proto/http/response.rb +0 -90
- data/lib/rex/proto/http/response.rb.ut.rb +0 -149
- data/lib/rex/proto/http/server.rb +0 -369
- data/lib/rex/proto/http/server.rb.ut.rb +0 -79
- data/lib/rex/proto/ntlm.rb +0 -7
- data/lib/rex/proto/ntlm.rb.ut.rb +0 -177
- data/lib/rex/proto/ntlm/base.rb +0 -326
- data/lib/rex/proto/ntlm/constants.rb +0 -74
- data/lib/rex/proto/ntlm/crypt.rb +0 -415
- data/lib/rex/proto/ntlm/exceptions.rb +0 -9
- data/lib/rex/proto/ntlm/message.rb +0 -533
- data/lib/rex/proto/ntlm/utils.rb +0 -763
- data/lib/rex/proto/proxy/socks4a.rb +0 -440
- data/lib/rex/proto/rfb.rb +0 -19
- data/lib/rex/proto/rfb.rb.ut.rb +0 -37
- data/lib/rex/proto/rfb/cipher.rb +0 -84
- data/lib/rex/proto/rfb/client.rb +0 -207
- data/lib/rex/proto/rfb/constants.rb +0 -52
- data/lib/rex/proto/smb.rb +0 -7
- data/lib/rex/proto/smb.rb.ts.rb +0 -8
- data/lib/rex/proto/smb/client.rb +0 -1952
- data/lib/rex/proto/smb/client.rb.ut.rb +0 -223
- data/lib/rex/proto/smb/constants.rb +0 -1047
- data/lib/rex/proto/smb/constants.rb.ut.rb +0 -18
- data/lib/rex/proto/smb/crypt.rb +0 -36
- data/lib/rex/proto/smb/evasions.rb +0 -66
- data/lib/rex/proto/smb/exceptions.rb +0 -858
- data/lib/rex/proto/smb/simpleclient.rb +0 -306
- data/lib/rex/proto/smb/simpleclient.rb.ut.rb +0 -128
- data/lib/rex/proto/smb/utils.rb +0 -103
- data/lib/rex/proto/smb/utils.rb.ut.rb +0 -20
- data/lib/rex/proto/sunrpc.rb +0 -1
- data/lib/rex/proto/sunrpc/client.rb +0 -195
- data/lib/rex/proto/tftp.rb +0 -12
- data/lib/rex/proto/tftp/constants.rb +0 -39
- data/lib/rex/proto/tftp/server.rb +0 -497
- data/lib/rex/proto/tftp/server.rb.ut.rb +0 -28
- data/lib/rex/script.rb +0 -42
- data/lib/rex/script/base.rb +0 -59
- data/lib/rex/script/meterpreter.rb +0 -15
- data/lib/rex/script/shell.rb +0 -9
- data/lib/rex/service.rb +0 -48
- data/lib/rex/service_manager.rb +0 -141
- data/lib/rex/service_manager.rb.ut.rb +0 -32
- data/lib/rex/services/local_relay.rb +0 -423
- data/lib/rex/socket.rb +0 -684
- data/lib/rex/socket.rb.ut.rb +0 -107
- data/lib/rex/socket/comm.rb +0 -119
- data/lib/rex/socket/comm/local.rb +0 -412
- data/lib/rex/socket/comm/local.rb.ut.rb +0 -75
- data/lib/rex/socket/ip.rb +0 -130
- data/lib/rex/socket/parameters.rb +0 -345
- data/lib/rex/socket/parameters.rb.ut.rb +0 -51
- data/lib/rex/socket/range_walker.rb +0 -346
- data/lib/rex/socket/range_walker.rb.ut.rb +0 -55
- data/lib/rex/socket/ssl_tcp.rb +0 -184
- data/lib/rex/socket/ssl_tcp.rb.ut.rb +0 -39
- data/lib/rex/socket/ssl_tcp_server.rb +0 -122
- data/lib/rex/socket/ssl_tcp_server.rb.ut.rb +0 -61
- data/lib/rex/socket/subnet_walker.rb +0 -75
- data/lib/rex/socket/subnet_walker.rb.ut.rb +0 -28
- data/lib/rex/socket/switch_board.rb +0 -278
- data/lib/rex/socket/switch_board.rb.ut.rb +0 -52
- data/lib/rex/socket/tcp.rb +0 -76
- data/lib/rex/socket/tcp.rb.ut.rb +0 -64
- data/lib/rex/socket/tcp_server.rb +0 -67
- data/lib/rex/socket/tcp_server.rb.ut.rb +0 -44
- data/lib/rex/socket/udp.rb +0 -164
- data/lib/rex/socket/udp.rb.ut.rb +0 -44
- data/lib/rex/struct2.rb +0 -5
- data/lib/rex/struct2/c_struct.rb +0 -181
- data/lib/rex/struct2/c_struct_template.rb +0 -39
- data/lib/rex/struct2/constant.rb +0 -26
- data/lib/rex/struct2/element.rb +0 -44
- data/lib/rex/struct2/generic.rb +0 -73
- data/lib/rex/struct2/restraint.rb +0 -54
- data/lib/rex/struct2/s_string.rb +0 -72
- data/lib/rex/struct2/s_struct.rb +0 -111
- data/lib/rex/sync.rb +0 -6
- data/lib/rex/sync/event.rb +0 -94
- data/lib/rex/sync/read_write_lock.rb +0 -176
- data/lib/rex/sync/ref.rb +0 -57
- data/lib/rex/sync/thread_safe.rb +0 -82
- data/lib/rex/test.rb +0 -35
- data/lib/rex/text.rb +0 -1149
- data/lib/rex/text.rb.ut.rb +0 -190
- data/lib/rex/thread_factory.rb +0 -42
- data/lib/rex/time.rb +0 -65
- data/lib/rex/transformer.rb +0 -115
- data/lib/rex/transformer.rb.ut.rb +0 -38
- data/lib/rex/ui.rb +0 -21
- data/lib/rex/ui/interactive.rb +0 -254
- data/lib/rex/ui/output.rb +0 -78
- data/lib/rex/ui/output/none.rb +0 -18
- data/lib/rex/ui/progress_tracker.rb +0 -96
- data/lib/rex/ui/subscriber.rb +0 -149
- data/lib/rex/ui/text/color.rb +0 -97
- data/lib/rex/ui/text/color.rb.ut.rb +0 -18
- data/lib/rex/ui/text/dispatcher_shell.rb +0 -467
- data/lib/rex/ui/text/input.rb +0 -117
- data/lib/rex/ui/text/input/buffer.rb +0 -75
- data/lib/rex/ui/text/input/readline.rb +0 -129
- data/lib/rex/ui/text/input/socket.rb +0 -95
- data/lib/rex/ui/text/input/stdio.rb +0 -45
- data/lib/rex/ui/text/irb_shell.rb +0 -57
- data/lib/rex/ui/text/output.rb +0 -80
- data/lib/rex/ui/text/output/buffer.rb +0 -61
- data/lib/rex/ui/text/output/file.rb +0 -43
- data/lib/rex/ui/text/output/socket.rb +0 -43
- data/lib/rex/ui/text/output/stdio.rb +0 -40
- data/lib/rex/ui/text/progress_tracker.rb +0 -56
- data/lib/rex/ui/text/progress_tracker.rb.ut.rb +0 -34
- data/lib/rex/ui/text/shell.rb +0 -328
- data/lib/rex/ui/text/table.rb +0 -279
- data/lib/rex/ui/text/table.rb.ut.rb +0 -55
- data/lib/rex/zip.rb +0 -93
- data/lib/rex/zip/archive.rb +0 -184
- data/lib/rex/zip/blocks.rb +0 -182
- data/lib/rex/zip/entry.rb +0 -104
- data/lib/rex/zip/samples/comment.rb +0 -32
- data/lib/rex/zip/samples/mkwar.rb +0 -138
- data/lib/rex/zip/samples/mkzip.rb +0 -19
- data/lib/rex/zip/samples/recursive.rb +0 -58
@@ -1,204 +0,0 @@
|
|
1
|
-
# Copyright (c) 2010, patrickHVE@googlemail.com
|
2
|
-
# All rights reserved.
|
3
|
-
#
|
4
|
-
# Redistribution and use in source and binary forms, with or without
|
5
|
-
# modification, are permitted provided that the following conditions are met:
|
6
|
-
# * Redistributions of source code must retain the above copyright
|
7
|
-
# notice, this list of conditions and the following disclaimer.
|
8
|
-
# * Redistributions in binary form must reproduce the above copyright
|
9
|
-
# notice, this list of conditions and the following disclaimer in the
|
10
|
-
# documentation and/or other materials provided with the distribution.
|
11
|
-
# * The names of the author may not be used to endorse or promote products
|
12
|
-
# derived from this software without specific prior written permission.
|
13
|
-
#
|
14
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
15
|
-
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
16
|
-
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
17
|
-
# DISCLAIMED. IN NO EVENT SHALL patrickHVE@googlemail.com BE LIABLE FOR ANY
|
18
|
-
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
19
|
-
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
20
|
-
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
21
|
-
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
22
|
-
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
23
|
-
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
24
|
-
|
25
|
-
#
|
26
|
-
# sf - Sept 2010 - Modified for x64 support and merged into the stdapi extension.
|
27
|
-
#
|
28
|
-
|
29
|
-
require 'pp'
|
30
|
-
require 'enumerator'
|
31
|
-
|
32
|
-
require 'rex/post/meterpreter/extensions/stdapi/railgun/api_constants'
|
33
|
-
require 'rex/post/meterpreter/extensions/stdapi/railgun/tlv'
|
34
|
-
require 'rex/post/meterpreter/extensions/stdapi/railgun/util'
|
35
|
-
require 'rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager'
|
36
|
-
require 'rex/post/meterpreter/extensions/stdapi/railgun/multicall'
|
37
|
-
require 'rex/post/meterpreter/extensions/stdapi/railgun/dll'
|
38
|
-
|
39
|
-
module Rex
|
40
|
-
module Post
|
41
|
-
module Meterpreter
|
42
|
-
module Extensions
|
43
|
-
module Stdapi
|
44
|
-
module Railgun
|
45
|
-
|
46
|
-
#
|
47
|
-
# The Railgun class to dynamically expose the Windows API.
|
48
|
-
#
|
49
|
-
class Railgun
|
50
|
-
def initialize( client )
|
51
|
-
|
52
|
-
@client = client
|
53
|
-
@dll = ::Hash.new
|
54
|
-
|
55
|
-
@win_consts = WinConstManager.new()
|
56
|
-
|
57
|
-
@constants_loaded = false
|
58
|
-
|
59
|
-
# Load the multi-caller
|
60
|
-
@multicaller = MultiCaller.new( @client, self, @win_consts )
|
61
|
-
|
62
|
-
# Load utility class
|
63
|
-
@util = Util.new( self, @client.platform )
|
64
|
-
end
|
65
|
-
|
66
|
-
# read data from a memory address on the host (useful for working with LPVOID parameters)
|
67
|
-
def memread( address, length )
|
68
|
-
|
69
|
-
raise "Invalid parameters." if( not address or not length )
|
70
|
-
|
71
|
-
request = Packet.create_request( 'stdapi_railgun_memread' )
|
72
|
-
|
73
|
-
request.add_tlv( TLV_TYPE_RAILGUN_MEM_ADDRESS, address )
|
74
|
-
request.add_tlv( TLV_TYPE_RAILGUN_MEM_LENGTH, length )
|
75
|
-
|
76
|
-
response = client.send_request( request )
|
77
|
-
if( response.result == 0 )
|
78
|
-
return response.get_tlv_value( TLV_TYPE_RAILGUN_MEM_DATA )
|
79
|
-
end
|
80
|
-
|
81
|
-
return nil
|
82
|
-
end
|
83
|
-
|
84
|
-
# write data to a memory address on the host (useful for working with LPVOID parameters)
|
85
|
-
def memwrite( address, data, length )
|
86
|
-
|
87
|
-
raise "Invalid parameters." if( not address or not data or not length )
|
88
|
-
|
89
|
-
request = Packet.create_request( 'stdapi_railgun_memwrite' )
|
90
|
-
|
91
|
-
request.add_tlv( TLV_TYPE_RAILGUN_MEM_ADDRESS, address )
|
92
|
-
request.add_tlv( TLV_TYPE_RAILGUN_MEM_DATA, data )
|
93
|
-
request.add_tlv( TLV_TYPE_RAILGUN_MEM_LENGTH, length )
|
94
|
-
|
95
|
-
response = client.send_request( request )
|
96
|
-
if( response.result == 0 )
|
97
|
-
return true
|
98
|
-
end
|
99
|
-
|
100
|
-
return false
|
101
|
-
end
|
102
|
-
|
103
|
-
# adds a function to an existing DLL-definition
|
104
|
-
def add_function(dll_name, function_name, return_type, params, windows_name=nil)
|
105
|
-
raise "DLL #{dll_name} not found. Known DLLs: #{PP.pp(@dll.keys, "")}" unless @dll.has_key? dll_name
|
106
|
-
@dll[dll_name].add_function(function_name, return_type, params, windows_name)
|
107
|
-
end
|
108
|
-
|
109
|
-
# adds a function to an existing DLL-definition
|
110
|
-
# you can override the dll name if you want to include a path or the DLL name contains
|
111
|
-
# non-ruby-approved characters
|
112
|
-
def add_dll(dll_name, windows_name=nil)
|
113
|
-
raise "DLL #{dll_name} already exists. Existing DLLs: #{PP.pp(@dll.keys, "")}" unless not @dll.has_key? dll_name
|
114
|
-
if( windows_name == nil )
|
115
|
-
windows_name = dll_name
|
116
|
-
end
|
117
|
-
@dll[dll_name] = DLL.new(windows_name, @client, @win_consts)
|
118
|
-
end
|
119
|
-
|
120
|
-
def get_dll( dll_name )
|
121
|
-
# sf: we now lazy load the module definitions as needed to avoid the performance hit
|
122
|
-
# to stdapi if we do it upon initilization (the user may never use railgun or else
|
123
|
-
# require only a portion of the modules exposed by railgun so no need to pre load them)
|
124
|
-
if( not @dll.has_key?( dll_name ) )
|
125
|
-
|
126
|
-
# the constants are also lazy loaded the first time we call const() or any API function...
|
127
|
-
if( not @constants_loaded )
|
128
|
-
ApiConstants.add_constants( @win_consts )
|
129
|
-
@constants_loaded = true
|
130
|
-
end
|
131
|
-
|
132
|
-
case dll_name
|
133
|
-
when 'kernel32'
|
134
|
-
require 'rex/post/meterpreter/extensions/stdapi/railgun/def/def_kernel32'
|
135
|
-
Def::Def_kernel32.add_imports(self)
|
136
|
-
when 'ntdll'
|
137
|
-
require 'rex/post/meterpreter/extensions/stdapi/railgun/def/def_ntdll'
|
138
|
-
Def::Def_ntdll.add_imports(self)
|
139
|
-
when 'user32'
|
140
|
-
require 'rex/post/meterpreter/extensions/stdapi/railgun/def/def_user32'
|
141
|
-
Def::Def_user32.add_imports(self)
|
142
|
-
when 'ws2_32'
|
143
|
-
require 'rex/post/meterpreter/extensions/stdapi/railgun/def/def_ws2_32'
|
144
|
-
Def::Def_ws2_32.add_imports(self)
|
145
|
-
when 'iphlpapi'
|
146
|
-
require 'rex/post/meterpreter/extensions/stdapi/railgun/def/def_iphlpapi'
|
147
|
-
Def::Def_iphlpapi.add_imports(self)
|
148
|
-
when 'netapi32'
|
149
|
-
require 'rex/post/meterpreter/extensions/stdapi/railgun/def/def_netapi32'
|
150
|
-
Def::Def_netapi32.add_imports(self)
|
151
|
-
when 'advapi32'
|
152
|
-
require 'rex/post/meterpreter/extensions/stdapi/railgun/def/def_advapi32'
|
153
|
-
Def::Def_advapi32.add_imports(self)
|
154
|
-
when 'shell32'
|
155
|
-
require 'rex/post/meterpreter/extensions/stdapi/railgun/def/def_shell32'
|
156
|
-
Def::Def_shell32.add_imports(self)
|
157
|
-
end
|
158
|
-
|
159
|
-
if( @dll.has_key?( dll_name ) )
|
160
|
-
return @dll[dll_name]
|
161
|
-
end
|
162
|
-
|
163
|
-
else
|
164
|
-
return @dll[dll_name]
|
165
|
-
end
|
166
|
-
|
167
|
-
return nil
|
168
|
-
end
|
169
|
-
|
170
|
-
# we fake having members like user32 and kernel32.
|
171
|
-
# reason is that
|
172
|
-
# ...user32.MessageBoxW()
|
173
|
-
# is prettier than
|
174
|
-
# ...dlls["user32"].functions["MessageBoxW"]()
|
175
|
-
def method_missing(dll_symbol, *args)
|
176
|
-
dll_name = dll_symbol.to_s
|
177
|
-
|
178
|
-
self.get_dll( dll_name )
|
179
|
-
|
180
|
-
raise "DLL #{dll_name} not found. Known DLLs: #{PP.pp(@dll.keys, "")}" unless @dll.has_key? dll_name
|
181
|
-
|
182
|
-
return @dll[dll_name]
|
183
|
-
end
|
184
|
-
|
185
|
-
# Give the programmer access to constants
|
186
|
-
def const(str)
|
187
|
-
# the constants are also lazy loaded the first time we call const() or any API function...
|
188
|
-
if( not @constants_loaded )
|
189
|
-
ApiConstants.add_constants( @win_consts )
|
190
|
-
@constants_loaded = true
|
191
|
-
end
|
192
|
-
return @win_consts.parse(str)
|
193
|
-
end
|
194
|
-
|
195
|
-
# The multi-call shorthand ( ["kernel32", "ExitProcess", [0]] )
|
196
|
-
def multi(functions)
|
197
|
-
@multicaller.call(functions)
|
198
|
-
end
|
199
|
-
|
200
|
-
attr_accessor :client, :dll, :multicaller, :win_consts, :util
|
201
|
-
|
202
|
-
end
|
203
|
-
|
204
|
-
end; end; end; end; end; end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
# Copyright (c) 2010, patrickHVE@googlemail.com
|
2
|
-
# All rights reserved.
|
3
|
-
#
|
4
|
-
# Redistribution and use in source and binary forms, with or without
|
5
|
-
# modification, are permitted provided that the following conditions are met:
|
6
|
-
# * Redistributions of source code must retain the above copyright
|
7
|
-
# notice, this list of conditions and the following disclaimer.
|
8
|
-
# * Redistributions in binary form must reproduce the above copyright
|
9
|
-
# notice, this list of conditions and the following disclaimer in the
|
10
|
-
# documentation and/or other materials provided with the distribution.
|
11
|
-
# * The names of the author may not be used to endorse or promote products
|
12
|
-
# derived from this software without specific prior written permission.
|
13
|
-
#
|
14
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
15
|
-
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
16
|
-
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
17
|
-
# DISCLAIMED. IN NO EVENT SHALL patrickHVE@googlemail.com BE LIABLE FOR ANY
|
18
|
-
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
19
|
-
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
20
|
-
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
21
|
-
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
22
|
-
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
23
|
-
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
24
|
-
|
25
|
-
module Rex
|
26
|
-
module Post
|
27
|
-
module Meterpreter
|
28
|
-
module Extensions
|
29
|
-
module Stdapi
|
30
|
-
module Railgun
|
31
|
-
|
32
|
-
TLV_TYPE_EXTENSION_RAILGUN = 0
|
33
|
-
TLV_TYPE_RAILGUN_SIZE_OUT = TLV_META_TYPE_UINT | (TLV_TYPE_EXTENSION_RAILGUN + TLV_EXTENSIONS + 1)
|
34
|
-
TLV_TYPE_RAILGUN_STACKBLOB = TLV_META_TYPE_RAW | (TLV_TYPE_EXTENSION_RAILGUN + TLV_EXTENSIONS + 2)
|
35
|
-
TLV_TYPE_RAILGUN_BUFFERBLOB_IN = TLV_META_TYPE_RAW | (TLV_TYPE_EXTENSION_RAILGUN + TLV_EXTENSIONS + 3)
|
36
|
-
TLV_TYPE_RAILGUN_BUFFERBLOB_INOUT = TLV_META_TYPE_RAW | (TLV_TYPE_EXTENSION_RAILGUN + TLV_EXTENSIONS + 4)
|
37
|
-
|
38
|
-
TLV_TYPE_RAILGUN_BACK_BUFFERBLOB_OUT = TLV_META_TYPE_RAW | (TLV_TYPE_EXTENSION_RAILGUN + TLV_EXTENSIONS + 5)
|
39
|
-
TLV_TYPE_RAILGUN_BACK_BUFFERBLOB_INOUT = TLV_META_TYPE_RAW | (TLV_TYPE_EXTENSION_RAILGUN + TLV_EXTENSIONS + 6)
|
40
|
-
TLV_TYPE_RAILGUN_BACK_RET = TLV_META_TYPE_QWORD | (TLV_TYPE_EXTENSION_RAILGUN + TLV_EXTENSIONS + 7)
|
41
|
-
TLV_TYPE_RAILGUN_BACK_ERR = TLV_META_TYPE_UINT | (TLV_TYPE_EXTENSION_RAILGUN + TLV_EXTENSIONS + 8)
|
42
|
-
|
43
|
-
TLV_TYPE_RAILGUN_DLLNAME = TLV_META_TYPE_STRING | (TLV_TYPE_EXTENSION_RAILGUN + TLV_EXTENSIONS + 9)
|
44
|
-
TLV_TYPE_RAILGUN_FUNCNAME = TLV_META_TYPE_STRING | (TLV_TYPE_EXTENSION_RAILGUN + TLV_EXTENSIONS + 10)
|
45
|
-
TLV_TYPE_RAILGUN_MULTI_GROUP = TLV_META_TYPE_GROUP | (TLV_TYPE_EXTENSION_RAILGUN + TLV_EXTENSIONS + 11)
|
46
|
-
|
47
|
-
TLV_TYPE_RAILGUN_MEM_ADDRESS = TLV_META_TYPE_QWORD | (TLV_TYPE_EXTENSION_RAILGUN + TLV_EXTENSIONS + 12 )
|
48
|
-
TLV_TYPE_RAILGUN_MEM_DATA = TLV_META_TYPE_RAW | (TLV_TYPE_EXTENSION_RAILGUN + TLV_EXTENSIONS + 13 )
|
49
|
-
TLV_TYPE_RAILGUN_MEM_LENGTH = TLV_META_TYPE_UINT | (TLV_TYPE_EXTENSION_RAILGUN + TLV_EXTENSIONS + 14 )
|
50
|
-
|
51
|
-
end; end; end; end; end; end
|
@@ -1,630 +0,0 @@
|
|
1
|
-
require 'rex/post/meterpreter/extensions/stdapi/railgun/dll_helper'
|
2
|
-
|
3
|
-
module Rex
|
4
|
-
module Post
|
5
|
-
module Meterpreter
|
6
|
-
module Extensions
|
7
|
-
module Stdapi
|
8
|
-
module Railgun
|
9
|
-
class Util
|
10
|
-
|
11
|
-
# Bring in some useful string manipulation utility functions
|
12
|
-
include DLLHelper
|
13
|
-
|
14
|
-
# Data type size info: http://msdn.microsoft.com/en-us/library/s3f49ktz(v=vs.80).aspx
|
15
|
-
PRIMITIVE_TYPE_SIZES = {
|
16
|
-
:int => 4,
|
17
|
-
:__int8 => 1,
|
18
|
-
:__int16 => 2,
|
19
|
-
:__int32 => 4,
|
20
|
-
:__int64 => 8,
|
21
|
-
:bool => 1,
|
22
|
-
:char => 1,
|
23
|
-
:short => 2,
|
24
|
-
:long => 4,
|
25
|
-
:long_long => 8,
|
26
|
-
:float => 4,
|
27
|
-
:double => 8,
|
28
|
-
:long_double => 8,
|
29
|
-
:wchar_t => 2,
|
30
|
-
}
|
31
|
-
|
32
|
-
# Maps a data type to its corresponding primitive or special type :pointer
|
33
|
-
# Note, primitive types are mapped to themselves
|
34
|
-
# typedef info: http://msdn.microsoft.com/en-us/library/aa383751(v=vs.85).aspx
|
35
|
-
TYPE_DEFINITIONS = {
|
36
|
-
##
|
37
|
-
# Primitives
|
38
|
-
##
|
39
|
-
:int => :int,
|
40
|
-
:__int8 => :__int8,
|
41
|
-
:__int16 => :__int16,
|
42
|
-
:__int32 => :__int32,
|
43
|
-
:__int64 => :__int64,
|
44
|
-
:bool => :bool,
|
45
|
-
:char => :char,
|
46
|
-
:short => :short,
|
47
|
-
:long => :long,
|
48
|
-
:long_long => :long_long,
|
49
|
-
:float => :float,
|
50
|
-
:double => :double,
|
51
|
-
:long_double => :long_double,
|
52
|
-
:wchar_t => :wchar_t,
|
53
|
-
##
|
54
|
-
# Non-pointers
|
55
|
-
##
|
56
|
-
#typedef WORD ATOM;
|
57
|
-
:ATOM => :short,
|
58
|
-
#typedef int BOOL;
|
59
|
-
:BOOL => :int,
|
60
|
-
#typedef BYTE BOOLEAN;
|
61
|
-
:BOOLEAN => :char,
|
62
|
-
#typedef unsigned char BYTE;
|
63
|
-
:BYTE => :char,
|
64
|
-
#typedef char CHAR;
|
65
|
-
:CHAR => :char,
|
66
|
-
#typedef DWORD COLORREF;
|
67
|
-
:COLORREF => :long,
|
68
|
-
#typedef unsigned long DWORD;
|
69
|
-
:DWORD => :long,
|
70
|
-
#typedef unsigned int DWORD32;
|
71
|
-
:DWORD32 => :int,
|
72
|
-
#typedef unsigned __int64 DWORD64;
|
73
|
-
:DWORD64 => :__int64,
|
74
|
-
#typedef float FLOAT;
|
75
|
-
:FLOAT => :float,
|
76
|
-
#typedef int HFILE;
|
77
|
-
:HFILE => :int,
|
78
|
-
#typedef LONG HRESULT;
|
79
|
-
:HRESULT => :long,
|
80
|
-
#typedef int INT;
|
81
|
-
:INT => :int,
|
82
|
-
#typedef signed int INT32;
|
83
|
-
:INT32 => :int,
|
84
|
-
#typedef signed __int64 INT64;
|
85
|
-
:INT64 => :__int64,
|
86
|
-
#typedef WORD LANGID;
|
87
|
-
:LANGID => :short,
|
88
|
-
#typedef DWORD LCID;
|
89
|
-
:LCID => :long,
|
90
|
-
#typedef DWORD LCTYPE;
|
91
|
-
:LCTYPE => :long,
|
92
|
-
#typedef DWORD LGRPID;
|
93
|
-
:LGRPID => :long,
|
94
|
-
#typedef long LONG;
|
95
|
-
:LONG => :long,
|
96
|
-
#typedef signed int LONG32;
|
97
|
-
:LONG32 => :int,
|
98
|
-
#typedef __int64 LONG64;
|
99
|
-
:LONG64 => :__int64,
|
100
|
-
#typedef PDWORD PLCID;
|
101
|
-
:PLCID => :pointer,
|
102
|
-
#typedef LPVOID SC_LOCK;
|
103
|
-
:SC_LOCK => :pointer,
|
104
|
-
#typedef short SHORT;
|
105
|
-
:SHORT => :short,
|
106
|
-
#typedef unsigned char UCHAR;
|
107
|
-
:UCHAR => :char,
|
108
|
-
#typedef unsigned int UINT;
|
109
|
-
:UINT => :int,
|
110
|
-
#typedef unsigned int UINT32;
|
111
|
-
:UINT32 => :int,
|
112
|
-
#typedef unsigned long ULONG;
|
113
|
-
:ULONG => :long,
|
114
|
-
#typedef unsigned int ULONG32;
|
115
|
-
:ULONG32 => :int,
|
116
|
-
#typedef unsigned __int64 ULONG64;
|
117
|
-
:ULONG64 => :__int64,
|
118
|
-
#typedef unsigned short USHORT;
|
119
|
-
:USHORT => :short,
|
120
|
-
#typedef wchar_t WCHAR;
|
121
|
-
:WCHAR => :wchar_t,
|
122
|
-
#typedef unsigned short WORD;
|
123
|
-
:WORD => :short,
|
124
|
-
##
|
125
|
-
# Pointers declared with *
|
126
|
-
##
|
127
|
-
#typedef DWORD* LPCOLORREF;
|
128
|
-
:LPCOLORREF => :pointer,
|
129
|
-
#typedef void* LPCVOID;
|
130
|
-
:LPCVOID => :pointer,
|
131
|
-
#typedef WCHAR* LPCWSTR;
|
132
|
-
:LPCWSTR => :pointer,
|
133
|
-
#typedef DWORD* LPDWORD;
|
134
|
-
:LPDWORD => :pointer,
|
135
|
-
#typedef HANDLE* LPHANDLE;
|
136
|
-
:LPHANDLE => :pointer,
|
137
|
-
#typedef int* LPINT;
|
138
|
-
:LPINT => :pointer,
|
139
|
-
#typedef long* LPLONG;
|
140
|
-
:LPLONG => :pointer,
|
141
|
-
#typedef CHAR* LPSTR;
|
142
|
-
:LPSTR => :pointer,
|
143
|
-
#typedef void* LPVOID;
|
144
|
-
:LPVOID => :pointer,
|
145
|
-
#typedef WORD* LPWORD;
|
146
|
-
:LPWORD => :pointer,
|
147
|
-
#typedef WCHAR* LPWSTR;
|
148
|
-
:LPWSTR => :pointer,
|
149
|
-
#typedef BOOL* PBOOL;
|
150
|
-
:PBOOL => :pointer,
|
151
|
-
#typedef BOOLEAN* PBOOLEAN;
|
152
|
-
:PBOOLEAN => :pointer,
|
153
|
-
#typedef BYTE* PBYTE;
|
154
|
-
:PBYTE => :pointer,
|
155
|
-
#typedef CHAR* PCHAR;
|
156
|
-
:PCHAR => :pointer,
|
157
|
-
#typedef CHAR* PCSTR;
|
158
|
-
:PCSTR => :pointer,
|
159
|
-
#typedef WCHAR* PCWSTR;
|
160
|
-
:PCWSTR => :pointer,
|
161
|
-
#typedef DWORD* PDWORD;
|
162
|
-
:PDWORD => :pointer,
|
163
|
-
#typedef DWORDLONG* PDWORDLONG;
|
164
|
-
:PDWORDLONG => :pointer,
|
165
|
-
#typedef DWORD_PTR* PDWORD_PTR;
|
166
|
-
:PDWORD_PTR => :pointer,
|
167
|
-
#typedef DWORD32* PDWORD32;
|
168
|
-
:PDWORD32 => :pointer,
|
169
|
-
#typedef DWORD64* PDWORD64;
|
170
|
-
:PDWORD64 => :pointer,
|
171
|
-
#typedef FLOAT* PFLOAT;
|
172
|
-
:PFLOAT => :pointer,
|
173
|
-
#typedef HANDLE* PHANDLE;
|
174
|
-
:PHANDLE => :pointer,
|
175
|
-
#typedef HKEY* PHKEY;
|
176
|
-
:PHKEY => :pointer,
|
177
|
-
#typedef int* PINT;
|
178
|
-
:PINT => :pointer,
|
179
|
-
#typedef INT_PTR* PINT_PTR;
|
180
|
-
:PINT_PTR => :pointer,
|
181
|
-
#typedef INT32* PINT32;
|
182
|
-
:PINT32 => :pointer,
|
183
|
-
#typedef INT64* PINT64;
|
184
|
-
:PINT64 => :pointer,
|
185
|
-
#typedef LONG* PLONG;
|
186
|
-
:PLONG => :pointer,
|
187
|
-
#typedef LONGLONG* PLONGLONG;
|
188
|
-
:PLONGLONG => :pointer,
|
189
|
-
#typedef LONG_PTR* PLONG_PTR;
|
190
|
-
:PLONG_PTR => :pointer,
|
191
|
-
#typedef LONG32* PLONG32;
|
192
|
-
:PLONG32 => :pointer,
|
193
|
-
#typedef LONG64* PLONG64;
|
194
|
-
:PLONG64 => :pointer,
|
195
|
-
#typedef SHORT* PSHORT;
|
196
|
-
:PSHORT => :pointer,
|
197
|
-
#typedef SIZE_T* PSIZE_T;
|
198
|
-
:PSIZE_T => :pointer,
|
199
|
-
#typedef SSIZE_T* PSSIZE_T;
|
200
|
-
:PSSIZE_T => :pointer,
|
201
|
-
#typedef CHAR* PSTR;
|
202
|
-
:PSTR => :pointer,
|
203
|
-
#typedef TBYTE* PTBYTE;
|
204
|
-
:PTBYTE => :pointer,
|
205
|
-
#typedef TCHAR* PTCHAR;
|
206
|
-
:PTCHAR => :pointer,
|
207
|
-
#typedef UCHAR* PUCHAR;
|
208
|
-
:PUCHAR => :pointer,
|
209
|
-
#typedef UINT* PUINT;
|
210
|
-
:PUINT => :pointer,
|
211
|
-
#typedef UINT_PTR* PUINT_PTR;
|
212
|
-
:PUINT_PTR => :pointer,
|
213
|
-
#typedef UINT32* PUINT32;
|
214
|
-
:PUINT32 => :pointer,
|
215
|
-
#typedef UINT64* PUINT64;
|
216
|
-
:PUINT64 => :pointer,
|
217
|
-
#typedef ULONG* PULONG;
|
218
|
-
:PULONG => :pointer,
|
219
|
-
#typedef ULONGLONG* PULONGLONG;
|
220
|
-
:PULONGLONG => :pointer,
|
221
|
-
#typedef ULONG_PTR* PULONG_PTR;
|
222
|
-
:PULONG_PTR => :pointer,
|
223
|
-
#typedef ULONG32* PULONG32;
|
224
|
-
:PULONG32 => :pointer,
|
225
|
-
#typedef ULONG64* PULONG64;
|
226
|
-
:PULONG64 => :pointer,
|
227
|
-
#typedef USHORT* PUSHORT;
|
228
|
-
:PUSHORT => :pointer,
|
229
|
-
#typedef void* PVOID;
|
230
|
-
:PVOID => :pointer,
|
231
|
-
#typedef WCHAR* PWCHAR;
|
232
|
-
:PWCHAR => :pointer,
|
233
|
-
#typedef WORD* PWORD;
|
234
|
-
:PWORD => :pointer,
|
235
|
-
#typedef WCHAR* PWSTR;
|
236
|
-
:PWSTR => :pointer,
|
237
|
-
#typedef HANDLE HACCEL;
|
238
|
-
:HACCEL => :pointer,
|
239
|
-
##
|
240
|
-
# Handles
|
241
|
-
##
|
242
|
-
#typedef PVOID HANDLE;
|
243
|
-
:HANDLE => :pointer,
|
244
|
-
#typedef HANDLE HBITMAP;
|
245
|
-
:HBITMAP => :pointer,
|
246
|
-
#typedef HANDLE HBRUSH;
|
247
|
-
:HBRUSH => :pointer,
|
248
|
-
#typedef HANDLE HCOLORSPACE;
|
249
|
-
:HCOLORSPACE => :pointer,
|
250
|
-
#typedef HANDLE HCONV;
|
251
|
-
:HCONV => :pointer,
|
252
|
-
#typedef HANDLE HCONVLIST;
|
253
|
-
:HCONVLIST => :pointer,
|
254
|
-
#typedef HANDLE HDC;
|
255
|
-
:HDC => :pointer,
|
256
|
-
#typedef HANDLE HDDEDATA;
|
257
|
-
:HDDEDATA => :pointer,
|
258
|
-
#typedef HANDLE HDESK;
|
259
|
-
:HDESK => :pointer,
|
260
|
-
#typedef HANDLE HDROP;
|
261
|
-
:HDROP => :pointer,
|
262
|
-
#typedef HANDLE HDWP;
|
263
|
-
:HDWP => :pointer,
|
264
|
-
#typedef HANDLE HENHMETAFILE;
|
265
|
-
:HENHMETAFILE => :pointer,
|
266
|
-
#typedef HANDLE HFONT;
|
267
|
-
:HFONT => :pointer,
|
268
|
-
#typedef HANDLE HGDIOBJ;
|
269
|
-
:HGDIOBJ => :pointer,
|
270
|
-
#typedef HANDLE HGLOBAL;
|
271
|
-
:HGLOBAL => :pointer,
|
272
|
-
#typedef HANDLE HHOOK;
|
273
|
-
:HHOOK => :pointer,
|
274
|
-
#typedef HANDLE HICON;
|
275
|
-
:HICON => :pointer,
|
276
|
-
#typedef HANDLE HINSTANCE;
|
277
|
-
:HINSTANCE => :pointer,
|
278
|
-
#typedef HANDLE HKEY;
|
279
|
-
:HKEY => :pointer,
|
280
|
-
#typedef HANDLE HKL;
|
281
|
-
:HKL => :pointer,
|
282
|
-
#typedef HANDLE HLOCAL;
|
283
|
-
:HLOCAL => :pointer,
|
284
|
-
#typedef HANDLE HMENU;
|
285
|
-
:HMENU => :pointer,
|
286
|
-
#typedef HANDLE HMETAFILE;
|
287
|
-
:HMETAFILE => :pointer,
|
288
|
-
#typedef HANDLE HPALETTE;
|
289
|
-
:HPALETTE => :pointer,
|
290
|
-
#typedef HANDLE HPEN;
|
291
|
-
:HPEN => :pointer,
|
292
|
-
#typedef HANDLE HRGN;
|
293
|
-
:HRGN => :pointer,
|
294
|
-
#typedef HANDLE HRSRC;
|
295
|
-
:HRSRC => :pointer,
|
296
|
-
#typedef HANDLE HSZ;
|
297
|
-
:HSZ => :pointer,
|
298
|
-
#typedef HANDLE WINSTA;
|
299
|
-
:WINSTA => :pointer,
|
300
|
-
#typedef HANDLE HWND;
|
301
|
-
:HWND => :pointer,
|
302
|
-
#typedef HANDLE SC_HANDLE;
|
303
|
-
:SC_HANDLE => :pointer,
|
304
|
-
#typedef HANDLE SERVICE_STATUS_HANDLE;
|
305
|
-
:SERVICE_STATUS_HANDLE => :pointer,
|
306
|
-
}
|
307
|
-
|
308
|
-
# param 'railgun' is a Railgun instance.
|
309
|
-
# param 'platform' is a value like client.platform
|
310
|
-
def initialize(railgun, platform)
|
311
|
-
@railgun = railgun
|
312
|
-
@is_64bit = is_64bit_platform?(platform)
|
313
|
-
end
|
314
|
-
|
315
|
-
# Given a packed pointer, unpacks it according to architecture
|
316
|
-
def unpack_pointer(packed_pointer)
|
317
|
-
if is_64bit
|
318
|
-
# XXX: Only works if attacker and victim are like-endianed
|
319
|
-
packed_pointer.unpack('Q')[0]
|
320
|
-
else
|
321
|
-
packed_pointer.unpack('V')[0]
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
###
|
326
|
-
# Summary: Returns true if pointer will be considered a 'null' pointer
|
327
|
-
#
|
328
|
-
# If given nil, returns true
|
329
|
-
# If given 0, returns true
|
330
|
-
# If given a string, if 0 after unpacking, returns true
|
331
|
-
# false otherwise
|
332
|
-
##
|
333
|
-
def is_null_pointer(pointer)
|
334
|
-
if pointer.class == String
|
335
|
-
pointer = unpack_pointer(pointer)
|
336
|
-
end
|
337
|
-
|
338
|
-
return pointer.nil? || pointer == 0
|
339
|
-
end
|
340
|
-
|
341
|
-
###
|
342
|
-
# Summary: Reads null-terminated unicode strings from memory.
|
343
|
-
#
|
344
|
-
# Given a pointer to a null terminated array of WCHARs, return a ruby string
|
345
|
-
# Null pointers cause an empty string to be returned
|
346
|
-
##
|
347
|
-
def read_wstring(pointer, length = nil)
|
348
|
-
# Return an empty string for null pointers
|
349
|
-
if is_null_pointer(pointer)
|
350
|
-
return ''
|
351
|
-
end
|
352
|
-
|
353
|
-
# If length not provided, use lstrlenW
|
354
|
-
if length.nil?
|
355
|
-
length = railgun.kernel32.lstrlenW(pointer)['return']
|
356
|
-
end
|
357
|
-
|
358
|
-
# Retrieve the array of characters
|
359
|
-
chars = read_array(:WCHAR, length, pointer)
|
360
|
-
|
361
|
-
# Concatenate the characters and convert to a ruby string
|
362
|
-
str = uniz_to_str(chars.join(''))
|
363
|
-
|
364
|
-
return str
|
365
|
-
end
|
366
|
-
|
367
|
-
###
|
368
|
-
# Summary: Read a given number of bytes from memory or from a provided buffer.
|
369
|
-
#
|
370
|
-
# If 'buffer' is not provided, read 'size' bytes from the client's memory
|
371
|
-
# If 'buffer' is provided, reads 'size' characters from the index of 'address'
|
372
|
-
##
|
373
|
-
def memread(address, size, buffer = nil)
|
374
|
-
if buffer.nil?
|
375
|
-
return railgun.memread(address, size)
|
376
|
-
else
|
377
|
-
return buffer[address .. (address + size - 1)]
|
378
|
-
end
|
379
|
-
end
|
380
|
-
|
381
|
-
# Read and unpack a pointer from the given buffer at a given offset
|
382
|
-
def read_pointer(buffer, offset = 0)
|
383
|
-
unpack_pointer(buffer[offset, (offset + pointer_size)])
|
384
|
-
end
|
385
|
-
|
386
|
-
# Reads data structures and several windows data types
|
387
|
-
def read_data(type, position, buffer = nil)
|
388
|
-
if buffer.nil?
|
389
|
-
buffer = memread(position, sizeof_type(type))
|
390
|
-
position = 0
|
391
|
-
end
|
392
|
-
|
393
|
-
# If we're asked to read a data structure, deligate to read_struct
|
394
|
-
if is_struct_type?(type)
|
395
|
-
return read_struct(type, buffer, position)
|
396
|
-
end
|
397
|
-
|
398
|
-
# If the type is an array with a given size...
|
399
|
-
# BYTE[3] for example or BYTE[ENCRYPTED_PWLEN] or even PDWORD[23]
|
400
|
-
if is_array_type?(type)
|
401
|
-
# Separate the element type from the size of the array
|
402
|
-
element_type, length = split_array_type(type)
|
403
|
-
|
404
|
-
# Have read_array take care of the rest
|
405
|
-
return read_array(element_type, length, position, buffer)
|
406
|
-
end
|
407
|
-
|
408
|
-
size = sizeof_type(type)
|
409
|
-
raw = memread(position, size, buffer)
|
410
|
-
|
411
|
-
# read/unpack data for the types we have hard-coded support for
|
412
|
-
case type
|
413
|
-
when :LPWSTR
|
414
|
-
# null-terminated string of 16-bit Unicode characters
|
415
|
-
return read_wstring(read_pointer(raw))
|
416
|
-
when :DWORD
|
417
|
-
# Both on x86 and x64, DWORD is 32 bits
|
418
|
-
return raw.unpack('V').first
|
419
|
-
when :BOOL
|
420
|
-
return raw.unpack('l').first == 1
|
421
|
-
when :LONG
|
422
|
-
return raw.unpack('l').first
|
423
|
-
end
|
424
|
-
|
425
|
-
#If nothing worked thus far, return it raw
|
426
|
-
return raw
|
427
|
-
end
|
428
|
-
|
429
|
-
# Read 'length' number of instances of 'type' from 'bufptr'
|
430
|
-
# bufptr is an index in 'buffer' or, if buffer is nil, a memory address
|
431
|
-
def read_array(type, length, bufptr, buffer = nil)
|
432
|
-
if length <= 0
|
433
|
-
return []
|
434
|
-
end
|
435
|
-
|
436
|
-
size = sizeof_type(type)
|
437
|
-
# Grab the bytes that the array consists of
|
438
|
-
buffer = memread(bufptr, size * length, buffer)
|
439
|
-
|
440
|
-
offset = 0
|
441
|
-
|
442
|
-
1.upto(length).map do |n|
|
443
|
-
data = read_data(type, offset, buffer)
|
444
|
-
|
445
|
-
offset = offset + size
|
446
|
-
|
447
|
-
data
|
448
|
-
end
|
449
|
-
end
|
450
|
-
|
451
|
-
# construct the data structure described in 'definition' from 'buffer'
|
452
|
-
# starting from the index 'offset'
|
453
|
-
def read_struct(definition, buffer, offset = 0)
|
454
|
-
data = {}
|
455
|
-
|
456
|
-
offsets = struct_offsets(definition, offset)
|
457
|
-
|
458
|
-
definition.each do |mapping|
|
459
|
-
key, data_type = mapping
|
460
|
-
|
461
|
-
data[key] = read_data(data_type, offsets.shift, buffer)
|
462
|
-
end
|
463
|
-
|
464
|
-
data
|
465
|
-
end
|
466
|
-
|
467
|
-
|
468
|
-
# Returns true if the data type is a pointer, false otherwise
|
469
|
-
def is_pointer_type?(type)
|
470
|
-
return TYPE_DEFINITIONS[type] == :pointer
|
471
|
-
end
|
472
|
-
|
473
|
-
# Returns whether the given type represents an array of another type
|
474
|
-
# For example BYTE[3], BYTE[ENCRYPTED_PWLEN], or even PDWORD[23]
|
475
|
-
def is_array_type?(type)
|
476
|
-
return type =~ /^\w+\[\w+\]$/ ? true : false
|
477
|
-
end
|
478
|
-
|
479
|
-
# Returns true if the type passed describes a data structure, false otherwise
|
480
|
-
def is_struct_type?(type)
|
481
|
-
return type.class == Array
|
482
|
-
end
|
483
|
-
|
484
|
-
|
485
|
-
# Returns the pointer size for this architecture
|
486
|
-
def pointer_size
|
487
|
-
is_64bit ? 8 : 4
|
488
|
-
end
|
489
|
-
|
490
|
-
# Return the size, in bytes, of the given type
|
491
|
-
def sizeof_type(type)
|
492
|
-
if is_pointer_type?(type)
|
493
|
-
return pointer_size
|
494
|
-
end
|
495
|
-
|
496
|
-
if is_array_type?(type)
|
497
|
-
element_type, length = split_array_type(type)
|
498
|
-
|
499
|
-
return length * sizeof_type(element_type)
|
500
|
-
end
|
501
|
-
|
502
|
-
if is_struct_type?(type)
|
503
|
-
return sizeof_struct(type)
|
504
|
-
end
|
505
|
-
|
506
|
-
if TYPE_DEFINITIONS.has_key?(type)
|
507
|
-
primitive = TYPE_DEFINITIONS[type]
|
508
|
-
|
509
|
-
if primitive == :pointer
|
510
|
-
return pointer_size
|
511
|
-
end
|
512
|
-
|
513
|
-
if PRIMITIVE_TYPE_SIZES.has_key?(primitive)
|
514
|
-
return PRIMITIVE_TYPE_SIZES[primitive]
|
515
|
-
else
|
516
|
-
raise "Type #{type} was mapped to non-existent primitive #{primitive}"
|
517
|
-
end
|
518
|
-
end
|
519
|
-
|
520
|
-
raise "Unable to determine size for type #{type}."
|
521
|
-
end
|
522
|
-
|
523
|
-
# Calculates the size of the struct after alignment
|
524
|
-
def sizeof_struct(struct)
|
525
|
-
offsets = struct_offsets(struct, 0)
|
526
|
-
last_data_size = sizeof_type(struct.last[1])
|
527
|
-
size_no_padding = offsets.last + last_data_size
|
528
|
-
|
529
|
-
return size_no_padding + calc_padding(size_no_padding)
|
530
|
-
end
|
531
|
-
|
532
|
-
# Given a description of a data structure, returns an array containing
|
533
|
-
# the offset from the beginning for each subsequent element, taking into
|
534
|
-
# consideration alignment and padding
|
535
|
-
def struct_offsets(definition, offset)
|
536
|
-
padding = 0
|
537
|
-
offsets = []
|
538
|
-
|
539
|
-
definition.each do |mapping|
|
540
|
-
key, data_type = mapping
|
541
|
-
|
542
|
-
if sizeof_type(data_type) > padding
|
543
|
-
offset = offset + padding
|
544
|
-
end
|
545
|
-
|
546
|
-
offsets.push(offset)
|
547
|
-
|
548
|
-
offset = offset + sizeof_type(data_type)
|
549
|
-
|
550
|
-
padding = calc_padding(offset)
|
551
|
-
end
|
552
|
-
|
553
|
-
offsets
|
554
|
-
end
|
555
|
-
|
556
|
-
# http://en.wikipedia.org/wiki/Data_structure_alignment
|
557
|
-
def required_alignment
|
558
|
-
is_64bit ? 8 : 4
|
559
|
-
end
|
560
|
-
|
561
|
-
# Bytes that needed to be added to be aligned
|
562
|
-
def calc_padding(offset)
|
563
|
-
align = required_alignment
|
564
|
-
|
565
|
-
# If offset is not aligned...
|
566
|
-
if (offset % align) != 0
|
567
|
-
# Calculate padding needed to be aligned
|
568
|
-
align - (offset & (align - 1))
|
569
|
-
else
|
570
|
-
0
|
571
|
-
end
|
572
|
-
end
|
573
|
-
|
574
|
-
# Given an explicit array definition (e.g. BYTE[23]) return size (e.g. 23) and
|
575
|
-
# and type (e.g. BYTE). If a constant is given, attempt to resolve it
|
576
|
-
# that constant
|
577
|
-
def split_array_type(type)
|
578
|
-
if type =~ /^(\w+)\[(\w+)\]$/
|
579
|
-
element_type = $1
|
580
|
-
length = $2
|
581
|
-
|
582
|
-
unless length =~ /^\d+$/
|
583
|
-
length = railgun.const(length)
|
584
|
-
end
|
585
|
-
|
586
|
-
return element_type, length
|
587
|
-
else
|
588
|
-
raise "Can not split non-array type #{type}"
|
589
|
-
end
|
590
|
-
end
|
591
|
-
|
592
|
-
# Returns true if given platform has 64bit architecture
|
593
|
-
# expects client.platform
|
594
|
-
def is_64bit_platform?(platform)
|
595
|
-
platform =~ /win64/
|
596
|
-
end
|
597
|
-
|
598
|
-
###
|
599
|
-
# Summary:
|
600
|
-
# Evaluates a bit field, returning a hash representing the meaning
|
601
|
-
# and state of each bit.
|
602
|
-
#
|
603
|
-
# Parameters:
|
604
|
-
# value: a bit field represented by a Fixnum
|
605
|
-
# mappings: { 'WINAPI_CONSTANT_NAME' => :descriptive_symbol, ... }
|
606
|
-
#
|
607
|
-
# Returns:
|
608
|
-
# { :descriptive_symbol => true/false, ... }
|
609
|
-
##
|
610
|
-
def judge_bit_field(value, mappings)
|
611
|
-
flags = {}
|
612
|
-
rg = railgun
|
613
|
-
|
614
|
-
mappings.each do |constant_name, key|
|
615
|
-
flags[key] = (value & rg.const(constant_name)) != 0
|
616
|
-
end
|
617
|
-
|
618
|
-
flags
|
619
|
-
end
|
620
|
-
|
621
|
-
protected
|
622
|
-
|
623
|
-
attr_accessor :railgun, :is_64bit
|
624
|
-
end # Util
|
625
|
-
end # Railgun
|
626
|
-
end # Stdapi
|
627
|
-
end # Extensions
|
628
|
-
end # Meterpreter
|
629
|
-
end # Post
|
630
|
-
end # Rex
|