New bind_redirect method added to the AssetHandler. See #664

This commit is contained in:
Christian Frichot
2013-01-20 16:59:01 +08:00
parent 63b7d44a5e
commit 3c4a0fad34
5 changed files with 119 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
#
# Copyright (c) 2006-2013 Wade Alcorn - wade@bindshell.net
# Browser Exploitation Framework (BeEF) - http://beefproject.com
# See the file 'doc/COPYING' for copying permission
#
require 'test/unit'
require 'rubygems'
require 'curb'
class TC_Redirector < Test::Unit::TestCase
@@port = 20000 + rand(10000)
def setup
$root_dir="../../"
$:.unshift File.join( %w{ ../../ } )
require 'core/loader'
require 'core/main/network_stack/assethandler.rb'
require 'core/main/network_stack/handlers/redirector.rb'
@@port += 1 # cycle through ports because the tcp teardown process is too slow
@port = @@port
config = {}
config[:BindAddress] = '127.0.0.1'
config[:Port] = @port.to_s
@mounts = {}
@mounts['/test'] = BeEF::Core::NetworkStack::Handlers::Redirector.new('http://www.beefproject.com')
@rackApp = Rack::URLMap.new(@mounts)
Thin::Logging.silent = true
@server = Thin::Server.new('127.0.0.1', @port.to_s, @rackApp)
trap("INT") { @server.stop }
trap("TERM") { @server.stop }
@pid = fork do
@server.start!
end
end
def teardown
Process.kill("INT",@pid)
$root_dir = nil
end
# the server doesn't offer a mutex or callback
def wait_for_server
max_waits = 3
sleep_length = 0.1
count = 0
while (count < max_waits)
break if @server.running?
count += 1
sleep sleep_length
end
end
def test_get
wait_for_server
response = Curl::Easy.http_get("http://127.0.0.1:" + @port.to_s + "/test/")
assert_equal 302, response.response_code
assert_equal "302 found", response.body_str
assert_match /Location: http:\/\/www\.beefproject\.com/, response.header_str
end
end

View File

@@ -9,6 +9,7 @@ require '../common/ts_common'
require './core/filter/tc_base'
require './core/filter/tc_command'
require './core/main/network_stack/handlers/redirector'
require './core/tc_loader'
require './core/tc_core'
require './core/tc_api'
@@ -53,6 +54,7 @@ class TS_BeefTests
suite << TC_Hackverter.suite
suite << TC_EventLogger.suite
suite << TC_Hooks.suite
suite << TC_Redirector.suite
return suite
end