From 7436fdad72fccf1a558a80650960fef5260b75f6 Mon Sep 17 00:00:00 2001 From: Tod Beardsley Date: Thu, 23 May 2013 11:26:53 -0500 Subject: [PATCH 1/6] First, copy-pasta and add a test --- lib/msf/base/simple/auxiliary.rb | 33 +++++++++++++ lib/msf/core/auxiliary.rb | 10 ++++ .../console/command_dispatcher/auxiliary.rb | 40 ++++++++++++++++ test/modules/auxiliary/test/check.rb | 47 +++++++++++++++++++ test/scripts/test-check.rc | 7 +++ 5 files changed, 137 insertions(+) create mode 100644 test/modules/auxiliary/test/check.rb create mode 100644 test/scripts/test-check.rc diff --git a/lib/msf/base/simple/auxiliary.rb b/lib/msf/base/simple/auxiliary.rb index ed9d7dafbb..e4019b984e 100644 --- a/lib/msf/base/simple/auxiliary.rb +++ b/lib/msf/base/simple/auxiliary.rb @@ -92,6 +92,39 @@ module Auxiliary Msf::Simple::Auxiliary.run_simple(self, opts, &block) end + # + # Initiates a check, setting up the exploit to be used. The following + # options can be specified: + # + # LocalInput + # + # The local input handle that data can be read in from. + # + # LocalOutput + # + # The local output through which data can be displayed. + # + def self.check_simple(mod, opts) + if opts['LocalInput'] + mod.init_ui(opts['LocalInput'], opts['LocalOutput']) + end + + # Validate the option container state so that options will + # be normalized + mod.validate + + # Run check + mod.check + end + + # + # Calls the class method. + # + def check_simple(opts) + Msf::Simple::Auxiliary.check_simple(self, opts) + end + + protected # diff --git a/lib/msf/core/auxiliary.rb b/lib/msf/core/auxiliary.rb index 571efef878..b79f43de73 100644 --- a/lib/msf/core/auxiliary.rb +++ b/lib/msf/core/auxiliary.rb @@ -44,6 +44,16 @@ class Auxiliary < Msf::Module self.queue = Array.new end + # + # Checks to see if the target is vulnerable, returning unsupported if it's + # not supported. + # + # This method is designed to be overriden by exploit modules. + # + def check + Msf::Exploit::CheckCode::Unsupported + end + # # Creates a singleton instance of this auxiliary class # diff --git a/lib/msf/ui/console/command_dispatcher/auxiliary.rb b/lib/msf/ui/console/command_dispatcher/auxiliary.rb index 096e0643ec..b4c4b1f03d 100644 --- a/lib/msf/ui/console/command_dispatcher/auxiliary.rb +++ b/lib/msf/ui/console/command_dispatcher/auxiliary.rb @@ -27,6 +27,7 @@ class Auxiliary # def commands super.update({ + "check" => "Check to see if a target is vulnerable", "run" => "Launches the auxiliary module", "rerun" => "Reloads and launches the auxiliary module", "exploit" => "This is an alias for the run command", @@ -57,6 +58,45 @@ class Auxiliary "Auxiliary" end + # + # Checks to see if a target is vulnerable. + # + def cmd_check(*args) + defanged? + + begin + + code = mod.check_simple( + 'LocalInput' => driver.input, + 'LocalOutput' => driver.output) + + if (code and code.kind_of?(Array) and code.length > 1) + + if (code == Msf::Exploit::CheckCode::Vulnerable) + print_good(code[1]) + else + print_status(code[1]) + end + + else + print_error("Check failed: The state could not be determined.") + end + + rescue ::Interrupt + raise $! + rescue ::Exception => e + print_error("Module check failed: #{e.class} #{e}") + if(e.class.to_s != 'Msf::OptionValidateError') + print_error("Call stack:") + e.backtrace.each do |line| + break if line =~ /lib.msf.base.simple/ + print_error(" #{line}") + end + end + end + end + + # # Reloads an auxiliary module and executes it # diff --git a/test/modules/auxiliary/test/check.rb b/test/modules/auxiliary/test/check.rb new file mode 100644 index 0000000000..07e14bd61f --- /dev/null +++ b/test/modules/auxiliary/test/check.rb @@ -0,0 +1,47 @@ +## +# This file is part of the Metasploit Framework and may be subject to +# redistribution and commercial restrictions. Please see the Metasploit +# Framework web site for more information on licensing and terms of use. +# http://metasploit.com/framework/ +## + +require 'msf/core' + +class Metasploit3 < Msf::Auxiliary + + include Msf::Auxiliary::Report + include Msf::Exploit::Remote::HttpClient + + def initialize(info = {}) + super(update_info(info, + 'Name' => "Check Test", + 'Description' => %q{ + This module ensures that 'check' actually functions for Auxiilary modules. + }, + 'References' => + [ + [ 'OSVDB', '0' ] + ], + 'Author' => + [ + 'todb' + ], + 'License' => MSF_LICENSE + )) + + register_options( + [ + Opt::RPORT(80) + ], self.class) + end + + def check + print_debug "Check is successful" + return Msf::Exploit::CheckCode::Vulnerable + end + + def run + print_debug "Run is successful." + end + +end diff --git a/test/scripts/test-check.rc b/test/scripts/test-check.rc new file mode 100644 index 0000000000..3440b21d41 --- /dev/null +++ b/test/scripts/test-check.rc @@ -0,0 +1,7 @@ +# Usage: +# msfconsole -qLm test/modules -r test/scripts/test-check.rc + +use auxiliary/test/check +set rhost www.metasploit.com +check +exit From a852304ba324458a0f80b66ecefb70184029463d Mon Sep 17 00:00:00 2001 From: Tod Beardsley Date: Thu, 23 May 2013 11:40:04 -0500 Subject: [PATCH 2/6] DRY: Move check things to the common module level While it makes lots of sense to bring check to all modules, of course some modules will not be able to actually use it. Namely modules like nop and payload modules. If you're feeling creative, you could probably come up with semantically similar checks for those, too. --- lib/msf/core/auxiliary.rb | 10 ----- lib/msf/core/exploit.rb | 10 ----- lib/msf/core/module.rb | 10 +++++ .../console/command_dispatcher/auxiliary.rb | 40 ------------------- .../ui/console/command_dispatcher/exploit.rb | 39 ------------------ .../ui/console/module_command_dispatcher.rb | 35 +++++++++++++++- 6 files changed, 44 insertions(+), 100 deletions(-) diff --git a/lib/msf/core/auxiliary.rb b/lib/msf/core/auxiliary.rb index b79f43de73..571efef878 100644 --- a/lib/msf/core/auxiliary.rb +++ b/lib/msf/core/auxiliary.rb @@ -44,16 +44,6 @@ class Auxiliary < Msf::Module self.queue = Array.new end - # - # Checks to see if the target is vulnerable, returning unsupported if it's - # not supported. - # - # This method is designed to be overriden by exploit modules. - # - def check - Msf::Exploit::CheckCode::Unsupported - end - # # Creates a singleton instance of this auxiliary class # diff --git a/lib/msf/core/exploit.rb b/lib/msf/core/exploit.rb index e059d0999b..f40320fa10 100644 --- a/lib/msf/core/exploit.rb +++ b/lib/msf/core/exploit.rb @@ -415,16 +415,6 @@ class Exploit < Msf::Module # ## - # - # Checks to see if the target is vulnerable, returning unsupported if it's - # not supported. - # - # This method is designed to be overriden by exploit modules. - # - def check - CheckCode::Unsupported - end - # # Kicks off the actual exploit. Prior to this call, the framework will # have validated the data store using the options associated with this diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index a62a8c12be..b5c4b5bac6 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -355,6 +355,16 @@ class Module date_str = Date.parse(module_info['DisclosureDate'].to_s) rescue nil end + # + # Checks to see if the target is vulnerable, returning unsupported if it's + # not supported. + # + # This method is designed to be overriden by exploit modules. + # + def check + Msf::Exploit::CheckCode::Unsupported + end + # # Returns the hash that describes this module's compatibilities. # diff --git a/lib/msf/ui/console/command_dispatcher/auxiliary.rb b/lib/msf/ui/console/command_dispatcher/auxiliary.rb index b4c4b1f03d..096e0643ec 100644 --- a/lib/msf/ui/console/command_dispatcher/auxiliary.rb +++ b/lib/msf/ui/console/command_dispatcher/auxiliary.rb @@ -27,7 +27,6 @@ class Auxiliary # def commands super.update({ - "check" => "Check to see if a target is vulnerable", "run" => "Launches the auxiliary module", "rerun" => "Reloads and launches the auxiliary module", "exploit" => "This is an alias for the run command", @@ -58,45 +57,6 @@ class Auxiliary "Auxiliary" end - # - # Checks to see if a target is vulnerable. - # - def cmd_check(*args) - defanged? - - begin - - code = mod.check_simple( - 'LocalInput' => driver.input, - 'LocalOutput' => driver.output) - - if (code and code.kind_of?(Array) and code.length > 1) - - if (code == Msf::Exploit::CheckCode::Vulnerable) - print_good(code[1]) - else - print_status(code[1]) - end - - else - print_error("Check failed: The state could not be determined.") - end - - rescue ::Interrupt - raise $! - rescue ::Exception => e - print_error("Module check failed: #{e.class} #{e}") - if(e.class.to_s != 'Msf::OptionValidateError') - print_error("Call stack:") - e.backtrace.each do |line| - break if line =~ /lib.msf.base.simple/ - print_error(" #{line}") - end - end - end - end - - # # Reloads an auxiliary module and executes it # diff --git a/lib/msf/ui/console/command_dispatcher/exploit.rb b/lib/msf/ui/console/command_dispatcher/exploit.rb index 9c7327002b..b7a157ce79 100644 --- a/lib/msf/ui/console/command_dispatcher/exploit.rb +++ b/lib/msf/ui/console/command_dispatcher/exploit.rb @@ -29,7 +29,6 @@ class Exploit # def commands super.update({ - "check" => "Check to see if a target is vulnerable", "exploit" => "Launch an exploit attempt", "rcheck" => "Reloads the module and checks if the target is vulnerable", "rexploit" => "Reloads the module and launches an exploit attempt", @@ -46,44 +45,6 @@ class Exploit "Exploit" end - # - # Checks to see if a target is vulnerable. - # - def cmd_check(*args) - defanged? - - begin - - code = mod.check_simple( - 'LocalInput' => driver.input, - 'LocalOutput' => driver.output) - - if (code and code.kind_of?(Array) and code.length > 1) - - if (code == Msf::Exploit::CheckCode::Vulnerable) - print_good(code[1]) - else - print_status(code[1]) - end - - else - print_error("Check failed: The state could not be determined.") - end - - rescue ::Interrupt - raise $! - rescue ::Exception => e - print_error("Exploit check failed: #{e.class} #{e}") - if(e.class.to_s != 'Msf::OptionValidateError') - print_error("Call stack:") - e.backtrace.each do |line| - break if line =~ /lib.msf.base.simple/ - print_error(" #{line}") - end - end - end - end - # # Launches an exploitation attempt. # diff --git a/lib/msf/ui/console/module_command_dispatcher.rb b/lib/msf/ui/console/module_command_dispatcher.rb index 8cc753cece..df35f8f917 100644 --- a/lib/msf/ui/console/module_command_dispatcher.rb +++ b/lib/msf/ui/console/module_command_dispatcher.rb @@ -17,7 +17,8 @@ module ModuleCommandDispatcher def commands { "pry" => "Open a Pry session on the current module", - "reload" => "Reload the current module from disk" + "reload" => "Reload the current module from disk", + "check" => "Check to see if a target is vulnerable" } end @@ -35,6 +36,38 @@ module ModuleCommandDispatcher self.driver.active_module = m end + # + # Checks to see if a target is vulnerable. + # + def cmd_check(*args) + defanged? + begin + code = mod.check_simple( + 'LocalInput' => driver.input, + 'LocalOutput' => driver.output) + if (code and code.kind_of?(Array) and code.length > 1) + if (code == Msf::Exploit::CheckCode::Vulnerable) + print_good(code[1]) + else + print_status(code[1]) + end + else + print_error("Check failed: The state could not be determined.") + end + rescue ::Interrupt + raise $! + rescue ::Exception => e + print_error("Exploit check failed: #{e.class} #{e}") + if(e.class.to_s != 'Msf::OptionValidateError') + print_error("Call stack:") + e.backtrace.each do |line| + break if line =~ /lib.msf.base.simple/ + print_error(" #{line}") + end + end + end + end + def cmd_pry_help print_line "Usage: pry" print_line From eeea1d9109b7999f91defafd651d8226be482e32 Mon Sep 17 00:00:00 2001 From: Tod Beardsley Date: Thu, 23 May 2013 11:46:16 -0500 Subject: [PATCH 3/6] Regression test for check in exploits --- test/modules/exploits/test/check.rb | 45 +++++++++++++++++++++++++++++ test/scripts/test-check.rc | 5 +++- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 test/modules/exploits/test/check.rb diff --git a/test/modules/exploits/test/check.rb b/test/modules/exploits/test/check.rb new file mode 100644 index 0000000000..a7aef9118b --- /dev/null +++ b/test/modules/exploits/test/check.rb @@ -0,0 +1,45 @@ +## +# This file is part of the Metasploit Framework and may be subject to +# redistribution and commercial restrictions. Please see the Metasploit +# Framework web site for more information on licensing and terms of use. +# http://metasploit.com/framework/ +## + +require 'msf/core' + +class Metasploit3 < Msf::Exploit + + def initialize(info = {}) + super(update_info(info, + 'Name' => "Check Test Exploit", + 'Description' => %q{ + This module ensures that 'check' actually functions for Exploit modules. + }, + 'References' => + [ + [ 'OSVDB', '0' ] + ], + 'Author' => + [ + 'todb' + ], + 'License' => MSF_LICENSE, + 'DisclosureDate' => 'May 23 2013' + )) + + register_options( + [ + Opt::RPORT(80) + ], self.class) + end + + def check + print_debug "Check is successful" + return Msf::Exploit::CheckCode::Vulnerable + end + + def exploit + print_debug "Exploit is successful." + end + +end diff --git a/test/scripts/test-check.rc b/test/scripts/test-check.rc index 3440b21d41..47c2a3d470 100644 --- a/test/scripts/test-check.rc +++ b/test/scripts/test-check.rc @@ -4,4 +4,7 @@ use auxiliary/test/check set rhost www.metasploit.com check -exit + +use exploit/test/check +set rhost www.metasploit.com +check From ff08fed987646acc9e4a5e86240e77c4e3821bf4 Mon Sep 17 00:00:00 2001 From: sinn3r Date: Thu, 23 May 2013 12:39:45 -0500 Subject: [PATCH 4/6] Revert master misfire, back to the firefox module --- test/modules/post/test/unix.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/modules/post/test/unix.rb b/test/modules/post/test/unix.rb index 5c32999a7b..74fb77240f 100644 --- a/test/modules/post/test/unix.rb +++ b/test/modules/post/test/unix.rb @@ -1,6 +1,5 @@ -$:.push "test/lib" unless $:.include? "test/lib" -require 'module_test' +require 'test/lib/module_test' #load 'test/lib/module_test.rb' #load 'lib/rex/text.rb' @@ -16,10 +15,11 @@ class Metasploit4 < Msf::Post def initialize(info={}) super( update_info( info, - 'Name' => 'Testing Remote UNIX System Manipulation', + 'Name' => 'Testing remote unix system manipulation', 'Description' => %q{ This module will test Post::File API methods }, 'License' => MSF_LICENSE, 'Author' => [ 'egypt'], + 'Version' => '$Revision$', 'Platform' => [ 'linux', 'java' ], 'SessionTypes' => [ 'meterpreter', 'shell' ] )) From 05916c079e8d0e755bdd5cb6abeefbc404794f7e Mon Sep 17 00:00:00 2001 From: Tod Beardsley Date: Thu, 23 May 2013 12:40:24 -0500 Subject: [PATCH 5/6] Inline unit tests are so last decade Aside from codebase-wide changes, nearly all of these tests haven't been touched since before 2010, and there is no effort to maintain this style of testing. We've moved on to (correctly) seperating out our tests from our codebase. --- lib/msf/base/sessions/command_shell.rb.ut.rb | 10 - lib/msf/core/exceptions.rb.ut.rb | 41 -- lib/msf/core/exploit.rb.ut.rb | 38 -- lib/msf/core/exploit/dcerpc.rb.ut.rb | 28 - lib/msf/core/exploit/seh.rb.ut.rb | 29 -- lib/msf/core/exploit/tcp.rb.ut.rb | 26 - lib/msf/core/handler/bind_tcp.rb.ut.rb | 53 -- lib/msf/core/handler/reverse_tcp.rb.ut.rb | 64 --- lib/msf/core/module/author.rb.ut.rb | 24 - lib/msf/core/module/platform_list.rb.ut.rb | 54 -- lib/msf/core/module/reference.rb.ut.rb | 27 - lib/msf/core/module/target.rb.ut.rb | 26 - lib/msf/core/option_container.rb.ut.rb | 140 ----- lib/msf/core/post/windows/registry.rb.ut.rb | 23 - .../core/post/windows/user_profiles.rb.ut.rb | 23 - lib/msf/core/session_manager.rb.ut.rb | 76 --- lib/net/ssh.rb.ut.rb | 92 ---- lib/net/ssh/utils.rb.ut.rb | 185 ------- lib/postgres_msf.rb.ut.rb | 55 -- lib/rex/arch/sparc.rb.ut.rb | 19 - lib/rex/arch/x86.rb.ut.rb | 94 ---- lib/rex/assembly/nasm.rb.ut.rb | 23 - lib/rex/encoder/ndr.rb.ut.rb | 45 -- lib/rex/encoder/xdr.rb.ut.rb | 30 -- lib/rex/encoders/xor_dword_additive.rb.ut.rb | 13 - lib/rex/encoding/xor/byte.rb.ut.rb | 22 - lib/rex/encoding/xor/dword.rb.ut.rb | 16 - lib/rex/encoding/xor/dword_additive.rb.ut.rb | 16 - lib/rex/encoding/xor/generic.rb.ut.rb | 121 ----- lib/rex/encoding/xor/word.rb.ut.rb | 14 - lib/rex/exceptions.rb.ut.rb | 45 -- lib/rex/exploitation/egghunter.rb.ut.rb | 28 - lib/rex/exploitation/omelet.rb.ut.rb | 27 - lib/rex/exploitation/opcodedb.rb.ut.rb | 280 ---------- lib/rex/exploitation/seh.rb.ut.rb | 20 - lib/rex/file.rb.ut.rb | 17 - lib/rex/io/ring_buffer.rb.ut.rb | 135 ----- lib/rex/nop/opty2.rb.ut.rb | 24 - lib/rex/parser/arguments.rb.ut.rb | 68 --- lib/rex/parser/ini.rb.ut.rb | 30 -- .../stdapi/railgun/api_constants.rb.ut.rb | 39 -- .../stdapi/railgun/buffer_item.rb.ut.rb | 37 -- .../extensions/stdapi/railgun/dll.rb.ut.rb | 52 -- .../stdapi/railgun/dll_function.rb.ut.rb | 43 -- .../stdapi/railgun/dll_helper.rb.ut.rb | 128 ----- .../stdapi/railgun/dll_wrapper.rb.ut.rb | 64 --- .../stdapi/railgun/platform_util.rb.ut.rb | 29 -- .../stdapi/railgun/railgun.rb.ut.rb | 155 ------ .../stdapi/railgun/type/pointer_util.rb.ut.rb | 128 ----- .../stdapi/railgun/win_const_manager.rb.ut.rb | 124 ----- lib/rex/proto/dcerpc/client.rb.ut.rb | 492 ------------------ lib/rex/proto/dcerpc/handle.rb.ut.rb | 86 --- lib/rex/proto/dcerpc/ndr.rb.ut.rb | 42 -- lib/rex/proto/dcerpc/packet.rb.ut.rb | 57 -- lib/rex/proto/dcerpc/response.rb.ut.rb | 16 - lib/rex/proto/dcerpc/uuid.rb.ut.rb | 47 -- lib/rex/proto/drda/constants.rb.ut.rb | 24 - lib/rex/proto/drda/packet.rb.ut.rb | 110 ---- lib/rex/proto/drda/utils.rb.ut.rb | 85 --- lib/rex/proto/http/client.rb.ut.rb | 96 ---- lib/rex/proto/http/handler/erb.rb.ut.rb | 22 - lib/rex/proto/http/handler/erb.rb.ut.rb.rhtml | 1 - lib/rex/proto/http/handler/proc.rb.ut.rb | 25 - lib/rex/proto/http/header.rb.ut.rb | 47 -- lib/rex/proto/http/packet.rb.ut.rb | 166 ------ lib/rex/proto/http/request.rb.ut.rb | 215 -------- lib/rex/proto/http/response.rb.ut.rb | 150 ------ lib/rex/proto/http/server.rb.ut.rb | 80 --- lib/rex/proto/ntlm.rb.ut.rb | 181 ------- lib/rex/proto/rfb.rb.ut.rb | 33 -- lib/rex/proto/smb/client.rb.ut.rb | 224 -------- lib/rex/proto/smb/constants.rb.ut.rb | 19 - lib/rex/proto/smb/simpleclient.rb.ut.rb | 129 ----- lib/rex/proto/smb/utils.rb.ut.rb | 21 - lib/rex/proto/tftp/server.rb.ut.rb | 24 - lib/rex/service_manager.rb.ut.rb | 33 -- lib/rex/socket.rb.ut.rb | 108 ---- lib/rex/socket/comm/local.rb.ut.rb | 76 --- lib/rex/socket/parameters.rb.ut.rb | 52 -- lib/rex/socket/range_walker.rb.ut.rb | 56 -- lib/rex/socket/ssl_tcp.rb.ut.rb | 40 -- lib/rex/socket/ssl_tcp_server.rb.ut.rb | 62 --- lib/rex/socket/subnet_walker.rb.ut.rb | 29 -- lib/rex/socket/switch_board.rb.ut.rb | 53 -- lib/rex/socket/tcp.rb.ut.rb | 65 --- lib/rex/socket/tcp_server.rb.ut.rb | 45 -- lib/rex/socket/udp.rb.ut.rb | 45 -- lib/rex/text.rb.ut.rb | 193 ------- lib/rex/transformer.rb.ut.rb | 39 -- lib/rex/ui/text/color.rb.ut.rb | 19 - lib/rex/ui/text/progress_tracker.rb.ut.rb | 35 -- lib/rex/ui/text/table.rb.ut.rb | 56 -- modules/encoders/encoder_test.rb.ut.rb | 47 -- modules/encoders/generic/none.rb.ut.rb | 38 -- modules/encoders/x86/call4_dword_xor.rb.ut.rb | 53 -- modules/encoders/x86/countdown.rb.ut.rb | 51 -- modules/encoders/x86/fnstenv_mov.rb.ut.rb | 52 -- modules/nops/nop_test.rb.ut.rb | 47 -- test/lib/regexr.rb.ut.rb | 73 --- 99 files changed, 6659 deletions(-) delete mode 100644 lib/msf/base/sessions/command_shell.rb.ut.rb delete mode 100644 lib/msf/core/exceptions.rb.ut.rb delete mode 100644 lib/msf/core/exploit.rb.ut.rb delete mode 100644 lib/msf/core/exploit/dcerpc.rb.ut.rb delete mode 100644 lib/msf/core/exploit/seh.rb.ut.rb delete mode 100644 lib/msf/core/exploit/tcp.rb.ut.rb delete mode 100644 lib/msf/core/handler/bind_tcp.rb.ut.rb delete mode 100644 lib/msf/core/handler/reverse_tcp.rb.ut.rb delete mode 100644 lib/msf/core/module/author.rb.ut.rb delete mode 100644 lib/msf/core/module/platform_list.rb.ut.rb delete mode 100644 lib/msf/core/module/reference.rb.ut.rb delete mode 100644 lib/msf/core/module/target.rb.ut.rb delete mode 100644 lib/msf/core/option_container.rb.ut.rb delete mode 100644 lib/msf/core/post/windows/registry.rb.ut.rb delete mode 100644 lib/msf/core/post/windows/user_profiles.rb.ut.rb delete mode 100644 lib/msf/core/session_manager.rb.ut.rb delete mode 100755 lib/net/ssh.rb.ut.rb delete mode 100644 lib/net/ssh/utils.rb.ut.rb delete mode 100644 lib/postgres_msf.rb.ut.rb delete mode 100644 lib/rex/arch/sparc.rb.ut.rb delete mode 100644 lib/rex/arch/x86.rb.ut.rb delete mode 100644 lib/rex/assembly/nasm.rb.ut.rb delete mode 100644 lib/rex/encoder/ndr.rb.ut.rb delete mode 100644 lib/rex/encoder/xdr.rb.ut.rb delete mode 100644 lib/rex/encoders/xor_dword_additive.rb.ut.rb delete mode 100644 lib/rex/encoding/xor/byte.rb.ut.rb delete mode 100644 lib/rex/encoding/xor/dword.rb.ut.rb delete mode 100644 lib/rex/encoding/xor/dword_additive.rb.ut.rb delete mode 100644 lib/rex/encoding/xor/generic.rb.ut.rb delete mode 100644 lib/rex/encoding/xor/word.rb.ut.rb delete mode 100644 lib/rex/exceptions.rb.ut.rb delete mode 100644 lib/rex/exploitation/egghunter.rb.ut.rb delete mode 100644 lib/rex/exploitation/omelet.rb.ut.rb delete mode 100644 lib/rex/exploitation/opcodedb.rb.ut.rb delete mode 100644 lib/rex/exploitation/seh.rb.ut.rb delete mode 100644 lib/rex/file.rb.ut.rb delete mode 100644 lib/rex/io/ring_buffer.rb.ut.rb delete mode 100644 lib/rex/nop/opty2.rb.ut.rb delete mode 100644 lib/rex/parser/arguments.rb.ut.rb delete mode 100644 lib/rex/parser/ini.rb.ut.rb delete mode 100644 lib/rex/post/meterpreter/extensions/stdapi/railgun/api_constants.rb.ut.rb delete mode 100644 lib/rex/post/meterpreter/extensions/stdapi/railgun/buffer_item.rb.ut.rb delete mode 100644 lib/rex/post/meterpreter/extensions/stdapi/railgun/dll.rb.ut.rb delete mode 100644 lib/rex/post/meterpreter/extensions/stdapi/railgun/dll_function.rb.ut.rb delete mode 100644 lib/rex/post/meterpreter/extensions/stdapi/railgun/dll_helper.rb.ut.rb delete mode 100644 lib/rex/post/meterpreter/extensions/stdapi/railgun/dll_wrapper.rb.ut.rb delete mode 100644 lib/rex/post/meterpreter/extensions/stdapi/railgun/platform_util.rb.ut.rb delete mode 100644 lib/rex/post/meterpreter/extensions/stdapi/railgun/railgun.rb.ut.rb delete mode 100644 lib/rex/post/meterpreter/extensions/stdapi/railgun/type/pointer_util.rb.ut.rb delete mode 100644 lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb.ut.rb delete mode 100755 lib/rex/proto/dcerpc/client.rb.ut.rb delete mode 100644 lib/rex/proto/dcerpc/handle.rb.ut.rb delete mode 100644 lib/rex/proto/dcerpc/ndr.rb.ut.rb delete mode 100644 lib/rex/proto/dcerpc/packet.rb.ut.rb delete mode 100644 lib/rex/proto/dcerpc/response.rb.ut.rb delete mode 100644 lib/rex/proto/dcerpc/uuid.rb.ut.rb delete mode 100644 lib/rex/proto/drda/constants.rb.ut.rb delete mode 100644 lib/rex/proto/drda/packet.rb.ut.rb delete mode 100644 lib/rex/proto/drda/utils.rb.ut.rb delete mode 100644 lib/rex/proto/http/client.rb.ut.rb delete mode 100644 lib/rex/proto/http/handler/erb.rb.ut.rb delete mode 100644 lib/rex/proto/http/handler/erb.rb.ut.rb.rhtml delete mode 100644 lib/rex/proto/http/handler/proc.rb.ut.rb delete mode 100644 lib/rex/proto/http/header.rb.ut.rb delete mode 100644 lib/rex/proto/http/packet.rb.ut.rb delete mode 100644 lib/rex/proto/http/request.rb.ut.rb delete mode 100644 lib/rex/proto/http/response.rb.ut.rb delete mode 100644 lib/rex/proto/http/server.rb.ut.rb delete mode 100644 lib/rex/proto/ntlm.rb.ut.rb delete mode 100644 lib/rex/proto/rfb.rb.ut.rb delete mode 100644 lib/rex/proto/smb/client.rb.ut.rb delete mode 100644 lib/rex/proto/smb/constants.rb.ut.rb delete mode 100644 lib/rex/proto/smb/simpleclient.rb.ut.rb delete mode 100644 lib/rex/proto/smb/utils.rb.ut.rb delete mode 100755 lib/rex/proto/tftp/server.rb.ut.rb delete mode 100644 lib/rex/service_manager.rb.ut.rb delete mode 100644 lib/rex/socket.rb.ut.rb delete mode 100644 lib/rex/socket/comm/local.rb.ut.rb delete mode 100644 lib/rex/socket/parameters.rb.ut.rb delete mode 100644 lib/rex/socket/range_walker.rb.ut.rb delete mode 100644 lib/rex/socket/ssl_tcp.rb.ut.rb delete mode 100644 lib/rex/socket/ssl_tcp_server.rb.ut.rb delete mode 100644 lib/rex/socket/subnet_walker.rb.ut.rb delete mode 100644 lib/rex/socket/switch_board.rb.ut.rb delete mode 100644 lib/rex/socket/tcp.rb.ut.rb delete mode 100644 lib/rex/socket/tcp_server.rb.ut.rb delete mode 100644 lib/rex/socket/udp.rb.ut.rb delete mode 100644 lib/rex/text.rb.ut.rb delete mode 100644 lib/rex/transformer.rb.ut.rb delete mode 100644 lib/rex/ui/text/color.rb.ut.rb delete mode 100644 lib/rex/ui/text/progress_tracker.rb.ut.rb delete mode 100644 lib/rex/ui/text/table.rb.ut.rb delete mode 100644 modules/encoders/encoder_test.rb.ut.rb delete mode 100644 modules/encoders/generic/none.rb.ut.rb delete mode 100644 modules/encoders/x86/call4_dword_xor.rb.ut.rb delete mode 100644 modules/encoders/x86/countdown.rb.ut.rb delete mode 100644 modules/encoders/x86/fnstenv_mov.rb.ut.rb delete mode 100644 modules/nops/nop_test.rb.ut.rb delete mode 100644 test/lib/regexr.rb.ut.rb diff --git a/lib/msf/base/sessions/command_shell.rb.ut.rb b/lib/msf/base/sessions/command_shell.rb.ut.rb deleted file mode 100644 index 365465a6c7..0000000000 --- a/lib/msf/base/sessions/command_shell.rb.ut.rb +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -require 'test/unit' -require 'msf/base' - -class Msf::Sessions::CommandShell::UnitTest < Test::Unit::TestCase - def test_cmdshell - end -end diff --git a/lib/msf/core/exceptions.rb.ut.rb b/lib/msf/core/exceptions.rb.ut.rb deleted file mode 100644 index f10326a339..0000000000 --- a/lib/msf/core/exceptions.rb.ut.rb +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'msf/core/exceptions' - -module Msf -module Exceptions - -class UnitTest < Test::Unit::TestCase - - def test_exceptions - Msf.constants.each { |const| - mod = Msf.const_get(const) - - if ((mod.kind_of?(Class) == false) || - (mod.ancestors.include?(Msf::Exception) == false)) - next - end - - begin - raise mod.new - rescue mod => detail - assert_respond_to(detail, 'to_s', "#{mod} does not implement to_s") - assert_not_nil(detail.to_s, "invalid to_s") - end - } - - begin - raise OptionValidateError.new([ 'test', 'best' ]) - rescue OptionValidateError => detail - assert_match(/^The following/, detail.to_s) - end - end - -end - -end -end diff --git a/lib/msf/core/exploit.rb.ut.rb b/lib/msf/core/exploit.rb.ut.rb deleted file mode 100644 index 494c091ce9..0000000000 --- a/lib/msf/core/exploit.rb.ut.rb +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'msf/core' - -module Msf - -class Exploit::UnitTest < Test::Unit::TestCase - - class StubExploit < Msf::Exploit - end - - class Stub2Exploit < Msf::Exploit - def check - end - end - - def test_support - assert_equal(false, Exploit.new.supports_check?, "auto target support check failed") - assert_equal(false, StubExploit.new.supports_check?, "auto target deriv enabled support check failed") - assert_equal(true, Stub2Exploit.new.supports_check?, "auto target deriv disabled support check failed") - assert_equal(false, Exploit.new.capabilities['check'], "auto target capabilities check failed") - assert_equal(false, StubExploit.new.capabilities['check'], "auto target deriv enabled capabilities check failed") - assert_equal(true, Stub2Exploit.new.capabilities['check'], "auto target deriv disabled capabilities check failed") - end - - def test_defaults - e = Exploit.new - - assert_equal(Msf::Exploit::CheckCode::Unsupported, e.check, "invalid default check") - end - -end - -end diff --git a/lib/msf/core/exploit/dcerpc.rb.ut.rb b/lib/msf/core/exploit/dcerpc.rb.ut.rb deleted file mode 100644 index 89b43df26e..0000000000 --- a/lib/msf/core/exploit/dcerpc.rb.ut.rb +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..', '..')) - -require 'test/unit' -require 'msf/core' - -module Msf - -class Exploit::Remote::DCERPC::UnitTest < Test::Unit::TestCase - - class Stub < Msf::Exploit::Remote - include Msf::Exploit::Remote::DCERPC - end - - def test_tcp - e = Stub.new - - assert_equal(true, e.options.get('RHOST').required?, "invalid RHOST requirement") - assert_equal(true, e.options.get('RPORT').required?, "invalid RPORT requirement") - assert_equal(135, e.options.get('RPORT').default, "invalid RPORT default") - end - -end - -end - diff --git a/lib/msf/core/exploit/seh.rb.ut.rb b/lib/msf/core/exploit/seh.rb.ut.rb deleted file mode 100644 index 54d668bdc5..0000000000 --- a/lib/msf/core/exploit/seh.rb.ut.rb +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'test/unit' -require 'rex' -require 'msf/core' -require 'msf/core/exploit/seh' - -module Msf - -class Exploit::Seh::UnitTest < Test::Unit::TestCase - - class Stub < Msf::Exploit::Remote - include Msf::Exploit::Seh - end - - def test_seh - e = Stub.new - r = e.generate_seh_record(0x41414141) - - assert_equal("\xeb\x06", r[0, 2]) - assert_equal("\x41\x41\x41\x41", r[4, 4]) - end - -end - -end diff --git a/lib/msf/core/exploit/tcp.rb.ut.rb b/lib/msf/core/exploit/tcp.rb.ut.rb deleted file mode 100644 index e8803fe043..0000000000 --- a/lib/msf/core/exploit/tcp.rb.ut.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..', '..')) - -require 'test/unit' -require 'msf/core' - -module Msf - -class Exploit::Remote::Tcp::UnitTest < Test::Unit::TestCase - - class Stub < Msf::Exploit::Remote - include Msf::Exploit::Remote::Tcp - end - - def test_tcp - e = Stub.new - - assert_equal(true, e.options.get('RHOST').required?, "invalid RHOST requirement") - assert_equal(true, e.options.get('RPORT').required?, "invalid RPORT requirement") - end - -end - -end diff --git a/lib/msf/core/handler/bind_tcp.rb.ut.rb b/lib/msf/core/handler/bind_tcp.rb.ut.rb deleted file mode 100644 index 436853974c..0000000000 --- a/lib/msf/core/handler/bind_tcp.rb.ut.rb +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'test/unit' -require 'msf/core' -require 'msf/core/handler/bind_tcp' - -module Msf - -class Handler::BindTcp::UnitTest < Test::Unit::TestCase - - class Stub < Msf::Payload - end - - module Foo - def handle_connection(client, opts={}) - self.success = 1 - end - - attr_accessor :success, :session - end - - def test_handler - c = Class.new(Stub) - - c.include(Foo, Msf::Handler::BindTcp) - - h = c.new({}) - - begin - t = Rex::Socket::TcpServer.create( - 'LocalPort' => 4444) - - h.datastore['RHOST'] = "127.0.0.1" - h.datastore['LPORT'] = 4444 - - h.start_handler - - Rex::ThreadSafe.sleep(1) - - assert_equal(1, h.success) - ensure - t.close if (t) - h.stop_handler if (h) - end - end - -end - -end - diff --git a/lib/msf/core/handler/reverse_tcp.rb.ut.rb b/lib/msf/core/handler/reverse_tcp.rb.ut.rb deleted file mode 100644 index 087a244bf5..0000000000 --- a/lib/msf/core/handler/reverse_tcp.rb.ut.rb +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'test/unit' -require 'msf/core' -require 'msf/core/handler/reverse_tcp' - -module Msf - -class Handler::ReverseTcp::UnitTest < Test::Unit::TestCase - - class Stub < Msf::Payload - include Msf::Handler::ReverseTcp - end - - module Foo - def handle_connection(client, opts={}) - self.success = 1 - end - - attr_accessor :success, :session - end - - def test_handler - c = Class.new(Stub) - c.include(Foo) - - h = c.new({}) - - begin - h.datastore['LPORT'] = 4444 - - h.setup_handler - h.start_handler - - 5.times { - t = Rex::Socket::Tcp.create( - 'PeerHost' => "127.0.0.1", - 'PeerPort' => 4444) - - assert_not_nil(t) - - begin - Rex::ThreadSafe.sleep(1) - - assert_equal(1, h.success) - - h.success = 0 - ensure - t.close - end - } - ensure - h.stop_handler if (h) - h.cleanup_handler if (h) - end - end - -end - -end - diff --git a/lib/msf/core/module/author.rb.ut.rb b/lib/msf/core/module/author.rb.ut.rb deleted file mode 100644 index 89785a4d67..0000000000 --- a/lib/msf/core/module/author.rb.ut.rb +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'test/unit' -require 'msf/core' - -module Msf - -class Module::Author::UnitTest < Test::Unit::TestCase - def test_known - assert_match(/^skape /, Author.from_s('skape').to_s) - assert_equal('skape ', Author.from_s('skape').to_s) - end - - def test_raw - assert_equal('skapino', Author.from_s('skapino ').name) - assert_equal('johnson@jones.com', Author.from_s('skapino ').email) - assert_equal('skapino ', Author.from_s('skapino ').to_s) - end -end - -end diff --git a/lib/msf/core/module/platform_list.rb.ut.rb b/lib/msf/core/module/platform_list.rb.ut.rb deleted file mode 100644 index d12854830d..0000000000 --- a/lib/msf/core/module/platform_list.rb.ut.rb +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'test/unit' -require 'msf/core' -require 'msf/core/module/platform_list' - -class Msf::Module::PlatformList::UnitTest < Test::Unit::TestCase - - def test_range - assert_equal( - [ Msf::Module::Platform::Windows::XP::SP0, - Msf::Module::Platform::Windows::XP::SP1 - ], Msf::Module::PlatformList.new('winxpsp0' .. 'winxpsp1').platforms - ) - end - - def test_names - assert_equal([ 'Windows XP SP2' ], Msf::Module::PlatformList.new('winxpsp2').names) - end - - def test_transform - assert_equal([ 'Windows XP SP2' ], Msf::Module::PlatformList.transform('winxpsp2').names) - assert_equal([ 'Windows XP SP2' ], Msf::Module::PlatformList.transform(['winxpsp2']).names) - assert_equal([ 'Windows 2000 SP3' ], Msf::Module::PlatformList.transform(['win2000sp3']).names) - assert_equal([ 'Windows 2000 SP3' ], Msf::Module::PlatformList.transform(['win2ksp3']).names) - end - - def test_all - assert_equal( [ Msf::Module::Platform ], Msf::Module::PlatformList.new('').platforms) - end - - def test_supports - l1 = Msf::Module::PlatformList.new('win') - l2 = Msf::Module::PlatformList.new('win xp sp0', 'win xp sp2') - assert_equal( true, l1.supports?(l2) ) - assert_equal( false, l2.supports?(l1) ) - end - - def test_intersect - l1 = Msf::Module::PlatformList.new('win') - l2 = Msf::Module::PlatformList.new('win xp sp0', 'win xp sp2') - assert_equal( - [ Msf::Module::Platform::Windows::XP::SP0, - Msf::Module::Platform::Windows::XP::SP2 - ], (l1 & l2).platforms - ) - - l1 = Msf::Module::PlatformList.new('win xp sp1') - assert_equal( [ ], (l1 & l2).platforms ) - end -end diff --git a/lib/msf/core/module/reference.rb.ut.rb b/lib/msf/core/module/reference.rb.ut.rb deleted file mode 100644 index 93936dfe13..0000000000 --- a/lib/msf/core/module/reference.rb.ut.rb +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'test/unit' -require 'msf/core' - -module Msf - -class Module::Reference::UnitTest < Test::Unit::TestCase - def test_ref - assert_equal('some cool book', Reference.from_s('some cool book').to_s) - end - - def test_site_ref - assert_equal('ftp://www.google.com', SiteReference.from_s('ftp://www.google.com').to_s) - assert_equal('http://www.google.com', SiteReference.from_s('http://www.google.com').to_s) - assert_equal('https://www.google.com', SiteReference.from_s('https://www.google.com').to_s) - assert_equal('http://www.osvdb.org/1', SiteReference.from_a([ 'OSVDB', 1 ]).to_s) - assert_equal('http://www.osvdb.org/1', SiteReference.from_a([ 'OSVDB', 1 ]).to_s) - assert_equal('jones (a)', SiteReference.from_a([ 'jones', 'a' ]).to_s) - assert_nil(SiteReference.from_s('whatever invalid shizzy')) - end -end - -end diff --git a/lib/msf/core/module/target.rb.ut.rb b/lib/msf/core/module/target.rb.ut.rb deleted file mode 100644 index 5ed119bbe3..0000000000 --- a/lib/msf/core/module/target.rb.ut.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'test/unit' -require 'msf/core' - -module Msf - -class Module::Target::UnitTest < Test::Unit::TestCase - def test_target - t = Target.from_a(['Universal', { - 'Platform' => 'winxpsp0', - 'Ret' => 0x12345678 - }]) - - assert_equal('Universal', t.name) - assert_equal(true, t.platform.supports?(Msf::Module::PlatformList.transform('winxpsp0'))) - assert_equal(false, t.platform.supports?(Msf::Module::PlatformList.transform('winxpsp1'))) - assert_equal(0x12345678, t['Ret']) - assert_equal(0x12345678, t.ret) - end -end - -end diff --git a/lib/msf/core/option_container.rb.ut.rb b/lib/msf/core/option_container.rb.ut.rb deleted file mode 100644 index f146b94cc7..0000000000 --- a/lib/msf/core/option_container.rb.ut.rb +++ /dev/null @@ -1,140 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'msf/core/option_container' - -module Msf - -class OptionContainer::UnitTest < Test::Unit::TestCase - - # Tests the initialization of the OptionContainer object - def test_initialize - # Make sure initialization works - options = nil - - assert_block("initialize failed") { - options = OptionContainer.new( - 'rhost' => [ OptAddress, true, nil, 'host.com' ], - 'rport' => [ OptPort, true, nil, 1234 ]) - - if (options == nil) - false - end - - true - } - - # Make sure there are 2 options - assert_equal(2, options.length, "invalid number of options #{options.length}") - - # Make sure that the constructor raises an argument error when - # an invalid option is supplied - assert_raise(ArgumentError, "initialize invalid failed") { - OptionContainer.new( - 'rhost' => 'invalid'); - } - end - - # Tests getting the value of an option - def test_get - options = OptionContainer.new( - 'rport' => [ OptPort, true, nil, 1234 ]) - - assert_equal(1234, options.get('rport').default, - "option default does not match") - assert_equal(true, options.get('rport').required?, - "option required does not match") - assert_equal('rport', options['rport'].name, - "option name does not match") - end - - # Tests validation - def test_validate - # Test validating required options - options = OptionContainer.new( - 'rhost' => [ OptAddress, true ], - 'rport' => [ OptPort, true ], - 'Lib' => [ OptString ]) - - ds = DataStore.new - - assert_raise(OptionValidateError, "required validation failed") { - options.validate(ds) - } - - ds['rhost'] = 'www.invalid.host.tldinvalid' - ds['rport'] = 1234 - - assert_raise(OptionValidateError, "host validation failed") { - options.validate(ds) - } - - # Make sure address validation does work - ds['rhost'] = 'www.google.com' - - assert_equal(true, options.validate(ds), "overall validation failed") - - # Make sure port validation does work - ds['rport'] = 23423423 - - assert_raise(OptionValidateError, "port validation failed") { - options.validate(ds) - } - end - - # Make sure advanced additions work - def test_advanced - options = OptionContainer.new - - options.add_advanced_options( - 'DONKEY' => [ OptString, false ]) - - assert_equal(true, options.get('DONKEY').advanced?, - "advanced option failed") - end - - def test_builtin - options = OptionContainer.new - - options.add_options( - [ - Opt::RHOST, - Opt::RPORT(135), - Opt::LHOST('127.0.0.1'), - Opt::SSL - ]) - - assert_equal(135, options.get('RPORT').default, "invalid RPORT default") - assert_equal(true, options.get('RPORT').required?, "invalid RPORT require") - assert_equal('127.0.0.1', options.get('LHOST').default, "invalid LHOST default") - assert_equal('LHOST', options.get('LHOST').name, "invalid LHOST name") - assert_equal(false, options.get('SSL').default, "invalid SSL default") - end - - def test_enum - options = OptionContainer.new( - 'testenum' => [ OptEnum, true, 'desc', nil, ['none','one','done']] - ) - - ds = DataStore.new - - assert_raise(OptionValidateError, "enum required") { - options.validate(ds) - } - - ds['testenum'] = 'done' - assert_equal(true, options.validate(ds), "enum valid") - - ds['testenum'] = 'foo' - assert_raise(OptionValidateError, "enum invalid") { - options.validate(ds) - } - - assert_equal('desc (accepted: none, one, done)', options['testenum'].desc, 'desc') - end -end - -end diff --git a/lib/msf/core/post/windows/registry.rb.ut.rb b/lib/msf/core/post/windows/registry.rb.ut.rb deleted file mode 100644 index 21ceae8079..0000000000 --- a/lib/msf/core/post/windows/registry.rb.ut.rb +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..','..','..','..','..', 'lib')) - -require 'msf/core/post/windows/registry' -require 'test/unit' - -module Msf -class Post -module Windows -class Registry::UnitTest < Test::Unit::TestCase - - def test_include - assert_nothing_raised do - Msf::Post.new.extend(Msf::Post::Windows::Registry) - end - end - -end -end -end -end diff --git a/lib/msf/core/post/windows/user_profiles.rb.ut.rb b/lib/msf/core/post/windows/user_profiles.rb.ut.rb deleted file mode 100644 index 5ddb6ca2b6..0000000000 --- a/lib/msf/core/post/windows/user_profiles.rb.ut.rb +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..','..','..','..','..', 'lib')) - -require 'msf/core/post/windows/user_profiles' -require 'test/unit' - -module Msf -class Post -module Windows -class UserProfiles::UnitTest < Test::Unit::TestCase - - def test_include - assert_nothing_raised do - Msf::Post.new.extend(Msf::Post::Windows::UserProfiles) - end - end - -end -end -end -end diff --git a/lib/msf/core/session_manager.rb.ut.rb b/lib/msf/core/session_manager.rb.ut.rb deleted file mode 100644 index 63d9cbfde6..0000000000 --- a/lib/msf/core/session_manager.rb.ut.rb +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'msf/core/session_manager' - -module Msf - -class SessionManager::UnitTest < Test::Unit::TestCase - -class UtSessionEvent - include SessionEvent - - def on_session_open(session) - self.open_session = session - end - def on_session_close(session,reason='') - self.close_session = session - end - - attr_accessor :open_session, :close_session -end - - # - # Tests to make sure session registration functions properly - # - def test_registration - framework = Framework.new - manager = SessionManager.new(framework) - - session = Class.new - session.extend(Session) - - assert_equal(1, manager.register(session), "Did not get expected sid") - assert_equal(1, session.sid, - "Session sid was not initialized properly") - assert_equal(framework, session.framework, - "Session framework was not initialized properly") - assert_equal(1, manager.entries.length, - "Number of session manager entries is not one") - assert_equal(session, manager[session.sid], - "Index of sid did not return session") - - manager.deregister(session) - - assert_equal(0, manager.entries.length, - "Number of session manager entries is not zero") - end - - # - # Test session notification events - # - def test_notify - framework = Framework.new - manager = SessionManager.new(framework) - handler = UtSessionEvent.new - session = Class.new - session.extend(Session) - - framework.events.add_session_subscriber(handler) - - manager.register(session) - assert_equal(handler.open_session, session, - "Open session handler not called") - - manager.deregister(session) - assert_equal(handler.close_session, session, - "Close session handler not called") - end - -end - -end - diff --git a/lib/net/ssh.rb.ut.rb b/lib/net/ssh.rb.ut.rb deleted file mode 100755 index e3884e81a9..0000000000 --- a/lib/net/ssh.rb.ut.rb +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -require 'test/unit' -require 'net/ssh' - -$_SSH_TEST_SERVERNAME = 'dbsrv' # Name or IP, default: dbsrv -$_SSH_TEST_SERVERPORT = 22 # Default: 22 -$_SSH_TEST_USERNAME = 'user' # Default: scott -$_SSH_TEST_PASSWORD = 'useruser' # Default: tiger -$_SSH_TEST_OS = 'Linux' # Default: Linux - -class Net::SSH::UnitTest < ::Test::Unit::TestCase - - # Need to do this or else we're talking about - # some other Net::SSH. - def test_local_version - if Net::SSH::Version::CURRENT.respond_to? :msf3 - assert Net::SSH::Version::CURRENT.msf3 - else - flunk "Not testing the MSF3 bundled version of SSH" - end - end - - # Tests that a connection happens, that failed logins - # are recorded, and that we're using Rex sockets instead - # of standard sockets. - def test_connection - - assert_nothing_raised do - conn = Net::SSH.start( - $_SSH_TEST_SERVERNAME, - $_SSH_TEST_USERNAME, - :password => $_SSH_TEST_PASSWORD, - :auth_methods => ['password'], - :port => $_SSH_TEST_SERVERPORT - ) - conn.close - end - - assert_raise Net::SSH::AuthenticationFailed do - conn = Net::SSH.start( - $_SSH_TEST_SERVERNAME, - $_SSH_TEST_USERNAME, - :password => $_SSH_TEST_PASSWORD+"bad", - :auth_methods => ['password'], - :port => $_SSH_TEST_SERVERPORT - ) - conn.close - end - end - - def test_rex_sockets - conn = Net::SSH.start( - $_SSH_TEST_SERVERNAME, - $_SSH_TEST_USERNAME, - :password => $_SSH_TEST_PASSWORD, - :auth_methods => ['password'], - :port => $_SSH_TEST_SERVERPORT - ) - assert_kind_of Rex::Socket::Tcp, conn.transport.socket - conn.close - end - - def _do_uname(host,user,pass) - ret = nil - conn = Net::SSH.start( - host, - user, - :password => pass, - :auth_methods => ['password'], - :port => 22 - ) do |ssh| - ret = ssh.exec!('/bin/uname -a') - ssh.loop - end - return ret - end - - def test_simple_exec - uname_ret = nil - assert_nothing_raised do - uname_ret = _do_uname( - $_SSH_TEST_SERVERNAME, - $_SSH_TEST_USERNAME, - $_SSH_TEST_PASSWORD - ) - end - - assert_match(/^#{$_SSH_TEST_OS}/, uname_ret) - end -end diff --git a/lib/net/ssh/utils.rb.ut.rb b/lib/net/ssh/utils.rb.ut.rb deleted file mode 100644 index 839684a94c..0000000000 --- a/lib/net/ssh/utils.rb.ut.rb +++ /dev/null @@ -1,185 +0,0 @@ -# -*- coding: binary -*- -require 'net/ssh' -require 'test/unit' - -# Unit tests for Net::SSH::Utils::Key.fingerprint. Not going -# to mess around with this weird story testing that the rest -# of Net::SSH uses. -# -# By the way, it would be extremely silly to actually use these -# keys for anything. They're passwordless and now quite effectively -# compromised. :) -class Fingerprint < Test::Unit::TestCase - - def test_rsa_private - rsa_private = <<-EOM ------BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEA/kDqlZOy4FE7+0m5rO/x1YDMxMnsj2SFIAtxF6TAAyxqPt7s -wJtuVhQv8xNvRYjoL2E7JH95gtIRmwOxLReRd0kVyrCi9mf9T7ninSKLb264IUfQ -VdivGdFGJbTxlxp2w9oXLt9jrUXWgYAn5z/4cauOtGQvvAJz4m/G+eJyafuvi83i -rnOP2v7fPtPY1Xzok0PvdOHDw9Vk8rOLAB4quOf0kSP2DMFOr5Kyk2qQvOar2wnd -npxdEaDgKrdnE6hQ1yv/uctEgP7/5UJ8RHrMp/D9DcTRYZMxxnCawt72jxYqgelL -3m/329ER/6StAsVce+sFPDIBsFssLwnJtJjzdwIBIwKCAQEArlhmV/BAJMn9Ppj0 -WVQTixZ9yMT5++0oFfk3my8klHY6Ob1vJPzd8eH0/nO6A8uX5fmHo/+jx2t5yWGe -EEqs5BTbvi/6t5fDpGI0/gkPJ9bkqRtNB6qGsp4hePEasMGwhkxnqxzWorOLxoPD -l0HO7twKFUwDeZtIJj4EyJtHJBjumimnG7cpjZi0w84XMQqpUyAcTkXhCICIiMtV -UwAfjsxiB+cyd9B3riWHtyyo8SCqH1qFELOB9goOVI7moXIB0Z6TwUrvBiDC7cDO -Qajj97kpeuQHRFSkqwZHVGkZ0Hy1mm7VTRNOfE590rv4daJDQTG5W2JbETAknbW8 -3El+CwKBgQD/iDIgEChLxufEKO4CpKFIHki+PmaFCm6zLILHbD6fV8oPL4iSF5T+ -9OmFXgTmscl6C4J3g2+mzuxN9uDiyUE6lVIDiKZzzd7Y+sdbmC1oUkrMviq9Uuc1 -lisPMKdfz2Xf6GJU52j6l0hg9FRAkcut0CkvGwZqOPrfBI5OYVtTzwKBgQD+uB8E -QIrSJZhoza6fCVa+28Gymaqr4lXqqV2R0CoIBjPWa2o6W8b2h10cn5neViLkYc4O -uCbuETs9Tdtz9Et+RX1kt0I0H4W1T8Hz4eHCjGLT0bg0IFs2ttxjjHOmb6UXGE// -5qAqz0DkN/5MxW0Ml1lSe+bSqPoXxH0dPKfH2QKBgQCvONHqGbU7RpBL/s8XwVim -eyqRFNiVvgLEAUO78nQVfgbl13OXYKCu09NUIzaPj9qc1LE8AlswjePdsJo1HEn8 -SSJLkOcq1k+qupdUwB8i9pmw923Dpo/qOxY2TT+SJ9DUDRA6OEf8SnrGI+IAY/lh -PkggTQu2jXjTcNacJYBz+wKBgQD3cQgwBC8VSRe2RCX5lAsfzingsoiJt0wlyRkR -Td+wBgZ4hZpkk6tV4pT3O/SO11UYXwKvNow3uPe35TuVNnU41cpElMP4Hp8lKOhL -///hj7B1/u10dzQJQ+wI7ta+8By3WXJJC+wMVE2qf4lR5FtOD14VnO7bRRA0WHmK -HapNGwKBgQCx09+WsoCTH6jIkfroT77t+DAMHrzH67AZy+hu1+dBCEyN4Mkw8CD6 -sRMIIcy/R5W1mlRFFaYMbtJogjtWwDUjzTEPvIU6tdJhj8GOg1pxPLqD+r/Mwc88 -228W9YHRSybK5kK61QmoWHDS13OJCOa+xA59ym1GpE1KyliwpsPajg== ------END RSA PRIVATE KEY----- - EOM - - fp = Net::SSH::Utils::Key.fingerprint(:data => rsa_private) - assert_equal("af:76:e4:f8:37:7b:52:8c:77:61:5b:d3:b0:d3:05:e4",fp) - - fp = Net::SSH::Utils::Key.fingerprint( - :data => rsa_private, - :format => :compact - ) - assert_equal("af76e4f8377b528c77615bd3b0d305e4",fp) - - fp = Net::SSH::Utils::Key.fingerprint( - :data => rsa_private, - :format => :bin - ) - assert_equal("\xaf\x76\xe4\xf8\x37\x7b\x52\x8c\x77\x61\x5b\xd3\xb0\xd3\x05\xe4", fp) - - assert_raise OpenSSL::PKey::PKeyError do - Net::SSH::Utils::Key.fingerprint( - :data => rsa_private, - :public => true - ) - end - end - - def test_rsa_public - rsa_public = <<-EOM -ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA/kDqlZOy4FE7+0m5rO/x1YDMxMnsj2SFIAtxF6TAAyxqPt7swJtuVhQv8xNvRYjoL2E7JH95gtIRmwOxLReRd0kVyrCi9mf9T7ninSKLb264IUfQVdivGdFGJbTxlxp2w9oXLt9jrUXWgYAn5z/4cauOtGQvvAJz4m/G+eJyafuvi83irnOP2v7fPtPY1Xzok0PvdOHDw9Vk8rOLAB4quOf0kSP2DMFOr5Kyk2qQvOar2wndnpxdEaDgKrdnE6hQ1yv/uctEgP7/5UJ8RHrMp/D9DcTRYZMxxnCawt72jxYqgelL3m/329ER/6StAsVce+sFPDIBsFssLwnJtJjzdw== user@msf3 - EOM - - fp = Net::SSH::Utils::Key.fingerprint( - :data => rsa_public, - :public => true - ) - assert_equal("af:76:e4:f8:37:7b:52:8c:77:61:5b:d3:b0:d3:05:e4",fp) - - fp = Net::SSH::Utils::Key.fingerprint( - :data => rsa_public, - :format => :compact, - :public => true - ) - - assert_equal("af76e4f8377b528c77615bd3b0d305e4",fp) - - fp = Net::SSH::Utils::Key.fingerprint( - :data => rsa_public, - :format => :bin, - :public => true - ) - assert_equal("\xaf\x76\xe4\xf8\x37\x7b\x52\x8c\x77\x61\x5b\xd3\xb0\xd3\x05\xe4", fp) - - assert_raise OpenSSL::PKey::PKeyError do - Net::SSH::Utils::Key.fingerprint( - :data => rsa_public, - :public => false - ) - end - end - - def test_dsa_private - dsa_private = <<-EOM ------BEGIN DSA PRIVATE KEY----- -MIIBugIBAAKBgQDee7R8F36phQQ5fnBf1HcOctMcWWXX6/2EXdOZMykRXgPpGloK -FaO/Wjo1Lnlot+O0rweu0VlOepNtpBCJu/kDHePci3kH8Uo/AMCUKb+72kZumJPr -N46WU3v4Shck4MUOXKW56/EkMXaHAQxM7wgFSRUbTYeyIxTOG+qH3Cc9KQIVANjT -p28ydND3lmXzw1YVwRSDO5LfAoGAatFZrDKn0DOKiJlPMGF/ES3Ktr+GpltAwrdp -WCgG8grKphnzpnfgcKra3TgMOzipovA362o91RQ9OO0UK2fnrzSpphl6AgAEQZ7m -+qgRWj4hfQZCik2p6rP2F1rgLlZw10OPJE4ECcgHJ5zXZMEzrc4ihGnIs0SF0Lbs -hgdI0N4CgYAjYXbR4tVZb9SrSjRw86n0p/90ec7zgyBZTZVF+ImkstVlnQFh5H3/ -Rf35YUjgsppnBo3sRT/aCEQmbBdzFBXwo0XLBkqFdg21ZtuJZCv6NrNr/Mn8zeVI -rtPv0QRjA/92/OQ5T6Gj7m8gqKEshzW5gj17KH3pdOnNaLBkfJVYvQIUHzk1VI9A -2NbDpCiAmhnqoeYeTXU= ------END DSA PRIVATE KEY----- - EOM - - fp = Net::SSH::Utils::Key.fingerprint(:data => dsa_private) - assert_equal("ad:64:88:d8:f6:78:65:d4:da:a9:ba:56:61:74:a5:1c",fp) - - fp = Net::SSH::Utils::Key.fingerprint( - :data => dsa_private, - :format => :compact - ) - assert_equal("ad6488d8f67865d4daa9ba566174a51c",fp) - - fp = Net::SSH::Utils::Key.fingerprint( - :data => dsa_private, - :format => :bin - ) - assert_equal("\xad\x64\x88\xd8\xf6\x78\x65\xd4\xda\xa9\xba\x56\x61\x74\xa5\x1c",fp) - - assert_raise OpenSSL::PKey::PKeyError do - Net::SSH::Utils::Key.fingerprint( - :data => dsa_private, - :public => true - ) - end - end - - def test_dsa_public - dsa_public = <<-EOM -ssh-dss AAAAB3NzaC1kc3MAAACBAN57tHwXfqmFBDl+cF/Udw5y0xxZZdfr/YRd05kzKRFeA+kaWgoVo79aOjUueWi347SvB67RWU56k22kEIm7+QMd49yLeQfxSj8AwJQpv7vaRm6Yk+s3jpZTe/hKFyTgxQ5cpbnr8SQxdocBDEzvCAVJFRtNh7IjFM4b6ofcJz0pAAAAFQDY06dvMnTQ95Zl88NWFcEUgzuS3wAAAIBq0VmsMqfQM4qImU8wYX8RLcq2v4amW0DCt2lYKAbyCsqmGfOmd+BwqtrdOAw7OKmi8Dfraj3VFD047RQrZ+evNKmmGXoCAARBnub6qBFaPiF9BkKKTanqs/YXWuAuVnDXQ48kTgQJyAcnnNdkwTOtziKEacizRIXQtuyGB0jQ3gAAAIAjYXbR4tVZb9SrSjRw86n0p/90ec7zgyBZTZVF+ImkstVlnQFh5H3/Rf35YUjgsppnBo3sRT/aCEQmbBdzFBXwo0XLBkqFdg21ZtuJZCv6NrNr/Mn8zeVIrtPv0QRjA/92/OQ5T6Gj7m8gqKEshzW5gj17KH3pdOnNaLBkfJVYvQ== user@msf3 - EOM - - fp = Net::SSH::Utils::Key.fingerprint( - :data => dsa_public, - :public => true - ) - assert_equal("ad:64:88:d8:f6:78:65:d4:da:a9:ba:56:61:74:a5:1c",fp) - - fp = Net::SSH::Utils::Key.fingerprint( - :data => dsa_public, - :format => :compact, - :public => true - ) - - assert_equal("ad6488d8f67865d4daa9ba566174a51c",fp) - - fp = Net::SSH::Utils::Key.fingerprint( - :data => dsa_public, - :format => :bin, - :public => true - ) - assert_equal("\xad\x64\x88\xd8\xf6\x78\x65\xd4\xda\xa9\xba\x56\x61\x74\xa5\x1c",fp) - - assert_raise OpenSSL::PKey::PKeyError do - Net::SSH::Utils::Key.fingerprint( - :data => dsa_public, - :public => false - ) - end - end - - # Notice how it's currently impossible to tell if a key is - # simply mistyped as a public or private key, or if it's a - # badly formatted key. Too bad. - def test_bogus_raise - bogus_key = "Oh hey I'm a key. Ok, not really." - assert_raise OpenSSL::PKey::PKeyError do - Net::SSH::Utils::Key.fingerprint(:data => bogus_key) - end - end - -end diff --git a/lib/postgres_msf.rb.ut.rb b/lib/postgres_msf.rb.ut.rb deleted file mode 100644 index 5feff33349..0000000000 --- a/lib/postgres_msf.rb.ut.rb +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -require 'test/unit' -require 'postgres_msf' - -$_POSTGRESQL_TEST_SERVERNAME = 'dbsrv' # Name or IP, default: dbsrv -$_POSTGRESQL_TEST_SERVERPORT = 5432 # Default: 5432 -$_POSTGRESQL_TEST_DATABASE = 'mydb' # Default: mydb -$_POSTGRESQL_TEST_USERNAME = 'scott' # Default: scott -$_POSTGRESQL_TEST_PASSWORD = 'tiger' # Default: tiger - -class Msf::Db::PostgresPR::UnitTest < ::Test::Unit::TestCase - - def test_connection - srv = "tcp://#{$_POSTGRESQL_TEST_SERVERNAME}:#{$_POSTGRESQL_TEST_SERVERPORT}" - conn = Msf::Db::PostgresPR::Connection.new($_POSTGRESQL_TEST_DATABASE, - $_POSTGRESQL_TEST_USERNAME, - $_POSTGRESQL_TEST_PASSWORD, - srv) - assert_kind_of Msf::Db::PostgresPR::Connection, conn - assert_kind_of Rex::Socket::Tcp, conn.conn, "should use Rex sockets for TCP" - assert_nothing_raised { conn.close } - end - - # Note that this will drop the "test" table for the named database. - # This is a destructive act! - def test_query - srv = "tcp://#{$_POSTGRESQL_TEST_SERVERNAME}:#{$_POSTGRESQL_TEST_SERVERPORT}" - conn = Msf::Db::PostgresPR::Connection.new($_POSTGRESQL_TEST_DATABASE, - $_POSTGRESQL_TEST_USERNAME, - $_POSTGRESQL_TEST_PASSWORD, - srv) - - begin - conn.query("drop table test") - rescue RuntimeError # Cleanup, it may or may not be there. - end - - assert_nothing_raised do - conn.query("CREATE TABLE test (i int, v varchar(5))") - conn.query(%q{INSERT INTO test VALUES (1, 'foo')}) - conn.query(%q{INSERT INTO test VALUES (2, 'bar')}) - end - - resp = conn.query("select * from test") - assert_equal(2, resp.rows.size) - assert_equal(2, resp.fields.size) - assert_equal("SELECT", resp.cmd_tag) - assert_nothing_raised { conn.query("drop table test") } - - end - -end - diff --git a/lib/rex/arch/sparc.rb.ut.rb b/lib/rex/arch/sparc.rb.ut.rb deleted file mode 100644 index bbe953fcab..0000000000 --- a/lib/rex/arch/sparc.rb.ut.rb +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex/text' -require 'rex/arch/sparc' - -class Rex::Arch::Sparc::UnitTest < ::Test::Unit::TestCase - - Klass = Rex::Arch::Sparc - - def test_set - assert_equal("\x88\x10\x20\x02", Klass.set(0x2, 'g4')) - assert_equal("\x09\x00\x00\x08\x88\x11\x22\x22", Klass.set(0x2222, 'g4')) - end - -end diff --git a/lib/rex/arch/x86.rb.ut.rb b/lib/rex/arch/x86.rb.ut.rb deleted file mode 100644 index de1f0292d0..0000000000 --- a/lib/rex/arch/x86.rb.ut.rb +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex/text' -require 'rex/arch/x86' - -class Rex::Arch::X86::UnitTest < ::Test::Unit::TestCase - - Klass = Rex::Arch::X86 - - def test_reg_number - assert_equal(Klass.reg_number('eax'), Klass::EAX) - assert_equal(Klass.reg_number('EsP'), Klass::ESP) - end - - def test_push_byte - assert_raise(::ArgumentError) { Klass.push_byte(-129) } - assert_raise(::ArgumentError) { Klass.push_byte(8732) } - assert_equal("\x6a\x10", Klass.push_byte(16)) - assert_equal("\x6a\xff", Klass.push_byte(-1)) - end - - def test_push_dword - assert_equal("\x68\x78\x56\x34\x12", Klass.push_dword(0x12345678)) - end - - def test_mov_dword - assert_equal("\xb8\x78\x56\x34\x12", Klass.mov_dword(Klass::EAX, 0x12345678)) - end - - def test_mov_word - assert_equal("\x66\xbc\x37\x13", Klass.mov_word(Klass::SP, 0x1337)) - end - - def test_mov_byte - assert_raise(::RangeError) { Klass.mov_byte(Klass::AL, 0x100) } - assert_raise(::RangeError) { Klass.mov_byte(Klass::AL, -1) } - assert_equal("\xb2\xb2", Klass.mov_byte(Klass::DL, 0xb2)) - end - - def test_check_reg - assert_raise(::ArgumentError) { Klass._check_reg(8) } - assert_raise(::ArgumentError) { Klass._check_reg(-1) } - - 0.upto(7) { |reg| - assert_nothing_raised { Klass._check_reg(reg) } - } - end - - def test_pop_dword - assert_raise(::ArgumentError) { Klass.pop_dword(8) } - assert_raise(::ArgumentError) { Klass.pop_dword(-1) } - - assert_equal("\x58", Klass.pop_dword(Klass::EAX)) - assert_equal("\x5a", Klass.pop_dword(Klass::EDX)) - assert_equal("\x5c", Klass.pop_dword(Klass::ESP)) - end - - def test_sub - assert_equal("\x83\xe8\x04", Klass.sub(4, Klass::EAX)[2, 3]) - assert_equal("\x66\x81\xe8\x80\xff", Klass.sub(-128, Klass::EAX)[2, 5]) - assert_equal("\x81\xe8\x00\x00\x01\x00", Klass.sub(65536, Klass::EAX)[2, 6]) - end - - def test_add - assert_equal("\x83\xc4\x47", Klass.add(0x47, Klass::ESP)[2,6]) - assert_equal("\x83\xc4\x47", Klass.add(0x47, Klass::ESP, '', true)) - assert_equal("\x81\xc4\x11\x11\x01\x00", Klass.add(0x11111, Klass::ESP, '', true)) - end - - def test_clear - assert_equal("\x33\xc0", Klass.clear(Klass::EAX, "\x29\x2b\x31")) - end - - def test_searcher - s = "\xbe"+ # mov esi, Tag - 1 - "\x03\x03\x02\x01"+ - "\x46"+ # inc esi - "\x47"+ # inc edi (end_search:) - "\x39\x37"+ # cmp [edi],esi - "\x75\xfb"+ # jnz 0xa (end_search) - "\x46"+ # inc esi - "\x4f"+ # dec edi (start_search:) - "\x39\x77\xfc"+ # cmp [edi-0x4],esi - "\x75\xfa"+ # jnz 0x10 (start_search) - "\xff\xe7" # jmp edi - - assert_equal(s, Klass.searcher("\x04\x03\x02\x01")) - end - -end diff --git a/lib/rex/assembly/nasm.rb.ut.rb b/lib/rex/assembly/nasm.rb.ut.rb deleted file mode 100644 index a4c4f27c6f..0000000000 --- a/lib/rex/assembly/nasm.rb.ut.rb +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex/text' -require 'rex/assembly/nasm' - -class Rex::Assembly::Nasm::UnitTest < ::Test::Unit::TestCase - - Klass = Rex::Assembly::Nasm - - def test_assemble - assert_equal("\x6a\x00", Klass.assemble("push byte 0x00")) - assert_equal("\xb2\xb4", Klass.assemble("mov dl, 0xb4")) - end - - def test_disassemble - assert_equal("00000000 31C0 xor eax,eax\n", Klass.disassemble("\x31\xc0")) - end - -end diff --git a/lib/rex/encoder/ndr.rb.ut.rb b/lib/rex/encoder/ndr.rb.ut.rb deleted file mode 100644 index 4c425e8345..0000000000 --- a/lib/rex/encoder/ndr.rb.ut.rb +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'rex/test' -require 'rex/exceptions' -require 'rex/encoder/ndr' - -class Rex::Encoder::NDR::UnitTest < Test::Unit::TestCase - - Klass = Rex::Encoder::NDR - - def test_align - assert_equal(0, Klass.align('').length, 'align 0') - assert_equal(3, Klass.align('f').length, 'align 1') - assert_equal(2, Klass.align('fo').length, 'align 2') - assert_equal(1, Klass.align('foo').length, 'align 3') - assert_equal(0, Klass.align('fooo').length, 'align 4') - assert_equal(3, Klass.align('foooo').length, 'align 5') - end - - def test_numbers - assert_equal("\x0a\x00\x00\x00", Klass.long(10), 'long') - assert_equal("\x0a\x00", Klass.short(10), 'short') - assert_equal("\x0a", Klass.byte(10), 'byte') - end - - def test_conformant_array - assert_equal("\x05\x00\x00\x00aaaaa", Klass.UniConformantArray('aaaaa').slice(0,9), 'UniConformantArray') - assert_equal(12, Klass.UniConformantArray('aaaaa').length, 'UniConformantArray length') - end - - def test_string - assert_equal("\x06\x00\x00\x00" + "\x00\x00\x00\x00" + "\x06\x00\x00\x00" "aaaaa\x00", Klass.string('aaaaa').slice(0,4+4+4+6), 'string') - assert_equal(20, Klass.string('aaaaa').length, 'string length') - - assert_equal("\x06\x00\x00\x00" + "\x00\x00\x00\x00" + "\x06\x00\x00\x00" "a\x00a\x00a\x00a\x00a\x00\x00\x00", Klass.wstring('aaaaa').slice(0,4+4+4+12), 'wstring') - assert_equal(24, Klass.wstring('aaaaa').length, 'wstring length') - - assert_equal("\x02\x00\x00\x00" + "\x00\x00\x00\x00" + "\x02\x00\x00\x00" "aa\x00\x00", Klass.wstring_prebuilt('aa' + "\x00\x00"), 'wstring_prebuilt') - assert_equal(16, Klass.wstring_prebuilt('aa' + "\x00\x00").length, 'wstring_prebuilt length') - end - -end diff --git a/lib/rex/encoder/xdr.rb.ut.rb b/lib/rex/encoder/xdr.rb.ut.rb deleted file mode 100644 index 01e1666a5e..0000000000 --- a/lib/rex/encoder/xdr.rb.ut.rb +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex/exceptions' -require 'rex/encoder/xdr' - -class Rex::Encoder::XDR::UnitTest < Test::Unit::TestCase - - def test_encode - assert_equal("\000\000\004\322", Rex::Encoder::XDR.encode_int(1234), 'encode_int') - assert_equal("\377\377\377\322", Rex::Encoder::XDR.encode_lchar(1234), 'encode_lchar') - assert_equal("\000\000\000\003abc\000", Rex::Encoder::XDR.encode_string('abc'), 'encode_string') - assert_equal("\000\000\000\003abc\000", Rex::Encoder::XDR.encode_string('abc', 4), 'encode_string with maxlen') - assert_raises(Rex::ArgumentError) { - Rex::Encoder::XDR.encode_string('abc', 2) - } - assert_equal("\000\000\000\003\000\000\000\001\000\000\000\002\000\000\000\003", Rex::Encoder::XDR.encode_varray([1,2,3]) {|i| Rex::Encoder::XDR.encode_int(i) }, 'encode_varray') - assert_equal("\000\000\000\000\000\000\000\002\000\000\000\000\000\000\000\001\000\000\000\003foo\000\000\000\000\003bar\000", Rex::Encoder::XDR.encode(0, [0, 1], "foo", ["bar", 4]), 'encode') - end - - def test_decode - assert_equal(1234, Rex::Encoder::XDR.decode_int!("\000\000\004\322"), 'decode_int!') - assert_equal('abc', Rex::Encoder::XDR.decode_string!("\000\000\000\003abc\000"), 'decode_string') - assert_equal([1,2,3], Rex::Encoder::XDR.decode_varray!("\000\000\000\003\000\000\000\001\000\000\000\002\000\000\000\003") { |i| Rex::Encoder::XDR.decode_int!(i) } , 'decode_varray!') - assert_equal(1234, Rex::Encoder::XDR.decode_lchar!("\377\377\377\322"), 'decode_lchar!') - end -end diff --git a/lib/rex/encoders/xor_dword_additive.rb.ut.rb b/lib/rex/encoders/xor_dword_additive.rb.ut.rb deleted file mode 100644 index b54737283f..0000000000 --- a/lib/rex/encoders/xor_dword_additive.rb.ut.rb +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..', 'dev', 'machinetest')) - -require 'test/unit' -require 'rex/encoders/xor_dword_additive' -require 'rex/encoders/xor_dword.rb.ut' - -class Rex::Encoders::XorDwordAdditive::UnitTest < Rex::Encoders::XorDword::UnitTest - Klass = Rex::Encoders::XorDwordAdditive -end diff --git a/lib/rex/encoding/xor/byte.rb.ut.rb b/lib/rex/encoding/xor/byte.rb.ut.rb deleted file mode 100644 index 8259a7c993..0000000000 --- a/lib/rex/encoding/xor/byte.rb.ut.rb +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'rex/encoding/xor/byte' -require 'rex/encoding/xor/generic.rb.ut' - -# -# I suck because I want to inherit a test case, but this will -# also cause it to run the test case I'm inheriting, so this runs both the -# Byte and Generic tests, oh well for now... -# - -module Rex::Encoding::Xor -class Byte::UnitTest < Generic::UnitTest - - def enc - Byte - end -end -end diff --git a/lib/rex/encoding/xor/dword.rb.ut.rb b/lib/rex/encoding/xor/dword.rb.ut.rb deleted file mode 100644 index b4380ba1da..0000000000 --- a/lib/rex/encoding/xor/dword.rb.ut.rb +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'rex/encoding/xor/dword' -require 'rex/encoding/xor/byte.rb.ut' - -module Rex::Encoding::Xor -class Dword::UnitTest < Byte::UnitTest - - def enc - Dword - end -end -end diff --git a/lib/rex/encoding/xor/dword_additive.rb.ut.rb b/lib/rex/encoding/xor/dword_additive.rb.ut.rb deleted file mode 100644 index c26d7600fb..0000000000 --- a/lib/rex/encoding/xor/dword_additive.rb.ut.rb +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'rex/encoding/xor/dword_additive' -require 'rex/encoding/xor/byte.rb.ut' - -module Rex::Encoding::Xor -class DwordAdditive::UnitTest < Byte::UnitTest - - def enc - DwordAdditive - end -end -end diff --git a/lib/rex/encoding/xor/generic.rb.ut.rb b/lib/rex/encoding/xor/generic.rb.ut.rb deleted file mode 100644 index 2088a1a46a..0000000000 --- a/lib/rex/encoding/xor/generic.rb.ut.rb +++ /dev/null @@ -1,121 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'test/unit' -require 'rex/encoding/xor/generic' - -module Rex::Encoding::Xor - -class Generic::UnitTest < ::Test::Unit::TestCase - - def enc - Generic - end - - def hook_static_encode(data, key, expected) - if enc.keysize != 0 && key.length != enc.keysize - assert_raise(::ArgumentError) { enc.encode(data,key) } - else - assert_equal(enc.encode(data, key), [ expected, key ]) - end - end - - def test_static_encode - # Test key of zero length - assert_raise(::ArgumentError) { enc.encode("\x00", "") } - - # Test non-string key - assert_raise(::ArgumentError) { enc.encode("\x00\x01", 1) } - - # some simple single byte tests with 0x00 - 30.times { - byte = rand(256).chr - hook_static_encode("\x00" * 3, byte, byte * 3) - } - - # misc tests, see below - misc_tests.each { |test| - hook_static_encode(test[0], test[1], test[2]) - } - - end - - # - # Misc (mostly) autogenerated tests, we need more with - # different keysizes! - # - - def misc_tests - [ - - # a 3 byte key test - [ - "\x54\x9a\x04\x02\x8f", - "\x6d\x4b\x3c", - "9\3218o\304" - ], - - # a 4 byte key test - [ - "\312/\216e\265\301\323\026Y\315", - "m2{b", - "\247\035\365\a\330\363\250t4\377" - ], - - # randomly generated 2 byte key tests... - [ - "\x82\x3f\xb4\x77\x55\x16\x4a\x56\x87\xad\x5b\xf5", - "\x33\xdb", - "\xb1\xe4\x87\xac\x66\xcd\x79\x8d\xb4\x76\x68\x2e" - ], - [ - "\x9c\xbd\xaa\x83\x8d\x7e\x76\xd9\x4b\xb2\x04\xd5\x2b\x58\x66", - "\xda\x10", - "\x46\xad\x70\x93\x57\x6e\xac\xc9\x91\xa2\xde\xc5\xf1\x48\xbc" - ], - [ - "\x7f\x3b\xfb\x3b\xce\x8c\xe8\x3d\x65\x40\x2d\x5a\x19", - "\x62\x28", - "\x1d\x13\x99\x13\xac\xa4\x8a\x15\x07\x68\x4f\x72\x7b" - ], - [ - "\xc8\xab\xa4\x56\xd5\xf0", - "\x1a\xd0", - "\xd2\x7b\xbe\x86\xcf\x20" - ], - [ - "\xcc\x5a\x84\xe0\x6c\x00\x7a\x20\xa0\xc9", - "\xe6\xb6", - "\x2a\xec\x62\x56\x8a\xb6\x9c\x96\x46\x7f" - ], - [ - "\x46\x96\x83\x1f\x6a\x79\xfe\xec\x24\xe0\xc3\x20\xe9\xa5\x3a\x76", - "\x36\x5e", - "\x70\xc8\xb5\x41\x5c\x27\xc8\xb2\x12\xbe\xf5\x7e\xdf\xfb\x0c\x28" - ], - [ - "\x74\x7c\xe9\x21\x30\x33\xb3\xe6\x77\x9e\x07\xbc\x6c\xee\xc5\x06", - "\x02\xa0", - "\x76\xdc\xeb\x81\x32\x93\xb1\x46\x75\x3e\x05\x1c\x6e\x4e\xc7\xa6" - ], - [ - "\x64\x8c\xc3\x41\x5d\xe5\x18\x36\xda\xc4\x86", - "\xe3\xb9", - "\x87\x35\x20\xf8\xbe\x5c\xfb\x8f\x39\x7d\x65" - ], - [ - "\xdb\xbb\xb2\x7c\xda\x1f\xd6\xa5\x34\x00\xad", - "\x20\xfc", - "\xfb\x47\x92\x80\xfa\xe3\xf6\x59\x14\xfc\x8d" - ], - [ - "\xc1\x2e\xfc\x7b\x98\x41\xec\xe3\x40\x98\x0b\xfd\x2c", - "\x4a\xd7", - "\x8b\xf9\xb6\xac\xd2\x96\xa6\x34\x0a\x4f\x41\x2a\x66" - ] - ] - end -end -end diff --git a/lib/rex/encoding/xor/word.rb.ut.rb b/lib/rex/encoding/xor/word.rb.ut.rb deleted file mode 100644 index 56e138c818..0000000000 --- a/lib/rex/encoding/xor/word.rb.ut.rb +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'rex/encoding/xor/word' -require 'rex/encoding/xor/byte.rb.ut' - -class Rex::Encoding::Xor::Word::UnitTest < Rex::Encoding::Xor::Byte::UnitTest - - def enc - Rex::Encoding::Xor::Word - end -end diff --git a/lib/rex/exceptions.rb.ut.rb b/lib/rex/exceptions.rb.ut.rb deleted file mode 100644 index 9ecb02b848..0000000000 --- a/lib/rex/exceptions.rb.ut.rb +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..')) - -require 'test/unit' -require 'rex/exceptions' - -module Rex -module Exceptions - -class UnitTest < Test::Unit::TestCase - - def test_exceptions - Rex.constants.each { |const| - mod = Rex.const_get(const) - - if ((mod.kind_of?(Class) == false) || - (mod.ancestors.include?(Rex::Exception) == false)) - next - end - - begin - raise mod.new - rescue ::ArgumentError - rescue mod => detail - assert_respond_to(detail, 'to_s', "#{mod} does not implement to_s") - assert_not_nil(detail.to_s, "invalid to_s") - end - } - - # Test communication error detail strings - begin - raise ConnectionRefused.new('127.0.0.1', 4444) - rescue HostCommunicationError => detail - assert_match(/^The connection(.*)\(127.0.0.1:4444\)/, detail.to_s) - assert_equal('127.0.0.1', detail.host) - assert_equal(4444, detail.port) - end - end - -end - -end -end diff --git a/lib/rex/exploitation/egghunter.rb.ut.rb b/lib/rex/exploitation/egghunter.rb.ut.rb deleted file mode 100644 index 1aac3151c0..0000000000 --- a/lib/rex/exploitation/egghunter.rb.ut.rb +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex/exploitation/egghunter' - -class Rex::Exploitation::Egghunter::UnitTest < Test::Unit::TestCase - - Klass = Rex::Exploitation::Egghunter - - def test_egghunter - payload = "\xcc" * 1023 - - r = Klass.new('bogus') - assert_nil(r.generate(payload)) - - r = Klass.new('win') - assert_nil(r.generate(payload)) - - r = Klass.new('win', ARCH_X86) - assert_not_nil(r.generate(payload)) - assert_not_nil(r.generate(payload)[0]) - assert_not_nil(r.generate(payload)[1]) - end - -end diff --git a/lib/rex/exploitation/omelet.rb.ut.rb b/lib/rex/exploitation/omelet.rb.ut.rb deleted file mode 100644 index f82fff22bd..0000000000 --- a/lib/rex/exploitation/omelet.rb.ut.rb +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex/exploitation/omelet' - -class Rex::Exploitation::Omelet::UnitTest < Test::Unit::TestCase - - Klass = Rex::Exploitation::Omelet - - def test_generate - x = Klass.new('win', ARCH_X86) - - om = x.generate("\xcc" * 1024, '', { - #:eggsize => 31336, # default: 123 - #:eggtag => "b00", # default: 00w - #:searchforward => false, # default: true - #:reset => true, # default: false - #:startreg => "EBP", # default: none - :checksum => true # default: false - }) - # XXX: TODO: assertions! - end - -end diff --git a/lib/rex/exploitation/opcodedb.rb.ut.rb b/lib/rex/exploitation/opcodedb.rb.ut.rb deleted file mode 100644 index 828fd3bb49..0000000000 --- a/lib/rex/exploitation/opcodedb.rb.ut.rb +++ /dev/null @@ -1,280 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex/exploitation/opcodedb' -require 'rex/socket' - -class Rex::Exploitation::OpcodeDb::UnitTest < Test::Unit::TestCase - - Klass = Rex::Exploitation::OpcodeDb::Client - SrvPort = 60000 - - def test_meta_types - srv_cli - - begin - proc_req_resp(%q{1foo2dog}) - - mt = @r.meta_types - - assert_kind_of(Array, mt) - assert_equal(2, mt.length) - assert_equal(1, mt[0].id) - assert_equal("foo", mt[0].name) - assert_equal(2, mt[1].id) - assert_equal("dog", mt[1].name) - ensure - @s.close - end - end - - def test_groups - srv_cli - - begin - proc_req_resp(%q{47foo2dog}) - - mt = @r.groups - - assert_kind_of(Array, mt) - assert_equal(2, mt.length) - assert_equal(47, mt[0].id) - assert_equal("foo", mt[0].name) - assert_equal(2, mt[1].id) - assert_equal("dog", mt[1].name) - ensure - @s.close - end - end - - def test_platforms - srv_cli - - begin - proc_req_resp(%q{12Windows XP SP2Windows Coolness512010}) - - osv = @r.platforms - - assert_kind_of(Array, osv) - assert_equal(1, osv.length) - assert_equal(12, osv[0].id) - assert_equal("Windows XP SP2", osv[0].name) - assert_equal("Windows Coolness", osv[0].desc) - assert_equal(5, osv[0].maj_ver) - assert_equal(1, osv[0].min_ver) - assert_equal(2, osv[0].maj_patch_level) - assert_equal(0, osv[0].min_patch_level) - assert_equal(10, osv[0].modules) - ensure - @s.close - end - end - - def test_modules - srv_cli - - begin - proc_req_resp(%q{ - 1 - kernel32.dll - - - 4 - English - - - 4 - 100 - 2 - 7 - 403242822 - 100000000 - 40000 - - - - text - 3228094 - 4000 - true - true - false - - - - - - - FoolFunction - 3242344 - 5 - - - - - - - FoolFunctionExport - 32423445 - 51 - - - - }) - - m = @r.modules - - assert_kind_of(Array, m) - assert_equal(1, m[0].id) - assert_equal("kernel32.dll", m[0].name) - assert_equal(4, m[0].locale.id) - assert_equal("English", m[0].locale.name) - assert_equal(4, m[0].maj_maj_ver) - assert_equal(100, m[0].maj_min_ver) - assert_equal(2, m[0].min_maj_ver) - assert_equal(7, m[0].min_min_ver) - assert_equal(403242822, m[0].timestamp.to_i) - assert_equal(100000000, m[0].base_address) - assert_equal(40000, m[0].image_size) - assert_kind_of(Array, m[0].segments) - assert_equal("text", m[0].segments[0].type) - assert_equal(3228094, m[0].segments[0].base_address) - assert_equal(4000, m[0].segments[0].size) - assert_equal(true, m[0].segments[0].writable) - assert_equal(true, m[0].segments[0].readable) - assert_equal(false, m[0].segments[0].executable) - assert_kind_of(Array, m[0].imports) - assert_equal("FoolFunction", m[0].imports[0].name) - assert_equal(3242344, m[0].imports[0].address) - assert_equal(5, m[0].imports[0].ordinal) - assert_kind_of(Array, m[0].exports) - assert_equal("FoolFunctionExport", m[0].exports[0].name) - assert_equal(32423445, m[0].exports[0].address) - assert_equal(51, m[0].exports[0].ordinal) - ensure - @s.close - end - end - - def test_locales - srv_cli - - begin - proc_req_resp(%q{ - 4 - English - - - 5 - French - }) - - l = @r.locales - - assert_kind_of(Array, l) - assert_equal(2, l.length) - assert_equal(4, l[0].id) - assert_equal("English", l[0].name) - assert_equal(5, l[1].id) - assert_equal("French", l[1].name) - ensure - @s.close - end - end - - def test_search - srv_cli - - begin - proc_req_resp(%q{ - - - 400 - 34242324 - - - 4 - jmp esp - - - 40 - reg - - - - - - }) - - o = @r.search - - assert_kind_of(Array, o) - assert_equal(1, o.length) - assert_equal(400, o[0].id) - assert_equal(34242324, o[0].address) - assert_equal(4, o[0].type.id) - assert_equal("jmp esp", o[0].type.name) - assert_equal(40, o[0].group.id) - assert_equal("reg", o[0].group.name) - ensure - @s.close - end - end - - def test_statistics - srv_cli - - begin - proc_req_resp(%q{ - - 40 - 50 - 60 - 70 - 80 - 90 - 100 - 110 - 120 - - }) - - s = @r.statistics - - assert_equal(40, s.modules) - assert_equal(50, s.opcodes) - assert_equal(60, s.opcode_types) - assert_equal(70, s.platforms) - assert_equal(80, s.architectures) - assert_equal(90, s.module_segments) - assert_equal(100, s.module_imports) - assert_equal(110, s.module_exports) - assert_equal(120, s.last_update.to_i) - ensure - @s.close - end - end - -protected - - def srv_cli - @r = Klass.new('127.0.0.1', SrvPort) - @s = Rex::Socket::TcpServer.create( - 'LocalHost' => '127.0.0.1', - 'LocalPort' => SrvPort) - end - - def proc_req_resp(buf) - thr = Thread.new { - cli = @s.accept - @buffer = cli.get - - cli.put("HTTP/1.0 200 OK\r\nConnection: close\r\n\r\n#{buf}") - cli.close - } - end - -end diff --git a/lib/rex/exploitation/seh.rb.ut.rb b/lib/rex/exploitation/seh.rb.ut.rb deleted file mode 100644 index d896fd22f3..0000000000 --- a/lib/rex/exploitation/seh.rb.ut.rb +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex/exploitation/seh' - -class Rex::Exploitation::Seh::UnitTest < Test::Unit::TestCase - - Klass = Rex::Exploitation::Seh - - def test_static_record - r = Klass.new - record = r.generate_static_seh_record(0x41414141) - assert_equal("\xeb\x06", record[0, 2]) - assert_equal("\x41\x41\x41\x41", record[4, 4]) - end - -end diff --git a/lib/rex/file.rb.ut.rb b/lib/rex/file.rb.ut.rb deleted file mode 100644 index 0a6ad15214..0000000000 --- a/lib/rex/file.rb.ut.rb +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..')) - -require 'test/unit' -require 'rex/file' - -class Rex::FileUtils::UnitTest < ::Test::Unit::TestCase - Klass = Rex::FileUtils - - def test_find_full_path - assert_not_nil(Klass.find_full_path("ls")) - assert_nil(Klass.find_full_path("cookie monster cake")) - end - -end diff --git a/lib/rex/io/ring_buffer.rb.ut.rb b/lib/rex/io/ring_buffer.rb.ut.rb deleted file mode 100644 index e436a9cbc9..0000000000 --- a/lib/rex/io/ring_buffer.rb.ut.rb +++ /dev/null @@ -1,135 +0,0 @@ -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex/socket' -require 'rex/io/ring_buffer' - -# -# TODO: Mock up the socket so this test doesn't take so long -# -class Rex::IO::RingBuffer::UnitTest < Test::Unit::TestCase - - def setup - server = Rex::Socket.create_tcp_server('LocalPort' => 0) - lport = server.getsockname[2] - @client = Rex::Socket.create_tcp('PeerHost' => '127.0.0.1', 'PeerPort' => lport) - conn = server.accept - #server.close - - @r = Rex::IO::RingBuffer.new(conn, {:size => 64}) - @r.start_monitor - end - - def teardown - begin - @client.close - @r.stop_monitor - rescue ::Exception - end - end - - def test_single_read_data - @client.put("123") - @r.wait(0) - s,d = @r.read_data - - assert_equal("123", d) - end - - def test_sequential_read_data - @r.clear_data - - s = nil - 0.upto(10) do |num| - @client.put(num.to_s) - @r.wait(s) - s,d = @r.read_data(s) - assert_equal(num.to_s, d) - end - end - - def test_wrap - @r.clear_data - 0.upto(@r.size - 1) { - @client.put("a") - # Need to sleep so the socket doesn't get all the data in one read() - sleep 0.05 - } - s,d = @r.read_data - - @client.put("b") - sleep 0.01 - s,d = @r.read_data(s) - - assert_equal("b", d) - - end - -end -=begin -client.put("4") -client.put("5") -client.put("6") -s,d = r.read_data(s) - -client.put("7") -client.put("8") -client.put("9") -s,d = r.read_data(s) - -client.put("0") -s,d = r.read_data(s) - -test_counter = 11 -1.upto(100) do - client.put( "X" ) - test_counter += 1 -end - -sleep(1) - -s,d = r.read_data -p s -p d - -fdata = '' -File.open("/bin/ls", "rb") do |fd| - fdata = fd.read(fd.stat.size) - fdata = fdata * 10 - client.put(fdata) -end - -sleep(1) - -s,vdata = r.read_data(s) - -if vdata != fdata - puts "DATA FAILED" -else - puts "DATA VERIFIED" -end - -r.clear_data - -a = r.create_stream -b = r.create_stream - -client.put("ABC123") -sleep(1) - -p a.read -p b.read - -client.put("$$$$$$") -sleep(1) - -p a.read -p b.read - -c = r.create_stream -p c.read - -end -=end diff --git a/lib/rex/nop/opty2.rb.ut.rb b/lib/rex/nop/opty2.rb.ut.rb deleted file mode 100644 index 5fe9da764b..0000000000 --- a/lib/rex/nop/opty2.rb.ut.rb +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex/nop/opty2' - -class Rex::Nop::Opty2::UnitTest < Test::Unit::TestCase - - Klass = Rex::Nop::Opty2 - - # TODO: machine test - def test_opty2 - o = Klass.new - - 100.times { - s = o.generate_sled(100) - - assert_equal(s.length, 100) - } - end - -end diff --git a/lib/rex/parser/arguments.rb.ut.rb b/lib/rex/parser/arguments.rb.ut.rb deleted file mode 100644 index 49a1549a5a..0000000000 --- a/lib/rex/parser/arguments.rb.ut.rb +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex/parser/arguments' - -class Rex::Parser::Arguments::UnitTest < Test::Unit::TestCase - - def test_parse - args = - [ - "-b", - "foo", - "-c", - "-f", - "-g", - "arg", - "none" - ] - - b = nil - c = false - f = false - g = nil - none = nil - - Rex::Parser::Arguments.new( - '-b' => [ true, "bee" ], - '-c' => [ false, "cee" ], - '-f' => [ false, "eff" ], - '-g' => [ true, "gee" ]).parse(args) { |opt, idx, val| - case opt - when nil - none = val - when '-b' - b = val - when '-c' - c = true - when '-f' - f = true - when '-g' - g = val - end - } - - assert_equal(b, "foo") - assert_equal(c, true) - assert_equal(f, true) - assert_equal(g, "arg") - assert_equal(none, "none") - end - - def test_from_s - args = Rex::Parser::Arguments.from_s( - "this is a test \"of the emergency pimping\" system \\\"buh lee dat\\\" yup") - - assert_equal(args[0], "this") - assert_equal(args[3], "test") - assert_equal(args[4], "of the emergency pimping") - assert_equal(args[5], "system") - assert_equal(args[6], "\"buh") - assert_equal(args[8], "dat\"") - assert_equal(args[9], "yup") - end - -end diff --git a/lib/rex/parser/ini.rb.ut.rb b/lib/rex/parser/ini.rb.ut.rb deleted file mode 100644 index 002384dbcf..0000000000 --- a/lib/rex/parser/ini.rb.ut.rb +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex/parser/ini' - -class Rex::Parser::Ini::UnitTest < Test::Unit::TestCase - - Klass = Rex::Parser::Ini - TestIni = < 1393720, - "\x1C\x84\x15\x00" => 1410076, - "\x0E\x84\x15\x00" => 1410062, - "\x02\x84\x15\x00" => 1410050, - "\xE6\x83\x15\x00" => 1410022, - "\xC4\x83\x15\x00" => 1409988, - "\x00\x00\x00\x00" => 0, - } - X86_64_POINTERS = { - "\x10^ \x00\x00\x00\x00\x00" => 2121232, - "\xCA\x9D \x00\x00\x00\x00\x00" => 2137546, - "\xC8\x9D \x00\x00\x00\x00\x00" => 2137544, - "Z\x9D \x00\x00\x00\x00\x00" => 2137434, - "X\x9D \x00\x00\x00\x00\x00" => 2137432, - "\x00\x00\x00\x00\x00\x00\x00\x00" => 0, - } - - X86_64_NULL_POINTER = "\x00\x00\x00\x00\x00\x00\x00\x00" - X86_32_NULL_POINTER = "\x00\x00\x00\x00" - - X86_64 = PlatformUtil::X86_64 - X86_32 = PlatformUtil::X86_32 - - def test_pack_pointer - X86_64_POINTERS.invert.each_pair do |unpacked, packed| - assert_equal(packed, PointerUtil.pack_pointer(unpacked.to_i, X86_64), - "pack_pointer should pack 64-bit numberic pointers") - end - - X86_32_POINTERS.invert.each_pair do |unpacked, packed| - assert_equal(packed, PointerUtil.pack_pointer(unpacked.to_i, X86_32), - "pack_pointer should pack 32-bit numberic pointers") - end - - assert_equal(X86_64_NULL_POINTER, PointerUtil.pack_pointer(nil, X86_64), - 'pack_pointer should pack "nil" as a null pointer for x86_64') - - assert_equal(X86_32_NULL_POINTER, PointerUtil.pack_pointer(nil, X86_32), - 'pack_pointer should pack "nil" as a null pointer for x86_32') - - assert_equal(X86_64_NULL_POINTER, PointerUtil.pack_pointer(0, X86_64), - 'pack_pointer should pack numeric 0 as a null pointer for x86_64') - - assert_equal(X86_32_NULL_POINTER, PointerUtil.pack_pointer(0, X86_32), - 'pack_pointer should pack numeric 9 as a null pointer for x86_32') - end - - def test_unpack_pointer - X86_64_POINTERS.each_pair do |packed, unpacked| - assert_equal(unpacked, PointerUtil.unpack_pointer(packed, X86_64), - "unpack_pointer should unpack 64-bit pointers") - end - - X86_32_POINTERS.each_pair do |packed, unpacked| - assert_equal(unpacked, PointerUtil.unpack_pointer(packed, X86_32), - "unpack_pointer should unpack 32-bit pointers") - end - - - end - - def test_is_null_pointer - [X86_32, X86_64].each do |platform| - assert(PointerUtil.is_null_pointer?(nil, platform), 'nil should be a null pointer') - assert(PointerUtil.is_null_pointer?(0, platform), 'numeric 0 should be a null pointer') - end - - assert_equal(true, PointerUtil.is_null_pointer?(X86_32_NULL_POINTER, X86_32), - 'is_null_pointer? should return true for packed 32-bit null pointers') - - assert_equal(true, PointerUtil.is_null_pointer?(X86_64_NULL_POINTER, X86_64), - 'is_null_pointer? should return true for packed 64-bit null pointers') - - end - - def test_pointer_size - assert_equal(8, PointerUtil.pointer_size(X86_64), - 'pointer_size should report X86_64 arch as 8 (bytes)') - - assert_equal(4, PointerUtil.pointer_size(X86_32), - 'pointer_size should report X86_32 arch as 4 (bytes)') - end - - def test_is_pointer_type - assert_equal(true, PointerUtil.is_pointer_type?(:pointer), - 'pointer_type should return true for the symbol :pointer') - - assert_equal(true, PointerUtil.is_pointer_type?('LPVOID'), - 'pointer_type should return true if string begins with LP') - - assert_equal(true, PointerUtil.is_pointer_type?('PDWORD'), - 'pointer_type should return true if string begins with P') - - assert_equal(false, PointerUtil.is_pointer_type?('LOLZ'), - 'pointer_type should return false if not a pointer type') - - end -end -end -end -end -end -end -end -end diff --git a/lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb.ut.rb b/lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb.ut.rb deleted file mode 100644 index de36574f45..0000000000 --- a/lib/rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager.rb.ut.rb +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..','..','..','..','..', 'lib')) - -require 'rex/post/meterpreter/extensions/stdapi/railgun/win_const_manager' -require 'test/unit' - -module Rex -module Post -module Meterpreter -module Extensions -module Stdapi -module Railgun -class WinConstManager::UnitTest < Test::Unit::TestCase - - def test_select_const_names - const_manager = WinConstManager.new - - names = %w(W WW WWW) - - names.each do |name| - const_manager.add_const(name, 23) - end - - assert(const_manager.select_const_names(23).sort == names, - 'select_const_names should return all names for given value') - - const_manager.add_const('Skidoo!', 23) - - assert(const_manager.select_const_names(23, /^\w{1,3}$/).sort == names, - 'select_const_names should filter names with provided regex') - - end - - def test_is_parseable - const_manager = WinConstManager.new - - first_key = 'SOME_NUMBER' - second_key = 'SOME_OTHER_NUMBER' - boolean_logic = first_key + ' | ' + second_key - - # XXX: Should check (un)parseability before adding constants too? - - const_manager.add_const(first_key, 43123) - const_manager.add_const(second_key, 234) - - assert(const_manager.is_parseable(boolean_logic), - "is_parseable should consider boolean logic statements parseable") - - assert(const_manager.is_parseable(first_key), - "is_parseable should consider constants parseable") - - assert(! const_manager.is_parseable(5), - "is_parseable should not consider non-string keys as parseable") - - assert(! const_manager.is_parseable('| FOO |'), - "is_parseable should not consider malformed boolean expressions parseable") - end - - def test_add_const - target_key = 'VALID_KEY' - target_value = 23 - - const_manager = WinConstManager.new - - const_manager.add_const(target_key, target_value) - - assert_equal(target_value, const_manager.parse(target_key), - "add_const should add a constant/value pair that can be trieved with parse") - - end - - def test_initialization - target_key = 'VALID_KEY' - target_value = 23 - - const_manager = WinConstManager.new(target_key => target_value) - - assert_equal(target_value, const_manager.parse(target_key), - "upon initialization, should add any provided constants.") - end - - def test_parse - target_key = 'VALID_KEY' - target_value = 23 - invalid_key = 8 - - const_manager = WinConstManager.new - - const_manager.add_const(target_key, target_value) - - assert_equal(target_value, const_manager.parse(target_key), - "parse should retrieve the corresponding value when a key is provided") - - # From API: "should not throw an exception given an invalid key" - assert_nothing_thrown do - const_manager.parse(invalid_key) - end - - assert_equal(nil, const_manager.parse(invalid_key), - "parse should return nil when an invalid key is provided") - - x_key = 'X' - x_value = 228 - y_key = 'Y' - y_value = 15 - - boolean_logic = x_key + ' | ' + y_key - target_boolean_logic_result = x_value | y_value - - const_manager.add_const(x_key, x_value) - const_manager.add_const(y_key, y_value) - - assert_equal(target_boolean_logic_result, const_manager.parse(boolean_logic), - "parse should evaluate boolean expressions consisting of OR") - end -end -end -end -end -end -end -end diff --git a/lib/rex/proto/dcerpc/client.rb.ut.rb b/lib/rex/proto/dcerpc/client.rb.ut.rb deleted file mode 100755 index 0ced7af783..0000000000 --- a/lib/rex/proto/dcerpc/client.rb.ut.rb +++ /dev/null @@ -1,492 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'rex/test' -require 'rex/socket' -require 'rex/proto/dcerpc/client' -require 'rex/proto/dcerpc/handle' - -begin -require 'flexmock' - -class Rex::Proto::DCERPC::Client::UnitTest < Test::Unit::TestCase - - Klass = Rex::Proto::DCERPC::Client - - def setup - @handle = Rex::Proto::DCERPC::Handle.new(['6bffd098-a112-3610-9833-46c3f87e345a', '1.0'], 'ncacn_ip_tcp', '1.2.3.4', [1026]) - end - - def setup_test(read, write, force_mock = false) - srand(0) - mock_unmake() # always do this, just to be sure. yes, it slows it down. but... - - if (force_mock or !$_REX_TEST_NO_MOCK) - mock_make(read,write) - end - end - - def mock_make(read, write) - func = ' - require "flexmock" - def self.create_tcp(opts = {}) - read = ' + read.inspect + ' - write = ' + write.inspect + ' - write_size = ' + write.size.to_s + ' - mock = FlexMock.new - mock.should_receive(:type?).returns("tcp") - mock.should_receive(:peerport).returns(opts["PeerPort"]) - mock.mock_handle(:close) { nil } - mock.mock_handle(:read) { read.shift } - mock.mock_handle(:get_once) { read.shift } - mock.mock_handle(:write) { |data| - expected = write.shift - if data != expected - write_id = write_size - write.size - require "pp" - raise "write #{write_id} failed\n\n<#{expected.inspect}> was expected but was\n<#{data.inspect}>" - end - data.length - } - mock.mock_handle(:put) { |data| - expected = write.shift - if data != expected - write_id = write_size - write.size - require "pp" - raise "write #{write_id} failed\n\n<#{expected.inspect}> was expected but was\n<#{data.inspect}>" - end - data.length - } - # mock.should_ignore_missing() - return mock - end - ' - Rex::Socket.module_eval(func) - end - - def mock_unmake - if Rex::Socket.create_tcp.class != 'Socket' - func = ' - def self.create_tcp(opts = {}) - return create_param(Rex::Socket::Parameters.from_hash(opts.merge("Proto" => "tcp"))) - end - ' - Rex::Socket.module_eval(func) - end - end - - # undo the mock object stuff, just in case... - def teardown - mock_unmake() - end - - def test_instance_no_setup - setup_test([],[]) - handle = Rex::Proto::DCERPC::Handle.new(['6bffd098-a112-3610-9833-46c3f87e345a', '1.0'], 'ncacn_ip_tcp', $_REX_TEST_SMB_HOST, [1026]) - s = Rex::Socket.create_tcp( 'PeerHost' => $_REX_TEST_SMB_HOST, 'PeerPort' => 1026) - c = Klass.new(@handle, s, 'no_autobind' => 1, 'no_socketsetup' => 1) - assert_instance_of(Rex::Proto::DCERPC::Client, c, 'instance') - end - - def test_bind - write = ["\005\000\v\003\020\000\000\000H\000\000\000\000\000\000\000\320\026\320\026\000\000\000\000\001\000\000\000\000\000\001\000\010\203\257\341\037]\311\021\221\244\010\000+\024\240\372\003\000\000\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000"] - read = ["\x05\x00\x0C\x03\x10\x00\x00\x00\x44\x00\x00\x00\x00\x00\x00\x00\xB8\x10\xB8\x10\xB2\x73\x00\x00\x0C\x00\x5C\x50\x49\x50\x45\x5C\x6C\x73\x61\x73\x73\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x04\x5D\x88\x8A\xEB\x1C\xC9\x11\x9F\xE8\x08\x00\x2B\x10\x48\x60\x02\x00\x00\x00",] - setup_test(read, write) - socket = Rex::Socket.create_tcp( 'PeerHost' => $_REX_TEST_SMB_HOST, 'PeerPort' => 135) - handle = Rex::Proto::DCERPC::Handle.new(['E1AF8308-5D1F-11C9-91A4-08002B14A0FA', '3.0'], 'ncacn_ip_tcp', $_REX_TEST_SMB_HOST, [135]) - c = Klass.new(handle, socket) - assert_instance_of(Rex::Proto::DCERPC::Client, c, 'instance') - end - - def test_bind_fail - write = ["\x05\x00\x0b\x03\x10\x00\x00\x00\x48\x00\x00\x00\x00\x00\x00\x00\xd0\x16\xd0\x16\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x01\x00\xbb\xbb\xaa\xaa\x00\x00\x10\x36\x98\x33\x46\xc3\xf8\x7e\x34\x5a\x02\x00\x00\x00\x04\x5d\x88\x8a\xeb\x1c\xc9\x11\x9f\xe8\x08\x00\x2b\x10\x48\x60\x02\x00\x00\x00"] - read = [ "\x05\x00\x0c\x03\x10\x00\x00\x00\x3c\x00\x00\x00\x00\x00\x00\x00\xd0\x16\xd0\x16\x6c\x66\x00\x00\x04\x00\x31\x33\x35\x00\x92\xc0\x01\x00\x00\x00\x02\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"] - setup_test(read, write) - socket = Rex::Socket.create_tcp('PeerHost' => $_REX_TEST_SMB_HOST, 'PeerPort' => 135) - handle = Rex::Proto::DCERPC::Handle.new(['AAAABBBB-0000-3610-9833-46c3f87e345a', '2.0'], 'ncacn_ip_tcp', $_REX_TEST_SMB_HOST, [135]) - - assert_raise(RuntimeError) { - c = Klass.new(handle, socket) - } - end - - def test_call - write = [ - "\x05\x00\x0b\x03\x10\x00\x00\x00\x48\x00\x00\x00\x00\x00\x00\x00\xd0\x16\xd0\x16\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x01\x00\x98\xd0\xff\x6b\x12\xa1\x10\x36\x98\x33\x46\xc3\xf8\x7e\x34\x5a\x01\x00\x00\x00\x04\x5d\x88\x8a\xeb\x1c\xc9\x11\x9f\xe8\x08\x00\x2b\x10\x48\x60\x02\x00\x00\x00", - "\x05\x00\x00\x03\x10\x00\x00\x00\x1c\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x0a\x00ABCD" - ] - read = [ - "\x05\x00\x0C\x03\x10\x00\x00\x00\x44\x00\x00\x00\x00\x00\x00\x00\xB8\x10\xB8\x10\xB2\x73\x00\x00\x0C\x00\x5C\x50\x49\x50\x45\x5C\x6C\x73\x61\x73\x73\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x04\x5D\x88\x8A\xEB\x1C\xC9\x11\x9F\xE8\x08\x00\x2B\x10\x48\x60\x02\x00\x00\x00", - "\x05\x00\x02\x23\x10\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x03\x00\x01\x1C\x00\x00\x00\x00foo" - ] - setup_test(read, write, true) - socket = Rex::Socket.create_tcp('PeerHost' => $_REX_TEST_SMB_HOST, 'PeerPort' => 135) - - c = Klass.new(@handle, socket) - assert_instance_of(Rex::Proto::DCERPC::Client, c, 'instance') - response = c.call(10, "ABCD") - assert_equal(response, 'foo', 'call') - end - - def test_fault - write = [ - "\005\000\v\003\020\000\000\000H\000\000\000\000\000\000\000\320\026\320\026\000\000\000\000\001\000\000\000\000\000\001\000\010\203\257\341\037]\311\021\221\244\010\000+\024\240\372\003\000\000\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000", - "\x05\x00\x00\x03\x10\x00\x00\x00\x1c\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x0a\x00ABCD" - ] - read = [ - "\x05\x00\x0C\x03\x10\x00\x00\x00\x44\x00\x00\x00\x00\x00\x00\x00\xB8\x10\xB8\x10\xB2\x73\x00\x00\x0C\x00\x5C\x50\x49\x50\x45\x5C\x6C\x73\x61\x73\x73\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x04\x5D\x88\x8A\xEB\x1C\xC9\x11\x9F\xE8\x08\x00\x2B\x10\x48\x60\x02\x00\x00\x00", - "\x05\x00\x03\x23\x10\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x01\x1c\x00\x00\x00\x00" - ] - setup_test(read, write) - - socket = Rex::Socket.create_tcp('PeerHost' => $_REX_TEST_SMB_HOST, 'PeerPort' => 135) - handle = Rex::Proto::DCERPC::Handle.new(['E1AF8308-5D1F-11C9-91A4-08002B14A0FA', '3.0'], 'ncacn_ip_tcp', $_REX_TEST_SMB_HOST, [135]) - - c = Klass.new(handle, socket) - assert_instance_of(Rex::Proto::DCERPC::Client, c, 'instance') - assert_raise(Rex::Proto::DCERPC::Exceptions::Fault) { - response = c.call(10, "ABCD") - } - # UGLY! - assert_equal(c.last_response.status, 0x1C010002, 'call op 10 with stub response') - end - - def test_segmented_read_writes - bind_expected = "\005\000\v\003\020\000\000\000H\000\000\000\000\000\000\000\320\026\320\026\000\000\000\000\001\000\000\000\000\000\001\000\230\320\377k\022\241\0206\2303F\303\370~4Z\001\000\000\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000" - bind_response = "\x05\x00\x0C\x03\x10\x00\x00\x00\x44\x00\x00\x00\x00\x00\x00\x00\xB8\x10\xB8\x10\xB2\x73\x00\x00\x0C\x00\x5C\x50\x49\x50\x45\x5C\x6C\x73\x61\x73\x73\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x04\x5D\x88\x8A\xEB\x1C\xC9\x11\x9F\xE8\x08\x00\x2B\x10\x48\x60\x02\x00\x00\x00" - - socket = FlexMock.new - #socket.should_ignore_missing() - - @write_data = '' - - socket.mock_handle(:write) { - |data| - @write_data += data - data.length - } - - read_data = bind_response.dup - socket.mock_handle(:read) { - |size| - if size.nil? - size = read_data.size - end - data = read_data.slice!(0, size) - if data.length == 0 - data = nil - end - data - } - socket.mock_handle(:get_once) { - |timeout, size| - if size.nil? - size = read_data.size - end - data = read_data.slice!(0, size) - if data.length == 0 - data = nil - end - data - } - socket.should_receive(:type?).returns('tcp') - - c = Klass.new(@handle, socket, 'segment_write' => 1, 'segment_read' => 1) - assert_equal(bind_expected, @write_data, 'bind') - assert_instance_of(Rex::Proto::DCERPC::Client, c, 'instance') - - # XXX - would be nice to test a success, as well as a failure, but - # hell... we don't care if the decoder is "right" here, just that it - # returns data. Test the decoder in the decoder I say! - call_data = "\005\000\000\003\020\000\000\000\034\000\000\000\000\000\000\000\004\000\000\000\000\000\n\000ABCD" - call_response = "\x05\x00\x02\x23\x10\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x03\x00\x01\x1C\x00\x00\x00\x00foo" - read_data = call_response - @write_data = '' - socket.mock_handle(:write) { - |data| - @write_data += data - data.length - } - read_data = call_response.dup - socket.mock_handle(:read) { - |size| - data = read_data.slice!(0, size) - if data.length == 0 - data = nil - else - end - data - } - - response = c.call(10, "ABCD") - assert_equal(response, 'foo', 'response') - assert_equal(@write_data, call_data, 'write') - end - - def test_dcerpc_over_smb - write = [ - "\x00\x00\x00\x54\xff\x53\x4d\x42\x72\x00\x00\x00\x00\x18\x01\x28\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x00\x00\xac\x0a\x00\x31\x00\x02\x4c\x41\x4e\x4d\x41\x4e\x31\x2e\x30\x00\x02\x4c\x4d\x31\x2e\x32\x58\x30\x30\x32\x00\x02\x4e\x54\x20\x4c\x41\x4e\x4d\x41\x4e\x20\x31\x2e\x30\x00\x02\x4e\x54\x20\x4c\x4d\x20\x30\x2e\x31\x32\x00", - "\x00\x00\x00\xb0\xff\x53\x4d\x42\x73\x00\x00\x00\x00\x18\x01\x28\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x00\x00\xac\x0a\x0c\xff\x00\x00\x00\xdf\xff\x02\x00\x01\x00\x00\x00\x00\x00\x52\x00\x00\x00\x00\x00\x5c\xd0\x00\x80\x75\x00\x60\x50\x06\x06\x2b\x06\x01\x05\x05\x02\xa0\x46\x30\x44\xa0\x0e\x30\x0c\x06\x0a\x2b\x06\x01\x04\x01\x82\x37\x02\x02\x0a\xa2\x32\x04\x30\x4e\x54\x4c\x4d\x53\x53\x50\x00\x01\x00\x00\x00\x01\x02\x08\x00\x00\x00\x00\x00\x20\x00\x00\x00\x10\x00\x10\x00\x20\x00\x00\x00\x31\x41\x44\x37\x44\x6e\x4a\x54\x56\x79\x6b\x58\x47\x59\x59\x4d\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x32\x31\x39\x35\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x35\x2e\x30\x00", - "\x00\x00\x00\xfa\xff\x53\x4d\x42\x73\x00\x00\x00\x00\x18\x01\x28\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x00\x08\xac\x0a\x0c\xff\x00\x00\x00\xdf\xff\x02\x00\x01\x00\x00\x00\x00\x00\x9c\x00\x00\x00\x00\x00\x5c\xd0\x00\x80\xbf\x00\xa1\x81\x99\x30\x81\x96\xa2\x81\x93\x04\x81\x90\x4e\x54\x4c\x4d\x53\x53\x50\x00\x03\x00\x00\x00\x18\x00\x18\x00\x40\x00\x00\x00\x18\x00\x18\x00\x58\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x20\x00\x20\x00\x70\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02\x08\x00\x3a\xc1\xe6\x27\x57\xae\x58\x51\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11\x48\x4d\x21\x82\x94\x0e\xb8\xf1\xe3\x71\xbd\x12\x19\x97\x88\x90\x8b\xa2\x23\xad\x71\x89\x4a\x31\x00\x41\x00\x44\x00\x37\x00\x44\x00\x6e\x00\x4a\x00\x54\x00\x56\x00\x79\x00\x6b\x00\x58\x00\x47\x00\x59\x00\x59\x00\x4d\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x32\x31\x39\x35\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x35\x2e\x30\x00", - "\x00\x00\x00\x62\xff\x53\x4d\x42\x73\x00\x00\x00\x00\x18\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x00\x00\xac\x0a\x0d\xff\x00\x00\x00\xdf\xff\x02\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x25\x00\x00\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x32\x31\x39\x35\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x35\x2e\x30\x00", - "\x00\x00\x00\x37\xff\x53\x4d\x42\x75\x00\x00\x00\x00\x18\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x01\x08\xac\x0a\x04\xff\x00\x00\x00\x00\x00\x01\x00\x0c\x00\x00\x49\x50\x43\x24\x00\x3f\x3f\x3f\x3f\x3f\x00", - "\x00\x00\x00\x5c\xff\x53\x4d\x42\xa2\x00\x00\x00\x00\x18\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x18\xff\x00\x00\x00\x00\x08\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x09\x00\x5c\x42\x52\x4f\x57\x53\x45\x52\x00", - "\x00\x00\x00\x87\xff\x53\x4d\x42\x2f\x00\x00\x00\x00\x18\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x0e\xff\x00\x00\x00\x00\x40\x00\x00\x00\x00\xff\xff\xff\xff\x08\x00\x48\x00\x00\x00\x48\x00\x3f\x00\x00\x00\x00\x00\x48\x00\x05\x00\x0b\x03\x10\x00\x00\x00\x48\x00\x00\x00\x00\x00\x00\x00\xd0\x16\xd0\x16\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x01\x00\xc8\x4f\x32\x4b\x70\x16\xd3\x01\x12\x78\x5a\x47\xbf\x6e\xe1\x88\x03\x00\x00\x00\x04\x5d\x88\x8a\xeb\x1c\xc9\x11\x9f\xe8\x08\x00\x2b\x10\x48\x60\x02\x00\x00\x00", - "\x00\x00\x00\x37\xff\x53\x4d\x42\x2e\x00\x00\x00\x00\x18\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x0a\xff\x00\x00\x00\x00\x40\x00\x00\x00\x00\x80\xbb\x80\xbb\x00\x00\x00\x00\x00\x00\x00\x00" - ] - - read = [ - "\x00\x00\x00\x55\xff\x53\x4d\x42\x72\x00\x00\x00\x00\x98\x01\x28\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x00\x00\xac\x0a\x11\x03\x00\x03\x0a\x00\x01\x00\x04\x11\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\xfd\xe3\x00\x80\x16\x12\x0a\x27\x2e\xfc\xc5\x01\xe0\x01\x00\x10\x00\x8b\x3c\x73\xd2\x53\x9e\x28\x48\xa2\xac\x68\xae\xd1\x2e\x41\x5a", - "\x00\x00\x01\xb3\xff\x53\x4d\x42\x73\x16\x00\x00\xc0\x98\x01\x68\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x00\x08\xac\x0a\x04\xff\x00\xb3\x01\x00\x00\x63\x01\x88\x01\xa1\x82\x01\x5f\x30\x82\x01\x5b\xa0\x03\x0a\x01\x01\xa1\x0c\x06\x0a\x2b\x06\x01\x04\x01\x82\x37\x02\x02\x0a\xa2\x81\xa1\x04\x81\x9e\x4e\x54\x4c\x4d\x53\x53\x50\x00\x02\x00\x00\x00\x12\x00\x12\x00\x30\x00\x00\x00\x05\x02\x8a\x00\x08\x78\x80\x62\x32\xc8\xeb\xe7\x00\x00\x00\x00\x00\x00\x00\x00\x5c\x00\x5c\x00\x42\x00\x00\x00\x57\x00\x49\x00\x4e\x00\x32\x00\x4b\x00\x42\x00\x41\x00\x53\x00\x45\x00\x02\x00\x12\x00\x57\x00\x49\x00\x4e\x00\x32\x00\x4b\x00\x42\x00\x41\x00\x53\x00\x45\x00\x01\x00\x12\x00\x57\x00\x49\x00\x4e\x00\x32\x00\x4b\x00\x42\x00\x41\x00\x53\x00\x45\x00\x04\x00\x12\x00\x77\x00\x69\x00\x6e\x00\x32\x00\x6b\x00\x62\x00\x61\x00\x73\x00\x65\x00\x03\x00\x12\x00\x77\x00\x69\x00\x6e\x00\x32\x00\x6b\x00\x62\x00\x61\x00\x73\x00\x65\x00\x00\x00\x00\x00\xa3\x81\xa1\x04\x81\x9e\x4e\x54\x4c\x4d\x53\x53\x50\x00\x02\x00\x00\x00\x12\x00\x12\x00\x30\x00\x00\x00\x05\x02\x8a\x00\x08\x78\x80\x62\x32\xc8\xeb\xe7\x00\x00\x00\x00\x00\x00\x00\x00\x5c\x00\x5c\x00\x42\x00\x00\x00\x57\x00\x49\x00\x4e\x00\x32\x00\x4b\x00\x42\x00\x41\x00\x53\x00\x45\x00\x02\x00\x12\x00\x57\x00\x49\x00\x4e\x00\x32\x00\x4b\x00\x42\x00\x41\x00\x53\x00\x45\x00\x01\x00\x12\x00\x57\x00\x49\x00\x4e\x00\x32\x00\x4b\x00\x42\x00\x41\x00\x53\x00\x45\x00\x04\x00\x12\x00\x77\x00\x69\x00\x6e\x00\x32\x00\x6b\x00\x62\x00\x61\x00\x73\x00\x65\x00\x03\x00\x12\x00\x77\x00\x69\x00\x6e\x00\x32\x00\x6b\x00\x62\x00\x61\x00\x73\x00\x65\x00\x00\x00\x00\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x35\x2e\x30\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x4c\x41\x4e\x20\x4d\x61\x6e\x61\x67\x65\x72\x00", - "\x00\x00\x00\x23\xff\x53\x4d\x42\x73\x6d\x00\x00\xc0\x98\x01\x68\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x00\x08\xac\x0a\x00\x00\x00", - "\x00\x00\x00\x58\xff\x53\x4d\x42\x73\x00\x00\x00\x00\x98\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x01\x08\xac\x0a\x03\xff\x00\x58\x00\x00\x00\x2f\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x35\x2e\x30\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x4c\x41\x4e\x20\x4d\x61\x6e\x61\x67\x65\x72\x00\x57\x4f\x52\x4b\x47\x52\x4f\x55\x50\x00", - "\x00\x00\x00\x2e\xff\x53\x4d\x42\x75\x00\x00\x00\x00\x98\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x03\xff\x00\x2e\x00\x01\x00\x05\x00\x49\x50\x43\x00\x00", - "\x00\x00\x00\x87\xff\x53\x4d\x42\xa2\x00\x00\x00\x00\x98\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x2a\xff\x00\x87\x00\x00\x00\x40\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xff\x05\x00\x00\x00\x00\x00\x00\x00\x00\x04\x5d\x88\x8a\xeb\x1c\xc9\x11\x9f\xe8\x08\x00\x2b\x10\x48\x60\x02\x9b\x01\x12\x00\x9b\x01\x12\x00\x00\x00", - "\x00\x00\x00\x2f\xff\x53\x4d\x42\x2f\x00\x00\x00\x00\x98\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x06\xff\x00\x2f\x00\x48\x00\xff\xff\x00\x00\x00\x00\x00\x00", - "\x00\x00\x00\x80\xff\x53\x4d\x42\x2e\x00\x00\x00\x00\x98\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x0c\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x44\x00\x3c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x45\x00\x00\x05\x00\x0c\x03\x10\x00\x00\x00\x44\x00\x00\x00\x00\x00\x00\x00\xb8\x10\xb8\x10\xdd\xe2\x00\x00\x0d\x00\x5c\x50\x49\x50\x45\x5c\x6e\x74\x73\x76\x63\x73\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x04\x5d\x88\x8a\xeb\x1c\xc9\x11\x9f\xe8\x08\x00\x2b\x10\x48\x60\x02\x00\x00\x00", - ] - setup_test(read, write) - require 'rex/proto/smb/simpleclient' - begin - Timeout.timeout($_REX_TEST_TIMEOUT) { - s = Rex::Socket.create_tcp( 'PeerHost' => $_REX_TEST_SMB_HOST, 'PeerPort' => 445) - - smb = Rex::Proto::SMB::SimpleClient.new(s, true) - assert_instance_of(Rex::Proto::SMB::SimpleClient, smb, 'instance of smb') - - user = '' - pass = '' - - smb.login('*SMBSERVER', user, pass) - smb.connect('IPC$') - f = smb.create_pipe('\BROWSER') - assert_instance_of(Rex::Proto::SMB::SimpleClient::OpenPipe, f, 'pipe') - - handle = Rex::Proto::DCERPC::Handle.new(['4b324fc8-1670-01d3-1278-5a47bf6ee188', '3.0'], 'ncacn_np', $_REX_TEST_SMB_HOST, ['\BROWSER']) - assert_instance_of(Rex::Proto::DCERPC::Handle, handle, 'handle') - dcerpc = Rex::Proto::DCERPC::Client.new(handle, f) # , 'segment_read' => 0) - assert_instance_of(Rex::Proto::DCERPC::Client, dcerpc, 'bind') - s.close - } - rescue Timeout::Error - flunk('timeout') - end - end - - def test_ncacn_ip_tcp - write = [ - "\x05\x00\x0b\x03\x10\x00\x00\x00\x48\x00\x00\x00\x00\x00\x00\x00\xd0\x16\xd0\x16\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x01\x00\x08\x83\xaf\xe1\x1f\x5d\xc9\x11\x91\xa4\x08\x00\x2b\x14\xa0\xfa\x03\x00\x00\x00\x04\x5d\x88\x8a\xeb\x1c\xc9\x11\x9f\xe8\x08\x00\x2b\x10\x48\x60\x02\x00\x00\x00", - "\x05\x00\x00\x03\x10\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x28\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00" - ] - read = [ - "\x05\x00\x0c\x03\x10\x00\x00\x00\x3c\x00\x00\x00\x00\x00\x00\x00\xd0\x16\xd0\x16\x12\x66\x00\x00\x04\x00\x31\x33\x35\x00\xec\xd7\x01\x00\x00\x00\x00\x00\x00\x00\x04\x5d\x88\x8a\xeb\x1c\xc9\x11\x9f\xe8\x08\x00\x2b\x10\x48\x60\x02\x00\x00\x00", - "\x05\x00\x02\x03\x10\x00\x00\x00\xb4\x00\x00\x00\x00\x00\x00\x00\x9c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc4\x49\xc2\xb8\x92\x78\x4e\x4f\xb3\xe7\xbf\x7e\x00\x2a\xd3\x39\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x4b\x00\x00\x00\x4b\x00\x00\x00\x05\x00\x13\x00\x0d\x80\xa9\x88\x10\xe5\xea\xd0\x11\x8d\x9b\x00\xa0\x24\x53\xc3\x37\x01\x00\x02\x00\x00\x00\x13\x00\x0d\x04\x5d\x88\x8a\xeb\x1c\xc9\x11\x9f\xe8\x08\x00\x2b\x10\x48\x60\x02\x00\x02\x00\x00\x00\x01\x00\x0b\x02\x00\x00\x00\x01\x00\x07\x02\x00\x08\x39\x01\x00\x09\x04\x00\x0a\x04\x0a\x3a\x00\x00\x00\x00\x00" - ] - setup_test(read, write) - begin - Timeout.timeout($_REX_TEST_TIMEOUT) { - s = Rex::Socket.create_tcp('PeerHost' => $_REX_TEST_SMB_HOST, 'PeerPort' => 135) - handle = Rex::Proto::DCERPC::Handle.new(['E1AF8308-5D1F-11C9-91A4-08002B14A0FA', '3.0'], 'ncacn_ip_tcp', $_REX_TEST_SMB_HOST, [135]) - assert_instance_of(Rex::Proto::DCERPC::Handle, handle, 'handle') - dcerpc = Rex::Proto::DCERPC::Client.new(handle, s) - assert_instance_of(Rex::Proto::DCERPC::Client, dcerpc, 'bind') - - stub = "\x00" * (4 * 9) + "\x01\x00\x00\x00" - got = dcerpc.call(0x02, stub) - s.close - } - rescue Timeout::Error - flunk('timeout') - end - end - - def test_ncacn_ip_tcp_objectid - write = [ - "\x05\x00\x0b\x03\x10\x00\x00\x00\x48\x00\x00\x00\x00\x00\x00\x00\xd0\x16\xd0\x16\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x01\x00\x08\x83\xaf\xe1\x1f\x5d\xc9\x11\x91\xa4\x08\x00\x2b\x14\xa0\xfa\x03\x00\x00\x00\x04\x5d\x88\x8a\xeb\x1c\xc9\x11\x9f\xe8\x08\x00\x2b\x10\x48\x60\x02\x00\x00\x00", - "\x05\x00\x00\x83\x10\x00\x00\x00\x50\x00\x00\x00\x00\x00\x00\x00\x28\x00\x00\x00\x00\x00\x02\x00\010\203\257\341\037]\311\021\221\244\010\000+\024\240\372\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00" - ] - read = [ - "\x05\x00\x0c\x03\x10\x00\x00\x00\x3c\x00\x00\x00\x00\x00\x00\x00\xd0\x16\xd0\x16\x12\x66\x00\x00\x04\x00\x31\x33\x35\x00\xec\xd7\x01\x00\x00\x00\x00\x00\x00\x00\x04\x5d\x88\x8a\xeb\x1c\xc9\x11\x9f\xe8\x08\x00\x2b\x10\x48\x60\x02\x00\x00\x00", - "\x05\x00\x02\x03\x10\x00\x00\x00\xb4\x00\x00\x00\x00\x00\x00\x00\x9c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc4\x49\xc2\xb8\x92\x78\x4e\x4f\xb3\xe7\xbf\x7e\x00\x2a\xd3\x39\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x4b\x00\x00\x00\x4b\x00\x00\x00\x05\x00\x13\x00\x0d\x80\xa9\x88\x10\xe5\xea\xd0\x11\x8d\x9b\x00\xa0\x24\x53\xc3\x37\x01\x00\x02\x00\x00\x00\x13\x00\x0d\x04\x5d\x88\x8a\xeb\x1c\xc9\x11\x9f\xe8\x08\x00\x2b\x10\x48\x60\x02\x00\x02\x00\x00\x00\x01\x00\x0b\x02\x00\x00\x00\x01\x00\x07\x02\x00\x08\x39\x01\x00\x09\x04\x00\x0a\x04\x0a\x3a\x00\x00\x00\x00\x00" - ] - setup_test(read, write) - begin - Timeout.timeout($_REX_TEST_TIMEOUT) { - s = Rex::Socket.create_tcp('PeerHost' => $_REX_TEST_SMB_HOST, 'PeerPort' => 135) - handle = Rex::Proto::DCERPC::Handle.new(['E1AF8308-5D1F-11C9-91A4-08002B14A0FA', '3.0'], 'ncacn_ip_tcp', $_REX_TEST_SMB_HOST, [135]) - assert_instance_of(Rex::Proto::DCERPC::Handle, handle, 'handle') - dcerpc = Rex::Proto::DCERPC::Client.new(handle, s, {'object_call' => 1}) - assert_instance_of(Rex::Proto::DCERPC::Client, dcerpc, 'bind') - - stub = "\x00" * (4 * 9) + "\x01\x00\x00\x00" - got = dcerpc.call(0x02, stub) - s.close - } - rescue Timeout::Error - flunk('timeout') - end - end - def test_ncacn_ip_tcp_objectid_random - write = [ - "\x05\x00\x0b\x03\x10\x00\x00\x00\x48\x00\x00\x00\x00\x00\x00\x00\xd0\x16\xd0\x16\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x01\x00\x08\x83\xaf\xe1\x1f\x5d\xc9\x11\x91\xa4\x08\x00\x2b\x14\xa0\xfa\x03\x00\x00\x00\x04\x5d\x88\x8a\xeb\x1c\xc9\x11\x9f\xe8\x08\x00\x2b\x10\x48\x60\x02\x00\x00\x00", - "\005\000\000\203\020\000\000\000P\000\000\000\000\000\000\000(\000\000\000\000\000\002\000\254/u\300C\373\303g\t\323\025\362$WF\330\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000" - ] - read = [ - "\x05\x00\x0c\x03\x10\x00\x00\x00\x3c\x00\x00\x00\x00\x00\x00\x00\xd0\x16\xd0\x16\x12\x66\x00\x00\x04\x00\x31\x33\x35\x00\xec\xd7\x01\x00\x00\x00\x00\x00\x00\x00\x04\x5d\x88\x8a\xeb\x1c\xc9\x11\x9f\xe8\x08\x00\x2b\x10\x48\x60\x02\x00\x00\x00", - "\x05\x00\x02\x03\x10\x00\x00\x00\xb4\x00\x00\x00\x00\x00\x00\x00\x9c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc4\x49\xc2\xb8\x92\x78\x4e\x4f\xb3\xe7\xbf\x7e\x00\x2a\xd3\x39\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x4b\x00\x00\x00\x4b\x00\x00\x00\x05\x00\x13\x00\x0d\x80\xa9\x88\x10\xe5\xea\xd0\x11\x8d\x9b\x00\xa0\x24\x53\xc3\x37\x01\x00\x02\x00\x00\x00\x13\x00\x0d\x04\x5d\x88\x8a\xeb\x1c\xc9\x11\x9f\xe8\x08\x00\x2b\x10\x48\x60\x02\x00\x02\x00\x00\x00\x01\x00\x0b\x02\x00\x00\x00\x01\x00\x07\x02\x00\x08\x39\x01\x00\x09\x04\x00\x0a\x04\x0a\x3a\x00\x00\x00\x00\x00" - ] - setup_test(read, write) - begin - Timeout.timeout($_REX_TEST_TIMEOUT) { - s = Rex::Socket.create_tcp('PeerHost' => $_REX_TEST_SMB_HOST, 'PeerPort' => 135) - handle = Rex::Proto::DCERPC::Handle.new(['E1AF8308-5D1F-11C9-91A4-08002B14A0FA', '3.0'], 'ncacn_ip_tcp', $_REX_TEST_SMB_HOST, [135]) - assert_instance_of(Rex::Proto::DCERPC::Handle, handle, 'handle') - dcerpc = Rex::Proto::DCERPC::Client.new(handle, s, {'random_object_id' => 1}) - assert_instance_of(Rex::Proto::DCERPC::Client, dcerpc, 'bind') - - stub = "\x00" * (4 * 9) + "\x01\x00\x00\x00" - got = dcerpc.call(0x02, stub) - s.close - } - rescue Timeout::Error - flunk('timeout') - end - end - - # this test is the same as test_ncanc_ip_tcp - def test_setup_socket_ncacn_ip_tcp - end - - def test_setup_socket_ncacn_ip_tcp_nil_socket - read = ["\x05\x00\x0c\x03\x10\x00\x00\x00\x3c\x00\x00\x00\x00\x00\x00\x00\xd0\x16\xd0\x16\x56\x66\x00\x00\x04\x00\x31\x33\x35\x00\xcd\x71\x01\x00\x00\x00\x00\x00\x00\x00\x04\x5d\x88\x8a\xeb\x1c\xc9\x11\x9f\xe8\x08\x00\x2b\x10\x48\x60\x02\x00\x00\x00"] - write = ["\005\000\v\003\020\000\000\000H\000\000\000\000\000\000\000\320\026\320\026\000\000\000\000\001\000\000\000\000\000\001\000\010\203\257\341\037]\311\021\221\244\010\000+\024\240\372\003\000\000\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000"] - setup_test(read, write) - begin - Timeout.timeout($_REX_TEST_TIMEOUT) { - handle = Rex::Proto::DCERPC::Handle.new(['E1AF8308-5D1F-11C9-91A4-08002B14A0FA', '3.0'], 'ncacn_ip_tcp', $_REX_TEST_SMB_HOST, [135]) - assert_instance_of(Rex::Proto::DCERPC::Handle, handle, 'handle') - dcerpc = Rex::Proto::DCERPC::Client.new(handle, nil) - assert_instance_of(Rex::Proto::DCERPC::Client, dcerpc, 'bind') - } - rescue Timeout::Error - flunk('timeout') - end - end - - def test_setup_socket_ncacn_np_socket - read = ["\x82\x00\x00\x00", - "\x00\x00\x00\x55\xff\x53\x4d\x42\x72\x00\x00\x00\x00\x98\x01\x28\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x00\x00\xac\x0a\x11\x03\x00\x03\x0a\x00\x01\x00\x04\x11\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\xfd\xe3\x00\x80\xca\x3d\x91\x3c\x0b\xfd\xc5\x01\xe0\x01\x00\x10\x00\x8b\x3c\x73\xd2\x53\x9e\x28\x48\xa2\xac\x68\xae\xd1\x2e\x41\x5a", - "\x00\x00\x01\xb3\xff\x53\x4d\x42\x73\x16\x00\x00\xc0\x98\x01\x68\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x00\x08\xac\x0a\x04\xff\x00\xb3\x01\x00\x00\x63\x01\x88\x01\xa1\x82\x01\x5f\x30\x82\x01\x5b\xa0\x03\x0a\x01\x01\xa1\x0c\x06\x0a\x2b\x06\x01\x04\x01\x82\x37\x02\x02\x0a\xa2\x81\xa1\x04\x81\x9e\x4e\x54\x4c\x4d\x53\x53\x50\x00\x02\x00\x00\x00\x12\x00\x12\x00\x30\x00\x00\x00\x05\x02\x8a\x00\x4a\xda\x31\xb4\x0f\x33\x09\x9f\x00\x00\x00\x00\x00\x00\x00\x00\x5c\x00\x5c\x00\x42\x00\x00\x00\x57\x00\x49\x00\x4e\x00\x32\x00\x4b\x00\x42\x00\x41\x00\x53\x00\x45\x00\x02\x00\x12\x00\x57\x00\x49\x00\x4e\x00\x32\x00\x4b\x00\x42\x00\x41\x00\x53\x00\x45\x00\x01\x00\x12\x00\x57\x00\x49\x00\x4e\x00\x32\x00\x4b\x00\x42\x00\x41\x00\x53\x00\x45\x00\x04\x00\x12\x00\x77\x00\x69\x00\x6e\x00\x32\x00\x6b\x00\x62\x00\x61\x00\x73\x00\x65\x00\x03\x00\x12\x00\x77\x00\x69\x00\x6e\x00\x32\x00\x6b\x00\x62\x00\x61\x00\x73\x00\x65\x00\x00\x00\x00\x00\xa3\x81\xa1\x04\x81\x9e\x4e\x54\x4c\x4d\x53\x53\x50\x00\x02\x00\x00\x00\x12\x00\x12\x00\x30\x00\x00\x00\x05\x02\x8a\x00\x4a\xda\x31\xb4\x0f\x33\x09\x9f\x00\x00\x00\x00\x00\x00\x00\x00\x5c\x00\x5c\x00\x42\x00\x00\x00\x57\x00\x49\x00\x4e\x00\x32\x00\x4b\x00\x42\x00\x41\x00\x53\x00\x45\x00\x02\x00\x12\x00\x57\x00\x49\x00\x4e\x00\x32\x00\x4b\x00\x42\x00\x41\x00\x53\x00\x45\x00\x01\x00\x12\x00\x57\x00\x49\x00\x4e\x00\x32\x00\x4b\x00\x42\x00\x41\x00\x53\x00\x45\x00\x04\x00\x12\x00\x77\x00\x69\x00\x6e\x00\x32\x00\x6b\x00\x62\x00\x61\x00\x73\x00\x65\x00\x03\x00\x12\x00\x77\x00\x69\x00\x6e\x00\x32\x00\x6b\x00\x62\x00\x61\x00\x73\x00\x65\x00\x00\x00\x00\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x35\x2e\x30\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x4c\x41\x4e\x20\x4d\x61\x6e\x61\x67\x65\x72\x00", - "\x00\x00\x00\x23\xff\x53\x4d\x42\x73\x6d\x00\x00\xc0\x98\x01\x68\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x00\x08\xac\x0a\x00\x00\x00", - "\x00\x00\x00\x58\xff\x53\x4d\x42\x73\x00\x00\x00\x00\x98\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x01\x08\xac\x0a\x03\xff\x00\x58\x00\x00\x00\x2f\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x35\x2e\x30\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x4c\x41\x4e\x20\x4d\x61\x6e\x61\x67\x65\x72\x00\x57\x4f\x52\x4b\x47\x52\x4f\x55\x50\x00", - "\x00\x00\x00\x2e\xff\x53\x4d\x42\x75\x00\x00\x00\x00\x98\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x03\xff\x00\x2e\x00\x01\x00\x05\x00\x49\x50\x43\x00\x00", - "\x00\x00\x00\x87\xff\x53\x4d\x42\xa2\x00\x00\x00\x00\x98\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x2a\xff\x00\x87\x00\x00\x00\x40\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xff\x05\x00\x00\x00\x70\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x20\x00\x20\x00\x70\x00\x00\x00\x00\x00\x9b\x01\x12\x00\x9b\x01\x12\x00\x08\x00", - "\x00\x00\x00\x2f\xff\x53\x4d\x42\x2f\x00\x00\x00\x00\x98\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x06\xff\x00\x2f\x00\x48\x00\xff\xff\x00\x00\x00\x00\x00\x00", - "\x00\x00\x00\x80\xff\x53\x4d\x42\x2e\x00\x00\x00\x00\x98\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x0c\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x44\x00\x3c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x45\x00\x00\x05\x00\x0c\x03\x10\x00\x00\x00\x44\x00\x00\x00\x00\x00\x00\x00\xb8\x10\xb8\x10\x98\x2d\x01\x00\x0d\x00\x5c\x50\x49\x50\x45\x5c\x6e\x74\x73\x76\x63\x73\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x04\x5d\x88\x8a\xeb\x1c\xc9\x11\x9f\xe8\x08\x00\x2b\x10\x48\x60\x02\x00\x00\x00", - "\x00\x00\x00\x2f\xff\x53\x4d\x42\x2f\x00\x00\x00\x00\x98\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x06\xff\x00\x2f\x00\x64\x00\xff\xff\x00\x00\x00\x00\x00\x00", - "\x00\x00\x00\x70\xff\x53\x4d\x42\x2e\x00\x00\x00\x00\x98\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x0c\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x34\x00\x3c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x35\x00\x00\x05\x00\x02\x03\x10\x00\x00\x00\x34\x00\x00\x00\x00\x00\x00\x00\x1c\x00\x00\x00\x00\x00\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x34\x00\x00\xc0" - ] - - - write = [ - "\x81\x00\x00\x44\x20\x43\x4b\x46\x44\x45\x4e\x45\x43\x46\x44\x45\x46\x46\x43\x46\x47\x45\x46\x46\x43\x43\x41\x43\x41\x43\x41\x43\x41\x43\x41\x43\x41\x00\x20\x43\x41\x43\x41\x43\x41\x43\x41\x43\x41\x43\x41\x43\x41\x43\x41\x43\x41\x43\x41\x43\x41\x43\x41\x43\x41\x43\x41\x43\x41\x41\x41\x00", - "\x00\x00\x00\x54\xff\x53\x4d\x42\x72\x00\x00\x00\x00\x18\x01\x28\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x00\x00\xac\x0a\x00\x31\x00\x02\x4c\x41\x4e\x4d\x41\x4e\x31\x2e\x30\x00\x02\x4c\x4d\x31\x2e\x32\x58\x30\x30\x32\x00\x02\x4e\x54\x20\x4c\x41\x4e\x4d\x41\x4e\x20\x31\x2e\x30\x00\x02\x4e\x54\x20\x4c\x4d\x20\x30\x2e\x31\x32\x00", - "\x00\x00\x00\xb0\xff\x53\x4d\x42\x73\x00\x00\x00\x00\x18\x01\x28\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x00\x00\xac\x0a\x0c\xff\x00\x00\x00\xdf\xff\x02\x00\x01\x00\x00\x00\x00\x00\x52\x00\x00\x00\x00\x00\x5c\xd0\x00\x80\x75\x00\x60\x50\x06\x06\x2b\x06\x01\x05\x05\x02\xa0\x46\x30\x44\xa0\x0e\x30\x0c\x06\x0a\x2b\x06\x01\x04\x01\x82\x37\x02\x02\x0a\xa2\x32\x04\x30\x4e\x54\x4c\x4d\x53\x53\x50\x00\x01\x00\x00\x00\x01\x02\x08\x00\x00\x00\x00\x00\x20\x00\x00\x00\x10\x00\x10\x00\x20\x00\x00\x00\x31\x41\x44\x37\x44\x6e\x4a\x54\x56\x79\x6b\x58\x47\x59\x59\x4d\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x32\x31\x39\x35\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x35\x2e\x30\x00", - "\x00\x00\x00\xfa\xff\x53\x4d\x42\x73\x00\x00\x00\x00\x18\x01\x28\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x00\x08\xac\x0a\x0c\xff\x00\x00\x00\xdf\xff\x02\x00\x01\x00\x00\x00\x00\x00\x9c\x00\x00\x00\x00\x00\x5c\xd0\x00\x80\xbf\x00\xa1\x81\x99\x30\x81\x96\xa2\x81\x93\x04\x81\x90\x4e\x54\x4c\x4d\x53\x53\x50\x00\x03\x00\x00\x00\x18\x00\x18\x00\x40\x00\x00\x00\x18\x00\x18\x00\x58\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x20\x00\x20\x00\x70\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02\x08\x00\x3a\xc1\xe6\x27\x57\xae\x58\x51\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x8c\x4d\x20\xdf\x63\xbd\xda\xdc\x62\x0d\x49\xe7\xf2\x7a\x86\x88\xe9\x5f\x03\x95\xbb\x9b\xc6\x85\x31\x00\x41\x00\x44\x00\x37\x00\x44\x00\x6e\x00\x4a\x00\x54\x00\x56\x00\x79\x00\x6b\x00\x58\x00\x47\x00\x59\x00\x59\x00\x4d\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x32\x31\x39\x35\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x35\x2e\x30\x00", - "\x00\x00\x00\x62\xff\x53\x4d\x42\x73\x00\x00\x00\x00\x18\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x00\x00\xac\x0a\x0d\xff\x00\x00\x00\xdf\xff\x02\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x25\x00\x00\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x32\x31\x39\x35\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x35\x2e\x30\x00", - "\x00\x00\x00\x37\xff\x53\x4d\x42\x75\x00\x00\x00\x00\x18\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x01\x08\xac\x0a\x04\xff\x00\x00\x00\x00\x00\x01\x00\x0c\x00\x00\x49\x50\x43\x24\x00\x3f\x3f\x3f\x3f\x3f\x00", - "\x00\x00\x00\x5c\xff\x53\x4d\x42\xa2\x00\x00\x00\x00\x18\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x18\xff\x00\x00\x00\x00\x08\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x09\x00\x5c\x42\x52\x4f\x57\x53\x45\x52\x00", - "\x00\x00\x00\x87\xff\x53\x4d\x42\x2f\x00\x00\x00\x00\x18\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x0e\xff\x00\x00\x00\x00\x40\x00\x00\x00\x00\xff\xff\xff\xff\x08\x00\x48\x00\x00\x00\x48\x00\x3f\x00\x00\x00\x00\x00\x48\x00\x05\x00\x0b\x03\x10\x00\x00\x00\x48\x00\x00\x00\x00\x00\x00\x00\xd0\x16\xd0\x16\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x01\x00\xc8\x4f\x32\x4b\x70\x16\xd3\x01\x12\x78\x5a\x47\xbf\x6e\xe1\x88\x03\x00\x00\x00\x04\x5d\x88\x8a\xeb\x1c\xc9\x11\x9f\xe8\x08\x00\x2b\x10\x48\x60\x02\x00\x00\x00", - "\000\000\0007\377SMB.\000\000\000\000\030\001 \000\000\000\000\000\000\000\000\000\000\000\000\000\010/\252\001\010\254\n\n\377\000\000\000\000@\000\000\000\000\200\273\200\273\000\000\000\000\000\000\000\000" - ] - setup_test(read, write) - begin - Timeout.timeout($_REX_TEST_TIMEOUT) { - s = Rex::Socket.create_tcp('PeerHost' => $_REX_TEST_SMB_HOST, 'PeerPort' => 139) - - handle = Rex::Proto::DCERPC::Handle.new(['4b324fc8-1670-01d3-1278-5a47bf6ee188', '3.0'], 'ncacn_np', $_REX_TEST_SMB_HOST, ['\BROWSER']) - assert_instance_of(Rex::Proto::DCERPC::Handle, handle, 'handle') - dcerpc = Rex::Proto::DCERPC::Client.new(handle, s) - assert_instance_of(Rex::Proto::DCERPC::Client, dcerpc, 'bind') - } - rescue Timeout::Error - flunk('timeout') - end - end - - # this test is the same as test_dcerpc_over_smb - def test_setup_socket_ncacn_np_filehandle - end - - # test connect to a dcerpc service via ncacn_np, without passing a socket. - # this should test the autosocket & autosmb foo - def test_setup_socket_ncacn_np_nil_socket - -write = [ -"\x00\x00\x00\x54\xff\x53\x4d\x42\x72\x00\x00\x00\x00\x18\x01\x28\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x00\x00\xac\x0a\x00\x31\x00\x02\x4c\x41\x4e\x4d\x41\x4e\x31\x2e\x30\x00\x02\x4c\x4d\x31\x2e\x32\x58\x30\x30\x32\x00\x02\x4e\x54\x20\x4c\x41\x4e\x4d\x41\x4e\x20\x31\x2e\x30\x00\x02\x4e\x54\x20\x4c\x4d\x20\x30\x2e\x31\x32\x00", -"\x00\x00\x00\xb0\xff\x53\x4d\x42\x73\x00\x00\x00\x00\x18\x01\x28\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x00\x00\xac\x0a\x0c\xff\x00\x00\x00\xdf\xff\x02\x00\x01\x00\x00\x00\x00\x00\x52\x00\x00\x00\x00\x00\x5c\xd0\x00\x80\x75\x00\x60\x50\x06\x06\x2b\x06\x01\x05\x05\x02\xa0\x46\x30\x44\xa0\x0e\x30\x0c\x06\x0a\x2b\x06\x01\x04\x01\x82\x37\x02\x02\x0a\xa2\x32\x04\x30\x4e\x54\x4c\x4d\x53\x53\x50\x00\x01\x00\x00\x00\x01\x02\x08\x00\x00\x00\x00\x00\x20\x00\x00\x00\x10\x00\x10\x00\x20\x00\x00\x00\x31\x41\x44\x37\x44\x6e\x4a\x54\x56\x79\x6b\x58\x47\x59\x59\x4d\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x32\x31\x39\x35\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x35\x2e\x30\x00", -"\000\000\000\372\377SMBs\000\000\000\000\030\001(\000\000\000\000\000\000\000\000\000\000\000\000\000\000/\252\000\010\254\n\f\377\000\000\000\337\377\002\000\001\000\000\000\000\000\234\000\000\000\000\000\\\320\000\200\277\000\241\201\2310\201\226\242\201\223\004\201\220NTLMSSP\000\003\000\000\000\030\000\030\000@\000\000\000\030\000\030\000X\000\000\000\000\000\000\000p\000\000\000\000\000\000\000p\000\000\000 \000 \000p\000\000\000\000\000\000\000\000\000\000\000\001\002\010\000:\301\346'W\256XQ\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\314\256\352Sm%S:f/\335\230\200\327K\023\241\366\353vX\016\256\3571\000A\000D\0007\000D\000n\000J\000T\000V\000y\000k\000X\000G\000Y\000Y\000M\000Windows 2000 2195\000Windows 2000 5.0\000", -"\x00\x00\x00\x62\xff\x53\x4d\x42\x73\x00\x00\x00\x00\x18\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x00\x00\xac\x0a\x0d\xff\x00\x00\x00\xdf\xff\x02\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x25\x00\x00\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x32\x31\x39\x35\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x35\x2e\x30\x00", -"\x00\x00\x00\x37\xff\x53\x4d\x42\x75\x00\x00\x00\x00\x18\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x01\x08\xac\x0a\x04\xff\x00\x00\x00\x00\x00\x01\x00\x0c\x00\x00\x49\x50\x43\x24\x00\x3f\x3f\x3f\x3f\x3f\x00", -"\x00\x00\x00\x5c\xff\x53\x4d\x42\xa2\x00\x00\x00\x00\x18\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x18\xff\x00\x00\x00\x00\x08\x00\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x09\x00\x5c\x42\x52\x4f\x57\x53\x45\x52\x00", -"\x00\x00\x00\x87\xff\x53\x4d\x42\x2f\x00\x00\x00\x00\x18\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x0e\xff\x00\x00\x00\x00\x40\x00\x00\x00\x00\xff\xff\xff\xff\x08\x00\x48\x00\x00\x00\x48\x00\x3f\x00\x00\x00\x00\x00\x48\x00\x05\x00\x0b\x03\x10\x00\x00\x00\x48\x00\x00\x00\x00\x00\x00\x00\xd0\x16\xd0\x16\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x01\x00\xc8\x4f\x32\x4b\x70\x16\xd3\x01\x12\x78\x5a\x47\xbf\x6e\xe1\x88\x03\x00\x00\x00\x04\x5d\x88\x8a\xeb\x1c\xc9\x11\x9f\xe8\x08\x00\x2b\x10\x48\x60\x02\x00\x00\x00", -"\000\000\0007\377SMB.\000\000\000\000\030\001 \000\000\000\000\000\000\000\000\000\000\000\000\000\010/\252\001\010\254\n\n\377\000\000\000\000@\000\000\000\000\200\273\200\273\000\000\000\000\000\000\000\000", -"\x00\x00\x00\xa3\xff\x53\x4d\x42\x2f\x00\x00\x00\x00\x18\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x0e\xff\x00\x00\x00\x00\x40\x00\x00\x00\x00\xff\xff\xff\xff\x08\x00\x64\x00\x00\x00\x64\x00\x3f\x00\x00\x00\x00\x00\x64\x00\x05\x00\x00\x03\x10\x00\x00\x00\x64\x00\x00\x00\x00\x00\x00\x00\x4c\x00\x00\x00\x00\x00\x30\x00\x01\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x41\x00\x41\x00\x41\x00\x41\x00\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x03\x00\x04\x00\x00\x00\x41\x41\x41\x41\x05\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x42\x00\x42\x00\x42\x00\x42\x00\x00\x00\x00\x00\x04\x00\x00\x00\x0a\x00\x00\x00", -"\000\000\0007\377SMB.\000\000\000\000\030\001 \000\000\000\000\000\000\000\000\000\000\000\000\000\010/\252\001\010\254\n\n\377\000\000\000\000@\000\000\000\000\200\273\200\273\000\000\000\000\000\000\000\000" -] -read = [ -"\x00\x00\x00\x55\xff\x53\x4d\x42\x72\x00\x00\x00\x00\x98\x01\x28\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x00\x00\xac\x0a\x11\x03\x00\x03\x0a\x00\x01\x00\x04\x11\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\xfd\xe3\x00\x80\x20\x5f\xf5\x32\x11\xfd\xc5\x01\xe0\x01\x00\x10\x00\x8b\x3c\x73\xd2\x53\x9e\x28\x48\xa2\xac\x68\xae\xd1\x2e\x41\x5a", -"\x00\x00\x01\xb3\xff\x53\x4d\x42\x73\x16\x00\x00\xc0\x98\x01\x68\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x00\x08\xac\x0a\x04\xff\x00\xb3\x01\x00\x00\x63\x01\x88\x01\xa1\x82\x01\x5f\x30\x82\x01\x5b\xa0\x03\x0a\x01\x01\xa1\x0c\x06\x0a\x2b\x06\x01\x04\x01\x82\x37\x02\x02\x0a\xa2\x81\xa1\x04\x81\x9e\x4e\x54\x4c\x4d\x53\x53\x50\x00\x02\x00\x00\x00\x12\x00\x12\x00\x30\x00\x00\x00\x05\x02\x8a\x00\xf5\xe4\x8c\x90\x50\xe3\xcd\x63\x00\x00\x00\x00\x00\x00\x00\x00\x5c\x00\x5c\x00\x42\x00\x00\x00\x57\x00\x49\x00\x4e\x00\x32\x00\x4b\x00\x42\x00\x41\x00\x53\x00\x45\x00\x02\x00\x12\x00\x57\x00\x49\x00\x4e\x00\x32\x00\x4b\x00\x42\x00\x41\x00\x53\x00\x45\x00\x01\x00\x12\x00\x57\x00\x49\x00\x4e\x00\x32\x00\x4b\x00\x42\x00\x41\x00\x53\x00\x45\x00\x04\x00\x12\x00\x77\x00\x69\x00\x6e\x00\x32\x00\x6b\x00\x62\x00\x61\x00\x73\x00\x65\x00\x03\x00\x12\x00\x77\x00\x69\x00\x6e\x00\x32\x00\x6b\x00\x62\x00\x61\x00\x73\x00\x65\x00\x00\x00\x00\x00\xa3\x81\xa1\x04\x81\x9e\x4e\x54\x4c\x4d\x53\x53\x50\x00\x02\x00\x00\x00\x12\x00\x12\x00\x30\x00\x00\x00\x05\x02\x8a\x00\xf5\xe4\x8c\x90\x50\xe3\xcd\x63\x00\x00\x00\x00\x00\x00\x00\x00\x5c\x00\x5c\x00\x42\x00\x00\x00\x57\x00\x49\x00\x4e\x00\x32\x00\x4b\x00\x42\x00\x41\x00\x53\x00\x45\x00\x02\x00\x12\x00\x57\x00\x49\x00\x4e\x00\x32\x00\x4b\x00\x42\x00\x41\x00\x53\x00\x45\x00\x01\x00\x12\x00\x57\x00\x49\x00\x4e\x00\x32\x00\x4b\x00\x42\x00\x41\x00\x53\x00\x45\x00\x04\x00\x12\x00\x77\x00\x69\x00\x6e\x00\x32\x00\x6b\x00\x62\x00\x61\x00\x73\x00\x65\x00\x03\x00\x12\x00\x77\x00\x69\x00\x6e\x00\x32\x00\x6b\x00\x62\x00\x61\x00\x73\x00\x65\x00\x00\x00\x00\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x35\x2e\x30\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x4c\x41\x4e\x20\x4d\x61\x6e\x61\x67\x65\x72\x00", -"\x00\x00\x00\x23\xff\x53\x4d\x42\x73\x6d\x00\x00\xc0\x98\x01\x68\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x00\x08\xac\x0a\x00\x00\x00", -"\x00\x00\x00\x58\xff\x53\x4d\x42\x73\x00\x00\x00\x00\x98\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\xaa\x01\x08\xac\x0a\x03\xff\x00\x58\x00\x00\x00\x2f\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x35\x2e\x30\x00\x57\x69\x6e\x64\x6f\x77\x73\x20\x32\x30\x30\x30\x20\x4c\x41\x4e\x20\x4d\x61\x6e\x61\x67\x65\x72\x00\x57\x4f\x52\x4b\x47\x52\x4f\x55\x50\x00", -"\x00\x00\x00\x2e\xff\x53\x4d\x42\x75\x00\x00\x00\x00\x98\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x03\xff\x00\x2e\x00\x01\x00\x05\x00\x49\x50\x43\x00\x00", -"\x00\x00\x00\x87\xff\x53\x4d\x42\xa2\x00\x00\x00\x00\x98\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x2a\xff\x00\x87\x00\x00\x00\x40\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xff\x05\x00\x00\x00\x00\x00\x00\x00\x00\xa0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\xff\x9b\x01\x12\x00\x9b\x01\x12\x00\x12\x00", -"\x00\x00\x00\x2f\xff\x53\x4d\x42\x2f\x00\x00\x00\x00\x98\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x06\xff\x00\x2f\x00\x48\x00\xff\xff\x00\x00\x00\x00\x00\x00", -"\x00\x00\x00\x80\xff\x53\x4d\x42\x2e\x00\x00\x00\x00\x98\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x0c\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x44\x00\x3c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x45\x00\x00\x05\x00\x0c\x03\x10\x00\x00\x00\x44\x00\x00\x00\x00\x00\x00\x00\xb8\x10\xb8\x10\xbe\x2f\x01\x00\x0d\x00\x5c\x50\x49\x50\x45\x5c\x6e\x74\x73\x76\x63\x73\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x04\x5d\x88\x8a\xeb\x1c\xc9\x11\x9f\xe8\x08\x00\x2b\x10\x48\x60\x02\x00\x00\x00", -"\x00\x00\x00\x2f\xff\x53\x4d\x42\x2f\x00\x00\x00\x00\x98\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x06\xff\x00\x2f\x00\x64\x00\xff\xff\x00\x00\x00\x00\x00\x00", -"\x00\x00\x00\x70\xff\x53\x4d\x42\x2e\x00\x00\x00\x00\x98\x01\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x2f\xaa\x01\x08\xac\x0a\x0c\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x34\x00\x3c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x35\x00\x25\x05\x00\x02\x03\x10\x00\x00\x00\x34\x00\x00\x00\x00\x00\x00\x00\x1c\x00\x00\x00\x00\x00\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x34\x00\x00\xc0", -] - setup_test(read, write) - - Timeout.timeout($_REX_TEST_TIMEOUT) { - handle = Rex::Proto::DCERPC::Handle.new(['4b324fc8-1670-01d3-1278-5a47bf6ee188', '3.0'], 'ncacn_np', $_REX_TEST_SMB_HOST, ['\BROWSER']) - dcerpc = Rex::Proto::DCERPC::Client.new(handle, nil) - assert_instance_of(Rex::Proto::DCERPC::Client, dcerpc, 'bind') - - require 'rex/proto/dcerpc/ndr' - stub = - Rex::Proto::DCERPC::NDR.long(1) + - Rex::Proto::DCERPC::NDR.UnicodeConformantVaryingString('AAAA') + - - # Type 33 - Rex::Proto::DCERPC::NDR.long(1) + - Rex::Proto::DCERPC::NDR.short(2) + - Rex::Proto::DCERPC::NDR.short(3) + - Rex::Proto::DCERPC::NDR.UniConformantArray('AAAA') + - - Rex::Proto::DCERPC::NDR.UnicodeConformantVaryingString('BBBB') + - Rex::Proto::DCERPC::NDR.long(4) + - Rex::Proto::DCERPC::NDR.long(10); - - response = dcerpc.call(48, stub) - assert_equal(response.length, 28, 'response') - } - end - - # makes two calls to create_tcp, first should raise Rex::ConnectionRefused, second should connect - def test_setup_socket_ncacn_np_nil_socket_first_connect_refused - - end - - def test_read - end - - def test_write - end -end - -rescue LoadError -end - diff --git a/lib/rex/proto/dcerpc/handle.rb.ut.rb b/lib/rex/proto/dcerpc/handle.rb.ut.rb deleted file mode 100644 index e25031923f..0000000000 --- a/lib/rex/proto/dcerpc/handle.rb.ut.rb +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'rex/test' -require 'rex/exceptions' -require 'rex/proto/dcerpc/handle' - -class Rex::Proto::DCERPC::Handle::UnitTest < Test::Unit::TestCase - Klass = Rex::Proto::DCERPC::Handle - - def test_ncacn_np - uuid = ['6bffd098-a112-3610-9833-46c3f87e345a', '1.0'] - protocol = 'ncacn_np' - host = '1.2.3.4' - options = ['\wkssvc'] - i = Klass.new(uuid, protocol, host, options) - assert(i, 'new') - assert_equal('6bffd098-a112-3610-9833-46c3f87e345a:1.0@ncacn_np:1.2.3.4[\wkssvc]', i.to_s, 'as string') - assert_equal(uuid, i.uuid, 'uuid') - assert_equal(protocol, i.protocol, 'protocol') - assert_equal(options, i.options, 'options') - end - - def test_ncacn_ip_tcp - uuid = ['6bffd098-a112-3610-9833-46c3f87e345a', '1.0'] - protocol = 'ncacn_ip_tcp' - host = '1.2.3.4' - options = [80] - i = Klass.new(uuid, protocol, host, options) - assert(i, 'new') - assert_equal('6bffd098-a112-3610-9833-46c3f87e345a:1.0@ncacn_ip_tcp:1.2.3.4[80]', i.to_s, 'as string') - assert_equal(uuid, i.uuid, 'uuid') - assert_equal(protocol, i.protocol, 'protocol') - assert_equal(options, i.options, 'options') - end - - def test_ncacn_ip_udp - uuid = ['6bffd098-a112-3610-9833-46c3f87e345a', '1.0'] - protocol = 'ncacn_ip_udp' - host = '1.2.3.4' - options = [80] - i = Klass.new(uuid, protocol, host, options) - assert(i, 'new') - assert_equal('6bffd098-a112-3610-9833-46c3f87e345a:1.0@ncacn_ip_udp:1.2.3.4[80]', i.to_s, 'as string') - assert_equal(uuid, i.uuid, 'uuid') - assert_equal(protocol, i.protocol, 'protocol') - assert_equal(options, i.options, 'options') - end - - def test_ncacn_http - uuid = ['6bffd098-a112-3610-9833-46c3f87e345a', '1.0'] - protocol = 'ncacn_http' - host = '1.2.3.4' - options = [80] - i = Klass.new(uuid, protocol, host, options) - assert(i, 'new') - assert_equal(i.to_s, '6bffd098-a112-3610-9833-46c3f87e345a:1.0@ncacn_http:1.2.3.4[80]', 'as string') - assert_equal(uuid, i.uuid, 'uuid') - assert_equal(protocol, i.protocol, 'protocol') - assert_equal(options, i.options, 'options') - end - - def test_invalid - assert_raise(Rex::ArgumentError, 'invalid uuid') { Klass.new(['a', '1.0'], 'ncacn_ip_tcp', '1.2.3.4', [80]) } - assert_raise(Rex::ArgumentError, 'invalid uuid version') { Klass.new(['6bffnd098-a112-3610-9833-46c3f87e345a', 'b'], 'ncacn_ip_tcp', '1.2.3.4', [80]) } - assert_raise(Rex::ArgumentError, 'invalid proto') { Klass.new(['6bffnd098-a112-3610-9833-46c3f87e345a', '1.0'], 'ncacn_ip_bmc', '1.2.3.4', [80]) } - assert_raise(Rex::ArgumentError, 'invalid empty uuid') { Klass.new([nil, '1.0'], 'ncacn_ip_tcp', '1.2.3.4', [80]) } - end - - def test_parser - handle = '6bffd098-a112-3610-9833-46c3f87e345a:1.0@ncacn_ip_tcp:10.4.10.10[80]' - i = Klass.parse( handle ) - assert(i) - assert_equal(['6bffd098-a112-3610-9833-46c3f87e345a', '1.0'], i.uuid, 'uuid') - assert_equal('ncacn_ip_tcp', i.protocol, 'protocol') - assert_equal('10.4.10.10', i.address, 'address') - assert_equal(['80'], i.options, 'options') - end - - def test_parser_invalid - handle = '6bffd098-a112-3610-9833-46c3f87e345a:1.0@ncacn_ip_tcp:10.4.10.10[80' - assert_raise(Rex::ArgumentError, 'invalid handle (parser)') { Klass.parse(handle) } - end -end diff --git a/lib/rex/proto/dcerpc/ndr.rb.ut.rb b/lib/rex/proto/dcerpc/ndr.rb.ut.rb deleted file mode 100644 index 70529d0458..0000000000 --- a/lib/rex/proto/dcerpc/ndr.rb.ut.rb +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'rex/test' -require 'rex/exceptions' -require 'rex/proto/dcerpc/ndr' - -class Rex::Proto::DCERPC::NDR::UnitTest < Test::Unit::TestCase - - Klass = Rex::Proto::DCERPC::NDR - - def test_align - assert_equal(0, Klass.align('').length, 'align 0') - assert_equal(3, Klass.align('f').length, 'align 1') - assert_equal(2, Klass.align('fo').length, 'align 2') - assert_equal(1, Klass.align('foo').length, 'align 3') - assert_equal(0, Klass.align('fooo').length, 'align 4') - assert_equal(3, Klass.align('foooo').length, 'align 5') - end - - def test_numbers - assert_equal("\x0a\x00\x00\x00", Klass.long(10), 'long') - assert_equal("\x0a\x00", Klass.short(10), 'short') - assert_equal("\x0a", Klass.byte(10), 'byte') - end - - def test_conformant_array - assert_equal("\x05\x00\x00\x00aaaaa", Klass.UniConformantArray('aaaaa').slice(0,9), 'UniConformantArray') - assert_equal(12, Klass.UniConformantArray('aaaaa').length, 'UniConformantArray length') - end - - def test_conformant_string - assert_equal("\x06\x00\x00\x00" + "\x00\x00\x00\x00" + "\x06\x00\x00\x00" "a\x00a\x00a\x00a\x00a\x00\x00\x00", Klass.UnicodeConformantVaryingString('aaaaa').slice(0,4+4+4+12), 'UniConformantVaryingString') - assert_equal(24, Klass.UnicodeConformantVaryingString('aaaaa').length, 'UniConformantVaryingString length') - - assert_equal("\x02\x00\x00\x00" + "\x00\x00\x00\x00" + "\x02\x00\x00\x00" "aa\x00\x00", Klass.UnicodeConformantVaryingStringPreBuilt('aa' + "\x00\x00"), 'UniConformantVaryingStringPreBuilt') - assert_equal(16, Klass.UnicodeConformantVaryingStringPreBuilt('aa' + "\x00\x00").length, 'UniConformantVaryingStringPreBuilt length') - end - -end diff --git a/lib/rex/proto/dcerpc/packet.rb.ut.rb b/lib/rex/proto/dcerpc/packet.rb.ut.rb deleted file mode 100644 index a3c62554b0..0000000000 --- a/lib/rex/proto/dcerpc/packet.rb.ut.rb +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'rex/test' -require 'rex/proto/dcerpc/packet' - -class Rex::Proto::DCERPC::Packet::UnitTest < Test::Unit::TestCase - - Klass = Rex::Proto::DCERPC::Packet - - def test_parse - - actual = Klass.make_bind('367abb81-9844-35f1-ad32-98f038001003', '2.0') - expected = ["\005\000\v\003\020\000\000\000H\000\000\000\000\000\000\000\320\026\320\026\000\000\000\000\001\000\000\000\000\000\001\000\201\273z6D\230\3615\2552\230\3608\000\020\003\002\000\000\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000", 0] - assert_equal(expected, actual, 'bind') - - srand(0) - actual = Klass.make_bind_fake_multi('367abb81-9844-35f1-ad32-98f038001003', '2.0') - expected = [ "\005\000\v\003\020\000\000\0004\003\000\000\000\000\000\000\320\026\320\026\000\000\000\000\022\000\000\000\000\000\001\000u\300C\373\303g\t\323\025\362$WF\330X\214\002\000\001\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000\001\000\001\000\346'W\256XQ\245\031MH\t\224s\320\363\305\000\000\002\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000\002\000\001\000c\330\261\363\035\223\223\216\247 \301\t\271\177 \037\002\000\000\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000\003\000\001\000\227\243\376\313r\267\034\"\200\200\2445\205&\350\364\001\000\003\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000\004\000\001\000\204i*\272\037x\001A\347\2519#fw\v\256\002\000\003\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000\005\000\001\000\200\216c5\214y\252T\313D\006\304/\177\364\203\004\000\000\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000\006\000\001\000\264\350N\217\224\343\272\027\317\215uU01E\251\003\000\000\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000\a\000\001\000_\305^\000q\262$\2420]\203b*\315p\347\005\000\001\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000\010\000\001\000\177\000\212r+\272\177\027\273\202yb>\243\336{\003\000\002\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000\t\000\001\000\256\343\224\3212\233\016):\301$\nV+h\v\002\000\003\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000\n\000\001\000P \266\200&\023\256*s\270\274\350M\036\030}\002\000\003\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000\v\000\001\000^\342k\rp(H\023_H\232\302\370\264C\354\005\000\002\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000\f\000\001\000`\004\303\355\213\374V\315ymK\270\020\230\235\225\001\000\000\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000\r\000\001\000\274yvu\275S\241h\240\344\373\373yF\325\037\005\000\003\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000\016\000\001\000\201\273z6D\230\3615\2552\230\3608\000\020\003\002\000\000\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000\017\000\001\000\270\230O)\022(\266\317\v\246o]\371\201\337v\004\000\000\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000\020\000\001\000}\030C\322\357\003\352\314\346#\326\376\275\305\327+\000\000\003\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000\021\000\001\000h\324\212\266\353\245}\234o\350\002\e\323\331\2275\003\000\002\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000", 14] - assert_equal(expected, actual, 'bind fake multi') - - actual = Klass.make_alter_context('367abb81-9844-35f1-ad32-98f038001003', '2.0') - expected = "\005\000\016\003\020\000\000\000H\000\000\000\000\000\000\000\320\026\320\026\000\000\000\000\001\000\000\000\000\000\001\000\201\273z6D\230\3615\2552\230\3608\000\020\003\002\000\000\000\004]\210\212\353\034\311\021\237\350\010\000+\020H`\002\000\000\000" - assert_equal(expected, actual, 'alter context') - - actual = Klass.make_request(1337, '', 1024, 7331) - expected = ["\005\000\000\003\020\000\000\000\030\000\000\000\000\000\000\000\000\000\000\000\243\0349\005"] - assert_equal(expected, actual, 'make_request with no stub') - - actual = Klass.make_request(1337, 'ABCD', 1024, 7331) - expected = ["\005\000\000\003\020\000\000\000\034\000\000\000\000\000\000\000\004\000\000\000\243\0349\005ABCD"] - assert_equal(expected, actual, 'make_request with stub') - - actual = Klass.make_request(1337, 'ABCD', 3, 7331) - expected = ["\005\000\000\001\020\000\000\000\e\000\000\000\000\000\000\000\003\000\000\000\243\0349\005ABC", "\005\000\000\002\020\000\000\000\031\000\000\000\000\000\000\000\001\000\000\000\243\0349\005D"] - assert_equal(expected, actual, 'make_request with 2 frags') - - actual = Klass.make_request(1337, 'ABCD', 1, 7331) - expected = ["\005\000\000\001\020\000\000\000\031\000\000\000\000\000\000\000\001\000\000\000\243\0349\005A", "\005\000\000\000\020\000\000\000\031\000\000\000\000\000\000\000\001\000\000\000\243\0349\005B", "\005\000\000\000\020\000\000\000\031\000\000\000\000\000\000\000\001\000\000\000\243\0349\005C", "\005\000\000\002\020\000\000\000\031\000\000\000\000\000\000\000\001\000\000\000\243\0349\005D"] - assert_equal(expected, actual, 'make_request with 4 frags') - - - actual = Klass.make_request(1337, '', 1024, 7331, '367abb81-9844-35f1-ad32-98f038001003') - expected = ["\005\000\000\x83\020\000\000\000\030\000\000\000\000\000\000\000\000\000\000\000\243\0349\005\201\273z6D\230\3615\2552\230\3608\000\020\003"] - assert_equal(expected, actual, 'make_request with no stub, with object_id') - - actual = Klass.make_request(1337, 'ABCD', 1024, 7331, '367abb81-9844-35f1-ad32-98f038001003') - expected = ["\005\000\000\x83\020\000\000\000\034\000\000\000\000\000\000\000\004\000\000\000\243\0349\005\201\273z6D\230\3615\2552\230\3608\000\020\003ABCD"] - assert_equal(expected, actual, 'make_request with stub, with object_id') - - actual = Klass.make_request(1337, 'ABCD', 1, 7331, '367abb81-9844-35f1-ad32-98f038001003') - expected = ["\005\000\000\x81\020\000\000\000\031\000\000\000\000\000\000\000\001\000\000\000\243\0349\005\201\273z6D\230\3615\2552\230\3608\000\020\003A", "\005\000\000\x80\020\000\000\000\031\000\000\000\000\000\000\000\001\000\000\000\243\0349\005\201\273z6D\230\3615\2552\230\3608\000\020\003B", "\005\000\000\x80\020\000\000\000\031\000\000\000\000\000\000\000\001\000\000\000\243\0349\005\201\273z6D\230\3615\2552\230\3608\000\020\003C", "\005\000\000\x82\020\000\000\000\031\000\000\000\000\000\000\000\001\000\000\000\243\0349\005\201\273z6D\230\3615\2552\230\3608\000\020\003D"] - assert_equal(expected, actual, 'make_request with 4 frags') - end -end diff --git a/lib/rex/proto/dcerpc/response.rb.ut.rb b/lib/rex/proto/dcerpc/response.rb.ut.rb deleted file mode 100644 index 1914e07170..0000000000 --- a/lib/rex/proto/dcerpc/response.rb.ut.rb +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'rex/test' -require 'rex/proto/dcerpc/response' - -class Rex::Proto::DCERPC::Response::UnitTest < Test::Unit::TestCase - - Klass = Rex::Proto::DCERPC::Response - - def test_parse - - end -end diff --git a/lib/rex/proto/dcerpc/uuid.rb.ut.rb b/lib/rex/proto/dcerpc/uuid.rb.ut.rb deleted file mode 100644 index e1f36c4ee9..0000000000 --- a/lib/rex/proto/dcerpc/uuid.rb.ut.rb +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'rex/test' -require 'rex/exceptions' -require 'rex/proto/dcerpc/uuid' - -class Rex::Proto::DCERPC::UUID::UnitTest < Test::Unit::TestCase - - Klass = Rex::Proto::DCERPC::UUID - - def test_is_uuid - assert(Klass.is?('afa8bd80-7d8a-11c9-bef4-08002b102989'), 'valid') - assert(!Klass.is?('afa8bd80-7d8a-11c9-bef4-08002b10298'), 'too short') - assert(!Klass.is?('afa8bd80-7d8a-11c9-bef4-08002b10298Z'), 'invalid character') - assert(!Klass.is?('afa8bd80-7d8a-11c9-bef4a08002b10298a'), 'missing dash') - assert(!Klass.is?('afa8bd80-7d8a-11c9-bef-a08002b10298a'), 'dash in wrong place') - assert_raise(Rex::ArgumentError, 'pack - too short') { Klass.is?(nil) } - end - - def test_lookup - assert_equal(Klass.uuid_by_name('MGMT'), 'afa8bd80-7d8a-11c9-bef4-08002b102989', 'uuid_by_name') - assert_equal(Klass.vers_by_name('MGMT'), '2.0', 'vers_by_name') - assert(!Klass.uuid_by_name('NO_SUCH_UUID'), 'uuid_by_name - invalid') - assert(!Klass.vers_by_name('NO_SUCH_UUID'), 'vers_by_name - invalid') - end - - def test_packing - uuid = '367abb81-9844-35f1-ad32-98f038001003' - assert_equal(Klass.uuid_pack(uuid), "\201\273z6D\230\3615\2552\230\3608\000\020\003", 'pack') - assert_equal(Klass.uuid_unpack("\201\273z6D\230\3615\2552\230\3608\000\020\003"), uuid, 'unpack') - assert_raise(Rex::ArgumentError, 'pack - too short') { Klass.uuid_pack('foo') } - assert_raise(Rex::ArgumentError, 'unpack - too short') { Klass.uuid_unpack('foo') } - end - - def test_xfer - assert_equal(Klass.xfer_syntax_uuid(), "\004]\210\212\353\034\311\021\237\350\010\000+\020H`", 'xfer_syntax_uuid') - assert_equal(Klass.xfer_syntax_vers(), '2.0', 'xfer_syntax_vers') - end - - def test_vers - assert_equal(Klass.vers_to_nums('2.0'), [2, 0], 'vers_to_nums') - assert_equal(Klass.vers_to_nums('2'), [2, 0], 'vers_to_nums (short)') - end -end diff --git a/lib/rex/proto/drda/constants.rb.ut.rb b/lib/rex/proto/drda/constants.rb.ut.rb deleted file mode 100644 index be3e4a82a0..0000000000 --- a/lib/rex/proto/drda/constants.rb.ut.rb +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'rex/test' -require 'rex/proto/drda/constants' - -class Rex::Proto::DRDA::Constants::UnitTest < Test::Unit::TestCase - - Konst = Rex::Proto::DRDA::Constants - - def test_defines - assert_equal(Konst::EXCSAT, 0x1041) - assert_equal(Konst::MGRLVLLS, 0x1404) - assert_equal(Konst::SECCHKCD, 0x11a4) - end - - def test_const_values - assert_kind_of(Array, Konst.const_values) - assert Konst.const_values.include? Konst::EXCSAT - end - -end diff --git a/lib/rex/proto/drda/packet.rb.ut.rb b/lib/rex/proto/drda/packet.rb.ut.rb deleted file mode 100644 index 20217c0150..0000000000 --- a/lib/rex/proto/drda/packet.rb.ut.rb +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'rex/test' -require 'rex/proto/drda/packet' - -class Rex::Proto::DRDA::UnitTest < Test::Unit::TestCase - - Klass = Rex::Proto::DRDA - Konst = Rex::Proto::DRDA::Constants - - # Test a sample param - def test_mgrlvlls_param - p = Klass::MGRLVLLS_PARAM.new - assert_kind_of(Struct, p) - assert_equal(Konst::MGRLVLLS, p.codepoint) - end - - # Test a sample ddm - def test_secchk_ddm - d = Klass::SECCHK_DDM.new - assert_kind_of Struct, d - assert_equal Konst::SECCHK, d.codepoint - end - - # All parameter names should have a corresponding codepoint, - # except "DDM_PARAM" (a generic parameter). - def test_all_param_codepoints - params = Klass.constants.map {|x| x if x =~ /PARAM$/}.compact - assert_operator params.size, :>=, 6 # Allow for more later. - params.each do |p| - cp = p.split(/_PARAM/).first - next if cp == "DDM" - assert Konst.const_defined? cp - assert_kind_of Numeric, Konst.const_get(cp) - end - end - - # Similarly, so should DDM Structs. - def test_all_ddm_codepoints - ddms = Klass.constants.map {|x| x if x =~ /DDM$/}.compact - assert_operator ddms.size, :>=, 4 # Allow for more later. - ddms.each do |p| - cp = p.split(/_DDM/).first - next if cp == "BASIC" - assert_kind_of Numeric, Konst.const_get(cp) - end - end - - # Ensure that all params have the same struct. - def test_param_struct - params = Klass.constants.map {|x| x if x =~ /PARAM$/}.compact - params.each do |p| - obj = Klass.const_get(p).new - assert_equal 3, obj.size - assert_respond_to obj, :codepoint - assert_respond_to obj, :length - assert_respond_to obj, :payload - end - end - - # Make some similiar assertions about DDMs, though specific DDMs - # will have particular elements after the codepoint, usually more - # than one. - def test_ddm_struct - ddms = Klass.constants.map {|x| x if x =~ /DDM$/}.compact - ddms.each do |d| - obj = Klass.const_get(d).new - assert_operator obj.size, :>=, 7 - assert_respond_to obj, :length - assert_respond_to obj, :magic - assert_respond_to obj, :format - assert_respond_to obj, :correlid - assert_respond_to obj, :length2 - assert_respond_to obj, :codepoint - end - end - - # The server packet is special since it's an Array of BASIC_DDM's, - # and doesn't have a particular, fixed struct. (It would be nice - # to build those up on the fly, but we're not really interested in - # validating most server responses right now. - def test_server_packet_structure - s = Klass::SERVER_PACKET.new - assert_kind_of Array, s - assert_respond_to s, :to_s - assert_respond_to s, :sz - assert_respond_to s, :read - end - - # Exercise the SERVER_PACKET#read function with a sample packet. - def test_server_packet_read - pkt = "0015d0420001000f1219000611490000000511a4000050d0520002004a2201000611490000000c112ee2d8d3f0f8f0f2f4000d002fd8e3c4e2d8d3e7f8f6000a00350006119c033300062103022e00172135c3f0c1f8f6c1f0f14bc5c6f1f2070402195612008cd0030002008624080000000000303030303053514c303830323400ffffffff0200000000000000030000000000000000000000202020202020202020202000124d59444232444220202020202020202020200000003331ff383139ff4d59555345522020ff4d594442324442ff514442322f4c494e5558ff353538ff353538ff30ff31323038ff30ffff".scan(/../).map {|x| x.to_i(16).chr}.join - s = Klass::SERVER_PACKET.new - assert_equal 0, s.size - s.read(pkt) - assert_equal 3, s.size - assert_equal Konst::SECCHKRM, s[0].codepoint - assert_equal Konst::ACCRDBRM, s[1].codepoint - assert_equal Konst::SQLCARD, s[2].codepoint - assert_equal 0xd0, s[0].magic - assert_equal 0x52, s[1].format - assert_equal 134, s[2].length2 - assert_equal 21+80+140, s.sz - end - -end - diff --git a/lib/rex/proto/drda/utils.rb.ut.rb b/lib/rex/proto/drda/utils.rb.ut.rb deleted file mode 100644 index fc251f4bff..0000000000 --- a/lib/rex/proto/drda/utils.rb.ut.rb +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'rex/test' -require 'rex/proto/drda/utils' -require 'rex/socket' - -class Rex::Proto::DRDA::Utils::UnitTest < Test::Unit::TestCase - - Klass = Rex::Proto::DRDA - - def test_socket_connectivity - assert_nothing_raised do - socket = Rex::Socket.create_tcp( - 'PeerHost' => $_REX_TEST_DRDA_HOST.to_s, # PeerHost can be nil! - 'PeerPort' => 50000 - ) - assert_kind_of Socket, socket - assert !socket.closed? - socket.close - assert socket.closed? - end - end - - def test_client_probe_create - probe_pkt = Klass::Utils.client_probe - assert_equal 54, probe_pkt.size - end - - def test_client_probe - probe_pkt = Klass::Utils.client_probe('toolsdb') - begin - Timeout.timeout($_REX_TEST_TIMEOUT) do - socket = Rex::Socket.create_tcp( - 'PeerHost' => $_REX_TEST_DRDA_HOST.to_s, - 'PeerPort' => 50000 - ) - sent = socket.put probe_pkt - assert_equal 76, sent - probe_reply = socket.get_once - assert_operator probe_reply.size, :>=, 10 - parsed_reply = Klass::SERVER_PACKET.new.read probe_reply - assert_kind_of Array, parsed_reply - assert_equal parsed_reply[0].codepoint, Klass::Constants::EXCSATRD - socket.close - end - rescue Timeout::Error - flunk("Timed out") - end - end - - # Client auth requires a successful probe. This is a complete authentication - # sequence, culminating in info[:db_login_sucess] returning either true or - # false. - def test_client_auth - probe_pkt = Klass::Utils.client_probe('toolsdb') - auth_pkt = Klass::Utils.client_auth(:dbname => 'toolsdb', - :dbuser => $_REX_TEST_DRDA_USER.to_s, - :dbpass => $_REX_TEST_DRDA_PASS.to_s - ) - begin - Timeout.timeout($_REX_TEST_TIMEOUT) do - socket = Rex::Socket.create_tcp( - 'PeerHost' => $_REX_TEST_DRDA_HOST.to_s, - 'PeerPort' => 50000 - ) - sent = socket.put probe_pkt - probe_reply = socket.get_once - sent = socket.put auth_pkt - assert_equal(75, sent) - auth_reply = socket.get_once - parsed_auth_reply = Klass::SERVER_PACKET.new.read auth_reply - info = Klass::Utils.server_packet_info(parsed_auth_reply) - assert info[:db_login_success] - socket.close - end - rescue Timeout::Error - flunk("Timed out") - end - end - -end - diff --git a/lib/rex/proto/http/client.rb.ut.rb b/lib/rex/proto/http/client.rb.ut.rb deleted file mode 100644 index bb57ff16f9..0000000000 --- a/lib/rex/proto/http/client.rb.ut.rb +++ /dev/null @@ -1,96 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'test/unit' -require 'rex/proto/http' - -class Rex::Proto::Http::Client::UnitTest < Test::Unit::TestCase - - Klass = Rex::Proto::Http::Client - - def test_parse - c = Klass.new('www.metasploit.com') - - # Set request factory parameters - c.set_config( - 'vhost' => 'www.metasploit.com', - 'agent' => 'Metasploit Framework/3.3', - 'version' => '1.1', - 'cookie' => 'NoCookie=NotACookie' - ) - - # Set client parameters - c.set_config( - 'read_max_data' => 1024 * 1024 - ) - - # - # Request the main web page - # - r = c.request_raw( - 'method' => 'GET', - 'uri' => '/' - ) - - resp = c.send_recv(r) - - assert_equal(200, resp.code) - assert_equal('OK', resp.message) - assert_equal('1.1', resp.proto) - - # - # Request a file that does not exist - # - r = c.request_raw( - 'method' => 'GET', - 'uri' => '/NoFileHere.404' - ) - - resp = c.send_recv(r) - - assert_equal(404, resp.code) - assert_equal('Not Found', resp.message) - assert_equal('1.1', resp.proto) - - - # - # Send a POST request that results in a 302 - # - c = Klass.new('beta.microsoft.com') - c.set_config('vhost' => 'beta.microsoft.com') - - r = c.request_cgi( - 'method' => 'POST', - 'uri' => '/', - 'vars_post' => { 'var' => 'val' }, - 'ctype' => 'application/x-www-form-urlencoded' - ) - - resp = c.send_recv(r) - - #assert_equal(200, resp.code) - #assert_equal('OK', resp.message) - assert_equal(301, resp.code) - assert_equal('Moved Permanently', resp.message) - assert_equal('1.1', resp.proto) - end - - def test_ssl - c = Klass.new('www.metasploit.com', 443, {}, true) - c.set_config('vhost' => 'www.metasploit.com') - r = c.request_raw( - 'method' => 'GET', - 'uri' => '/' - ) - resp = c.send_recv(r) - - assert_equal(200, resp.code) - assert_equal('OK', resp.message) - assert_equal('1.0', resp.proto) - c.close - end - -end - diff --git a/lib/rex/proto/http/handler/erb.rb.ut.rb b/lib/rex/proto/http/handler/erb.rb.ut.rb deleted file mode 100644 index 97d808c6ff..0000000000 --- a/lib/rex/proto/http/handler/erb.rb.ut.rb +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..', '..')) - -require 'test/unit' -require 'rex/proto/http' - -class Rex::Proto::Http::Handler::Erb::UnitTest < Test::Unit::TestCase - - Klass = Rex::Proto::Http::Handler::Erb - Request = Rex::Proto::Http::Request - - def test_erb - k = Klass.new(nil, File.dirname(__FILE__)) - r = k.on_request(nil, Request::Get.new("/erb.rb.ut.rb.rhtml")) - - assert_not_nil(r) - assert_equal("foo 4\n", r.body) - end - -end diff --git a/lib/rex/proto/http/handler/erb.rb.ut.rb.rhtml b/lib/rex/proto/http/handler/erb.rb.ut.rb.rhtml deleted file mode 100644 index 7f6479f936..0000000000 --- a/lib/rex/proto/http/handler/erb.rb.ut.rb.rhtml +++ /dev/null @@ -1 +0,0 @@ -foo <%= 2 + 2 %> diff --git a/lib/rex/proto/http/handler/proc.rb.ut.rb b/lib/rex/proto/http/handler/proc.rb.ut.rb deleted file mode 100644 index 26332ab0a7..0000000000 --- a/lib/rex/proto/http/handler/proc.rb.ut.rb +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..', '..')) - -require 'test/unit' -require 'rex/proto/http' - -class Rex::Proto::Http::Handler::Proc::UnitTest < Test::Unit::TestCase - - Klass = Rex::Proto::Http::Handler::Proc - Request = Rex::Proto::Http::Request - - def test_proc - cool = 0 - k = Klass.new(nil, Proc.new { |cli, req| - cool = 1 - }) - - r = k.on_request(nil, Request::Get.new("/erb.rb.ut.rb.rhtml")) - - assert_equal(1, cool) - end - -end diff --git a/lib/rex/proto/http/header.rb.ut.rb b/lib/rex/proto/http/header.rb.ut.rb deleted file mode 100644 index 719d762789..0000000000 --- a/lib/rex/proto/http/header.rb.ut.rb +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'test/unit' -require 'rex/proto/http' - -class Rex::Proto::Http::Packet::Header::UnitTest < Test::Unit::TestCase - - Klass = Rex::Proto::Http::Packet::Header - - def test_to_s - h = Klass.new - - h['Foo'] = 'Fishing' - h['Chicken'] = 47 - - assert_equal( - "Foo: Fishing\r\n" + - "Chicken: 47\r\n\r\n", h.to_s) - end - - def test_from_s - h = Klass.new - - h.from_s( - "POST /foo HTTP/1.0\r\n" + - "Lucifer: Beast\r\n" + - "HoHo: Satan\r\n" + - "Eat: Babies\r\n" + - "\r\n") - - assert_equal('Babies', h['Eat'], 'header') - assert_equal('Satan', h['HoHo'], 'header') - assert_equal('Satan', h['hOhO'], 'header') - - assert_equal("POST /foo HTTP/1.0\r\n", h.cmd_string, 'cmd_string') - end - - def test_just_cmdstring - h = Klass.new - - h.from_s("POST /foo HTTP/1.0") - assert_equal("POST /foo HTTP/1.0\r\n", h.cmd_string, 'just cmd_string') - end -end diff --git a/lib/rex/proto/http/packet.rb.ut.rb b/lib/rex/proto/http/packet.rb.ut.rb deleted file mode 100644 index 193d892b61..0000000000 --- a/lib/rex/proto/http/packet.rb.ut.rb +++ /dev/null @@ -1,166 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'test/unit' -require 'rex/proto/http' - -class Rex::Proto::Http::Packet::UnitTest < Test::Unit::TestCase - - Klass = Rex::Proto::Http::Packet - - def test_junk_headers - srand(0) - h = Klass.new - h.headers.cmd_string = "GET / HTTP/1.0\r\n" - h.headers['TestMe'] = 'bob' - h.headers.junk_headers = 1 - expected = "GET / HTTP/1.0\r\nX-v1AD7DnJTVykXGYYM: BmnXuYRlZNIJUzQzFPvASjYxzdTTOngBJ5gfK0XjLy3ciAAk1Fmo0RPEpq6f4BBnp5jm3LuSbAOj1M5qULEGEv0DMk0oOPUj6XPN1VwxFpjAfFeAxykiwdDiqNwnVJAKyr6X7C5ije7DSujURybOp6BkKWroLCzQg2AmTuqz48oNeY9CDeirNwoITfIaC40Ds9OgEDtL8WN5tL4QYdVuZQ85219Thogk775GVfNH4YPpSo2PLmvd5Bf2sY9YDSvDqMmjW9FXrgLoUK2rl9cvoCbTZX1zuU1dDjnJJpXDuaysDfJKbtHn9VhsiiY\r\nX-FokALi: 1QI9BRwj4bo0kwZDn8jyedxhSRdU9CFlMs19CvbVnnLWeRGHScrTxpduVJZygbJcrRp6AWQqkeY0DzI4bd7uXgTIHXN6R403ALckZgqOWcUSEWj6THI9NFAIPP1LEnctaK0uxbzjpS1ize16r388StXBGq1we7Qa8j6xqJsN5GmnIN4HQ4W4PZIjGRHUZC8Q4ytXYE\r\nX-sxXe2ZUhl: Xbdhz13zW2HpxJ2AT4kRU1wDqBUkEQwvKtoebrfUGJ8bvjTMSxKihrDMk6BxAnY6kjFGDi5o8hcEag4tzJ1FhH9eI2UHDVbsDmUHTfAFbreJTHVlcIruAozmZKzi7XgTaOgzGhs75ytpE5dbRjCUt5P3kpExyNetXijJa3a2WMPiazmuQ98v6oAKLNHeGt1ePpm1rSHcBpCycOlb2kfdy8udyhMgpQCIz9Kwab44BAFYiPD8ulrTYGUGczGCccml7FtJk2NV7fRjtz6IZVtlWQZu3lBFGMaK72OIHtFv7qDKy5bZD9OSF6ERFeYDFok6x3YhShOxH1ruw0hRdM2u2gizX8Zuyr0puAM2JSEHDwMl0twtSzxHaxudDKUqB3UQqycaX0wCmJC0spZ81kaEpKMohlng6hajZyYSUecISZYnq7cYSDsTt2AKDGbj5GTiyymUr2AktpChMP2hXMFmBKG9GmmLyVyyzCMdJzIF01rBrPMvMV4SZNecspVGkwoaeFPll7xfgwQgKMdAdanWTFkTkFcMaxTMmH0QdAXPK8D9DQwJU0l44wR15JsPmOhEQkHXbuH9Wie2QbvvyLXOneai2RjHt7wlE1NlTrIgRF8kB9dFQm4oWeTEUqK7DW8l6dpo8Rzo7qedheulYQjnd8BXIAXlvaZZGY3PlpRQwruF2TvWtLLhH3awHv\r\nX-gkSXVCIKFmmkB17kFFmjYxPUyJ3: xYeCTDNLNkRaGviVUq65RlZ0V3kEviLihuTwLhZhftGZYtmzQXaDau6dCF5HPOj0n2Hzm5zd3xLDN63Y784E1zW5dmLOSZsDlHdOLJLQ87n7BS1cAVYJISLc1zR3PDqYVc6VO\r\nX-BMLZnLatiBQBQhhsmoIN: TygXEfWAlfPTPz5MtK0pQGVeDQABygr7SS5WPPcHbY56YMNSOOUH3sr1bsP9XLNdfuSEcBxxX5QpawCvRUmAGsWPKiom2Vi1gqsjp5nb7wK\r\nX-RDleXdm7e: Cd8Hz0JXAwRozVeaPwRKRDnJdDHQiE9akGgR321l3bzO7WfI4dcfi6RcvQI73sHMgUrLdoAUtcNlv9nyEuM53lwEpkQSle1ujwAx5JyhwxMG8zkjmkeyTmsjOdz84RDdbDh1z2bk4VnqKdxd96YyQAki7NB7CCT06MenVNxazMxABkKqgc6CcBNTvRkH1GJPSd18qSCdRj4T\r\nX-XMjt4CUDRsmqKlqovbEzW: jeHYYvPKTNn4lnSH8Ygsn0ov0kqQ0aoQugeUXPsT33ibtiRXbNwXeF5nhxic0BEVI8yh2jwjZFBjHBBHZkNsybgrTitkQwq5rDITuA0UgirFVYC99HsLzc2fBQySOVvvFhqCbo3TPHsdjhwxQ4Y6Fz69qTRtgWhmJFM9q3Q7RE8ZOt91RdGcKFkkU3yyW1Kr7e7Ozw494BoHFP3p0gXOidzZ1EA7aUF6YRE4gxRIJkfeJswjgO9Xg4crhyusIl4CRPDVwydl4WSH3xa4EtZa8zvTOS5gbkmUsDSNzxfhSMvbniHetQBYQtblyYwMEwzuoOxKbOmNEWPdOqZLfbWurU39CZ94Af4uGSWu7ZNMlTf3c74Too5Zvdc0qKURAnmiBwWt6xWncBVCgyGmj1kXz6SmZuPxbVBJzRLA3D592kUTvFU9EpQQ5FgWDIcpKmcfsLibxHnm36FJYMoh7OtPEW0CHtIFnPPpZWZZTdJL9janSIBjyxu3KKYfrbNO3FXqnxlmL14rYRVeSZdlxoxqfnL41OgB51Bk6ZMIyMYTDKH0cOIujjRX911MtH6vuneTqtyBrSO7Zl44IyiaLsLokxMRfKwKLdiKMxnwKC5vLuz0p6bDQANmEDTRQHYLW8bCIIZm0hYVEfzLlHW8q7f2JzzSXTZ5FZtvYz7sa4\r\nX-r5geOHg9B2v8t2raPEKVnqreWA: 6Mbr29vWf0iiqE6kTsRwvGGwJcN4JVCJu4kc0AK8NrClHXeRDviQzSy9qScj1axnquFcrTKKJbjLgmfzWb5Vh9spzrjp6X9o0X6Ipt8vPkBelqATGdDfdQDa9GplLR39rDUb3cOOQj1mrbmXU7XigBWV5EtonYWR0aIFhW6SKdLeH6eqVHZs22TZt5qD0UxT5lh8sZH8lU6iQtonhhBJXEYGhy8Y90735Kdv4cYDSVGUV3baZAuD1lH4QLLsC2FR69OFORpuseiDAdsssz9ARdbiyzk7Ve4lRmPBPpWtRs1WNyvCLJyo2zvEKxG2sIIIslSCFd5lkqdbR6LxIYDwL5yP5D2k8nVd1D4L3PtaPhL3Fe6E7glr98td6bnbdILhOmLK2ZgyoGeW7LjUEEx0d9bvToaaJyfeRH4zjJcvw3H1D7HIlFh3cumxI6BCQ9CLfKUkO40HdFOyuPzgX5bGJ4BLX8Go8kMjF6MSABUNawrVONoDpRFabrtpNtw46RWfZcNHaRErve9c5I6bGH134a7LldxUd3493cX5JAmTHymD8el4pF7Qa9fGZLRffUan1yKmE7nPNjm7LnLw2k\r\nX-Lzi6QcJlIRwscZe7l77e576: MBbKD9Qb8GAHZD740ksVx2IvmqhkEbNNpIGeMiDoQFo3d1WlX76kr7iGGYMRfwlAKxsEf8KdhpwNTpMszrQ4ylOkyEyvAxlLsFouQQKFXvDmwSeQfqvVh3KsfTCTfyTnn9hs0s2e6nMQQGEtU6eM71haSG4CauZNb5ltVr4F5xZM0Gv9JKIaQfelmw8GwG3BvB9VuAWkaUUnixu9ebkJI0UXwn7rqN4v5JbaliGptlG6VDLqLdOTarQj0RQK58JjZazPbEmVnx1XsmrrWcu\r\nX-GNNRo9eESwCbIrPz: veNcuOyuthE0K0SkI36JuNMdOoNJu8MldtLspxY7IP2gsQyzsyxLPZVWRc6bsIbcnrnje0p2J20rRyQAaH2S6L56MNIoSRqsiLXGOu2yrBOlG5vsJDJ707ieBmOQeyNWujXldtqaSWGKrBJawPRTTBbzkjJpN1GYK5rlFo0POVAjhOGY2DElofbypDipNxRqotKmqDb8PyikqnysU0ZLsRFT\r\nX-EfdqybgrpSdN: sJ2IZhRxvQxHeQW7lJuMY91W4OthEF9MpMAFWphxzBKG6QHbmrUpSzqGmixKnoobe7ki7Zb46fwrDAl3nMULM4ybv5VsMvRnfvd3BlAXNIU1SQNIGbljoaeM5tQ6XyqI32Q19SKPm9YkvADaUvvhYSoJIHcvpTWD3O3CXrYUj6ugiqclkS3qjnjBdUljuibx7OqebzEEGppDnskbNsAKdOAAg0LdFF5eSqQ3RLJJaMAnc2NX65wbrZUvMYFiM7rP7VkxsMwiFU8fiXTVv6GEJYvgKabQiW9ccxOlZFCjLzNj4feFdb51B9oacnnhpvtg5E2ALzjEaPxcqQ0G4fC8RyBghmEeE7PV5zmKQCu9uugnX9BkZIvbAjav0qWfBdDDi0kquUpFYT2lDTXweeZHqMEwbMvK8r1uKzrGHAzigXAHeSgCmMA8IDNaDmGGU6CVv06uSQ5rhqFdPZt1Yk85A9NMGxxDgzxjNLREXvKm01mwkdZjHAAIDGl8HzNS4RDIvr9DsL1xyKrPbmjS91jVc7hZKB6VZK4pNzCSUHo4VluTa3GAI8V7vlDuopc53knBz9tF6bfoJ14HjvFpc26VLDSjupRvb2vJTHHlrsuuihK3FcugTnefvvBgox3t3u2AlVWbFtjtj8oDcb7JrDrLzWqqEd8sCeFvMRP4pYVoD8uwfGzhvLnID3r2np2ZtGHodFmDHyrXYydzR4rhwOqqQv1Bq1Az4PQIpU92rZA7xnCGDeNU0LLFwQNIbGs2qEopP8AnlGzd6vZMA0yxc6HBswyHoao9wuWOfV0HkQGqUmEQiv47vOvnPYOK2EUpo0L81dD0sa8bC8C9Xtc51Sv7BEkRYZrMiV4yJkrpGRf6yvsGyQecLgmZmdCTMSApWRqEESFOKydTiDIaSEHqdjPutD6DGClY37jDHbyCwHKt7w5F0oW0rBGcFoKHdkSv87Cpdgx80ZkTg1ba44ctXSFBViBdtiOqeJ2bHMdkmcxVXlUNtoyp2BI\r\nContent-Length: 0\r\nTestMe: bob\r\n\r\n" - assert_equal(expected, h.to_s, 'junk headers') - h.headers.cmd_string = "HTTP/1.0 OK\r\n" - h.headers.fold = 1 - expected = "HTTP/1.0 OK\r\nX-nsJxRxZX5o5zKaNf8VhtBgr3Gieuamk:\r\n\twM0v0nww3ZA8mepvkmcqXPmmWwHlyCNUudg03Tss4WWsl8i92mVcwi9B2tuR0irNRfVitBFvymfcm6ywElHD2VV5aCcvglhj6gnRJjsWFWJ2B9rFqEH2Tyzm13NLXm21Lo1fD39CHCZuFQyIR4ycO4GN4cDs7mvEALmGzU4GQAD7Fv9n7QZ5ebLoAhZ0Owi0oyyr3mTqimVUajbDZ8HEE1JEhxKX5wgNVcXwF9CAJHdVQOTlaMPTSqCQ4LjJ5JeWqUpTEuPhAvPNJxqKxninwssqBIALaerqTVvB68ScL7x0nJYEa0r2VOdBOAPhg9zlFe2pvy6J1HeVepIBtVI5tx0AbywZdHafO5TIndXNoBZYepQ8LnHmVYlr7kgJxoQj3Dnl6Do6jBDLDu7MgnyA22vXH7BiN4eVRXjhGYi3o5mJYdFwwZEumA7OJkvycPCkHRfrpPc202q4fW5yX8EARGELgQC6Knm28n93AJLs0RkpvFpwmkE7xLndrtLqgBsviqqsKq8ounPtaposwQrcAs9CW8YsTeNHTj11dUIKpiu9L9I13V0EvH44VWGTrGg7lWpV0LrDgdVRFvbBhorn5rzleS2P8ztodE4w4qUQ1VCUt4YrUtPhYYob9DTMysKJc1ufXNFtoHpuQynjqc\r\nX-RlBRei0DhrZBi4xnoSp2VvcBpm:\r\n\tPcZ7y1WbNhO1IEu2VtcWOAyl2yJh0oozHady5RKrhBm9TdGFEC3ooQHoYX06WpG4OznYfUSjgUYgbs6kSWifyS8OHLK56mpWAiRq0GDo7bMnVZAri9BwrlurZXqzE0HdBXXYZFWxQfwAyDhfG0AIYGLE1lH3ZzqFlE8q5MQ5FNLWqnAYwb3eYcYe50ug9ujWvIDk0O8k7R7TYYjyBMUHWs4PghNBDn4kmb6itmvZQwyJZAP1Qq9kHXxomtlxlEiW86xe7hbHNZlfk6xv1nISUZndCoyRonhDa1vYxez5BqSHrF6olTiVkYeBAYtv4EAk8y3UEF9OWPTM9ng5eUU6FKYLV8GB0NPvrVDdJ2Y3k8634xUl19uToDlDUmehZps3WlC5buzl64c8j\r\nX-hZ2KnIRZHzdnpUhx48KM:\r\n\tCgY1FTARXuU6kkMskPl2Yt0U68HuXUFHkvJFZhUAhTJCQX96yZ6qQRo8R69xlpmMGvYhOFJlmLZQT96Xy5wJqppna32qLHbg9eWdgCWvovY2zOCDhqkAYym3M9PaX4dQSth2D6mH5UwYC8KziYAGNmZbvFt9pXz2YNVNC4pB6t0A58OkHwJsxEQQ5QDo2Cg5GVcWb5xEEfCZeLKCLMUJ6jzGfbKwIZlPaFSAkglSNTCv5opAmAJxDFR8StLA1mspRsSGP28nAlkHtLEGm8oGQiQg4ckgxwIVyYQVKgI7lGaqb6tZUUNiEwOYBnrNkhMQ5Fh7fIh2AgfCqbQXCHltUAHZYBjeiciVXRFDZV7G9TWXVMW8KOs5pFn1zK9aaTu0QBTOJs8jjIa4zotN9Zs0OwN6Gr8ImzOucdfeIrC4P44cilqmlYFO4iLQfyM67A9i5A45QEkDFe7yqUwtPlp1cb377t39hLbiYNHYBjSuo3BqbPPpNG6gc40GOfGh66uazg87ufHxnBFlbmtXMJddNXYJEl4LW8Yloo01iuh6NhHMJudM\r\nX-w2ji68BRrw3J359QDpWvUYh76UVk:\r\n\tMaC66WuT5SifDAbwuW0D8gLwYcoJCO70KEJtar9Ilois2mbw66x1Tjk8KxSEYPxeNzQ3otL9iRGYddCL6uoRnJraU5EqC0nT0HfgE0bYq3Is1ambirMvIo4tgAvRMQ14LPczAuck8SRZoZEKhWhuSjwUF6jvNoneLI5aofaylT38fGzlLPs1EjyRsZ26MAgGjpoT7jdqXZU7sImWny1PELaLaMcAF5mNW77Y9aFSsucDXJzFahBgU59vbqMftb6DzUKzJFN8oR6tZDA2O0OXGPF2AnH9Rg6dfPLrfSrmWH0jTFxArBy186O05SpGkrxgLX7YyI1TCycm4urh0NthKzX9NzueArHDuAfIDLXUBGu8Eqj8vWemL0i3DxqAGhdVO0WbDxenuXYrNggy2xZJlsRXj75jiUFUGIA9sZmHJ6GdFkdnTvWDH4dUISWWVun4i8iQNc47Nh6aN59K6XVbt38VfmSb9aXHNUejKjFlWhSAfsetCVSQjMI8a8jJfsxrvAt82Ucmkehjp2auSYYOcypTCqx6dBV2R3ZO5WPySL2YFrG9p8rvMMtlSJI1oIAgM0U571yPX2sRXJtigpG3bjTmBhlhhDWl6yhDNiPrhepcJLZw85J8gVkLj45sCgck4Kjd9rpXldh9jqQUhDftkIYZZlKgDVoNgqFVoNbiA35snwvz7Rg4gLqGShz0FR2KMpRfDoiqeGAEEsAzjWendWXxa24LCVMQCbM155pjA9NlS\r\nX-KTsbJwm6:\r\n\tvmxmFWMC7AxYqdcgEIStcHIQWqPUwVXhCwaLYPvZFW2zidMs68UuhLueu4LGfipVKbRm5GL9wdNuT5H5QGoPCKpqodKKfR7jkk9RxVbZv2Ih6vJLwvcQwCIh7wOoBufWtAMo4Acf8c845Tzgqr3EyRdmaZSzUv5pHicgxmMYuuHJ8nthej8inCd4nWj1AaE1rvJGdFB8WadFQasaOYITd37LuVC95a1wrE5WSmBE9nTbHw1diY5MFsNwmPAxzEtWe9g3ftkD8jTiRsD8IBPpI40WKsMDWMZ1aopA37m0bokVVGMHD4Kb5xxYxuJsskIJjBmUtZsZFAn6GGnyRLRle5yxJMRkgD52M1vl0Hu9FRSSRhKxJaEoZylHhR8vnwRmIm6X3ilbECtxZGKTtPU1P2jvHo8kxcsuJkXjcSOnUkIwnN3roV7v9ggeJb9c4rXc4CUWgH4VUTZvlYT3qNsbWbD5hdVCmYRNJpZlOdvH6bcWEDYna6J7p03HULGctCn56bfjMAXF3AjKdRwoS70v9KTlN5DkDjH2KUcIIRR8Ffd7Q50WjyjQ1bgvCLSYYAt8IXB7dvmmsyyRT9ZF7uVihmybplx8ETzhVEzZ9zH4kzf99vC5ZM0959Fje00JxzR4dL9ir46rh6cWZbRhh0ZU7HAMxHsXmC7JeyaMSnxd6um3GC8xN4zQfIpnfZSTcB5azeV0Lji92A5Yugo6Edz240S0lnCzhZbtWqxG1dgnXlKJBADZ9oMDibxBImhrfdw88tNOcQjYtGS4h\r\nX-IOSp7nYMJwhxhyYPunG9RIvBHUoI0A3pC:\r\n\tW8KeIV35tDFbaMAD9rgoUOYDgJGD6cDPg\r\nX-sc1yFBRvIJ0:\r\n\twpYEHFnUDBJaBowmuVMGgqUMWUthgJ7kDpIczNXHzMCktNXn752JnPLJBaLfw6LB5IZ4ehsXUxIAiemUlW9qwWpUrHB4teMF4VFQrXolvwnomr6wAJ8P0s1EcxjUGpfZQEuNhRvBZvWqWRDTud2EUtesPh8ETl0ARRxnoSFiD6A3jZUdBOsmEGRd94BQCOqxYF5VIIhFg1ArzGOlcQ1d0Sd46lDqKpnggcOfi9ljDNSR9iiTyELVDxiTaIpOjMRqXRgxLoCwWEpqP78RnNfj8xD6tZzcSsfXuKNNNTBDMIzK9G0f3rfVNHtcSd9ayPuBtzZS1nwtWbLsmxAJWF9XGWXB33afT9ZoHL753R2oALkjN8ImKZpJ2UE7nQSuOXu0j7weDKgVp6uhShzM0CZqezcpRO78NhW09YeKDfxgNxnAuYUrpabXaJhapvfofIxkReB6d1QUI3kd7rsPNZlQyLuChcapBaITb5jWZYsUk1YeM03q4cyEBFsV6xYI4s6w6egVD51URRLS5j6VtrizhJbXpz7kwhLtIrudhvOeufXrVCakuJB4DRBweihvwK5GFqGpmF8e7IR3WDPmu0eGdWKcHbwTCzHMzTzeebPvX6eTINmmCqzEmF71uyhYscV9sOy0EpRPZkMm7deiTqTfpkpLHFNiuggcMdzKq3Jzx7TWXe80Nyf68QSBPgOJGzvDG2PdVzK6NbaapE7dwc98Pu5bogtxOEZgMsp7q0N0y4yxFXl0ec2VTY5vXtKegVo2eGZF3fvubZhbQQPei7FIQmzncFATX8e0umoiRPKSobz8qmOvR83psDw1ZYsfX9PV8dWYDJmAPspOFR6pDwTSrxxBHIf8OOUSvjsonfBa5Ympf4Lw7jLxvxxyvytdky5Kqa8L5pH90gbH3U\r\nContent-Length:\r\n\t0\r\nTestMe:\r\n\tbob\r\n\r\n" - assert_equal(expected, h.to_s, 'junk headers') - end - - def test_pipeline - req_normalized = - "GET / HTTP/1.0\r\n" + - "Foo: Bar\r\n" + - "Content-Length: 10\r\n" + - "\r\n" + - "Super body" - - req = req_normalized + req_normalized - - req_base = req.dup - req_fold = req.gsub(/:/, ':' + Rex::Text.rand_base(rand(10) + 1,'',"\s","\t") + "\r\n" + Rex::Text.rand_base(rand(10) + 1,'',"\s","\t")) - req_nocr = req.gsub(/\r\n/, "\n") - req_junk = req + "junk" - - { 'base' => req_base, 'fold' => req_fold, 'no cr' => req_nocr, 'extra junk' => req_junk }.each_pair { |name, test| - h = Klass.new - h.auto_cl = false - assert_equal(Klass::ParseCode::Completed, h.parse(test), "parse #{name}") - assert_equal(req_normalized, h.to_s, "to string #{name}") - assert_equal(true, h.completed?, "completed parsing #{name}") - assert_equal('Bar', h.headers['Foo'], "first header #{name}") - assert_equal('10', h.headers['Content-Length'], "second header #{name}") - assert_equal("Super body", h.body, "body #{name}") - } - end - - - def test_chunked - req_start = - "GET / HTTP/1.0\r\n" + - "Transfer-Encoding: chunked\r\n" + - "Foo: Bar\r\n" + - "\r\n" - - req_normalized = req_start + "Super body" - - req = req_start + "1\r\nS\r\n1\r\nu\r\n1\r\np\r\n1\r\ne\r\n1\r\nr\r\n1\r\n \r\n1\r\nb\r\n1\r\no\r\n1\r\nd\r\n1\r\ny\r\n0\r\n\r\n" - - req_base = req.dup - req_fold = req.gsub(/:/, ':' + Rex::Text.rand_base(rand(10) + 1,'',"\s","\t") + "\r\n" + Rex::Text.rand_base(rand(10) + 1,'',"\s","\t")) - req_nocr = req.gsub(/\r\n/, "\n") - req_junk = req + "junk" - - { 'base' => req_base, 'fold' => req_fold, 'no cr' => req_nocr, 'extra junk' => req_junk }.each_pair { |name, test| - h = Klass.new - h.auto_cl = false - assert_equal(Klass::ParseCode::Completed, h.parse(test), "parse #{name}") - assert_equal(req_normalized, h.to_s, "to string #{name}") - assert_equal(true, h.completed?, "completed parsing #{name}") - assert_equal('Bar', h.headers['Foo'], "first header #{name}") - assert_equal('chunked', h.headers['Transfer-Encoding'], "second header #{name}") - assert_equal("Super body", h.body, "body #{name}") - } - end - - def test_content_length - req = - "GET / HTTP/1.0\r\n" + - "Foo: Bar\r\n" + - "Content-Length: 10\r\n" + - "\r\n" + - "Super body" - - req_base = req.dup - req_fold = req.gsub(/:/, ':' + Rex::Text.rand_base(rand(10) + 1,'',"\s","\t") + "\r\n" + Rex::Text.rand_base(rand(10) + 1,'',"\s","\t")) - req_nocr = req.gsub(/\r\n/, "\n") - req_junk = req + "junk" - - { 'base' => req_base, 'fold' => req_fold, 'no cr' => req_nocr, 'extra junk' => req_junk }.each_pair { |name, test| - h = Klass.new - h.auto_cl = false - assert_equal(Klass::ParseCode::Completed, h.parse(test), "parse #{name}") - assert_equal(req, h.to_s, "to string #{name}") - assert_equal(true, h.completed?, "completed parsing #{name}") - assert_equal('Bar', h.headers['Foo'], "first header #{name}") - assert_equal('10', h.headers['Content-Length'], "second header #{name}") - assert_equal("Super body", h.body, "body #{name}") - } - end - - def test_parse_connection_close - req = - "GET / HTTP/1.0\r\n" + - "Foo: Bar\r\n" + - "Connection: close\r\n" + - "\r\n" + - "Super body" - - req_base = req.dup - req_fold = req.gsub(/:/, ':' + Rex::Text.rand_base(rand(10) + 1,'',"\s","\t") + "\r\n" + Rex::Text.rand_base(rand(10) + 1,'',"\s","\t")) - req_nocr = req.gsub(/\r\n/, "\n") - - { 'base' => req_base, 'fold' => req_fold, 'no cr' => req_nocr }.each_pair { |name, test| - h = Klass.new - h.auto_cl = false - assert_equal(Klass::ParseCode::Completed, h.parse(test), "parse #{name}") - assert_equal(req, h.to_s, "to string #{name}") - assert_equal(true, h.completed?, "completed parsing #{name}") - assert_equal('Bar', h.headers['Foo'], "first header #{name}") - assert_equal('close', h.headers['Connection'], "second header #{name}") - assert_equal("Super body", h.body, "body #{name}") - } - end - - def test_to_s - h = Klass.new - - h.headers['Foo'] = 'Fishing' - h.headers['Chicken'] = 47 - - assert_equal( - "Foo: Fishing\r\n" + - "Content-Length: 0\r\n" + - "Chicken: 47\r\n\r\n", h.to_s) - end - - def test_from_s - h = Klass.new - - h.from_s( - "HTTP/1.0 200 OK\r\n" + - "Lucifer: Beast\r\n" + - "HoHo: Satan\r\n" + - "Eat: Babies\r\n" + - "\r\n") - - assert_equal('Babies', h['Eat']) - h['Eat'] = "fish" - assert_equal('fish', h['Eat']) - end - - # XXX - def test_no_headers - h = Klass.new - h.from_s("GET / HTTP/1.0\r\n\r\n") - assert_equal("GET / HTTP/1.0\r\n", h.headers.cmd_string, 'cmd string') - end - -end diff --git a/lib/rex/proto/http/request.rb.ut.rb b/lib/rex/proto/http/request.rb.ut.rb deleted file mode 100644 index e7cf091a6c..0000000000 --- a/lib/rex/proto/http/request.rb.ut.rb +++ /dev/null @@ -1,215 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'test/unit' -require 'rex/proto/http' - -class Rex::Proto::Http::Request::UnitTest < Test::Unit::TestCase - - Klass = Rex::Proto::Http::Request - - def test_to_s - h = Klass.new - - h.headers['Foo'] = 'Fishing' - h.headers['Chicken'] = 47 - h.auto_cl = true - - assert_equal( - "GET / HTTP/1.1\r\n" + - "Foo: Fishing\r\n" + - "Content-Length: 0\r\n" + - "Chicken: 47\r\n\r\n", h.to_s) - end - - def test_from_s - h = Klass.new - - h.from_s( - "POST /foo HTTP/1.0\r\n" + - "Lucifer: Beast\r\n" + - "HoHo: Satan\r\n" + - "Eat: Babies\r\n" + - "\r\n") - - assert_equal('POST', h.method, 'method') - assert_equal('/foo', h.uri, 'uri') - assert_equal('1.0', h.proto, 'proto') - assert_equal('Babies', h['Eat'], 'header') - - assert_equal("POST /foo HTTP/1.0\r\n", h.cmd_string, 'cmd_string') - - h.method = 'GET' - assert_equal("GET /foo HTTP/1.0\r\n", h.cmd_string, 'set method') - - h.uri = '/bar' - assert_equal("GET /bar HTTP/1.0\r\n", h.cmd_string, 'set uri') - - h.proto = '1.2' - assert_equal("GET /bar HTTP/1.2\r\n", h.cmd_string, 'set proto') - end - - def junk_request - h = Klass.new - h.from_s("GET /foo/bar.html HTTP/1.0\r\n" + "Foo: Bar\r\n\r\n") - return h - end - - def test_junk_slashes - srand(0) - - h = junk_request - assert_equal('GET', h.method, 'method') - assert_equal('1.0', h.proto, 'proto') - assert_equal('Bar', h['Foo'], 'header') - assert_equal('/foo/bar.html', h.uri, 'uri') - - h = junk_request - h.junk_directories = 1 - assert_equal('/D/../DnJT/../kXG/../Y/../BmnXu/../foo/lZ/../J/../zQzFP/../S/../Yxzd/../bar.html', h.uri, 'junk directories') - - h = junk_request - h.junk_slashes = 1 - assert_equal('/foo//bar.html', h.uri, 'junk slashes') - - h = junk_request - h.junk_self_referring_directories = 1 - assert_equal('/././foo/././bar.html', h.uri, 'junk referring directories') - - h = junk_request - h.junk_param_start = 1 - assert_equal('/%3fgf=XjLyc/../foo/bar.html', h.uri, 'junk start of params') - - h = junk_request - h.junk_end_of_uri = 1 - assert_equal('/%20HTTP/1.0%0d%0a/../../foo/bar.html', h.uri, 'junk end of URI') - end - - def test_params - srand(0) - - h = junk_request - assert_equal('/foo/bar.html', h.uri, 'uri') - - h.uri_parts['QueryString']['B'] = 'a' - assert_equal('/foo/bar.html?B=a', h.uri, 'uri with param') - - h.uri_parts['QueryString']['B'] = ['a','b'] - assert_equal('/foo/bar.html?B=a&B=b', h.uri, 'uri with a param with multiple values') - - h.uri_parts['QueryString']['B'] = '=' - assert_equal('/foo/bar.html?B=%3d', h.uri, 'uri with a param that requires escaping') - - assert_equal( - "GET /foo/bar.html?B=%3d HTTP/1.0\r\n" + - "Foo: Bar\r\n" + - "Content-Length: 0\r\n" + - "\r\n", h.to_s, 'GET to_s' - ) - - h.method = 'POST' - assert_equal( - "POST /foo/bar.html HTTP/1.0\r\n" + - "Foo: Bar\r\n" + - "Content-Length: 5\r\n" + - "\r\n" + - 'B=%3d', - h.to_s, 'POST to_s' - ) - - h.body = 'FOO' - assert_equal( - "POST /foo/bar.html HTTP/1.0\r\n" + - "Foo: Bar\r\n" + - "Content-Length: 3\r\n" + - "\r\n" + - 'FOO', - h.to_s, 'POST to_s, with hardcoded body' - ) - - end - - def test_junk_params - srand(0) - h = junk_request - - h.junk_params = 1 - h.uri_parts['QueryString']['a'] = 'b' - h.uri_parts['QueryString']['c'] = 'd' - - assert_equal("GET /foo/bar.html?eZUhlXbdhzzW=HpxJATk&UwDqBU=EQwvK&oebrfUGJbvjTMSxKih=MkBx&nYkjF=DiohcEa&tzJFh=eIUHDVbs&a=b&UHTfAFbreJT=VlcIruAo&mZKziXgT=z&hsytpEdbRjC=tPkpE&yNetXi=JaaW&PiazmuQvoAKLNHeGt=ePpmrS&c=d&BpCycOlbkfdyudyhMgpQCIzKwabBAFYiP=ulrTYGUG&zGCccmlFtJkNVfRjtzIZVtlWQZulBFGMa=OIHtFvqDKybZDOS&ERFeYDFokx=YhShOxHruwhRdMugizXZuyrpuAMJSEHDwMltwtSzxHaxudDKUqBUQqycaXwC&JCspZkaEpKM=hlnghajZyYSUecISZYnqcYSDsTtAKDGbjGTiyymUrAktp&hMPhXMF=BKGGmmLyVyyzCMdJzIFrBrPMvMVSZNecspVGkwoaeFP HTTP/1.0\r\nFoo: Bar\r\nContent-Length: 0\r\n\r\n", h.to_s, 'junk params (GET)') - - h.method = 'POST' - assert_equal("POST /foo/bar.html HTTP/1.0\r\nFoo: Bar\r\nContent-Length: 591\r\n\r\nxfgwQgKMdA=WTFkTkFc&axTMmHQdAXPKDDQwJ=lwRJs&PmOhEQkHXbuHWieQbvv=LXO&eaiRjHtwlENl=rIgR&kBdFQmoWeT=UqKDW&a=b&dpoRzoqedheulYQ=ndBX&AXlvaZZGYPlpR=w&uFTvWtLLhHawHvgk=XVC&KFmmkBkFFmjYx=yJExY&CTDNLNkRaGviVUqRlZV=kEviLihu&c=d&LhZhftGZYtmzQXaDaudCF=HPOjnHzmzdxLDNYEzWdmLOSZsDlHdOLJLQnBScAVYJISLczRPDqYVcVOvBMLZn&atiBQBQhhsmoINqT=gXEfWAlfPTPzMtKpQGVeDQABygrSSWPPcHbYYMNSOOUHsrbsPXLNdfu&EcBxxXQpawCvRUmAGsWPKio=VigqsjpnbwKERDleXdmeLCdHzJXAwRozVeaPwRKRDnJ&DHQiEakGgRlbzOWfIdcfiRcvQIsHMgUrLd=AUtcNlvnyEuMlwEpkQSleujwAxJyhwxMGzkjmkeyTmsjO&zRDdbDhzbkVnqKdxdYyQAkiNBCCTMenVNx=zMxABkKqgcCcBNTvRkHGJPSdqSCdRjT",h.to_s, 'junk params (POST)') - - h.method = 'SEARCH' - assert_equal("SEARCH /foo/bar.html HTTP/1.0\r\nFoo: Bar\r\nContent-Length: 522\r\n\r\nMjtCUDRsmqKl=vbEzWljeH&YvPKTNnlnSHYg=ovkqQaoQ&geUXPsTibtiRXbNwXeF=nhxicBEVIy&jwjZFB=HBBH&kNsybgrTitkQwq=rDITuAUgir&a=b&YCHsLzcfBQ=SOV&vFhqCboTPHsdjhwxQYFz=RtgW&mJFMqQ=EZ&tRdGcKFkkUyyWKreOzw=BoHFPpgXO&dzZEAaU=YREgxR&c=d&kfeJswjgOXgcrh=usIlCRPDVwydlWSHxaEtZazvTOSgbkmUsDSNzxfhSMvbniHetQBYQtb&yYwMEwzuoO=KbOmNEWPdOqZLfbWurUCZAfuGSWuZNMlTfcTooZvdcqKURAnmiBwWt&xWncBVCgyGmjkXzSmZuPxbVBJzRLADk=TvFUEpQQFgWDIcpKmcfsLibxH&mFJYMohOtPEW=CHtIFnPPpZWZZTdJLjanSIBjyxuKKYfrbNOFXqnxlmLrYRVeSZdlxoxqf&LOgBBkZMIyMY=DKHcOIujjRXMtHvuneTqtyBr", h.to_s, 'junk params (SEARCH)') - end - - def test_junk_pipelining - srand(0) - - h = Klass.new - h.from_s("GET /foo HTTP/1.0\r\n" + "Foo: Bar\r\n\r\n") - h.junk_pipeline = 1 - assert_equal("GET / HTTP/1.1\r\nConnection: Keep-Alive\r\n\r\nGET /foo HTTP/1.0\r\nFoo: Bar\r\nContent-Length: 0\r\nConnection: Closed\r\n\r\n", h.to_s, 'pipeline') - end - - def test_junk_all - srand(0) - - h = junk_request - h.junk_slashes = 1 - h.junk_directories = 1 - h.junk_self_referring_directories = 1 - h.junk_end_of_uri = 1 - h.junk_param_start = 1 - - seen = {} - expect = [ - {"//"=>145, "/./"=>35, "param"=>1, "http"=>1, "/w/../"=>3}, - {"//"=>149, "/./"=>35, "param"=>1, "http"=>1, "/w/../"=>3}, - {"//"=>130, "/./"=>30, "param"=>1, "http"=>1, "/w/../"=>2}, - {"//"=>165, "/./"=>40, "param"=>1, "http"=>1, "/w/../"=>4}, - {"//"=>145, "/./"=>35, "param"=>1, "http"=>1, "/w/../"=>3}, - ] - i = 0 - 5.times { - str = h.uri.dup - assert_not_equal('/foo/bar.html', str, 'all the junk') - assert_nil(seen[str], 'all the junk, not a dup rand') - seen[str] = 1 - - seen = { '/./' => 0, '//' => 0, '/w/../' => 0, 'http' => 0, 'param' => 0} - matched = 1 - while matched == 1 - # p str - if str.sub!(/\/%20HTTP\/1.0%0d%0a\/\.\.\/\.\.\//, '/') - seen['http'] += 1; - elsif str.sub!(/\/%3f\w+=\w+\/\.\.\//i, '/') - seen['param'] += 1; - elsif str.sub!(/\/\w+\/\.\.\//, '/') - seen['/./'] += 1; - elsif str.sub!(/\/\//, '/') - seen['//'] += 1; - elsif str.sub!(/\/.\//, '/') - seen['/w/../'] += 1; - else - matched = 0 - end - end - - assert_equal('/foo/bar.html', str, 'normalized') - assert_equal(expect[i], seen, 'expected counts') - i += 1 - } - end - - def test_normalize - h = junk_request - h.uri = '/foo/..////./././asdf/././//../bar.html' - assert_equal('/bar.html', h.uri, 'normalize on set') - end -end diff --git a/lib/rex/proto/http/response.rb.ut.rb b/lib/rex/proto/http/response.rb.ut.rb deleted file mode 100644 index 085d898203..0000000000 --- a/lib/rex/proto/http/response.rb.ut.rb +++ /dev/null @@ -1,150 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'test/unit' -require 'rex/proto/http' - -class Rex::Proto::Http::Response::UnitTest < Test::Unit::TestCase - - Klass = Rex::Proto::Http::Response - - def test_deflate - h = Klass.new - h.body = 'hi mom' - h.compress = 'deflate' - assert_equal( - "HTTP/1.1 200 OK\r\n" + - "Content-Length: 14\r\n" + - "Content-Encoding: deflate\r\n\r\n" + - "x\234\313\310T\310\315\317\005\000\a\225\002;", - h.to_s, 'deflate' - ) - end - - def test_gzip - h = Klass.new - h.body = 'hi mom' - h.compress = 'gzip' - srand(0) - - response = h.to_s - - http_header = response.slice!(0,63) - - assert_equal( - "HTTP/1.1 200 OK\r\n" + - "Content-Length: 26\r\n"+ - "Content-Encoding: gzip\r\n\r\n", - http_header, 'http headers' - ) - - assert_equal("\x1f\x8b\x08\x00", response.slice!(0,4), 'gzip headers') - - # skip the next 6 bytes as it is host & time specific (zlib's example gun does, so why not us too?) - response.slice!(0,6) - - assert_equal("\xcb\xc8\x54\xc8\xcd\xcf\x05\x00\x68\xa4\x1c\xf0\x06\x00\x00\x00", response, 'gzip data') - end - - - def test_to_s - h = Klass.new - - h.headers['Foo'] = 'Fishing' - h.headers['Chicken'] = 47 - - assert_equal( - "HTTP/1.1 200 OK\r\n" + - "Content-Length: 0\r\n" + - "Foo: Fishing\r\n" + - "Chicken: 47\r\n\r\n", h.to_s, 'to_s w/o body') - - h.body = 'hi mom' - assert_equal( - "HTTP/1.1 200 OK\r\n" + - "Content-Length: 6\r\n" + - "Foo: Fishing\r\n" + - "Chicken: 47\r\n\r\nhi mom", h.to_s, 'to_s w/ body') - end - - - def test_chunked - h = Klass.new - - h.headers['Foo'] = 'Fishing' - h.headers['Chicken'] = 47 - h.auto_cl = false - h.transfer_chunked = true - - - assert_equal( - "HTTP/1.1 200 OK\r\n" + - "Transfer-Encoding: chunked\r\n" + - "Foo: Fishing\r\n" + - "Chicken: 47\r\n\r\n0\r\n\r\n", h.to_s, 'chunked w/o body' - ) - - srand(0) - h.body = Rex::Text.rand_text_alphanumeric(100) - assert_equal( - "HTTP/1.1 200 OK\r\n" + - "Transfer-Encoding: chunked\r\n" + - "Foo: Fishing\r\n" + - "Chicken: 47\r\n\r\n" + - "5\r\nsv1AD\r\n7\r\n7DnJTVy\r\n5\r\nkXGYY\r\n5\r\nM6Bmn\r\n4\r\nXuYR\r\n5\r\nlZNIJ\r\n5\r\nUzQzF\r\n9\r\nPvASjYxzd\r\n5\r\nTTOng\r\n4\r\nBJ5g\r\n8\r\nfK0XjLy3\r\n6\r\nciAAk1\r\n6\r\nFmo0RP\r\n1\r\nE\r\n2\r\npq\r\n6\r\n6f4BBn\r\n4\r\np5jm\r\n1\r\n3\r\n6\r\nLuSbAO\r\n1\r\nj\r\n2\r\n1M\r\n3\r\n5qU\r\n0\r\n\r\n", - h.to_s, 'random chunk sizes' - ) - - h.chunk_max_size = 1 - h.body = 'hi mom' - assert_equal( - "HTTP/1.1 200 OK\r\n" + - "Transfer-Encoding: chunked\r\n" + - "Foo: Fishing\r\n" + - "Chicken: 47\r\n\r\n" + - "1\r\nh\r\n1\r\ni\r\n1\r\n \r\n1\r\nm\r\n1\r\no\r\n1\r\nm\r\n0\r\n\r\n", - h.to_s, '1 byte chunks' - ) - - h.chunk_min_size = 2 - assert_equal( - "HTTP/1.1 200 OK\r\n" + - "Transfer-Encoding: chunked\r\n" + - "Foo: Fishing\r\n" + - "Chicken: 47\r\n\r\n" + - "2\r\nhi\r\n2\r\n m\r\n2\r\nom\r\n0\r\n\r\n", - h.to_s, '2 byte chunks' - ) - - h = Klass.new(200, 'OK', '1.0') - h.body = 'hi mom' - h.auto_cl = false - h.transfer_chunked = true - assert_raise(Rex::RuntimeError, 'chunked encoding via 1.0') { - h.to_s - } - - end - - def test_from_s - h = Klass.new - - h.from_s( - "HTTP/1.0 404 File not found\r\n" + - "Lucifer: Beast\r\n" + - "HoHo: Satan\r\n" + - "Eat: Babies\r\n" + - "\r\n") - - assert_equal(404, h.code) - assert_equal('File not found', h.message) - assert_equal('1.0', h.proto) - assert_equal("HTTP/1.0 404 File not found\r\n", h.cmd_string) - h.code = 470 - assert_equal("HTTP/1.0 470 File not found\r\n", h.cmd_string) - assert_equal('Babies', h['Eat']) - end - -end diff --git a/lib/rex/proto/http/server.rb.ut.rb b/lib/rex/proto/http/server.rb.ut.rb deleted file mode 100644 index c8307ebc5f..0000000000 --- a/lib/rex/proto/http/server.rb.ut.rb +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'test/unit' -require 'rex/proto/http' - -class Rex::Proto::Http::Server::UnitTest < Test::Unit::TestCase - - ListenPort = 8090 - ListenHost = '127.0.0.1' - - SrvKlass = Rex::Proto::Http::Server - CliKlass = Rex::Proto::Http::Client - - def test_server - begin - s = start_srv - c = CliKlass.new(ListenHost, ListenPort) - - 1.upto(10) { - req = c.request_raw('uri' => '/') - res = c.send_recv(req) - assert_not_nil(res) - assert_equal(404, res.code) - } - ensure - stop_srv - end - end - - def test_resource - begin - s = start_srv - c = CliKlass.new(ListenHost, ListenPort) - - s.add_resource('/foo', - 'Proc' => Proc.new { |cli, req| - resp = Rex::Proto::Http::Response::OK.new - - resp.body = "Chickens everywhere" - - cli.send_response(resp) - }) - - 1.upto(10) { - req = c.request_raw('uri' => '/foo') - res = c.send_recv(req) - assert_not_nil(res) - assert_equal(200, res.code) - assert_equal("Chickens everywhere", res.body) - } - - s.remove_resource('/foo') - - req = c.request_raw('uri' => '/foo') - res = c.send_recv(req) - assert_not_nil(res) - assert_equal(404, res.code) - ensure - stop_srv - end - end - -protected - - def start_srv - self.srv = SrvKlass.new(ListenPort, ListenHost) - self.srv.start - self.srv - end - - def stop_srv - self.srv.stop if (self.srv) - end - -attr_accessor :srv - -end diff --git a/lib/rex/proto/ntlm.rb.ut.rb b/lib/rex/proto/ntlm.rb.ut.rb deleted file mode 100644 index 3eee949b36..0000000000 --- a/lib/rex/proto/ntlm.rb.ut.rb +++ /dev/null @@ -1,181 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex/proto/ntlm' -require 'rex/socket' - -class ConnectionTest < Test::Unit::TestCase - def setup - @user = "admin" - @pass = "1234" - @domain = "" - @host = "192.168.145.161" - end - - def test_socket_connectivity - assert_nothing_raised do - socket = Rex::Socket.create_tcp( - 'PeerHost' => @host, - 'PeerPort' => 80 - ) - assert_kind_of Socket, socket - assert !socket.closed? - socket.close - assert socket.closed? - end - end - - def http_message(msg) - get_req = "GET / HTTP/1.1\r\n" - get_req += "Host: #{@host}\r\n" - get_req += "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n" - get_req += "Authorization: NTLM #{msg.encode64}\r\n" - get_req += "Content-type: application/x-www-form-urlencoded\r\n" - get_req += "Content-Length: 0\r\n" - get_req += "\r\n" - end - - def client_auth(pw) - msg_1 = Rex::Proto::NTLM::Message::Type1.new - get_req = http_message(msg_1) - socket = Rex::Socket.create_tcp( - 'PeerHost' => @host, - 'PeerPort' => 80 - ) - socket.put get_req - res = socket.get(3) - assert res =~ /WWW-Authenticate: NTLM TlRM/ - res_ntlm = res.match(/WWW-Authenticate: NTLM ([A-Z0-9\x2b\x2f=]+)/i)[1] - assert_operator res_ntlm.size, :>=, 24 - msg_2 = Rex::Proto::NTLM::Message.decode64(res_ntlm) - assert msg_2 - msg_3 = msg_2.response({:user => @user, :password => pw}, {:ntlmv2 => true}) - assert msg_3 - auth_req = http_message(msg_3) - socket.put auth_req - auth_res = socket.get(3) - socket.close - return auth_res - end - - def test_client_auth_success - assert_equal client_auth(@pass)[0,12], "HTTP/1.1 200" - end - - def test_client_auth_fail - assert_not_equal client_auth("badpass")[0,12], "HTTP/1.1 200" - assert_equal client_auth("badpass")[0,12], "HTTP/1.1 401" - end -end - -# FunctionTest by Minero Aoki - -class FunctionTest < Test::Unit::TestCase #:nodoc: - def setup - @passwd = "SecREt01" - @user = "user" - @domain = "domain" - @challenge = ["0123456789abcdef"].pack("H*") - @client_ch = ["ffffff0011223344"].pack("H*") - @timestamp = 1055844000 - @trgt_info = [ - "02000c0044004f004d00410049004e00" + - "01000c00530045005200560045005200" + - "0400140064006f006d00610069006e00" + - "2e0063006f006d000300220073006500" + - "72007600650072002e0064006f006d00" + - "610069006e002e0063006f006d000000" + - "0000" - ].pack("H*") - end - - def test_lm_hash - ahash = ["ff3750bcc2b22412c2265b23734e0dac"].pack("H*") - assert_equal ahash, Rex::Proto::NTLM::Crypt::lm_hash(@passwd) - end - - def test_ntlm_hash - ahash = ["cd06ca7c7e10c99b1d33b7485a2ed808"].pack("H*") - assert_equal ahash, Rex::Proto::NTLM::Crypt::ntlm_hash(@passwd) - end - - def test_ntlmv2_hash - ahash = ["04b8e0ba74289cc540826bab1dee63ae"].pack("H*") - assert_equal ahash, Rex::Proto::NTLM::Crypt::ntlmv2_hash(@user, @passwd, @domain) - end - - def test_lm_response - ares = ["c337cd5cbd44fc9782a667af6d427c6de67c20c2d3e77c56"].pack("H*") - assert_equal ares, Rex::Proto::NTLM::Crypt::lm_response( - { - :lm_hash => Rex::Proto::NTLM::Crypt::lm_hash(@passwd), - :challenge => @challenge - } - ) - end - - def test_ntlm_response - ares = ["25a98c1c31e81847466b29b2df4680f39958fb8c213a9cc6"].pack("H*") - ntlm_hash = Rex::Proto::NTLM::Crypt::ntlm_hash(@passwd) - assert_equal ares, Rex::Proto::NTLM::Crypt::ntlm_response( - { - :ntlm_hash => ntlm_hash, - :challenge => @challenge - } - ) - end - - def test_lmv2_response - ares = ["d6e6152ea25d03b7c6ba6629c2d6aaf0ffffff0011223344"].pack("H*") - assert_equal ares, Rex::Proto::NTLM::Crypt::lmv2_response( - { - :ntlmv2_hash => Rex::Proto::NTLM::Crypt::ntlmv2_hash(@user, @passwd, @domain), - :challenge => @challenge - }, - { :client_challenge => @client_ch } - ) - end - - def test_ntlmv2_response - ares = [ - "cbabbca713eb795d04c97abc01ee4983" + - "01010000000000000090d336b734c301" + - "ffffff00112233440000000002000c00" + - "44004f004d00410049004e0001000c00" + - "53004500520056004500520004001400" + - "64006f006d00610069006e002e006300" + - "6f006d00030022007300650072007600" + - "650072002e0064006f006d0061006900" + - "6e002e0063006f006d00000000000000" + - "0000" - ].pack("H*") - assert_equal ares, Rex::Proto::NTLM::Crypt::ntlmv2_response( - { - :ntlmv2_hash => Rex::Proto::NTLM::Crypt::ntlmv2_hash(@user, @passwd, @domain), - :challenge => @challenge, - :target_info => @trgt_info - }, - { - :timestamp => @timestamp, - :client_challenge => @client_ch - } - ) - end - - def test_ntlm2_session - acha = ["ffffff001122334400000000000000000000000000000000"].pack("H*") - ares = ["10d550832d12b2ccb79d5ad1f4eed3df82aca4c3681dd455"].pack("H*") - session = Rex::Proto::NTLM::Crypt::ntlm2_session( - { - :ntlm_hash => Rex::Proto::NTLM::Crypt::ntlm_hash(@passwd), - :challenge => @challenge - }, - { :client_challenge => @client_ch } - ) - assert_equal acha, session[0] - assert_equal ares, session[1] - end -end diff --git a/lib/rex/proto/rfb.rb.ut.rb b/lib/rex/proto/rfb.rb.ut.rb deleted file mode 100644 index cb9900de64..0000000000 --- a/lib/rex/proto/rfb.rb.ut.rb +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- -# -# RFB protocol support -# -# @author Joshua J. Drake -# -# Based on: -# vnc_auth_none contributed by Matteo Cantoni -# vnc_auth_login contributed by carstein -# - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'rex/socket' -require 'rex/proto/rfb' - -sd = Rex::Socket::Tcp.create('PeerHost' => ENV["VNCHOST"], 'PeerPort' => Rex::Proto::RFB::DefaultPort) - -v = Rex::Proto::RFB::Client.new(sd) -if not v.connect('password') - $stderr.puts v.error - exit(1) -end - -loop { - sret = select([sd],nil,nil,10) - puts sret.inspect - if sret and sret[0].include? sd - buf = sd.sysread(8192) - puts "read #{buf.length} bytes: #{buf.inspect}" - end -} diff --git a/lib/rex/proto/smb/client.rb.ut.rb b/lib/rex/proto/smb/client.rb.ut.rb deleted file mode 100644 index e4f3ae046a..0000000000 --- a/lib/rex/proto/smb/client.rb.ut.rb +++ /dev/null @@ -1,224 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'rex/test' -require 'rex/proto/smb/constants' -require 'rex/proto/smb/exceptions' -require 'rex/proto/smb/utils' -require 'rex/proto/smb/client' -require 'rex/proto/dcerpc' -require 'rex/socket' - -class Rex::Proto::SMB::Client::UnitTest < Test::Unit::TestCase - - Klass = Rex::Proto::SMB::Client - - # Alias over the Rex DCERPC protocol modules - DCERPCPacket = Rex::Proto::DCERPC::Packet - DCERPCClient = Rex::Proto::DCERPC::Client - DCERPCResponse = Rex::Proto::DCERPC::Response - DCERPCUUID = Rex::Proto::DCERPC::UUID - - def test_smb_open_share - - share = 'C$' - - write_data = ('A' * 256) - filename = 'smb_test.txt' - - begin - Timeout.timeout($_REX_TEST_TIMEOUT) { - s = Rex::Socket.create_tcp( - 'PeerHost' => $_REX_TEST_SMB_HOST, - 'PeerPort' => 139 - ) - - c = Klass.new(s) - - # Request a SMB session over NetBIOS - # puts "[*] Requesting a SMB session over NetBIOS..." - ok = c.session_request() - assert_kind_of(Rex::Struct2::CStruct, ok) - - # Check for a positive session response - # A negative response is 0x83 - assert_equal(ok.v['Type'], 0x82) - - # puts "[*] Negotiating SMB dialects..." - ok = c.negotiate() - assert_kind_of(Rex::Struct2::CStruct, ok) - - # puts "[*] Authenticating with NTLMv2..." - ok = c.session_setup_with_ntlmssp($_REX_TEXT_SMB_USER, $_REX_TEXT_SMB_PASS) - assert_kind_of(Rex::Struct2::CStruct, ok) - assert_not_equal(c.auth_user_id, 0) - - # puts "[*] Connecting to the share..." - ok = c.tree_connect(share) - assert_kind_of(Rex::Struct2::CStruct, ok) - assert_not_equal(c.last_tree_id, 0) - - # puts "[*] Opening a file for write..." - ok = c.open(filename) - assert_kind_of(Rex::Struct2::CStruct, ok) - assert_not_equal(c.last_file_id, 0) - - # puts "[*] Writing data to the test file..." - ok = c.write(c.last_file_id, 0, write_data) - assert_kind_of(Rex::Struct2::CStruct, ok) - assert_equal(ok['Payload'].v['CountLow'], write_data.length) - - # puts "[*] Closing the test file..." - ok = c.close(c.last_file_id) - assert_kind_of(Rex::Struct2::CStruct, ok) - - # puts "[*] Opening a file for read..." - ok = c.open(filename, 1) - assert_kind_of(Rex::Struct2::CStruct, ok) - assert_not_equal(c.last_file_id, 0) - - # puts "[*] Reading data from the test file..." - ok = c.read(c.last_file_id, 0, write_data.length) - assert_kind_of(Rex::Struct2::CStruct, ok) - assert_equal(ok['Payload'].v['DataLenLow'], write_data.length) - - read_data = ok.to_s.slice( - ok['Payload'].v['DataOffset'] + 4, - ok['Payload'].v['DataLenLow'] - ) - assert_equal(read_data, write_data) - - # puts "[*] Closing the test file..." - ok = c.close(c.last_file_id) - assert_kind_of(Rex::Struct2::CStruct, ok) - - # puts "[*] Disconnecting from the tree..." - ok = c.tree_disconnect - assert_kind_of(Rex::Struct2::CStruct, ok) - - s.close - - - # Reconnect and delete the file - s = Rex::Socket.create_tcp( - 'PeerHost' => $_REX_TEST_SMB_HOST, - 'PeerPort' => 139 - ) - - c = Klass.new(s) - - # Request a SMB session over NetBIOS - # puts "[*] Requesting a SMB session over NetBIOS..." - ok = c.session_request() - assert_kind_of(Rex::Struct2::CStruct, ok) - - # Check for a positive session response - # A negative response is 0x83 - assert_equal(ok.v['Type'], 0x82) - - # puts "[*] Negotiating SMB dialects..." - ok = c.negotiate() - assert_kind_of(Rex::Struct2::CStruct, ok) - - # puts "[*] Authenticating with NTLMv2..." - ok = c.session_setup_with_ntlmssp($_REX_TEXT_SMB_USER, $_REX_TEXT_SMB_PASS) - assert_kind_of(Rex::Struct2::CStruct, ok) - assert_not_equal(c.auth_user_id, 0) - - # puts "[*] Connecting to the share..." - ok = c.tree_connect(share) - assert_kind_of(Rex::Struct2::CStruct, ok) - assert_not_equal(c.last_tree_id, 0) - - # puts "[*] Deleting the test file..." - ok = c.delete(filename) - assert_kind_of(Rex::Struct2::CStruct, ok) - - # puts "[*] Diconnecting from the tree..." - ok = c.tree_disconnect - assert_kind_of(Rex::Struct2::CStruct, ok) - - s.close - } - rescue Timeout::Error - flunk('timeout') - end - - end - - def test_smb_session_request - begin - Timeout.timeout($_REX_TEST_TIMEOUT) { - s = Rex::Socket.create_tcp( - 'PeerHost' => $_REX_TEST_SMB_HOST, - 'PeerPort' => 139 - ) - - c = Klass.new(s) - - # Request a SMB session over NetBIOS - # puts "[*] Requesting a SMB session over NetBIOS..." - ok = c.session_request() - assert_kind_of(Rex::Struct2::CStruct, ok) - - # Check for a positive session response - # A negative response is 0x83 - assert_equal(ok.v['Type'], 0x82) - - # puts "[*] Negotiating SMB dialects..." - ok = c.negotiate() - assert_kind_of(Rex::Struct2::CStruct, ok) - - # puts "[*] Authenticating with NTLMv2..." - ok = c.session_setup_with_ntlmssp - assert_kind_of(Rex::Struct2::CStruct, ok) - - # puts "[*] Authenticating with NTLMv1..." - ok = c.session_setup_no_ntlmssp - assert_kind_of(Rex::Struct2::CStruct, ok) - - # puts "[*] Authenticating with clear text passwords..." - begin - ok = c.session_setup_clear - assert_kind_of(Rex::Struct2::CStruct, ok) - rescue Rex::Proto::SMB::Exceptions::ErrorCode - if ($!.error_code != 0x00010002) - raise $! - end - end - - # puts "[*] Connecting to IPC$..." - ok = c.tree_connect - assert_kind_of(Rex::Struct2::CStruct, ok) - - # puts "[*] Opening the \BROWSER pipe..." - ok = c.create_pipe('\BROWSER') - assert_kind_of(Rex::Struct2::CStruct, ok) - - vers = DCERPCUUID.vers_by_name('SRVSVC') - uuid = DCERPCUUID.uuid_by_name('SRVSVC') - bind, ctx = DCERPCPacket.make_bind_fake_multi(uuid, vers) - - # puts "[*] Binding to the Server Service..." - ok = c.trans_named_pipe(c.last_file_id, bind) - assert_kind_of(Rex::Struct2::CStruct, ok) - - data = ok.to_s.slice( - ok['Payload'].v['DataOffset'] + 4, - ok['Payload'].v['DataCount'] - ) - assert_not_equal(data, nil) - - resp = DCERPCResponse.new(data) - assert_equal(resp.type, 12) - } - rescue Timeout::Error - flunk('timeout') - end - end - - -end - diff --git a/lib/rex/proto/smb/constants.rb.ut.rb b/lib/rex/proto/smb/constants.rb.ut.rb deleted file mode 100644 index e0db0419df..0000000000 --- a/lib/rex/proto/smb/constants.rb.ut.rb +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'rex/test' -require 'rex/proto/smb/constants' - -class Rex::Proto::SMB::Constants::UnitTest < Test::Unit::TestCase - - Klass = Rex::Proto::SMB::Constants - - def test_defines - assert_equal(Klass::SMB_COM_CREATE_DIRECTORY, 0x00 ) - assert_equal(Klass::SMB_COM_NT_CREATE_ANDX, 0xa2 ) - assert_equal(Klass::NT_TRANSACT_QUERY_SECURITY_DESC, 0x06) - end - -end diff --git a/lib/rex/proto/smb/simpleclient.rb.ut.rb b/lib/rex/proto/smb/simpleclient.rb.ut.rb deleted file mode 100644 index e946f08278..0000000000 --- a/lib/rex/proto/smb/simpleclient.rb.ut.rb +++ /dev/null @@ -1,129 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'rex/test' -require 'rex/proto/smb' -require 'rex/proto/dcerpc' -require 'rex/socket' - -class Rex::Proto::SMB::SimpleClient::UnitTest < Test::Unit::TestCase - - Klass = Rex::Proto::SMB::SimpleClient - - # Alias over the Rex DCERPC protocol modules - DCERPCPacket = Rex::Proto::DCERPC::Packet - DCERPCClient = Rex::Proto::DCERPC::Client - DCERPCResponse = Rex::Proto::DCERPC::Response - DCERPCUUID = Rex::Proto::DCERPC::UUID - XCEPT = Rex::Proto::SMB::Exceptions - - FILE_CREATE = 0x10 - FILE_TRUNC = 0x02 - FILE_OPEN = 0x01 - - - def test_smb_open_share - user = 'SMBTest' - pass = 'SMBTest' - share = 'C$' - - write_data = ('A' * (1024 * 8)) - filename = 'smb_tester.txt' - begin - Timeout.timeout($_REX_TEST_TIMEOUT) { - s = Rex::Socket.create_tcp( - 'PeerHost' => $_REX_TEST_SMB_HOST, - 'PeerPort' => 445 - ) - - c = Klass.new(s, true) - - begin - c.login('*SMBSERVER', user, pass) - rescue XCEPT::LoginError - flunk('login failure') - end - - c.connect(share) - - f = c.open(filename, 'rwct') - f << write_data - f.close - - f = c.open(filename, 'ro') - d = f.read() - f.close - - c.delete(filename) - c.disconnect(share) - - s.close - } - rescue Timeout::Error - flunk('timeout') - end - end - - def test_smb_dcerpc - begin - Timeout.timeout($_REX_TEST_TIMEOUT) { - s = Rex::Socket.create_tcp( - 'PeerHost' => $_REX_TEST_SMB_HOST, - 'PeerPort' => 445 - ) - - c = Klass.new(s, true) - - user = '' - pass = '' - - begin - c.login('*SMBSERVER', user, pass) - rescue XCEPT::LoginError - flunk('login failure') - end - - c.connect('IPC$') - f = c.create_pipe('\BROWSER') - - bind, ctx = DCERPCPacket.make_bind_fake_multi( - '4b324fc8-1670-01d3-1278-5a47bf6ee188', '3.0', - 10, - 4 - ) - - # Evasion techniques: - # 1) Write the bind out a few bytes at a time with a random offset - # 2) Read the response back a few bytes at a time with a random offset - - # Write the bind request out in random chunk sizes - while (bind.length > 0) - f.write( bind.slice!(0, (rand(20)+5)), rand(1024)+1 ) - end - - d = '' - # Read the response back a few bytes a time - begin - while(true) - t = (f.read((rand(20)+5), rand(1024)+1)) - last if ! t.length - d << t - end - rescue XCEPT::NoReply - end - - r = DCERPCResponse.new(d) - assert_equal(r.type, 12) - assert_equal(r.ack_result[ctx-0], 0) - assert_equal(r.ack_result[ctx-1], 2) - - s.close - } - rescue Timeout::Error - flunk('timeout') - end - end -end - diff --git a/lib/rex/proto/smb/utils.rb.ut.rb b/lib/rex/proto/smb/utils.rb.ut.rb deleted file mode 100644 index 6cc882ac19..0000000000 --- a/lib/rex/proto/smb/utils.rb.ut.rb +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'rex/test' -require 'rex/proto/smb/utils' - -class Rex::Proto::SMB::Utils::UnitTest < Test::Unit::TestCase - - Klass = Rex::Proto::SMB::Utils - - def test_nbname - - nbdecoded = 'METASPLOITROCKS!' - nbencoded = 'ENEFFEEBFDFAEMEPEJFEFCEPEDELFDCB' - - assert_equal(Klass.nbname_encode(nbdecoded), nbencoded ) - assert_equal(Klass.nbname_decode(nbencoded), nbdecoded ) - end -end diff --git a/lib/rex/proto/tftp/server.rb.ut.rb b/lib/rex/proto/tftp/server.rb.ut.rb deleted file mode 100755 index 32a0647518..0000000000 --- a/lib/rex/proto/tftp/server.rb.ut.rb +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -require 'rex/compat' -require 'rex/proto/tftp' - -content = nil - -fn = ARGV.shift -if (fn and fn.length > 0) - File.open(fn, "rb") do |fd| - content = fd.read(fd.stat.size) - end -end - -content ||= "A" * (1024*1024) - - -tftp = Rex::Proto::TFTP::Server.new -tftp.register_file("poo", content) -tftp.start - -#loop { break if not tftp.thread.alive? } -tftp.thread.join diff --git a/lib/rex/service_manager.rb.ut.rb b/lib/rex/service_manager.rb.ut.rb deleted file mode 100644 index 0386f0692c..0000000000 --- a/lib/rex/service_manager.rb.ut.rb +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..')) - -require 'test/unit' -require 'rex/service_manager' - -class Rex::ServiceManager::UnitTest < Test::Unit::TestCase - - Klass = Rex::ServiceManager - - def test_svcm - begin - c = Klass - s = c.start(Rex::Proto::Http::Server, 8090) - assert_not_nil(s) - t = c.start(Rex::Proto::Http::Server, 8090) - assert_not_nil(t) - assert_equal(s, t) - z = c.start(Rex::Proto::Http::Server, 8091) - assert_not_equal(t, z) - assert_equal("HTTP Server", s.alias) - assert_equal("HTTP Server 1", z.alias) - ensure - c.stop_by_alias(s.alias) if (s) - c.stop_by_alias(z.alias) if (z) - c.stop_by_alias(t.alias) if (t) - end - - end - -end diff --git a/lib/rex/socket.rb.ut.rb b/lib/rex/socket.rb.ut.rb deleted file mode 100644 index 25bcefa801..0000000000 --- a/lib/rex/socket.rb.ut.rb +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..')) - -require 'test/unit' -require 'rex/socket' -require 'rex/socket/tcp' - -class Rex::Socket::UnitTest < Test::Unit::TestCase - - def test_ip - assert_equal(true,Rex::Socket.dotted_ip?('0.0.0.0'), 'valid IP min') - assert_equal(true,Rex::Socket.dotted_ip?('255.255.255.255'), 'valid IP max') - assert_equal(false,Rex::Socket.dotted_ip?('0.0.0.0.0'), 'too many sections') - assert_equal(false,Rex::Socket.dotted_ip?('0..0.0.0'), 'too many dots') - assert_equal(false,Rex::Socket.dotted_ip?('00.0.0'), 'not enough dots') - assert_equal(false,Rex::Socket.dotted_ip?('256.256.256.256'), 'numbers too big') - end - - def test_create - port = 64442 - serv = TCPServer.new('127.0.0.1', port) - - sock = nil - assert_nothing_raised { - sock = Rex::Socket.create( - 'PeerHost' => '127.0.0.1', - 'PeerPort' => port, - 'Proto' => 'tcp') - } - assert_kind_of(Rex::Socket::Tcp, sock, "socket factory creation") - - sock = nil - assert_nothing_raised { - sock = Rex::Socket.create_tcp( - 'PeerHost' => '127.0.0.1', - 'PeerPort' => port) - } - assert_kind_of(Rex::Socket::Tcp, sock, "tcp socket factory creation") - - serv.close - end - - def test_to_sockaddr - assert_equal(([2] + [0]*14).pack("sC*"), Rex::Socket.to_sockaddr(0, 0), "null sockaddr") -=begin -# This is platform dependent, pain to test - if (Rex::Socket.support_ipv6?) - # Use the constant for AF_INET6 since it is different per platform - # (10 on linux and 28 on BSD) - inaddr_any_sockaddr = ([::Socket::AF_INET6, 22] + [0]*24).pack('sSC*') - else - inaddr_any_sockaddr = ([2, 22] + [0]*12).pack('snC*') - end -=end - assert_equal(([2, 0x16, 1, 2, 3, 4] + [0]*8).pack('snC*'), Rex::Socket.to_sockaddr("1.2.3.4", 22), "1.2.3.4 addr, port 22 sockaddr") - end - - def test_from_sockaddr - # 1.9.1 raises ArgumentError if we don't have an af == AF_INET or AF_INET6 - af, host, port = Rex::Socket.from_sockaddr(([2, 0] + [0]*12).pack('snC*')) - assert_equal(2, af, "af = 2") - assert_equal('0.0.0.0', host, "zero host") - assert_equal(0, port, "zero port") - - af, host, port = Rex::Socket.from_sockaddr(([2, 22]+[0]*12).pack('snC*')) - assert_equal(2, af, "af = 2") - assert_equal(22, port, "port = 22") - assert_equal('0.0.0.0', host, "zero host") - - af, host, port = Rex::Socket.from_sockaddr(([2, 22, 1, 2, 3, 4] + [0]*8).pack('snC*') ) - assert_equal(2, af, "af = 2") - assert_equal('1.2.3.4', host, "host = '1.2.3.4'") - assert_equal(22, port, "port = 22") - end - - def test_resolv_nbo - assert_equal("\x04\x03\x02\x01", Rex::Socket.resolv_nbo("4.3.2.1")) - end - - def test_net2bitmask - assert_equal(32, Rex::Socket.net2bitmask('255.255.255.255')) - assert_equal(28, Rex::Socket.net2bitmask('255.255.255.240')) - assert_equal(24, Rex::Socket.net2bitmask('255.255.255.0')) - assert_equal(16, Rex::Socket.net2bitmask('255.255.0.0')) - end - - def test_bit2netmask - assert_equal("255.255.255.255", Rex::Socket.bit2netmask(32)) - assert_equal("255.255.255.254", Rex::Socket.bit2netmask(31)) - assert_equal("255.255.255.240", Rex::Socket.bit2netmask(28)) - assert_equal("255.255.255.0", Rex::Socket.bit2netmask(24)) - assert_equal("255.255.0.0", Rex::Socket.bit2netmask(16)) - end - - def test_is_internal - assert( ! Rex::Socket.is_internal?("1.2.3.4")) - assert( ! Rex::Socket.is_internal?("172.15.3.4")) - assert( ! Rex::Socket.is_internal?("172.32.3.4")) - assert(Rex::Socket.is_internal?("10.2.3.4")) - assert(Rex::Socket.is_internal?("192.168.3.4")) - 16.upto(31) do |octet| - assert(Rex::Socket.is_internal?("172.#{octet}.3.4")) - end - end - -end diff --git a/lib/rex/socket/comm/local.rb.ut.rb b/lib/rex/socket/comm/local.rb.ut.rb deleted file mode 100644 index 760152f59e..0000000000 --- a/lib/rex/socket/comm/local.rb.ut.rb +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'test/unit' -require 'rex/exceptions' -require 'rex/socket/parameters' -require 'rex/socket/comm/local' - -class Rex::Socket::Comm::Local::UnitTest < Test::Unit::TestCase - - def test_create_tcp - test_port = 64432 - test_server = TCPServer.new('127.0.0.1', test_port) - - # Create a stream connection to the stub listener - stream = nil - - assert_nothing_raised { - stream = Rex::Socket::Comm::Local.create( - Rex::Socket::Parameters.from_hash( - 'PeerHost' => '127.0.0.1', - 'PeerPort' => test_port, - 'Proto' => 'tcp')) - } - - assert_kind_of(Rex::IO::Stream, stream, "valid Stream instance") - assert_kind_of(Rex::Socket::Tcp, stream, "valid Tcp instance") - stream.close - - # Now create a bare connection to the listener - stream = nil - - assert_nothing_raised { - stream = Rex::Socket::Comm::Local.create( - Rex::Socket::Parameters.from_hash( - 'PeerHost' => '127.0.0.1', - 'PeerPort' => test_port, - 'Proto' => 'tcp', - 'Bare' => true)) - } - - assert_kind_of(Socket, stream, "valid Socket instance") - - assert_raise(Rex::ConnectionRefused, "connection refused failed") { - Rex::Socket::Comm::Local.create( - Rex::Socket::Parameters.from_hash( - 'PeerHost' => '127.0.0.1', - 'PeerPort' => 1, - 'Proto' => 'tcp', - 'Bare' => true)) - } - - stream.close - - test_server.close - end - - def test_create_tcp_server - # TODO - end - - def test_create_udp - # TODO - end - - def test_create_invalid - assert_raise(Rex::UnsupportedProtocol, "invalid protocol check failed") { - Rex::Socket::Comm::Local.create( - Rex::Socket::Parameters.from_hash( - 'Proto' => 'invalid')) - } - end - -end diff --git a/lib/rex/socket/parameters.rb.ut.rb b/lib/rex/socket/parameters.rb.ut.rb deleted file mode 100644 index 2ab504e3c9..0000000000 --- a/lib/rex/socket/parameters.rb.ut.rb +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex/socket/parameters' - -class Rex::Socket::Parameters::UnitTest < Test::Unit::TestCase - - def test_parameters - h = { - 'PeerHost' => 'phost', - 'PeerPort' => 12, - 'LocalHost' => 'lhost', - 'LocalPort' => 47, - 'Bare' => true, - 'Server' => true, - 'Comm' => 'nothing', - 'Proto' => 'tcp', - 'SSL' => true - } - - p = Rex::Socket::Parameters.from_hash(h) - - assert_equal('phost', p.peerhost, "peerhost") - assert_equal('phost', p.peeraddr, "peeraddr") - assert_equal(12, p.peerport, "peerport") - assert_equal('lhost', p.localhost, "localhost") - assert_equal('lhost', p.localaddr, "localaddr") - assert_equal(47, p.localport, "localport") - assert_equal(true, p.bare?, "bare") - assert_equal(true, p.server?, "server") - assert_equal(false, p.client?, "client") - assert_equal('nothing', p.comm, "comm") - assert_equal(true, p.tcp?, "proto tcp") - assert_equal(false, p.udp?, "proto udp") - assert_equal(true, p.ssl, "ssl") - - p = Rex::Socket::Parameters.from_hash({}) - - assert_equal(nil, p.peerhost, "null peerhost") - assert_equal('0.0.0.0', p.localhost, "default localhost") - assert_equal(0, p.peerport, "0 peerport") - assert_equal(0, p.localport, "0 localport") - assert_equal(false, p.bare, "default false bare") - assert_equal('tcp', p.proto, "default tcp proto") - assert_equal(false, p.server, "default false server") - assert_equal(false, p.ssl, "default false ssl") - end - -end diff --git a/lib/rex/socket/range_walker.rb.ut.rb b/lib/rex/socket/range_walker.rb.ut.rb deleted file mode 100644 index c2aa6914a3..0000000000 --- a/lib/rex/socket/range_walker.rb.ut.rb +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex/socket/range_walker' - -class Rex::Socket::RangeWalker::UnitTest < Test::Unit::TestCase - - Klass = Rex::Socket::RangeWalker - - def test_walker - - # - # Single argument - # - s = Klass.new('10.0.0.0-10.0.0.255') - - 0.upto(255) { |x| - assert_equal('10.0.0.' + x.to_s, s.next_ip) - } - assert_nil(s.next_ip) - - s.reset - - 0.upto(255) { |x| - assert_equal('10.0.0.' + x.to_s, s.next_ip) - } - assert_nil(s.next_ip) - - # - - - # - # Backwards - # - s = Klass.new('10.0.0.255-10.0.0.0') - - 0.upto(255) { |x| - assert_equal('10.0.0.' + x.to_s, s.next_ip) - } - assert_nil(s.next_ip) - - # - # Same address - # - s = Klass.new('10.0.0.255-10.0.0.255') - assert_equal('10.0.0.255', s.next_ip) - assert_nil(s.next_ip) - - - - end - -end diff --git a/lib/rex/socket/ssl_tcp.rb.ut.rb b/lib/rex/socket/ssl_tcp.rb.ut.rb deleted file mode 100644 index 8a6809d831..0000000000 --- a/lib/rex/socket/ssl_tcp.rb.ut.rb +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex/socket/ssl_tcp' - -class Rex::Socket::SslTcp::UnitTest < Test::Unit::TestCase - - def test_ssltcp - - # Create an SslTcp instance - t = nil - assert_nothing_raised { - t = Rex::Socket::SslTcp.create( - 'PeerHost' => 'www.google.com', - 'PeerPort' => 443) - } - assert_kind_of(Rex::Socket::SslTcp, t, "valid ssl tcp") - - # Send a HEAD request and make sure we get some kind of response - head_request = "HEAD / HTTP/1.0\r\n\r\n" - - assert_equal(19, t.put(head_request), "sending head request") - - head_response = "" - - assert_nothing_raised { - head_response = t.get(nil) || "" - } - - assert_match(/^HTTP\/1./, head_response, "valid head response") - - assert_nothing_raised { - t.close - } - end - -end diff --git a/lib/rex/socket/ssl_tcp_server.rb.ut.rb b/lib/rex/socket/ssl_tcp_server.rb.ut.rb deleted file mode 100644 index 9b26dd8376..0000000000 --- a/lib/rex/socket/ssl_tcp_server.rb.ut.rb +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex/socket/ssl_tcp_server' -require 'rex/socket/ssl_tcp' -require 'rex/text' - -class Rex::Socket::SslTcpServer::UnitTest < Test::Unit::TestCase - - # XXX. The client data is sent & decrypted just fine. The server data is not. the client thread just spins. BAH. - # - # As of 2011-03-04, works fine on 1.8.6-p399, 1.8.7-p330, 1.9.1-p378 - # - def test_tcp_server - #return; - - serv_port = 65433 - c = nil - - threads = [] - - # Server thread - threads << Thread.new() { - serv = Rex::Socket.create_tcp_server('LocalPort' => serv_port, 'SSL' => true) - assert_kind_of(Rex::Socket::SslTcpServer, serv, "type => ssl") - assert_kind_of(Rex::Socket::TcpServer, serv, "type => tcp") - assert_kind_of(Rex::IO::StreamServer, serv, "type => stream") - s = serv.accept - assert_equal("client_data\n", s.get_once(), "s: get_once") - assert_equal(3, s.write("Yo\n"), "s: put Yo") - # Make sure methods are Strings for 1.9 compat (which returns - # symbols) - meths = s.methods.map {|m| m.to_s} - assert(meths.include?("<<"), "Has <<") - assert(meths.include?(">>"), "Has >>") - assert(meths.include?("has_read_data?"), "Has has_read_data?") - serv.close - } - - # Client thread - threads << Thread.new() { - sleep(2) - assert_nothing_raised { - c = Rex::Socket::SslTcp.create( - 'PeerHost' => '127.0.0.1', - 'PeerPort' => serv_port - ) - } - assert_kind_of(Rex::Socket::Tcp, c, "TCP") - assert_kind_of(Rex::Socket::SslTcp, c, "SSL") - assert_equal(12, c.write("client_data\n"), "c: write") - assert_equal("Yo\n", c.get_once(), "c: get_once") - c.close if (c) - } - - threads.each { |aThread| aThread.join } - end - -end diff --git a/lib/rex/socket/subnet_walker.rb.ut.rb b/lib/rex/socket/subnet_walker.rb.ut.rb deleted file mode 100644 index a65f5c56a2..0000000000 --- a/lib/rex/socket/subnet_walker.rb.ut.rb +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex/socket/subnet_walker' - -class Rex::Socket::SubnetWalker::UnitTest < Test::Unit::TestCase - - Klass = Rex::Socket::SubnetWalker - - def test_walker - s = Klass.new('10.0.0.0', '255.255.255.0') - - 0.upto(255) { |x| - assert_equal('10.0.0.' + x.to_s, s.next_ip) - } - assert_nil(s.next_ip) - - s.reset - - 0.upto(255) { |x| - assert_equal('10.0.0.' + x.to_s, s.next_ip) - } - assert_nil(s.next_ip) - end - -end diff --git a/lib/rex/socket/switch_board.rb.ut.rb b/lib/rex/socket/switch_board.rb.ut.rb deleted file mode 100644 index 4045beb7aa..0000000000 --- a/lib/rex/socket/switch_board.rb.ut.rb +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex/socket/switch_board' - -class Rex::Socket::SwitchBoard::UnitTest < Test::Unit::TestCase - - Klass = Rex::Socket::SwitchBoard - - def test_add - Klass.flush_routes - assert_equal(true, Klass.add_route('0.0.0.0', 0, 'foo')) - assert_equal(false, Klass.add_route('0.0.0.0', 0, 'foo')) - assert_equal(1, Klass.routes.length) - - assert_equal('0.0.0.0', Klass.routes[0].subnet) - assert_equal('0.0.0.0', Klass.routes[0].netmask) - assert_equal(0, Klass.routes[0].bitmask) - assert_equal('foo', Klass.routes[0].comm) - end - - def test_remove - Klass.flush_routes - assert_equal(true, Klass.add_route('0.0.0.0', 0, 'foo')) - assert_equal(true, Klass.remove_route('0.0.0.0', 0, 'foo')) - assert_equal(false, Klass.remove_route('0.0.0.0', 0, 'foo')) - assert_equal(0, Klass.routes.length) - end - - def test_best_comm - Klass.flush_routes - Klass.add_route('0.0.0.0', 0, 'default') - Klass.add_route('1.2.3.0', 24, 'spec') - - assert_equal('default', Klass.best_comm('4.5.6.7')) - assert_equal('spec', Klass.best_comm('1.2.3.7')) - end - - def test_remove_by_comm - Klass.flush_routes - Klass.add_route('1.2.3.0', 24, 'foo') - Klass.add_route('1.2.4.0', 24, 'dog') - - Klass.remove_by_comm('foo') - - assert_equal('dog', Klass.best_comm('1.2.4.7')) - assert_nil(Klass.best_comm('1.2.3.7')) - end - -end diff --git a/lib/rex/socket/tcp.rb.ut.rb b/lib/rex/socket/tcp.rb.ut.rb deleted file mode 100644 index 8818c8f735..0000000000 --- a/lib/rex/socket/tcp.rb.ut.rb +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex' - -class Rex::Socket::Tcp::UnitTest < Test::Unit::TestCase - - def test_tcp - port = 65434 - listener = Rex::Socket.create_tcp_server( 'LocalPort' => port ) - client = nil - - begin - # Connect to the temp server - assert_nothing_raised { - client = Rex::Socket.create_tcp( - 'PeerHost' => '127.0.0.1', - 'PeerPort' => port) - } - - assert_kind_of(Rex::Socket::Tcp, client, 'kindof?') - assert_equal('127.0.0.1', client.peerhost, 'peerhost') - assert_equal(port, client.peerport, 'peerport') - - # Accept the client connection - server = listener.accept - assert_kind_of(Socket, server, "valid server socket connection") - - # do all of the tests, once for each side - { 'c/s' => [client, server], 's/c' => [server, client] }.each_pair { |mode, sockets| - a = sockets[0] - b = sockets[1] - - string = "test\n" - assert_equal(false, a.has_read_data?(1), "#{mode} : has_read_data?, no data") - assert_equal(string.length, b.write(string), "#{mode} : write") - assert_equal(true, a.has_read_data?(1), "#{mode} : has_read_data?, with data") - assert_equal(string, a.recv(string.length), "#{mode} : recv") - - string = "string\rtest\nwith\x00null" - assert_equal(string.length, a << string, "#{mode} : append") - tmp = ''; tmp = b.>> - assert_equal(string, tmp, "#{mode} : append (reverse)") - - string = "\x00foobar\x00" - assert_equal(string.length, a.send(string, 0), "#{mode} : send") - assert_equal(string, b.get(), "#{mode} : get") - } - - assert_equal(true, client.shutdown(::Socket::SHUT_RD), 'client: shutdown read handle') - assert_equal(true, client.shutdown(::Socket::SHUT_WR), 'client: shutdown write handle') - assert_nothing_raised { - client.close - client = nil - } - ensure - client.close if (client) - listener.close - end - end - -end diff --git a/lib/rex/socket/tcp_server.rb.ut.rb b/lib/rex/socket/tcp_server.rb.ut.rb deleted file mode 100644 index 6acafd9186..0000000000 --- a/lib/rex/socket/tcp_server.rb.ut.rb +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex/socket/tcp_server' - -class Rex::Socket::TcpServer::UnitTest < Test::Unit::TestCase - - def test_tcp_server - serv_port = 65433 - serv = Rex::Socket.create_tcp_server( - 'LocalPort' => serv_port) - ccli = nil - - begin - assert_kind_of(Rex::Socket::TcpServer, serv, "valid TcpServer") - assert_kind_of(Rex::IO::StreamServer, serv, "valid StreamServer") - - # Connect to the server - assert_nothing_raised { - ccli = Rex::Socket.create_tcp( - 'PeerHost' => '127.0.0.1', - 'PeerPort' => serv_port) - } - assert_kind_of(Rex::Socket::Tcp, ccli, "valid client client Tcp") - - # Accept the client connection - scli = serv.accept - assert_kind_of(Rex::Socket::Tcp, scli, "valid server client Tcp") - - assert_equal(2, scli.put("Yo"), "scli: put Yo") - assert_equal("Yo", ccli.get(), "ccli: get Yo") - assert(scli.methods.include?('<<'), "no << operator") - assert(scli.methods.include?('>>'), "no >> operator") - assert(scli.methods.include?('has_read_data?'), "no has_read_data?") - - ensure - ccli.close if (ccli) - serv.close - end - end - -end diff --git a/lib/rex/socket/udp.rb.ut.rb b/lib/rex/socket/udp.rb.ut.rb deleted file mode 100644 index b72c37b048..0000000000 --- a/lib/rex/socket/udp.rb.ut.rb +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..')) - -require 'test/unit' -require 'rex/socket/udp' - -class Rex::Socket::Udp::UnitTest < Test::Unit::TestCase - - def test_udp - serv_port = 55432 - serv = Rex::Socket::Udp.create( - 'LocalHost' => '127.0.0.1', - 'LocalPort' => serv_port) - - begin - assert_kind_of(Rex::Socket::Udp, serv, "valid Udp server instance") - - # Test connected socket - concli = Rex::Socket::Udp.create( - 'PeerHost' => '127.0.0.1', - 'PeerPort' => serv_port) - - assert_equal('127.0.0.1', concli.peerhost, "matching peerhost") - assert_equal(serv_port, concli.peerport, "matching peerport") - assert_equal(2, concli.write('yo'), "write succeeded") - - data, host, port = serv.recvfrom - - assert_equal('yo', data, "read data match") - assert_equal('127.0.0.1', host, "matching client host") - - # Test non-connected socket - concli = Rex::Socket::Udp.create - - assert_equal(3, concli.sendto('bob', '127.0.0.1', serv_port), "sendto") - data, host, port = serv.recvfrom - assert_equal('bob', data, "read data match") - ensure - serv.close - end - end - -end diff --git a/lib/rex/text.rb.ut.rb b/lib/rex/text.rb.ut.rb deleted file mode 100644 index d9c5520c3c..0000000000 --- a/lib/rex/text.rb.ut.rb +++ /dev/null @@ -1,193 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..')) - -require 'test/unit' -require 'rex/text' -require 'rex/exceptions' -class Rex::Text::UnitTest < Test::Unit::TestCase - - def test_pattern_create - set1 = %w{AB ab 12} - assert_equal 'Aa1Aa2', Rex::Text.pattern_create(6,set1) - set2 = %w{ABC abc 123} - assert_equal 'Aa1Aa2Aa3Ab1Ab2Ab3', Rex::Text.pattern_create(18,set2) - assert_equal 'Zz8Zz9', Rex::Text.pattern_create(20280)[-6,6] # Bug #2952 - end - - def test_pattern_create_silly - assert_equal "", Rex::Text.pattern_create(nil) - assert_equal "", Rex::Text.pattern_create(0) - assert_equal 'AAAAAAAAA', Rex::Text.pattern_create(9,['A']) - end - - def test_uri_encode - srand(0) - assert_equal('A1%21', Rex::Text.uri_encode('A1!'), 'uri encode') - assert_equal('A1!', Rex::Text.uri_encode('A1!', 'none'), 'uri encode: none') - assert_equal('A1%21', Rex::Text.uri_encode('A1!', 'hex-normal'), 'uri encode: hex-normal') - assert_equal('%41%31%21', Rex::Text.uri_encode('A1!', 'hex-all'), 'uri encode: hex-all') - assert_equal('A1%u01c3', Rex::Text.uri_encode('A1!', 'u-normal'), 'uri encode: u-normal') - assert_equal('%uff21%u2081%uff01', Rex::Text.uri_encode('A1!', 'u-all'), 'uri encode: u-all') - srand(0) - assert_equal("%uff2d%uff49%uff43%uff52%uff4f%uff53%uff4f%uff46%uff54%u2004%uff45%uff4e%uff43%uff4f%uff44%uff49%uff4e%uff47%u3000%uff44%uff52%uff49%uff56%uff45%uff53%u2005%uff4d%uff45%u2000%uff43%uff52%uff41%uff5a%uff59%uff01", Rex::Text.uri_encode('Microsoft encoding drives me crazy!', 'u-half')) - - assert_raises(TypeError) { - Rex::Text.uri_encode('a', 'umpa lumpa') - } - end - - def test_html_encode - assert_equal('A', Rex::Text.html_encode('A'), 'html_encode default') - assert_equal('A', Rex::Text.html_encode('A','hex'), 'html_encode hex') - assert_equal('A', Rex::Text.html_encode('A','int'), 'html_encode int') - assert_equal('A', Rex::Text.html_encode('A','int-wide'), 'html_encode int-wide') - - assert_raises(TypeError) { - Rex::Text.html_encode('a', 'umpa lumpa') - } - end - - def test_rand_text - srand(0) - assert_equal("\254/u\300C\373\303g\t\323", Rex::Text.rand_text(10), 'rand text 1') - assert_equal("\025\362$WF\330X\214:\301", Rex::Text.rand_text(10), 'rand text 2') - assert_equal("\346'W\256XQ\245\031MH", Rex::Text.rand_text(10), 'rand text 3') - assert_equal('bababbabba', Rex::Text.rand_text(10, nil, 'ab'), 'rand text with specified "good"') - assert_equal('MA', Rex::Text.rand_state(), 'rand state') - assert_equal('xzdttongb.5gfk0xjly3.aak.fmo0rp.com', Rex::Text.rand_hostname(), 'rand hostname') - assert_equal('9aaf811799', Rex::Text.rand_text_hex(10), 'rand hex') - end - - - def test_unicode - assert_equal("a\x00b\x00c\x00", Rex::Text.to_unicode('abc'), 'unicode, default = little endian') - assert_equal("a\x00b\x00c\x00", Rex::Text.to_unicode('abc', 'utf-16le'), 'utf-16le') - assert_equal("\x00a\x00b\x00c", Rex::Text.to_unicode('abc', 'utf-16be'), 'utf-16be') - assert_equal("a\x00\x00\x00b\x00\x00\x00c\x00\x00\x00", Rex::Text.to_unicode('abc', 'utf-32le'), 'utf-32le') - assert_equal("\x00\x00\x00a\x00\x00\x00b\x00\x00\x00c", Rex::Text.to_unicode('abc', 'utf-32be'), 'utf-32be') - assert_equal("abc+-abc-+AAA-", Rex::Text.to_unicode("abc+abc-\x00", 'utf-7'), 'utf-7') - assert_equal("+AGE-+AGI-+AGM-+ACs-+AGE-+AGI-+AGM-+AC0-+AAA-", Rex::Text.to_unicode("abc+abc-\x00", 'utf-7', 'all'), 'utf-7-all') - - assert_equal("a\303\272", Rex::Text.to_unicode("a\xFA", 'utf-8')) - assert_equal("\xC1\xA1", Rex::Text.to_unicode('a', 'utf-8', 'overlong', 2), 'utf-8 overlong') - assert_equal("\xE0\x81\xA1", Rex::Text.to_unicode('a', 'utf-8', 'overlong', 3), 'utf-8 overlong') - assert_equal("\xF0\x80\x81\xA1", Rex::Text.to_unicode('a', 'utf-8', 'overlong', 4), 'utf-8 overlong') - assert_equal("\xF8\x80\x80\x81\xA1", Rex::Text.to_unicode('a', 'utf-8', 'overlong', 5), 'utf-8 overlong') - assert_equal("\xFC\x80\x80\x80\x81\xA1", Rex::Text.to_unicode('a', 'utf-8', 'overlong', 6), 'utf-8 overlong') - assert_equal("\xFE\x80\x80\x80\x80\x81\xA1", Rex::Text.to_unicode('a', 'utf-8', 'overlong', 7), 'utf-8 overlong') - 100.times { - assert(["\xC1\x21","\xC1\x61","\xC1\xE1"].include?(Rex::Text.to_unicode('a', 'utf-8', 'invalid')), 'utf-8 invalid') - assert(["\xE0\x01\x21","\xE0\x01\x61","\xE0\x01\xA1","\xE0\x01\xE1","\xE0\x41\x21","\xE0\x41\x61","\xE0\x41\xA1","\xE0\x41\xE1","\xE0\x81\x21","\xE0\x81\x61","\xE0\x81\xA1","\xE0\x81\xE1","\xE0\xC1\x21","\xE0\xC1\x61","\xE0\xC1\xA1","\xE0\xC1\xE1"].include?(Rex::Text.to_unicode('a', 'utf-8', 'invalid', 3)), 'utf-8 invalid 3 byte') - } - - a = ["\xC1\x21","\xC1\x61","\xC1\xE1"] - 10.times { - encoded = Rex::Text.to_unicode('a', 'utf-8', 'invalid') - if a.include?(encoded) - a.delete(encoded) - end - } - assert_equal([], a, 'all possible values') - - assert_raises(TypeError) { - Rex::Text.to_unicode('a', 'utf-8', '', 8) - } - assert_raises(TypeError) { - Rex::Text.to_unicode('a', 'utf-8', 'foo', 6) - } - - assert_raises(TypeError) { - Rex::Text.to_unicode('a', 'uhwtfms', -1) - } - - 100.times { - assert(["\x01\x00","\x01\x02","\x01\x04","\x01\xcd","\x01\xde","\xff\x21"].include?(Rex::Text.to_unicode('A', 'uhwtfms')), 'uhwtfms') - assert(["\x00\xc0","\x00\xc1","\x00\xc2","\x00\xc3","\x00\xc4","\x00\xc5"].include?(Rex::Text.to_unicode('A', 'uhwtfms', 949)), 'uhwtfms codepage 949') - } - - a = ["\x01\x00","\x01\x02","\x01\x04","\x01\xcd","\x01\xde","\xff\x21"] - 20.times { - encoded = Rex::Text.to_unicode('A', 'uhwtfms') - if a.include?(encoded) - a.delete(encoded) - end - } - assert_equal([], a, 'all possible values uhwtfms') - - assert_raises(TypeError) { - Rex::Text.to_unicode('a', 'uhwtfms-half', 1) - } - - assert_equal("\xFF\x01", Rex::Text.to_unicode('!', 'uhwtfms-half')) - srand(0) - assert_equal("\xff\x2d\xff\x49\xff\x43\xff\x52\xff\x4f\xff\x53\xff\x4f\xff\x46\xff\x54\x20\x04\xff\x45\xff\x4e\xff\x43\xff\x4f\xff\x44\xff\x49\xff\x4e\xff\x47\x30\x00\xff\x44\xff\x52\xff\x49\xff\x56\xff\x45\xff\x53\x20\x05\xff\x4d\xff\x45\x20\x00\xff\x43\xff\x52\xff\x41\xff\x5a\xff\x59\xff\x01", Rex::Text.to_unicode('Microsoft encoding drives me crazy!', 'uhwtfms-half')) - end - - def test_zlib - assert_equal("x\332\313\310T\310\315\317\005\000\a\225\002;", Rex::Text.zlib_deflate('hi mom'), 'compress') - assert_equal('hi mom', Rex::Text.zlib_inflate("x\234\313\310T\310\315\317\005\000\a\225\002;"), 'decompress') - end - - def test_gzip - string = Rex::Text.gzip('hi mom') - assert_equal("\x1f\x8b\x08\x00", string.slice!(0,4), 'gzip headers') - - # skip the next 6 bytes as it is host & time specific (zlib's example gun does, so why not us too?) - string.slice!(0,6) - - assert_equal("\xcb\xc8\x54\xc8\xcd\xcf\x05\x00\x68\xa4\x1c\xf0\x06\x00\x00\x00", string, 'gzip data') - - assert_equal('hi mom', Rex::Text.ungzip("\037\213\010\000|\261\275C\002\003\313\310T\310\315\317\005\000h\244\034\360\006\000\000\000"), 'ungzip') - end - - def test_badchar_index - assert_equal(nil, Rex::Text.badchar_index('abcdef', 'gzk')) - assert_equal(2, Rex::Text.badchar_index('123avd', 'ly3')) - end - - def test_hexify - str = "\x01\x02\xff\x00" - - assert_equal("\\x01\\x02\\xff\\x00", Rex::Text.to_hex(str), 'to_hex') - assert_equal("ABC01ABC02ABCffABC00", Rex::Text.to_hex(str, 'ABC'), 'to_hex with prefix') - assert_equal('%u0102%uff00', Rex::Text.to_hex(str, '%u', 2), 'to_hex with chunk size of 2') - - # to_hex, without providing enouigh data to chunk on a given size - assert_raises(RuntimeError){ Rex::Text.to_hex('a', '', 2) } - - assert_equal("buf = \n\"\\x01\\x02\\xff\\x00\"\n", Rex::Text.to_ruby(str), 'to_ruby') - assert_equal("my $buf = \n\"\\x01\\x02\\xff\\x00\";\n", Rex::Text.to_perl(str), 'to_perl') - assert_equal("export buf=\\\n$'\\x01\\x02\\xff\\x00\'\n", Rex::Text.to_bash(str), 'to_bash') - assert_equal("unsigned char buf[] = \n\"\\x01\\x02\\xff\\x00\";\n", Rex::Text.to_c(str), 'to_c') - - # 0 -> 20 - str = "\000\001\002\003\004\005\006\a\010\t\n\v\f\r\016\017\020\021\022\023" - - assert_equal("buf = \n\"\\x00\\x01\\x02\\x03\" +\n\"\\x04\\x05\\x06\\x07\" +\n\"\\x08\\x09\\x0a\\x0b\" +\n\"\\x0c\\x0d\\x0e\\x0f\" +\n\"\\x10\\x11\\x12\\x13\"\n", Rex::Text.to_ruby(str, 20), 'to_ruby with wrap') - assert_equal("my $buf = \n\"\\x00\\x01\\x02\\x03\" .\n\"\\x04\\x05\\x06\\x07\" .\n\"\\x08\\x09\\x0a\\x0b\" .\n\"\\x0c\\x0d\\x0e\\x0f\" .\n\"\\x10\\x11\\x12\\x13\";\n", Rex::Text.to_perl(str, 20), 'to_perl with wrap') - assert_equal("export buf=\\\n$'\\x00\\x01\\x02\\x03\'\\\n$'\\x04\\x05\\x06\\x07\'\\\n$'\\x08\\x09\\x0a\\x0b'\\\n$'\\x0c\\x0d\\x0e\\x0f'\\\n$'\\x10\\x11\\x12\\x13\'\n", Rex::Text.to_bash(str, 20), 'to_bash with wrap') - assert_equal("unsigned char buf[] = \n\"\\x00\\x01\\x02\\x03\\x04\"\n\"\\x05\\x06\\x07\\x08\\x09\"\n\"\\x0a\\x0b\\x0c\\x0d\\x0e\"\n\"\\x0f\\x10\\x11\\x12\\x13\";\n", Rex::Text.to_c(str, 20, "buf"), 'to_c with wrap') - assert_equal("\\x0a", Rex::Text.to_hex("\n"), 'to_hex newline') - - str = "\x05Hello\x06World!\x03\x41\x42\x43" - assert_equal("\\x05Hello\\x06World!\\x03ABC", Rex::Text.to_hex_ascii(str)) - end - - def test_xml_char_encode - str = "\x05hello\x06world" - assert_equal("helloworld", Rex::Text.xml_char_encode(str)) - end - - def test_wordwrap - txt = "this is a test of the word wrap features" - - assert_equal("this is a \ntest of \nthe word \nwrap \nfeatures\n", Rex::Text.wordwrap(txt, 0, 10)) - end - - def test_transforms - assert_equal("acbd18db4cc2f85cedef654fccc4a4d8", Rex::Text.md5('foo')) - end - -end diff --git a/lib/rex/transformer.rb.ut.rb b/lib/rex/transformer.rb.ut.rb deleted file mode 100644 index 26db466610..0000000000 --- a/lib/rex/transformer.rb.ut.rb +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..')) - -require 'test/unit' -require 'rex/exceptions' -require 'rex/transformer' - -class Rex::Transformer::UnitTest < Test::Unit::TestCase - class Pizza - def Pizza.from_s(str) - end - end - - class ArrayTester - def self.from_a(a) - a[0] + a[1] - end - end - - def test_transformer - a = Rex::Transformer.transform([ 'yo', 'ho' ], Array, [ String ], 'Jones') - - assert_equal(2, a.length, "invalid array length") - assert_equal('yo', a[0], "invalid first element") - assert_equal('ho', a[1], "invalid second element") - - assert_raise(Rex::ArgumentError, "invalid transform") { - Rex::Transformer.transform('dog', Array, [ Pizza ], 'bob') - } - end - - def test_from_a - a = Rex::Transformer.transform([ [ 'one', 'two' ] ], Array, [ ArrayTester ], 'Jimmy') - - assert_equal('onetwo', a[0], "invalid from_a conversion") - end -end diff --git a/lib/rex/ui/text/color.rb.ut.rb b/lib/rex/ui/text/color.rb.ut.rb deleted file mode 100644 index c20de93a24..0000000000 --- a/lib/rex/ui/text/color.rb.ut.rb +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'test/unit' -require 'rex/ui/text/color' - -class Rex::Ui::Text::Color::UnitTest < Test::Unit::TestCase - - def test_color - color = Rex::Ui::Text::Color.new.ansi('bold', 'red') - color += 'hey sup' - color += Rex::Ui::Text::Color.new.ansi('clear') - - assert_equal("\e[1;31mhey sup\e[0m", color) - end - -end diff --git a/lib/rex/ui/text/progress_tracker.rb.ut.rb b/lib/rex/ui/text/progress_tracker.rb.ut.rb deleted file mode 100644 index bef742aac2..0000000000 --- a/lib/rex/ui/text/progress_tracker.rb.ut.rb +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'test/unit' -require 'rex/ui' - -class Rex::Ui::Text::ProgressTracker::UnitTest < Test::Unit::TestCase - - def test_stuff - output = Rex::Ui::Text::Output::Buffer.new - pt = Rex::Ui::Text::ProgressTracker.new(output) - - pt.range = 1..10 - - assert_equal(1, pt.start) - assert_equal(10, pt.stop) - - pt.start = 2 - assert_equal(2, pt.start) - pt.stop = 9 - assert_equal(9, pt.stop) - assert_equal(2, pt.pos) - assert_equal('', output.buf) - assert_equal(3, pt.step) - assert_equal(4, pt.step("test")) - assert_equal("[*] 4: test\n", output.buf) - output.reset - assert_equal("[-] bad\n", pt.error("bad")) - output.reset - assert_equal("[-] fatal: bad\n", pt.abort("bad")) - end - -end diff --git a/lib/rex/ui/text/table.rb.ut.rb b/lib/rex/ui/text/table.rb.ut.rb deleted file mode 100644 index 00b63208d1..0000000000 --- a/lib/rex/ui/text/table.rb.ut.rb +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env ruby -# -*- coding: binary -*- - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) - -require 'test/unit' -require 'rex/ui/text/table' - -class Rex::Ui::Text::Table::UnitTest < Test::Unit::TestCase - - def new_table(opts = {}) - if (opts['Columns'] == nil) - opts['Columns'] = - [ - 'col1', - 'col2', - 'col3' - ] - end - - tbl = Rex::Ui::Text::Table.new(opts) - - tbl << [ "r1cell1", "r1cell2", "r1cell3" ] - tbl << [ "r2cell1", "r2cell2", "r2cell3" ] - - return tbl - end - - def test_basic - tbl = new_table - - dstr = < 4) - - dstr = < - [ - "\x29\xc9\x83\xe9\xff\xe8\xff\xff\xff\xff\xc0\x5e\x81\x76" + - "\x0e\x66\x30\x86\x84\x83\xee\xfc\xe2\xf4\x27\x72\xc5\xc0", - 0x84863066 - ], - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" => - [ - "\x29\xc9\x83\xe9\xf9\xe8\xff\xff\xff\xff\xc0\x5e\x81\x76" + - "\x0e\xad\x6c\x5d\xb4\x83\xee\xfc\xe2\xf4\xec\x2e\x1e\xf0" + - "\xe8\x2a\x1a\xfc\xe4\x26\x16\xf8\xe0\x22\x12\xe4\xfc\x3e" + - "\x0e\xe0\xf8\x3a\x0a\xec\xf4\x36\x5d\xb4", - 0xb45d6cad, - 2 - ] - }.each_pair { |raw, real| - offset = real[2] || 0 - - encoded = k.encode(raw, '', Msf::EncoderState.new(real[1])) - - assert_equal(real[0][offset, -1], encoded[offset, -1]) - } - - end - -end diff --git a/modules/encoders/x86/countdown.rb.ut.rb b/modules/encoders/x86/countdown.rb.ut.rb deleted file mode 100644 index 5c1755275b..0000000000 --- a/modules/encoders/x86/countdown.rb.ut.rb +++ /dev/null @@ -1,51 +0,0 @@ -## -# This file is part of the Metasploit Framework and may be subject to -# redistribution and commercial restrictions. Please see the Metasploit -# web site for more information on licensing and terms of use. -# http://metasploit.com/ -## - - -#!/usr/bin/env ruby - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')) -$:.unshift(File.dirname(__FILE__)) - -require 'test/unit' -require 'rex/ui' -require 'msf/core' -require 'countdown' - -class Metasploit3 < Msf::Test::Unit::TestCase - - Klass = Msf::Encoders::X86::Countdown - - def test_encoder - - k = Klass.new - - { - "\xcc\xcc\xcc\xcc" => - [ - "\x6a\x03\x59\xe8\xff\xff\xff\xff\xc1\x5e\x30\x4c\x0e\x07" + - "\xe2\xfa\xcd\xce\xcf\xc8", - 4 - ], - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" => - [ - "\x6a\x19\x59\xe8\xff\xff\xff\xff\xc1\x5e\x30\x4c\x0e\x07" + - "\xe2\xfa\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40" + - "\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40", - 4 - ] - }.each_pair { |raw, real| - offset = real[1] || 0 - - encoded = k.encode(raw, '') - - assert_equal(real[0][offset, -1], encoded[offset, -1]) - } - - end - -end diff --git a/modules/encoders/x86/fnstenv_mov.rb.ut.rb b/modules/encoders/x86/fnstenv_mov.rb.ut.rb deleted file mode 100644 index a486d675f2..0000000000 --- a/modules/encoders/x86/fnstenv_mov.rb.ut.rb +++ /dev/null @@ -1,52 +0,0 @@ -## -# This file is part of the Metasploit Framework and may be subject to -# redistribution and commercial restrictions. Please see the Metasploit -# web site for more information on licensing and terms of use. -# http://metasploit.com/ -## - - -#!/usr/bin/env ruby - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')) -$:.unshift(File.dirname(__FILE__)) - -require 'test/unit' -require 'rex/ui' -require 'msf/core' -require 'fnstenv_mov' - -class Metasploit3 < Msf::Test::Unit::TestCase - - Klass = Msf::Encoders::X86::FnstenvMov - - def test_encoder - - k = Klass.new - - { - "\xcc\xcc\xcc\xcc" => - [ - "\x6a\x01\x59\xd9\xee\xd9\x74\x24\xf4\x5b\x81\x73\x13\x3e" + - "\x33\x75\x05\x83\xeb\xfc\xe2\xf4\xf2\xff\xb9\xc9", - 4 - ], - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" => - [ - "\x6a\x07\x59\xd9\xee\xd9\x74\x24\xf4\x5b\x81\x73\x13\x39" + - "\xaf\x73\x32\x83\xeb\xfc\xe2\xf4\x78\xed\x30\x76\x7c\xe9" + - "\x34\x7a\x70\xe5\x38\x7e\x74\xe1\x3c\x62\x68\xfd\x20\x66" + - "\x6c\xf9\x24\x6a\x60\xf5\x73\x32", - 4 - ] - }.each_pair { |raw, real| - offset = real[1] || 0 - - encoded = k.encode(raw, '') - - assert_equal(real[0][offset, -1], encoded[offset, -1]) - } - - end - -end diff --git a/modules/nops/nop_test.rb.ut.rb b/modules/nops/nop_test.rb.ut.rb deleted file mode 100644 index 17a5a201ad..0000000000 --- a/modules/nops/nop_test.rb.ut.rb +++ /dev/null @@ -1,47 +0,0 @@ -## -# This file is part of the Metasploit Framework and may be subject to -# redistribution and commercial restrictions. Please see the Metasploit -# web site for more information on licensing and terms of use. -# http://metasploit.com/ -## - - -#!/usr/bin/env ruby -# -# This file tests all x86 nops to ensure that they execute correctly. -# - -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib')) -$:.unshift(File.join(File.dirname(__FILE__), '..', '..', 'dev', 'machinetest')) - -require 'rex' -require 'msf/core' -require 'msf/base' -require 'machinetest' - -$framework = Msf::Simple::Framework.create - -$framework.nops.each_module { |name, mod| - e = mod.new - h = {} - failed = 0 - passed = 0 - - next if (e.arch?(ARCH_X86) == false) - - 1000.times { - - if (off = MachineTest.test(buf = e.generate_sled(64), true)) - failed += 1 - $stderr.puts("#{name.ljust(25)}: failure at byte #{off}: #{Rex::Text.to_hex(buf)}") - else - passed += 1 - end - - h[buf] = true - - } - - $stderr.puts("#{name.ljust(25)}: Passed: #{passed}, Failed: #{failed}, Unique: #{h.keys.length}") - -} diff --git a/test/lib/regexr.rb.ut.rb b/test/lib/regexr.rb.ut.rb deleted file mode 100644 index 5baba765c6..0000000000 --- a/test/lib/regexr.rb.ut.rb +++ /dev/null @@ -1,73 +0,0 @@ -## -## Tests for the regexr library -## $Id$ - -$:.unshift(File.expand_path(File.dirname(__FILE__)) ) - -require 'test/unit' -require 'regexr' - -class RegexrTest < Test::Unit::TestCase - - def setup - @r = Regexr.new - end - - def teardown - @r = nil - end - - def test_determine_start - assert @r.verify_start("this is the start\nof a line", "this is the start") - end - - def test_determine_end - assert @r.verify_end("this is the start\nof a line", "of a line") - end - - def test_determine start_end - assert @r.verify_start_and_end("this is the start\nof a line", "this is the start", "of a line") - end - - def test_success_not_defined - assert @r.ensure_all_exist_in_data("i can't get no\nsatisfaction") - end - - def test_no_success - assert !@r.ensure_all_exist_in_data("i can't get no\nsatisfaction", ["beast of burden"]) - end - - def test_single_success - assert @r.ensure_all_exist_in_data("this is the start\nof a line\nbut it's not the end", ["of a line"]) - end - - def test_multiple_successes - assert @r.ensure_all_exist_in_data("this is the start\nof a line\nbut it's not the end", ["this is the start","of a line"]) - end - - def test_failure_not_defined - assert @r.ensure_none_exist_in_data("this is the start\nof a line\nbut it's not the end") - end - - def test_no_failure - assert @r.ensure_none_exist_in_data("this is the start\nof a line\nbut it's not the end", ["nope, no failure here"]) - end - - def test_single_failure - assert !@r.ensure_none_exist_in_data("this is the start\nof a line\nbut it's not the end", ["of a line", "there's a failure here somewhere"]) - end - - def test_multiple_failures - assert !@r.ensure_none_exist_in_data("this is the start\nof a line\nbut it's not the end", ["of a line","but it's not the end"]) - end - - def test_excepted_failure - assert @r.ensure_none_exist_in_data("this is the start\nof a line\nbut it's not the end", ["no way man", "end"], ["but it's not the end"]) - end - - def test_success_and_failure - assert @r.ensure_all_exist_in_data("this is the start\nof a line\nbut it's not the end", ["but it's not the end"]) - assert !@r.ensure_none_exist_in_data("this is the start\nof a line\nbut it's not the end", ["no way man", "end"]) - end - -end From ea7805d3c83188a196d095680056ec093db136fd Mon Sep 17 00:00:00 2001 From: Matt Andreko Date: Thu, 23 May 2013 15:02:39 -0400 Subject: [PATCH 6/6] Fixed a bug in the HSTS module around null headers --- modules/auxiliary/scanner/http/http_hsts.rb | 24 ++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/modules/auxiliary/scanner/http/http_hsts.rb b/modules/auxiliary/scanner/http/http_hsts.rb index c1925c84c8..a51a0d5268 100644 --- a/modules/auxiliary/scanner/http/http_hsts.rb +++ b/modules/auxiliary/scanner/http/http_hsts.rb @@ -35,18 +35,22 @@ class Metasploit3 < Msf::Auxiliary 'method' => 'GET', }, 25) - hsts = res.headers['Strict-Transport-Security'] + if res + hsts = res.headers['Strict-Transport-Security'] - if res and hsts - print_good("#{ip}:#{rport} - Strict-Transport-Security:#{hsts}") - report_note({ - :data => hsts, - :type => "hsts.data", - :host => ip, - :port => rport - }) + if hsts + print_good("#{ip}:#{rport} - Strict-Transport-Security:#{hsts}") + report_note({ + :data => hsts, + :type => "hsts.data", + :host => ip, + :port => rport + }) + else + print_error("#{ip}:#{rport} No HSTS found.") + end else - print_error("#{ip}:#{rport} No HSTS found.") + print_error("#{ip}:#{rport} No headers were returned.") end rescue ::Timeout::Error, ::Errno::EPIPE