diff --git a/Gemfile b/Gemfile index 65bf1aa85..c043c0d78 100644 --- a/Gemfile +++ b/Gemfile @@ -83,23 +83,25 @@ end # For running unit tests group :test do -if ENV['BEEF_TEST'] - gem 'rake' - gem 'test-unit' - gem 'test-unit-full' - gem 'curb' - gem 'selenium' - # selenium-webdriver 3.x is incompatible with Firefox version 48 and prior - gem 'selenium-webdriver', '~> 2.53.4' - gem 'rspec' - gem 'bundler-audit' - # nokogirl is needed by capybara which may require one of the below commands - # sudo apt-get install libxslt-dev libxml2-dev - # sudo port install libxml2 libxslt - gem 'capybara' - # RESTful API tests/generic command module tests - gem 'rest-client', '>= 2.0.1' -end + if ENV['BEEF_TEST'] + gem 'rake' + gem 'test-unit' + gem 'test-unit-full' + gem 'curb' + gem 'selenium' + # selenium-webdriver 3.x is incompatible with Firefox version 48 and prior + gem 'selenium-webdriver', '~> 2.53.4' + gem 'rspec' + gem 'bundler-audit' + # nokogirl is needed by capybara which may require one of the below commands + # sudo apt-get install libxslt-dev libxml2-dev + # sudo port install libxml2 libxslt + gem 'capybara' + # RESTful API tests/generic command module tests + gem 'rest-client', '>= 2.0.1' + gem 'pry' + gem 'pry-byebug' + end end source 'https://rubygems.org' diff --git a/Rakefile b/Rakefile index 248390365..1af190e9e 100644 --- a/Rakefile +++ b/Rakefile @@ -3,6 +3,8 @@ # Browser Exploitation Framework (BeEF) - http://beefproject.com # See the file 'doc/COPYING' for copying permission # +require 'yaml' +require 'pry-byebug' task :default => ["quick"] @@ -50,6 +52,14 @@ task :rdoc do Rake::Task['rdoc:rerdoc'].invoke end +desc 'rest test examples' +task :rest_test do + Rake::Task['beef_start'].invoke + + sh 'cd test/api/; ruby -W2 1333_auth_rate.rb' + + Rake::Task['beef_stop'].invoke +end ################################ # run bundle-audit @@ -155,28 +165,53 @@ end task :xserver_stop do puts "\nShutting down X11 Server...\n" - sh "ps -ef|grep Xvfb|grep -v grep|awk '{print $2}'|xargs kill" + sh "ps -ef|grep Xvfb|grep -v grep|grep -v rake|awk '{print $2}'|xargs kill" end ################################ # BeEF environment set up @beef_process_id = nil; +@beef_config_file = 'tmp/rk_beef_conf.yaml'; + task :beef_start => 'beef' do + # read environment param for creds or use bad_fred + test_user = ENV['TEST_BEEF_USER'] || 'bad_fred' + test_pass = ENV['TEST_BEEF_PASS'] || 'bad_fred_no_access' + + # write a rake config file for beef + config = YAML.load(File.read('./config.yaml')) + config['beef']['credentials']['user'] = test_user + config['beef']['credentials']['passwd'] = test_pass + File.open(@beef_config_file, 'w') { |f| YAML.dump(config, f) } + + # set the environment creds -- in case we're using bad_fred + ENV['TEST_BEEF_USER'] = test_user + ENV['TEST_BEEF_PASS'] = test_pass + config = nil + puts "Using config file: #{@beef_config_file}\n" + printf "Starting BeEF (wait a few seconds)..." - @beef_process_id = IO.popen("ruby ./beef -x 2> /dev/null", "w+") - delays = [10, 10, 5, 5, 4, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1] + @beef_process_id = IO.popen("ruby ./beef -c #{@beef_config_file} -x 2> /dev/null", "w+") + delays = [5, 5, 5, 4, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1] delays.each do |i| # delay for a few seconds printf '.' sleep (i) end - puts '.' + puts ".\n\n" end task :beef_stop do - puts "\nShutting down BeEF...\n" - sh "ps -ef|grep beef|grep -v grep|awk '{print $2}'|xargs kill" + # cleanup tmp/config files + puts "\nCleanup config file:\n" + rm_f @beef_config_file + ENV['TEST_BEEF_USER'] = nil + ENV['TEST_BEEF_PASS'] = nil + + # shutting down + puts "Shutting down BeEF...\n" + sh "ps -ef|grep beef|grep -v grep|grep -v rake|awk '{print $2}'|xargs kill" end ################################ @@ -233,7 +268,7 @@ end ################################ # Create CDE Package -# This will download and make the CDE Executable and +# This will download and make the CDE Executable and # gnereate a CDE Package in cde-package task :cde do @@ -270,5 +305,3 @@ end ################################ - - diff --git a/beef b/beef index d894654f9..c5f9137eb 100755 --- a/beef +++ b/beef @@ -1,5 +1,7 @@ #!/usr/bin/env ruby +require 'pry-byebug' + # # Copyright (c) 2006-2018 Wade Alcorn - wade@bindshell.net # Browser Exploitation Framework (BeEF) - http://beefproject.com diff --git a/config.yaml b/config.yaml index 2a83015f8..1f9d654ae 100644 --- a/config.yaml +++ b/config.yaml @@ -27,6 +27,8 @@ beef: # subnet of IP addresses that can connect to the admin UI #permitted_ui_subnet: "127.0.0.1/32" permitted_ui_subnet: "0.0.0.0/0" + # slow API calls to 1 every api_attempt_delay seconds + api_attempt_delay: "0.05" # HTTP server http: @@ -106,6 +108,8 @@ beef: # db_file is only used for sqlite db_file: "beef.db" + #db_pool: 50 # Issues with sqlite locking. + #db_timeout: 500 # https://stackoverflow.com/questions/7154664/ruby-sqlite3busyexception-database-is-locked # db connection information is only used for mysql/postgres db_host: "localhost" diff --git a/core/main/rest/api.rb b/core/main/rest/api.rb index 53ebdc541..24f9af12a 100644 --- a/core/main/rest/api.rb +++ b/core/main/rest/api.rb @@ -63,7 +63,7 @@ module BeEF # This is from extensions/admin_ui/controllers/authentication/authentication.rb # def self.permitted_source?(ip) - # get permitted subnet + # get permitted subnet permitted_ui_subnet = BeEF::Core::Configuration.instance.get("beef.restrictions.permitted_ui_subnet") target_network = IPAddr.new(permitted_ui_subnet) @@ -74,6 +74,32 @@ module BeEF return target_network.include?(ip) end + # + # Rate limit through timeout + # This is from extensions/admin_ui/controllers/authentication/ + # + # Brute Force Mitigation + # Only one login request per config_delay_id seconds + # + # @param config_delay_id configuration name for the timeout + # @param last_time_attempt