bind and reverse handler unit tests
git-svn-id: file:///home/svn/incoming/trunk@2999 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
1605e575cd
commit
a9c7ecc42b
|
@ -81,7 +81,7 @@ module BindTcp
|
|||
rescue
|
||||
wlog("Exception caught in bind handler: #{$!}")
|
||||
end
|
||||
|
||||
|
||||
ctx.call if (client)
|
||||
|
||||
# Wait a second before trying again
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/ruby
|
||||
|
||||
$:.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::Module
|
||||
end
|
||||
|
||||
module Foo
|
||||
def handle_connection(client)
|
||||
self.success = 1
|
||||
end
|
||||
|
||||
attr_accessor :success, :session
|
||||
end
|
||||
|
||||
def test_handler
|
||||
h = Stub.new({})
|
||||
|
||||
h.extend(Msf::Handler::BindTcp)
|
||||
h.extend(Foo)
|
||||
|
||||
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
|
|
@ -0,0 +1,61 @@
|
|||
#!/usr/bin/ruby
|
||||
|
||||
$:.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::Module
|
||||
include Msf::Handler::ReverseTcp
|
||||
end
|
||||
|
||||
module Foo
|
||||
def handle_connection(client)
|
||||
self.success = 1
|
||||
end
|
||||
|
||||
attr_accessor :success, :session
|
||||
end
|
||||
|
||||
def test_handler
|
||||
h = Stub.new({})
|
||||
|
||||
h.extend(Foo)
|
||||
|
||||
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
|
Loading…
Reference in New Issue