diff --git a/Gemfile b/Gemfile index 2365d22a4..69911f74b 100644 --- a/Gemfile +++ b/Gemfile @@ -88,23 +88,23 @@ end # For running unit tests group :test do -if ENV['BEEF_TEST'] - 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 'byebug' -end + if ENV['BEEF_TEST'] + 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 'byebug' + end end source 'https://rubygems.org' diff --git a/INSTALL.txt b/INSTALL.txt index eee69bce5..ab5ca94b4 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -6,98 +6,66 @@ =============================================================================== +Source +------ + +Obtain application source code either by downloading the latest archive: + + $ wget https://github.com/beefproject/beef/archive/master.zip + +Or cloning the Git repository from Github: + + $ git clone https://github.com/beefproject/beef + + +Prerequisites +-------------- + +BeEF requires Ruby 2.3+. + +If your operating system package manager does not support Ruby version 2.3, +you can add the brightbox ppa repository for the latest version of Ruby: + + $ sudo apt-add-repository -y ppa:brightbox/ruby-ng + +Alternatively, consider using a Ruby environment manager such as rbenv or rvm +to manager your Ruby versions. Refer to the following for more information: + + * rbenv: https://github.com/rbenv/rbenv + * rvm: https://rvm.io/rvm/install' + + Installation ------------ - 1. Prerequisites (platform independent) - 2. Prerequisites (Windows) - 3. Prerequisites (Linux) - 4. Prerequisites (Mac OSX) - 5. Install instructions - 6. Run instructions +Once Ruby is installed, run the install script in the BeEF directory: + + ./install + +This script installs the required operating system packages and all the +prerequisite Ruby gems. + +Upon successful installation, be sure to read the Configuration page +on the wiki for important details on configuring and securing BeEF. + + https://github.com/beefproject/beef/wiki/Configuration +Start BeEF +---------- - 1. Prerequisites (platform independent) +To start BeEF, simply run: - BeEF requires Ruby 2.2+ and the "bundler" gem. Bundler can be installed by: - - gem install bundler - - - 2. Prerequisites (Windows) - - Windows is no longer supported. The following instructions are outdated. - - !!! This must be done PRIOR to running the bundle install command !!! - - Windows requires the sqlite.dll. Simply grab the zip file below and extract it to your Ruby bin directory: - - http://www.sqlite.org/sqlitedll-3_7_0_1.zip - - Other than that, you also need TheRubyRacer. As it's painful to install it on Windows, you can download 2 pre-compiled V8 DLLs and 2 gems from https://github.com/eakmotion/therubyracer_for_windows. - - Finally, edit beef's gem lock file by replacing the required ruby racer version with the version downloaded from the link above. - - 3. Prerequisites (Linux) - - !!! This must be done PRIOR to running the bundle install command !!! - - On linux you will need to find the packages specific to your distribution for sqlite. An example build script for Ubuntu 14.04 systems is: - - # Set your prefered build dir - BUILDDIR=/opt && \ - cd $BUILDDIR && \ - \ - # Install dependences - sudo apt-get update && \ - sudo apt-get install -y \ - build-essential \ - git \ - libsqlite3-dev \ - software-properties-common \ - sqlite3 \ - sqlite3-doc && \ - \ - # Add brightbox ppa for the latest version of ruby - sudo apt-add-repository -y \ - ppa:brightbox/ruby-ng && \ - \ - # Install ruby (2.2 in this example) - sudo apt-get update && \ - sudo apt-get install -y \ - ruby2.2 \ - ruby2.2-dev && \ - \ - # Install bundler using gem - sudo gem install bundler - - 3.1. It is recommended not to use rvm. If you use rvm the ruby binaries are installed to locations outside of your default path which may cause problems later. - - 4. Prerequisites (Mac OSX) - - - XCode: provides the sqlite support BeEF needs - - - Ruby 2.1 - To install RVM and Ruby 2.1.5 on Mac OS: - $ bash -s stable < <(curl -Ls https://raw.githubusercontent.com/wayneeseguin/rvm/master/binscripts/rvm-installer) source ~/.bash_profile - $ rvm install 2.1.5 - $ rvm use 2.1.5 + $ ./beef - 5. Install instructions - - Obtain application code either by downloading an archive from https://github.com/beefproject/beef/archive/master.zip or cloning the GIT repo https://github.com/beefproject/beef.git +Updating +-------- - Enter into the newly created BeEF directory, and type: +Due to the fast-paced nature of web browser development and webappsec landscape, +it's best to regularly update BeEF to the latest version. - bundle install +If you're using BeEF from the GitHub repository, updating is as simple as: - Bundler installs all the pre-requisite gems. - - 6. Run instructions - - Simply run: - - ./beef -x + $ git pull diff --git a/README.md b/README.md index 77a6695d0..738d4d96d 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,9 @@ __Twitter:__ @beefproject Requirements ------------ -* OSX 10.5.0 or higher, modern Linux -* [Ruby](http://rubylang.org) version 2.2 or newer -* [SQLite](http://sqlite.org) 3.x +* Operating System: Mac OSX 10.5.0 or higher / modern Linux +* [Ruby](http://rubylang.org): 2.3 or newer +* [SQLite](http://sqlite.org): 3.x * The gems listed in the Gemfile: https://github.com/beefproject/beef/blob/master/Gemfile * brew install selenium-server-standalone (See https://github.com/shvets/selenium) @@ -47,12 +47,14 @@ Quick Start __The following is for the impatient.__ +The `install` script installs the required operating system packages and all the prerequisite Ruby gems: + + $ ./install + For full installation details, please refer to [INSTALL.txt](https://github.com/beefproject/beef/blob/master/INSTALL.txt). We also have an [Installation](https://github.com/beefproject/beef/wiki/Installation) page on the wiki. - $ curl -L https://raw.githubusercontent.com/beefproject/beef/a6a7536e/install-beef | bash -s stable - Upon successful installation, be sure to read the [Configuration](https://github.com/beefproject/beef/wiki/Configuration) page on the wiki for important details on configuring and securing BeEF. diff --git a/Rakefile b/Rakefile index d1aade0c0..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 ################################ diff --git a/beef b/beef index d894654f9..0942b0153 100755 --- a/beef +++ b/beef @@ -12,11 +12,11 @@ $VERBOSE = nil # -# @note Version check to ensure BeEF is running Ruby 2.2+ +# @note Version check to ensure BeEF is running Ruby 2.3+ # -if RUBY_VERSION < '2.2' +if RUBY_VERSION < '2.3' puts - puts "Ruby version #{RUBY_VERSION} is no longer supported. Please upgrade to Ruby version 2.2 or later." + puts "Ruby version #{RUBY_VERSION} is no longer supported. Please upgrade to Ruby version 2.3 or later." puts exit 1 end diff --git a/config.yaml b/config.yaml index 2a83015f8..14843747c 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: 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