Path: blob/master/test/integration/tc_social_engineering_rest.rb
1154 views
#1# Copyright (c) 2006-2025 Wade Alcorn - [email protected]2# Browser Exploitation Framework (BeEF) - https://beefproject.com3# See the file 'doc/COPYING' for copying permission4#5require 'test/unit'6require 'rest-client'7require 'json'8require '../common/test_constants'910# @todo RESTful API for the social engineering extension lacks some serious test coverage.11class TC_SocialEngineeringRest < Test::Unit::TestCase1213class << self1415# Login to API before performing any tests16def startup17json = {:username => BEEF_USER, :password => BEEF_PASSWD}.to_json18@@headers = {:content_type => :json, :accept => :json}1920response = RestClient.post("#{RESTAPI_ADMIN}/login",21json,22@@headers)2324result = JSON.parse(response.body)25@@token = result['token']2627$root_dir = '../../'28$:.unshift($root_dir)2930require 'core/loader'3132BeEF::Core::Configuration.new(File.join($root_dir, 'config.yaml'))33BeEF::Core::Configuration.instance.load_extensions_config3435@@config = BeEF::Core::Configuration.instance36end3738def shutdown39$root_dir = nil40end4142end4344# Tests DNS spoofing of cloned webpages45def test_1_dns_spoof46url = 'https://beefproject.com'47mount = '/beefproject'48dns_spoof = true4950json = {:url => url, :mount => mount, :dns_spoof => dns_spoof}.to_json5152domain = url.gsub(%r{^https?://}, '')5354response = RestClient.post("#{RESTAPI_SENG}/clone_page?token=#{@@token}",55json,56@@headers)5758check_response(response)5960# Send DNS request to server to verify that a new rule was added61dns_address = @@config.get('beef.extension.dns.address')62dns_port = @@config.get('beef.extension.dns.port')63dig_output = IO.popen(["dig", "@#{dns_address}", "-p", "#{dns_port}", "-t",64"A", "+short", "#{domain}"], 'r+').read.strip!6566foundmatch = false6768# Iterate local IPs (excluding loopbacks) to find a match to the 'dig'69# output70assert_block do71Socket.ip_address_list.each { |i|72if !(i.ipv4_loopback? || i.ipv6_loopback?)73return true if i.ip_address.to_s.eql?(dig_output.to_s)74end75}76end7778# assert(foundmatch)79end8081private8283# Assertions for verifying a response from the RESTful API84def check_response(response)85assert_not_nil(response.body)86assert_equal(200, response.code)8788result = JSON.parse(response.body)8990assert(result['success'])91assert(result['mount'])92end9394end959697