port login tests to rspec

This commit is contained in:
Stephen
2024-03-28 08:21:46 +10:00
parent cdba6b632f
commit b5bbe9ed6a
2 changed files with 73 additions and 150 deletions

View File

@@ -7,72 +7,90 @@ require 'rspec'
require 'spec/support/constants.rb'
# require '../common/beef_test'
RSpec.describe 'Beef Login' do
# let(:session) { Capybara::Session.new(:selenium_headless) }
let(:session) { Capybara::Session.new(:selenium_headless) }
# before(:each) do
# session.visit(ATTACK_URL)
# sleep 2.0
# end
before(:each) do
@pid = start_beef_server
# sleep 2.0
end
# after(:each) do
# BeefTest.save_screenshot(session)
# session.driver.browser.close
# end
after(:each) do
stop_beef_server(@pid)
# BeefTest.save_screenshot(session)
session.driver.browser.close
end
# it 'logs in successfully' do
# session.fill_in 'user', with: BEEF_USER
# session.fill_in 'pass', with: BEEF_PASSWD
# session.click_button('Login')
# sleep 10.0
# expect(session).to have_content('Logout')
# end
it 'logs in successfully' do
session.visit(ATTACK_URL)
# it 'logs out successfully' do
# session.fill_in 'user', with: BEEF_USER
# session.fill_in 'pass', with: BEEF_PASSWD
# session.click_button('Login')
# sleep 2.0
# session.click_link('Logout')
# sleep 2.0
# expect(session).to have_title('BeEF Authentication')
# end
expect(session.has_content?('Authentication', wait: 10))
expect(session.has_no_content?('Hooked Browsers', wait: 10))
# it 'displays logs tab' do
# session.fill_in 'user', with: BEEF_USER
# session.fill_in 'pass', with: BEEF_PASSWD
# session.click_button('Login')
# sleep 2.0
# session.click_on('Logs')
# expect(session).to have_content('Logout')
# expect(session).to have_content('Hooked Browsers')
# expect(session).to have_content('Type')
# expect(session).to have_content('Event')
# expect(session).to have_content('Date')
# expect(session).to have_content('Page')
# expect(session).to have_content('User with ip 127.0.0.1 has successfully authenticated in the application')
# end
if session.has_field?('user', visible: true)
session.fill_in 'user', with: BEEF_USER
end
# it 'hooks a browser successfully' do
# attacker = BeefTest.new_attacker
# victim = BeefTest.new_victim
if session.has_field?('pass', visible: true)
session.fill_in 'pass', with: BEEF_PASSWD
end
# sleep 5.0
if session.has_button?('Login', visible: true)
session.click_button('Login')
end
# expect(attacker).to have_content(VICTIM_DOMAIN)
# expect(attacker).to have_content('127.0.0.1')
# attacker.click_on("127.0.0.1", match: :first)
expect(session.has_no_content?('Authentication', wait: 10))
expect(session.has_content?('Hooked Browsers', wait: 10))
end
# sleep 1.0
it 'logs out successfully' do
session = BeefTest.login()
# expect(attacker).to have_content('Details')
# expect(attacker).to have_content('Commands')
expect(session).not_to be_nil
expect(session.has_content?('Hooked Browsers', wait: 10))
expect(session.has_content?('Logout', wait: 10))
# BeefTest.save_screenshot(attacker)
# BeefTest.save_screenshot(victim)
session.click_link('Logout')
# BeefTest.logout(attacker)
# attacker.driver.browser.close
# victim.driver.browser.close
# end
expect(session.has_no_content?('Hooked Browsers', wait: 10))
expect(session.has_content?('Logout', wait: 10))
expect(session.has_content?('BeEF Authentication', wait: 10))
end
it 'displays logs tab' do
session = BeefTest.login()
expect(session.has_content?('Hooked Browsers', wait: 10))
expect(session.has_content?('Logout', wait: 10))
expect(session.has_content?('Logs', wait: 10))
session.click_on('Logs')
expect(session).to have_content('Logout', wait: 10)
expect(session).to have_content('Hooked Browsers', wait: 10)
expect(session).to have_content('Type', wait: 10)
expect(session).to have_content('Event', wait: 10)
expect(session).to have_content('Date', wait: 10)
expect(session).to have_content('Page', wait: 10)
expect(session).to have_content('User with ip 127.0.0.1 has successfully authenticated in the application', wait: 10)
end
it 'hooks a browser successfully' do
attacker = BeefTest.new_attacker
victim = BeefTest.new_victim
expect(attacker).to have_content('Logout', wait: 10)
expect(attacker).to have_content(VICTIM_DOMAIN, wait: 10)
attacker.click_on("127.0.0.1", match: :first)
expect(attacker).to have_content('Details')
expect(attacker).to have_content('Commands')
BeefTest.logout(attacker)
attacker.driver.browser.close
victim.driver.browser.close
end
end

View File

@@ -1,95 +0,0 @@
#
# Copyright (c) 2006-2024 Wade Alcorn - wade@bindshell.net
# Browser Exploitation Framework (BeEF) - https://beefproject.com
# See the file 'doc/COPYING' for copying permission
#
require 'test/unit'
require '../common/test_constants'
require '../common/beef_test'
require 'rspec/expectations'
class TC_Login < Test::Unit::TestCase
include RSpec::Matchers
def test_log_in
session = Capybara::Session.new(:selenium_headless)
session.visit(ATTACK_URL)
sleep 2.0
BeefTest.save_screenshot(session)
session.should have_title('BeEF Authentication')
session.fill_in 'user', :with => BEEF_USER
session.fill_in 'pass', :with => BEEF_PASSWD
BeefTest.save_screenshot(session)
session.click_button('Login')
sleep 10.0
session.should have_content('Logout')
BeefTest.save_screenshot(session)
session.driver.browser.close
end
def test_beef_test_login_function
session = BeefTest.login
session.should have_content('Logout')
BeefTest.save_screenshot(session)
session.driver.browser.close
end
def test_log_out
session = BeefTest.login
session.click_link('Logout')
sleep 2.0
session.should have_title('BeEF Authentication')
BeefTest.save_screenshot(session)
session.driver.browser.close
end
def test_beef_test_logout_function
session = BeefTest.login
session = BeefTest.logout(session)
sleep 2.0
session.should have_title('BeEF Authentication')
BeefTest.save_screenshot(session)
session.driver.browser.close
end
def test_logs_tab
session = BeefTest.login
session.click_on('Logs')
session.should have_content('Logout')
session.should have_content('Hooked Browsers')
session.should have_content('Type')
session.should have_content('Event')
session.should have_content('Date')
session.should have_content('Page')
session.should have_content('User with ip 127.0.0.1 has successfully authenticated in the application')
BeefTest.save_screenshot(session)
BeefTest.logout(session)
session.driver.browser.close
end
def test_hooking_browser
attacker = BeefTest.new_attacker
victim = BeefTest.new_victim
sleep 5.0
attacker.should have_content(VICTIM_DOMAIN)
attacker.should have_content('127.0.0.1')
attacker.click_on("127.0.0.1", match: :first)
sleep 1.0
attacker.should have_content('Details')
attacker.should have_content('Commands')
# attacker.should have_content('Rider') # Old functionality
BeefTest.save_screenshot(attacker)
BeefTest.save_screenshot(victim)
BeefTest.logout(attacker)
attacker.driver.browser.close
victim.driver.browser.close
end
end