Added RESTful API tests for /api/auth, /api/hooks, /api/modules. Added Test_return_long_string Debug module test using the API :D
This commit is contained in:
@@ -1,6 +1,17 @@
|
||||
BEEF_TEST_DIR = "/tmp/beef-test/"
|
||||
|
||||
# General constants
|
||||
ATTACK_DOMAIN = "attacker.beefproject.com"
|
||||
VICTIM_DOMAIN = "attacker.beefproject.com"
|
||||
ATTACK_URL = "http://" + ATTACK_DOMAIN + ":3000/ui/panel"
|
||||
VICTIM_URL = "http://" + VICTIM_DOMAIN + ":3000/demos/basic.html"
|
||||
|
||||
# Credentials
|
||||
BEEF_USER = "beef"
|
||||
BEEF_PASSWD = "beef"
|
||||
|
||||
# RESTful API root endpoints
|
||||
RESTAPI_HOOKS = "http://" + ATTACK_DOMAIN + ":3000/api/hooks"
|
||||
RESTAPI_LOGS = "http://" + ATTACK_DOMAIN + ":3000/api/logs"
|
||||
RESTAPI_MODULES = "http://" + ATTACK_DOMAIN + ":3000/api/modules"
|
||||
RESTAPI_ADMIN = "http://" + ATTACK_DOMAIN + ":3000/api/admin"
|
||||
|
||||
93
test/integration/tc_debug_modules.rb
Normal file
93
test/integration/tc_debug_modules.rb
Normal file
@@ -0,0 +1,93 @@
|
||||
require 'test/unit'
|
||||
require 'rest_client'
|
||||
require 'json'
|
||||
require '../common/test_constants'
|
||||
require '../common/beef_test'
|
||||
|
||||
class TC_DebugModules < Test::Unit::TestCase
|
||||
|
||||
@@token = nil
|
||||
@@hb_session = nil
|
||||
|
||||
@@mod_debug_long_string = nil
|
||||
@@mod_debug_ascii_chars = nil
|
||||
@@mod_debug_test_network = nil
|
||||
|
||||
# Test RESTful API authentication with default credentials, returns the API token to be used later.
|
||||
def test_restful_auth
|
||||
response = RestClient.post "#{RESTAPI_ADMIN}/login",
|
||||
{ 'username' => "#{BEEF_USER}",
|
||||
'password' => "#{BEEF_PASSWD}"}.to_json,
|
||||
:content_type => :json,
|
||||
:accept => :json
|
||||
assert_equal 200, response.code
|
||||
assert_not_nil response.body
|
||||
result = JSON.parse(response.body)
|
||||
success = result['success']
|
||||
@@token = result['token']
|
||||
assert(success)
|
||||
end
|
||||
|
||||
# Test RESTful API hooks handler hooking a victim browser, and then retrieving his BeEF session
|
||||
def test_restful_hooks
|
||||
BeefTest.new_victim
|
||||
sleep 2.0
|
||||
response = RestClient.get "#{RESTAPI_HOOKS}", {:params => {:token => @@token}}
|
||||
assert_equal 200, response.code
|
||||
assert_not_nil response.body
|
||||
result = JSON.parse(response.body)
|
||||
@@hb_session = result["hooked-browsers"]["online"]["0"]["session"]
|
||||
assert_not_nil @@hb_session
|
||||
end
|
||||
|
||||
# Test RESTful API modules handler, retrieving the IDs of the 3 debug modules currently in the framework
|
||||
def test_restful_modules
|
||||
response = RestClient.get "#{RESTAPI_MODULES}", {:params => {:token => @@token}}
|
||||
assert_equal 200, response.code
|
||||
assert_not_nil response.body
|
||||
result = JSON.parse(response.body)
|
||||
result.each do |mod|
|
||||
case mod[1]["class"]
|
||||
when "Test_return_long_string"
|
||||
@@mod_debug_long_string = mod[1]["id"]
|
||||
when "Test_return_ascii_chars"
|
||||
@@mod_debug_ascii_chars = mod[1]["id"]
|
||||
when "Test_network_request"
|
||||
@@mod_debug_test_network = mod[1]["id"]
|
||||
end
|
||||
end
|
||||
assert_not_nil @@mod_debug_long_string
|
||||
assert_not_nil @@mod_debug_ascii_chars
|
||||
assert_not_nil @@mod_debug_test_network
|
||||
end
|
||||
|
||||
# Test debug module "Test_return_long_string" using the RESTful API
|
||||
def test_return_long_string
|
||||
repeat_string = "BeEF"
|
||||
repeat_count = 20
|
||||
|
||||
BeefTest.new_victim
|
||||
sleep 2.0
|
||||
response = RestClient.post "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_long_string}?token=#{@@token}",
|
||||
{ 'repeat_string' => repeat_string,
|
||||
'repeat' => repeat_count}.to_json,
|
||||
:content_type => :json,
|
||||
:accept => :json
|
||||
assert_equal 200, response.code
|
||||
assert_not_nil response.body
|
||||
result = JSON.parse(response.body)
|
||||
success = result['success']
|
||||
assert success
|
||||
|
||||
cmd_id = result['command_id']
|
||||
sleep 3.0
|
||||
response = RestClient.get "#{RESTAPI_MODULES}/#{@@hb_session}/#{@@mod_debug_long_string}/#{cmd_id}", {:params => {:token => @@token}}
|
||||
assert_equal 200, response.code
|
||||
assert_not_nil response.body
|
||||
result = JSON.parse(response.body)
|
||||
data = JSON.parse(result["data"])
|
||||
assert_not_nil data
|
||||
assert data["data"] == (repeat_string * repeat_count)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -23,6 +23,7 @@ Capybara.run_server = false # we need to run our own BeEF server
|
||||
require 'selenium/webdriver'
|
||||
|
||||
require './check_environment' # Basic log in and log out tests
|
||||
require './tc_debug_modules' # RESTful API tests (as well as debug modules)
|
||||
require './tc_login' # Basic log in and log out tests
|
||||
|
||||
class TS_BeefIntegrationTests
|
||||
@@ -30,6 +31,7 @@ class TS_BeefIntegrationTests
|
||||
|
||||
suite = Test::Unit::TestSuite.new(name="BeEF Integration Test Suite")
|
||||
suite << TC_CheckEnvironment.suite
|
||||
suite << TC_DebugModules.suite
|
||||
suite << TC_login.suite
|
||||
|
||||
return suite
|
||||
|
||||
Reference in New Issue
Block a user