Enabled debug_modules tests. Now they work properly and are effective to automatically check if command modules generally work.

This commit is contained in:
antisnatchor
2013-01-17 14:17:04 +00:00
parent f584403a92
commit 63b7d44a5e
3 changed files with 53 additions and 26 deletions

View File

@@ -18,8 +18,13 @@ class TC_DebugModules < Test::Unit::TestCase
@@mod_debug_ascii_chars = nil @@mod_debug_ascii_chars = nil
@@mod_debug_test_network = nil @@mod_debug_test_network = nil
# NOTE: Tests within the same test class are called in the order they are defined.
# NOTE: However, test classes are run in alphabetical order by classname.
# That's why we use the prefix x_N_y, with N being the order of execution.
#
# Test RESTful API authentication with default credentials, returns the API token to be used later. # Test RESTful API authentication with default credentials, returns the API token to be used later.
def test_restful_auth def test_1_restful_auth
response = RestClient.post "#{RESTAPI_ADMIN}/login", response = RestClient.post "#{RESTAPI_ADMIN}/login",
{ 'username' => "#{BEEF_USER}", { 'username' => "#{BEEF_USER}",
'password' => "#{BEEF_PASSWD}"}.to_json, 'password' => "#{BEEF_PASSWD}"}.to_json,
@@ -34,9 +39,9 @@ class TC_DebugModules < Test::Unit::TestCase
end end
# Test RESTful API hooks handler hooking a victim browser, and then retrieving his BeEF session # Test RESTful API hooks handler hooking a victim browser, and then retrieving his BeEF session
def test_restful_hooks def test_2_restful_hooks
BeefTest.new_victim BeefTest.new_victim
sleep 2.0 sleep 5.0
response = RestClient.get "#{RESTAPI_HOOKS}", {:params => {:token => @@token}} response = RestClient.get "#{RESTAPI_HOOKS}", {:params => {:token => @@token}}
assert_equal 200, response.code assert_equal 200, response.code
assert_not_nil response.body assert_not_nil response.body
@@ -46,7 +51,7 @@ class TC_DebugModules < Test::Unit::TestCase
end end
# Test RESTful API modules handler, retrieving the IDs of the 3 debug modules currently in the framework # Test RESTful API modules handler, retrieving the IDs of the 3 debug modules currently in the framework
def test_restful_modules def test_3_restful_modules
response = RestClient.get "#{RESTAPI_MODULES}", {:params => {:token => @@token}} response = RestClient.get "#{RESTAPI_MODULES}", {:params => {:token => @@token}}
assert_equal 200, response.code assert_equal 200, response.code
assert_not_nil response.body assert_not_nil response.body
@@ -65,8 +70,8 @@ class TC_DebugModules < Test::Unit::TestCase
assert_not_nil @@mod_debug_ascii_chars assert_not_nil @@mod_debug_ascii_chars
assert_not_nil @@mod_debug_test_network assert_not_nil @@mod_debug_test_network
end end
#
# Test debug module "Test_return_long_string" using the RESTful API ## Test debug module "Test_return_long_string" using the RESTful API
def test_return_long_string def test_return_long_string
repeat_string = "BeEF" repeat_string = "BeEF"
repeat_count = 20 repeat_count = 20
@@ -83,17 +88,25 @@ class TC_DebugModules < Test::Unit::TestCase
assert success assert success
cmd_id = result['command_id'] cmd_id = result['command_id']
sleep 3.0 count = 0
response = RestClient.get "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_long_string}/#{cmd_id}", {:params => {:token => @@token}} response = RestClient.get "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_long_string}/#{cmd_id}?token=#{@@token}"
#TODO if the response is empty, the body size is 2, basically an empty Hash.
# don't know why empty?, nil and other checks are not working.
while(response.body.size <= 2 && count < 10)
response = RestClient.get "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_long_string}/#{cmd_id}?token=#{@@token}"
sleep 2
count += 1
end
assert_equal 200, response.code assert_equal 200, response.code
assert_not_nil response.body assert_not_nil response.body
result = JSON.parse(response.body) result = JSON.parse(response.body)
data = JSON.parse(result["data"]) data = JSON.parse(result['0']['data'])['data']
assert_not_nil data assert_not_nil data
assert_equal data["data"],(repeat_string * repeat_count) assert_equal data,(repeat_string * repeat_count)
end end
#
# Test debug module "Test_return_ascii_chars" using the RESTful API ## Test debug module "Test_return_ascii_chars" using the RESTful API
def test_return_ascii_chars def test_return_ascii_chars
response = RestClient.post "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_ascii_chars}?token=#{@@token}", response = RestClient.post "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_ascii_chars}?token=#{@@token}",
{}.to_json, # module does not expect any input {}.to_json, # module does not expect any input
@@ -104,18 +117,25 @@ class TC_DebugModules < Test::Unit::TestCase
result = JSON.parse(response.body) result = JSON.parse(response.body)
success = result['success'] success = result['success']
assert success assert success
cmd_id = result['command_id'] cmd_id = result['command_id']
sleep 3.0 count = 0
response = RestClient.get "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_ascii_chars}/#{cmd_id}", {:params => {:token => @@token}} response = RestClient.get "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_ascii_chars}/#{cmd_id}?token=#{@@token}"
#TODO if the response is empty, the body size is 2, basically an empty Hash.
# don't know why empty?, nil and other checks are not working.
while(response.body.size <= 2 && count < 10)
response = RestClient.get "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_ascii_chars}/#{cmd_id}?token=#{@@token}"
sleep 2
count += 1
end
assert_equal 200, response.code assert_equal 200, response.code
assert_not_nil response.body assert_not_nil response.body
result = JSON.parse(response.body) result = JSON.parse(response.body)
data = JSON.parse(result["data"]) data = JSON.parse(result['0']['data'])['data']
assert_not_nil data assert_not_nil data
ascii_chars = "" ascii_chars = ""
(32..127).each do |i| ascii_chars << i.chr end (32..127).each do |i| ascii_chars << i.chr end
assert_equal ascii_chars,data["data"] assert_equal ascii_chars,data
end end
# Test debug module "Test_network_request" using the RESTful API # Test debug module "Test_network_request" using the RESTful API
@@ -134,16 +154,23 @@ class TC_DebugModules < Test::Unit::TestCase
assert success assert success
cmd_id = result['command_id'] cmd_id = result['command_id']
sleep 3.0 count = 0
response = RestClient.get "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_test_network}/#{cmd_id}", {:params => {:token => @@token}} response = RestClient.get "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_test_network}/#{cmd_id}?token=#{@@token}"
#TODO if the response is empty, the body size is 2, basically an empty Hash.
# don't know why empty?, nil and other checks are not working.
while(response.body.size <= 2 && count < 10)
response = RestClient.get "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_test_network}/#{cmd_id}?token=#{@@token}"
sleep 2
count += 1
end
assert_equal 200, response.code assert_equal 200, response.code
assert_not_nil response.body assert_not_nil response.body
result = JSON.parse(response.body) result = JSON.parse(response.body)
data = JSON.parse(result["data"]) data = JSON.parse(result['0']['data'])['data']
res = JSON.parse(data["data"]) assert_not_nil data
assert_not_nil res assert_equal 200, JSON.parse(data)["status_code"]
assert_equal 200, res["status_code"] assert JSON.parse(data)["response_body"].include?("However you should still be capable of accessing it\n\t\tusing the Requester")
assert res["response_body"].include?("However you should still be capable of accessing it\n\t\tusing the Requester")
end end
end end

View File

@@ -63,7 +63,7 @@ class TC_login < Test::Unit::TestCase
attacker = BeefTest.new_attacker attacker = BeefTest.new_attacker
victim = BeefTest.new_victim victim = BeefTest.new_victim
sleep 2.0 sleep 5.0
attacker.has_content?(VICTIM_DOMAIN) attacker.has_content?(VICTIM_DOMAIN)
attacker.has_content?('127.0.0.1') attacker.has_content?('127.0.0.1')

View File

@@ -22,8 +22,8 @@ class TS_BeefIntegrationTests
suite = Test::Unit::TestSuite.new(name="BeEF Integration Test Suite") suite = Test::Unit::TestSuite.new(name="BeEF Integration Test Suite")
suite << TC_CheckEnvironment.suite suite << TC_CheckEnvironment.suite
#suite << TC_DebugModules.suite
suite << TC_login.suite suite << TC_login.suite
suite << TC_DebugModules.suite
suite << TC_Jools.suite suite << TC_Jools.suite
return suite return suite