diff --git a/.gitignore b/.gitignore index 905997e6f..d31fc6c38 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ ### BeEF ### beef.db +beef.log test/msf-test extensions/admin_ui/media/javascript-min/ custom-config.yaml diff --git a/Gemfile b/Gemfile index 44cf8ecee..2acb15ecb 100644 --- a/Gemfile +++ b/Gemfile @@ -8,37 +8,23 @@ gem 'eventmachine' gem 'thin' -gem 'sinatra', '~> 2.0' -gem 'rack', '~> 2.0' -gem 'rack-protection', '~> 2.0' +gem 'sinatra' +gem 'rack' +gem 'rack-protection' gem 'em-websocket' # WebSocket support gem 'uglifier' gem 'mime-types' gem 'execjs' gem 'ansi' gem 'term-ansicolor', :require => 'term/ansicolor' -gem 'dm-core' gem 'json' -gem 'data_objects' gem 'rubyzip', '>= 1.2.2' gem 'espeak-ruby', '>= 1.0.4' # Text-to-Voice gem 'nokogiri', '>= 1.10.4' gem 'rake' -# SQLite support -group :sqlite do - gem 'dm-sqlite-adapter' -end - -# PostgreSQL support -group :postgres do - #gem dm-postgres-adapter -end - -# MySQL support -group :mysql do - #gem dm-mysql-adapter -end +gem 'otr-activerecord' +gem 'sqlite3' # Geolocation support group :geoip do @@ -47,7 +33,6 @@ end gem 'parseconfig' gem 'erubis' -gem 'dm-migrations' # Metasploit Integration extension group :ext_msf do @@ -94,7 +79,8 @@ group :test do gem 'capybara' # RESTful API tests/generic command module tests gem 'rest-client', '>= 2.0.1' - gem 'byebug' + gem 'irb' + gem 'pry-byebug' end source 'https://rubygems.org' diff --git a/Rakefile b/Rakefile index 1ed8fcc45..7a07c5b1a 100644 --- a/Rakefile +++ b/Rakefile @@ -4,6 +4,8 @@ # See the file 'doc/COPYING' for copying permission # require 'yaml' +require 'bundler/setup' +load 'tasks/otr-activerecord.rake' #require 'pry-byebug' @@ -236,6 +238,10 @@ task :cde_beef_start => 'beef' do puts '.' end - ################################ - +# ActiveRecord +namespace :db do + task :environment do + require_relative "beef" + end +end diff --git a/beef b/beef index 2e2d83ba2..15e62b422 100755 --- a/beef +++ b/beef @@ -119,14 +119,6 @@ unless config.get('beef.http.public_port').to_s.eql?('') || BeEF::Filters.is_val exit 1 end -# -# @note Validate database driver -# -unless ['sqlite', 'postgres', 'mysql'].include? config.get('beef.database.driver') - print_error 'No default database selected. Please add one in config.yaml' - exit 1 -end - # # @note After the BeEF core is loaded, bootstrap the rest of the framework internals # @@ -160,43 +152,25 @@ BeEF::Modules.load Socket.do_not_reverse_lookup = true # -# @note Database setup - use DataMapper::Logger.new($stdout, :debug) for development debugging +# @note Database setup # -case config.get("beef.database.driver") - when "sqlite" - DataMapper.setup(:default, "sqlite3://#{$root_dir}/#{config.get("beef.database.db_file")}") - when "mysql", "postgres" - DataMapper.setup(:default, - :adapter => config.get("beef.database.driver"), - :host => config.get("beef.database.db_host"), - :port => config.get("beef.database.db_port"), - :username => config.get("beef.database.db_user"), - :password => config.get("beef.database.db_passwd"), - :database => config.get("beef.database.db_name"), - :encoding => config.get("beef.database.db_encoding") - ) - else - print_error 'No default database selected. Please add one in config.yaml' - exit 1 -end - # # @note Load the database # -begin - # @note Resets the database if the -x flag was passed - if BeEF::Core::Console::CommandLine.parse[:resetdb] - print_info 'Resetting the database for BeEF.' - DataMapper.auto_migrate! - else - DataMapper.auto_upgrade! - end -rescue => e - print_error "Could not connect to database: #{e.message}" - if config.get("beef.database.driver") == 'sqlite' - print_error "Ensure the #{$root_dir}/#{config.get("beef.database.db_file")} database file is writable" - end - exit 1 +db_file = config.get('beef.database.file') +# @note Resets the database if the -x flag was passed +if BeEF::Core::Console::CommandLine.parse[:resetdb] + print_info 'Resetting the database for BeEF.' + File.delete(db_file) if File.exists?(db_file) +end +# Connect to DB +ActiveRecord::Base.logger = nil +OTR::ActiveRecord.migrations_paths = [File.join('core', 'main', 'ar-migrations')] +OTR::ActiveRecord.configure_from_hash!(adapter:'sqlite3', database:db_file) +# Migrate (if required) +context = ActiveRecord::Migration.new.migration_context +if context.needs_migration? + ActiveRecord::Migrator.new(:up, context.migrations, context.schema_migration).migrate end # diff --git a/config.yaml b/config.yaml index d79087c6a..c896e16c7 100644 --- a/config.yaml +++ b/config.yaml @@ -90,28 +90,7 @@ beef: cert: "beef_cert.pem" database: - # For information on using other databases please read the - # README.databases file - - # supported DBs: sqlite, mysql, postgres - # NOTE: you must change the Gemfile adding a gem require line like: - # gem "dm-postgres-adapter" - # or - # gem "dm-mysql-adapter" - # if you want to switch drivers from sqlite to postgres (or mysql). - # Finally, run a 'bundle install' command and start BeEF. - driver: "sqlite" - - # db_file is only used for sqlite - db_file: "beef.db" - - # db connection information is only used for mysql/postgres - db_host: "localhost" - db_port: 3306 - db_name: "beef" - db_user: "beef" - db_passwd: "beef" - db_encoding: "UTF-8" + file: "beef.db" # Autorun Rule Engine autorun: diff --git a/core/bootstrap.rb b/core/bootstrap.rb index 9be4b48b6..2eb259cb7 100644 --- a/core/bootstrap.rb +++ b/core/bootstrap.rb @@ -30,8 +30,6 @@ require 'core/main/network_stack/assethandler' require 'core/main/network_stack/api' # @note Include the autorun engine -require 'core/main/autorun_engine/models/rule' -require 'core/main/autorun_engine/models/execution' require 'core/main/autorun_engine/parser' require 'core/main/autorun_engine/engine' require 'core/main/autorun_engine/rule_loader' diff --git a/core/core.rb b/core/core.rb index ed84f1aa9..ca989944a 100644 --- a/core/core.rb +++ b/core/core.rb @@ -10,6 +10,7 @@ end end # @note Includes database models - the order must be consistent otherwise DataMapper goes crazy +require 'core/main/model' require 'core/main/models/commandmodule' require 'core/main/models/hookedbrowser' require 'core/main/models/log' @@ -17,6 +18,8 @@ require 'core/main/models/command' require 'core/main/models/result' require 'core/main/models/optioncache' require 'core/main/models/browserdetails' +require 'core/main/models/rule' +require 'core/main/models/execution' # @note Include the constants require 'core/main/constants/browsers' diff --git a/core/hbmanager.rb b/core/hbmanager.rb index 21f45c3ad..047eb40b5 100644 --- a/core/hbmanager.rb +++ b/core/hbmanager.rb @@ -10,14 +10,14 @@ module BeEF # @param [String] sid hooked browser session id string # @return [BeEF::Core::Models::HookedBrowser] returns the associated Hooked Browser def self.get_by_session(sid) - BeEF::Core::Models::HookedBrowser.first(:session => sid) + BeEF::Core::Models::HookedBrowser.where(:session => sid).first end # Get hooked browser by id # @param [Integer] id hooked browser database id # @return [BeEF::Core::Models::HookedBrowser] returns the associated Hooked Browser def self.get_by_id(id) - BeEF::Core::Models::HookedBrowser.first(:id => id) + BeEF::Core::Models::HookedBrowser.find(id) end end diff --git a/core/loader.rb b/core/loader.rb index 10c57333b..22fb7d119 100644 --- a/core/loader.rb +++ b/core/loader.rb @@ -31,8 +31,7 @@ require 'execjs' require 'ansi' require 'term/ansicolor' require 'json' -require 'data_objects' -require 'dm-do-adapter' +require 'otr-activerecord' require 'parseconfig' require 'erubis' require 'mime/types' @@ -41,7 +40,6 @@ require 'resolv' require 'digest' require 'zip' require 'logger' - # @note Logger require 'core/logger' diff --git a/core/main/ar-migrations/001_create_command_modules.rb b/core/main/ar-migrations/001_create_command_modules.rb new file mode 100644 index 000000000..d43259b89 --- /dev/null +++ b/core/main/ar-migrations/001_create_command_modules.rb @@ -0,0 +1,12 @@ +class CreateCommandModules < ActiveRecord::Migration[6.0] + + def change + + create_table :command_modules do |t| + t.text :name + t.text :path + end + + end + +end diff --git a/core/main/ar-migrations/002_create_hooked_browsers.rb b/core/main/ar-migrations/002_create_hooked_browsers.rb new file mode 100644 index 000000000..c1e932888 --- /dev/null +++ b/core/main/ar-migrations/002_create_hooked_browsers.rb @@ -0,0 +1,19 @@ +class CreateHookedBrowsers < ActiveRecord::Migration[6.0] + + def change + + create_table :hooked_browsers do |t| + t.text :session + t.text :ip + t.text :firstseen + t.text :lastseen + t.text :httpheaders + t.text :domain + t.integer :port + t.integer :count + t.boolean :is_proxy + end + + end + +end diff --git a/core/main/ar-migrations/003_create_logs.rb b/core/main/ar-migrations/003_create_logs.rb new file mode 100644 index 000000000..e3614718a --- /dev/null +++ b/core/main/ar-migrations/003_create_logs.rb @@ -0,0 +1,14 @@ +class CreateLogs < ActiveRecord::Migration[6.0] + + def change + + create_table :logs do |t| + t.text :logtype + t.text :event + t.datetime :date + t.references :hooked_browser + end + + end + +end diff --git a/core/main/ar-migrations/004_create_commands.rb b/core/main/ar-migrations/004_create_commands.rb new file mode 100644 index 000000000..20c9d632a --- /dev/null +++ b/core/main/ar-migrations/004_create_commands.rb @@ -0,0 +1,16 @@ +class CreateCommands < ActiveRecord::Migration[6.0] + + def change + + create_table :commands do |t| + t.references :command_module + t.references :hooked_browser + t.text :data + t.datetime :creationdate + t.text :label + t.boolean :instructions_sent, default: false + end + + end + +end diff --git a/core/main/ar-migrations/005_create_results.rb b/core/main/ar-migrations/005_create_results.rb new file mode 100644 index 000000000..97d1c6fad --- /dev/null +++ b/core/main/ar-migrations/005_create_results.rb @@ -0,0 +1,15 @@ +class CreateResults < ActiveRecord::Migration[6.0] + + def change + + create_table :results do |t| + t.references :command + t.references :hooked_browser + t.datetime :date + t.integer :status + t.text :data + end + + end + +end diff --git a/core/main/ar-migrations/006_create_option_caches.rb b/core/main/ar-migrations/006_create_option_caches.rb new file mode 100644 index 000000000..6f605663a --- /dev/null +++ b/core/main/ar-migrations/006_create_option_caches.rb @@ -0,0 +1,12 @@ +class CreateOptionCaches < ActiveRecord::Migration[6.0] + + def change + + create_table :option_caches do |t| + t.text :name + t.text :value + end + + end + +end diff --git a/core/main/ar-migrations/007_create_browser_details.rb b/core/main/ar-migrations/007_create_browser_details.rb new file mode 100644 index 000000000..5404453d2 --- /dev/null +++ b/core/main/ar-migrations/007_create_browser_details.rb @@ -0,0 +1,13 @@ +class CreateBrowserDetails < ActiveRecord::Migration[6.0] + + def change + + create_table :browser_details do |t| + t.text :session_id + t.text :detail_key + t.text :detail_value + end + + end + +end diff --git a/core/main/ar-migrations/008_create_executions.rb b/core/main/ar-migrations/008_create_executions.rb new file mode 100644 index 000000000..172d1cc01 --- /dev/null +++ b/core/main/ar-migrations/008_create_executions.rb @@ -0,0 +1,17 @@ +class CreateExecutions < ActiveRecord::Migration[6.0] + + def change + + create_table :executions do |t| + t.text :session_id + t.integer :mod_count + t.integer :mod_successful + t.text :mod_body + t.text :exec_time + t.text :rule_token + t.boolean :is_sent + end + + end + +end diff --git a/core/main/ar-migrations/009_create_rules.rb b/core/main/ar-migrations/009_create_rules.rb new file mode 100644 index 000000000..de5367791 --- /dev/null +++ b/core/main/ar-migrations/009_create_rules.rb @@ -0,0 +1,20 @@ +class CreateRules < ActiveRecord::Migration[6.0] + + def change + + create_table :rules do |t| + t.text :name + t.text :author + t.text :browser + t.text :browser_version + t.text :os + t.text :os_version + t.text :modules + t.text :execution_order + t.text :execution_delay + t.text :chain_mode + end + + end + +end diff --git a/core/main/ar-migrations/010_create_interceptor.rb b/core/main/ar-migrations/010_create_interceptor.rb new file mode 100644 index 000000000..1dbb6d6b7 --- /dev/null +++ b/core/main/ar-migrations/010_create_interceptor.rb @@ -0,0 +1,12 @@ +class CreateInterceptor < ActiveRecord::Migration[6.0] + + def change + + create_table :interceptors do |t| + t.text :ip + t.text :post_data + end + + end + +end diff --git a/core/main/ar-migrations/011_create_web_cloner.rb b/core/main/ar-migrations/011_create_web_cloner.rb new file mode 100644 index 000000000..00fe9d575 --- /dev/null +++ b/core/main/ar-migrations/011_create_web_cloner.rb @@ -0,0 +1,12 @@ +class CreateWebCloner < ActiveRecord::Migration[6.0] + + def change + + create_table :web_cloner do |t| + t.text :uri + t.text :mount + end + + end + +end diff --git a/core/main/ar-migrations/012_create_mass_mailer.rb b/core/main/ar-migrations/012_create_mass_mailer.rb new file mode 100644 index 000000000..fb06ddfd8 --- /dev/null +++ b/core/main/ar-migrations/012_create_mass_mailer.rb @@ -0,0 +1,11 @@ +class CreateMassMailer < ActiveRecord::Migration[6.0] + + def change + + create_table :mass_mailer do |t| + #todo fields + end + + end + +end diff --git a/core/main/ar-migrations/013_create_network_host.rb b/core/main/ar-migrations/013_create_network_host.rb new file mode 100644 index 000000000..3c977b247 --- /dev/null +++ b/core/main/ar-migrations/013_create_network_host.rb @@ -0,0 +1,17 @@ +class CreateNetworkHost < ActiveRecord::Migration[6.0] + + def change + + create_table :network_hosts do |t| + t.references :hooked_browser + t.text :ip + t.text :hostname + t.text :ntype + t.text :os + t.text :mac + t.text :lastseen + end + + end + +end diff --git a/core/main/ar-migrations/014_create_network_service.rb b/core/main/ar-migrations/014_create_network_service.rb new file mode 100644 index 000000000..1f521a19e --- /dev/null +++ b/core/main/ar-migrations/014_create_network_service.rb @@ -0,0 +1,15 @@ +class CreateNetworkService < ActiveRecord::Migration[6.0] + + def change + + create_table :network_services do |t| + t.references :hooked_browser + t.text :proto + t.text :ip + t.text :port + t.text :ntype + end + + end + +end diff --git a/core/main/ar-migrations/015_create_http.rb b/core/main/ar-migrations/015_create_http.rb new file mode 100644 index 000000000..31d821f71 --- /dev/null +++ b/core/main/ar-migrations/015_create_http.rb @@ -0,0 +1,44 @@ +class CreateHttp < ActiveRecord::Migration[6.0] + + def change + + create_table :http do |t| + t.references :hooked_browser + # The http request to perform. In clear text. + t.text :request + # Boolean value as string to say whether cross-domain requests are allowed + t.boolean :allow_cross_domain, :default => true + # The http response body received. In clear text. + t.text :response_data + # The http response code. Useful to handle cases like 404, 500, 302, ... + t.integer :response_status_code + # The http response code. Human-readable code: success, error, ecc.. + t.text :response_status_text + # The port status. closed, open or not http + t.text :response_port_status + # The XHR Http response raw headers + t.text :response_headers + # The http response method. GET or POST. + t.text :method + # The content length for the request. + t.text :content_length, :default => 0 + # The request protocol/scheme (http/https) + t.text :proto + # The domain on which perform the request. + t.text :domain + # The port on which perform the request. + t.text :port + # Boolean value to say if the request was cross-domain + t.text :has_ran, :default => "waiting" + # The path of the request. + # Example: /secret.html + t.text :path + # The date at which the http response has been saved. + t.datetime :response_date + # The date at which the http request has been saved. + t.datetime :request_date + end + + end + +end diff --git a/core/main/ar-migrations/016_create_rtc_status.rb b/core/main/ar-migrations/016_create_rtc_status.rb new file mode 100644 index 000000000..cdb7389d6 --- /dev/null +++ b/core/main/ar-migrations/016_create_rtc_status.rb @@ -0,0 +1,13 @@ +class CreateRtcStatus < ActiveRecord::Migration[6.0] + + def change + + create_table :rtc_status do |t| + t.references :hooked_browser + t.integer :target_hooked_browser_id + t.text :status + end + + end + +end diff --git a/core/main/ar-migrations/017_create_rtc_manage.rb b/core/main/ar-migrations/017_create_rtc_manage.rb new file mode 100644 index 000000000..64b0962c2 --- /dev/null +++ b/core/main/ar-migrations/017_create_rtc_manage.rb @@ -0,0 +1,13 @@ +class CreateRtcManage < ActiveRecord::Migration[6.0] + + def change + + create_table :rtc_manage do |t| + t.references :hooked_browser + t.text :message + t.text :has_sent, default: "waiting" + end + + end + +end diff --git a/core/main/ar-migrations/018_create_rtc_signal.rb b/core/main/ar-migrations/018_create_rtc_signal.rb new file mode 100644 index 000000000..3b51862eb --- /dev/null +++ b/core/main/ar-migrations/018_create_rtc_signal.rb @@ -0,0 +1,14 @@ +class CreateRtcSignal < ActiveRecord::Migration[6.0] + + def change + + create_table :rtc_signal do |t| + t.references :hooked_browser + t.integer :target_hooked_browser_id + t.text :signal + t.text :has_sent, default: "waiting" + end + + end + +end diff --git a/core/main/ar-migrations/019_create_rtc_module_status.rb b/core/main/ar-migrations/019_create_rtc_module_status.rb new file mode 100644 index 000000000..7c47f8730 --- /dev/null +++ b/core/main/ar-migrations/019_create_rtc_module_status.rb @@ -0,0 +1,14 @@ +class CreateRtcModuleStatus < ActiveRecord::Migration[6.0] + + def change + + create_table :rtc_module_status do |t| + t.references :hooked_browser + t.references :command_module + t.integer :target_hooked_browser_id + t.text :status + end + + end + +end diff --git a/core/main/ar-migrations/020_create_xssrays_detail.rb b/core/main/ar-migrations/020_create_xssrays_detail.rb new file mode 100644 index 000000000..73ca3314a --- /dev/null +++ b/core/main/ar-migrations/020_create_xssrays_detail.rb @@ -0,0 +1,14 @@ +class CreateXssraysDetail < ActiveRecord::Migration[6.0] + + def change + + create_table :xssrays_detail do |t| + t.references :hooked_browser + t.text :vector_name + t.text :vector_method + t.text :vector_poc + end + + end + +end diff --git a/core/main/ar-migrations/021_create_dns_rule.rb b/core/main/ar-migrations/021_create_dns_rule.rb new file mode 100644 index 000000000..79058c823 --- /dev/null +++ b/core/main/ar-migrations/021_create_dns_rule.rb @@ -0,0 +1,14 @@ +class CreateDnsRule < ActiveRecord::Migration[6.0] + + def change + + create_table :dns_rule do |t| + t.text :pattern + t.text :resource + t.text :response + t.text :callback + end + + end + +end diff --git a/core/main/ar-migrations/022_create_ipec_exploit.rb b/core/main/ar-migrations/022_create_ipec_exploit.rb new file mode 100644 index 000000000..8e6150b4f --- /dev/null +++ b/core/main/ar-migrations/022_create_ipec_exploit.rb @@ -0,0 +1,13 @@ +class CreateIpecExploit < ActiveRecord::Migration[6.0] + + def change + + create_table :ipec_exploit do |t| + t.text :name + t.text :protocol + t.text :os + end + + end + +end diff --git a/core/main/ar-migrations/023_create_ipec_exploit_run.rb b/core/main/ar-migrations/023_create_ipec_exploit_run.rb new file mode 100644 index 000000000..66d939722 --- /dev/null +++ b/core/main/ar-migrations/023_create_ipec_exploit_run.rb @@ -0,0 +1,13 @@ +class CreateIpecExploitRun < ActiveRecord::Migration[6.0] + + def change + + create_table :ipec_exploit_run do |t| + t.boolean :launched + t.text :http_headers + t.text :junk_size + end + + end + +end diff --git a/core/main/ar-migrations/024_create_autoloader.rb b/core/main/ar-migrations/024_create_autoloader.rb new file mode 100644 index 000000000..16a4f4962 --- /dev/null +++ b/core/main/ar-migrations/024_create_autoloader.rb @@ -0,0 +1,12 @@ +class CreateAutoloader < ActiveRecord::Migration[6.0] + + def change + + create_table :autoloader do |t| + t.references :command + t.boolean :in_use + end + + end + +end diff --git a/core/main/ar-migrations/025_create_xssrays_scan.rb b/core/main/ar-migrations/025_create_xssrays_scan.rb new file mode 100644 index 000000000..8c6f0cfc5 --- /dev/null +++ b/core/main/ar-migrations/025_create_xssrays_scan.rb @@ -0,0 +1,18 @@ +class CreateXssraysScan < ActiveRecord::Migration[6.0] + + def change + + create_table :xssrays_scan do |t| + t.references :hooked_browser + t.datetime :scan_start + t.datetime :scan_finish + t.text :domain + t.text :cross_domain + t.integer :clean_timeout + t.boolean :is_started + t.boolean :is_finished + end + + end + +end diff --git a/core/main/autorun_engine/engine.rb b/core/main/autorun_engine/engine.rb index 5ae992afc..679e8f01d 100644 --- a/core/main/autorun_engine/engine.rb +++ b/core/main/autorun_engine/engine.rb @@ -41,7 +41,7 @@ module BeEF hb_session = hb.session rule_ids.each do |rule_id| - rule = BeEF::Core::AutorunEngine::Models::Rule.get(rule_id) + rule = BeEF::Core::Models::Rule.find(rule_id) modules = JSON.parse(rule.modules) execution_order = JSON.parse(rule.execution_order) @@ -57,7 +57,7 @@ module BeEF rule_token = SecureRandom.hex(5) modules.each do |cmd_mod| - mod = BeEF::Core::Models::CommandModule.first(:name => cmd_mod['name']) + mod = BeEF::Core::Models::CommandModule.where(:name => cmd_mod['name']).first options = [] replace_input = false cmd_mod['options'].each do|k,v| @@ -85,7 +85,7 @@ module BeEF # TODO catch error, which should never happen as values are checked way before ;-) end - are_exec = BeEF::Core::AutorunEngine::Models::Execution.new( + are_exec = BeEF::Core::Models::Execution.new( :session => hb_session, :mod_count => modules.length, :mod_successful => 0, @@ -94,7 +94,7 @@ module BeEF :is_sent => false, :rule_id => rule_id ) - are_exec.save + are_exec.save! # Once Engine.check() verified that the hooked browser match a Rule, trigger the Rule ;-) print_more "Triggering ruleset #{rule_ids.to_s} on HB #{hb_id}" end @@ -272,9 +272,9 @@ module BeEF :creationdate => Time.new.to_i, :instructions_sent => true ) - command.save + command.save! - command_module = BeEF::Core::Models::CommandModule.first(:id => mod.id) + command_module = BeEF::Core::Models::CommandModule.find(mod.id) if (command_module.path.match(/^Dynamic/)) # metasploit and similar integrations command_module = BeEF::Modules::Commands.const_get(command_module.path.split('/').last.capitalize).new @@ -385,9 +385,9 @@ module BeEF def match(browser, browser_version, os, os_version, rule_id=nil) match_rules = [] if rule_id != nil - rules = [BeEF::Core::AutorunEngine::Models::Rule.get(rule_id)] + rules = [BeEF::Core::Models::Rule.find(rule_id)] else - rules = BeEF::Core::AutorunEngine::Models::Rule.all() + rules = BeEF::Core::Models::Rule.all end return nil if rules == nil return nil unless rules.length > 0 diff --git a/core/main/autorun_engine/models/execution.rb b/core/main/autorun_engine/models/execution.rb deleted file mode 100644 index cc22c709f..000000000 --- a/core/main/autorun_engine/models/execution.rb +++ /dev/null @@ -1,31 +0,0 @@ -# -# Copyright (c) 2006-2019 Wade Alcorn - wade@bindshell.net -# Browser Exploitation Framework (BeEF) - http://beefproject.com -# See the file 'doc/COPYING' for copying permission -# - -module BeEF - module Core - module AutorunEngine - module Models - # @note Stored info about the execution of the ARE on hooked browsers. - class Execution - - include DataMapper::Resource - - storage_names[:default] = 'core_areexecution' - - property :id, Serial - property :session, Text # hooked browser session where a ruleset triggered - property :mod_count, Integer # number of command modules of the ruleset - property :mod_successful, Integer # number of command modules that returned with success - # By default Text is only 65K, so field length increased to 1 MB - property :mod_body, Text, :length => 1024000 # entire command module(s) body to be sent - property :exec_time, String, :length => 15 # timestamp of ruleset triggering - property :rule_token, String, :length => 10 # unique token to be appended to wrapper function names - property :is_sent, Boolean - end - end - end - end -end diff --git a/core/main/autorun_engine/models/rule.rb b/core/main/autorun_engine/models/rule.rb deleted file mode 100644 index 56a5df925..000000000 --- a/core/main/autorun_engine/models/rule.rb +++ /dev/null @@ -1,34 +0,0 @@ -# -# Copyright (c) 2006-2019 Wade Alcorn - wade@bindshell.net -# Browser Exploitation Framework (BeEF) - http://beefproject.com -# See the file 'doc/COPYING' for copying permission -# - -module BeEF - module Core - module AutorunEngine - module Models - # @note Table stores the rules for the Distributed Engine. - class Rule - include DataMapper::Resource - - storage_names[:default] = 'core_arerules' - - property :id, Serial - property :name, Text # rule name - property :author, String # rule author - property :browser, String, :length => 10 # browser name - property :browser_version, String, :length => 15 # browser version - property :os, String, :length => 10 # OS name - property :os_version, String, :length => 15 # OS version - property :modules, Text # JSON stringyfied representation of the JSON rule for further parsing - property :execution_order, Text # command module execution order - property :execution_delay, Text # command module time delays - property :chain_mode, String, :length => 40 # rule chaining mode - - has n, :executions - end - end - end - end -end diff --git a/core/main/autorun_engine/parser.rb b/core/main/autorun_engine/parser.rb index 27faa444b..43c05f24e 100644 --- a/core/main/autorun_engine/parser.rb +++ b/core/main/autorun_engine/parser.rb @@ -53,7 +53,7 @@ module BeEF # check if module names, conditions and options are ok modules.each do |cmd_mod| - mod = BeEF::Core::Models::CommandModule.first(:name => cmd_mod['name']) + mod = BeEF::Core::Models::CommandModule.where(:name => cmd_mod['name']).first if mod != nil modk = BeEF::Module.get_key_by_database_id(mod.id) mod_options = BeEF::Module.get_options(modk) diff --git a/core/main/autorun_engine/rule_loader.rb b/core/main/autorun_engine/rule_loader.rb index 8d9904ce2..faed997c3 100644 --- a/core/main/autorun_engine/rule_loader.rb +++ b/core/main/autorun_engine/rule_loader.rb @@ -52,7 +52,7 @@ module BeEF print_more "Exec order: #{exec_order}" print_more "Exec delay: #{exec_delay}" end - are_rule = BeEF::Core::AutorunEngine::Models::Rule.new( + are_rule = BeEF::Core::Models::Rule.new( :name => name, :author => author, :browser => browser, diff --git a/core/main/command.rb b/core/main/command.rb index 116da56f1..e4e0778c7 100644 --- a/core/main/command.rb +++ b/core/main/command.rb @@ -179,7 +179,7 @@ module BeEF return end - command = BeEF::Core::Models::Command.first(:id => @command_id) + command = BeEF::Core::Models::Command.find(@command_id) @eruby = Erubis::FastEruby.new(File.read(f)) @@ -237,7 +237,7 @@ module BeEF # @todo TODO Document def oc_value(name) - option = BeEF::Core::Models::OptionCache.first(:name => name) + option = BeEF::Core::Models::OptionCache.where(:name => name).first return nil unless option option.value end diff --git a/core/main/crypto.rb b/core/main/crypto.rb index 6da601f9c..1258cb38c 100644 --- a/core/main/crypto.rb +++ b/core/main/crypto.rb @@ -82,7 +82,7 @@ module Core begin id = random_hex_string(8) - BeEF::Core::Models::Dns::Rule.each { |rule| throw StandardError if id == rule.id } + BeEF::Core::Models::Dns::Rule.all.each { |rule| throw StandardError if id == rule.id } rescue StandardError retry end diff --git a/core/main/handlers/browserdetails.rb b/core/main/handlers/browserdetails.rb index 17f5d5a5b..d9592ccb2 100644 --- a/core/main/handlers/browserdetails.rb +++ b/core/main/handlers/browserdetails.rb @@ -30,7 +30,7 @@ module BeEF # validate hook session value session_id = get_param(@data, 'beefhook') (self.err_msg "session id is invalid"; return) if not BeEF::Filters.is_valid_hook_session_id?(session_id) - hooked_browser = HB.first(:session => session_id) + hooked_browser = HB.where(:session => session_id).first return if not hooked_browser.nil? # browser is already registered with framework # create the structure representing the hooked browser @@ -73,7 +73,7 @@ module BeEF @http_headers[key.sub(/^HTTP_/, '')] = value.force_encoding('UTF-8') } zombie.httpheaders = @http_headers.to_json - zombie.save + zombie.save! #print_debug "[INIT] HTTP Headers: #{zombie.httpheaders}" # add a log entry for the newly hooked browser @@ -211,7 +211,7 @@ module BeEF if config.get("beef.extension.network.enable") == true if proxy_server =~ /^([\d\.]+):([\d]+)$/ print_debug("Hooked browser [id:#{zombie.id}] is using a proxy [ip: #{$1}]") - BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => $1, :type => 'Proxy') + BeEF::Core::Models::NetworkHost.create(:hooked_browser_id => session_id, :ip => $1, :type => 'Proxy') end end end @@ -504,7 +504,7 @@ module BeEF # add localhost as network host if config.get('beef.extension.network.enable') print_debug("Hooked browser has network interface 127.0.0.1") - BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => '127.0.0.1', :hostname => 'localhost', :os => BeEF::Core::Models::BrowserDetails.get(session_id, 'host.os.name')) + BeEF::Core::Models::NetworkHost.create(:hooked_browser_id => session_id, :ip => '127.0.0.1', :hostname => 'localhost', :os => BeEF::Core::Models::BrowserDetails.get(session_id, 'host.os.name')) end # check if any ARE rules shall be triggered only if the channel is != WebSockets (XHR). If the channel diff --git a/core/main/handlers/hookedbrowsers.rb b/core/main/handlers/hookedbrowsers.rb index 1e6f70691..502f02325 100644 --- a/core/main/handlers/hookedbrowsers.rb +++ b/core/main/handlers/hookedbrowsers.rb @@ -24,7 +24,7 @@ module Handlers # and deploy some command modules or extensions to the hooked browser. get '/' do @body = '' - @params = request.query_string + params = request.query_string #@response = Rack::Response.new(body=[], 200, header={}) config = BeEF::Core::Configuration.instance @@ -48,7 +48,12 @@ module Handlers # @note get zombie if already hooked the framework hook_session_name = config.get('beef.http.hook_session_name') hook_session_id = request[hook_session_name] - hooked_browser = BeEF::Core::Models::HookedBrowser.first(:session => hook_session_id) if not hook_session_id.nil? + begin + raise ActiveRecord::RecordNotFound if hook_session_id.nil? + hooked_browser = BeEF::Core::Models::HookedBrowser.where(:session => hook_session_id).first + rescue ActiveRecord::RecordNotFound + hooked_browser = false + end # @note is a new browser so return instructions to set up the hook if not hooked_browser @@ -82,21 +87,21 @@ module Handlers end hooked_browser.count! - hooked_browser.save + hooked_browser.save! # @note add all available command module instructions to the response - zombie_commands = BeEF::Core::Models::Command.all(:hooked_browser_id => hooked_browser.id, :instructions_sent => false) + zombie_commands = BeEF::Core::Models::Command.where(:hooked_browser_id => hooked_browser.id, :instructions_sent => false) zombie_commands.each{|command| add_command_instructions(command, hooked_browser)} # @note Check if there are any ARE rules to be triggered. If is_sent=false rules are triggered - are_executions = BeEF::Core::AutorunEngine::Models::Execution.all(:is_sent => false, :session => hook_session_id) + are_executions = BeEF::Core::Models::Execution.where(:is_sent => false, :session_id => hook_session_id) are_executions.each do |are_exec| @body += are_exec.mod_body are_exec.update(:is_sent => true, :exec_time => Time.new.to_i) end # @note We dynamically get the list of all browser hook handler using the API and register them - BeEF::API::Registrar.instance.fire(BeEF::API::Server::Hook, 'pre_hook_send', hooked_browser, @body, @params, request, response) + BeEF::API::Registrar.instance.fire(BeEF::API::Server::Hook, 'pre_hook_send', hooked_browser, @body, params, request, response) end # @note set response headers and body diff --git a/core/main/handlers/modules/command.rb b/core/main/handlers/modules/command.rb index 48e873887..9409de26e 100644 --- a/core/main/handlers/modules/command.rb +++ b/core/main/handlers/modules/command.rb @@ -21,7 +21,7 @@ module BeEF config = BeEF::Core::Configuration.instance # @note get the command module - command_module = BeEF::Core::Models::CommandModule.first(:id => command.command_module_id) + command_module = BeEF::Core::Models::CommandModule.where(:id => command.command_module_id).first (print_error "command_module is nil"; return) if command_module.nil? (print_error "command_module.path is nil"; return) if command_module.path.nil? @@ -70,7 +70,7 @@ module BeEF # @note flag that the command has been sent to the hooked browser command.instructions_sent = true - command.save + command.save! end end diff --git a/core/main/logger.rb b/core/main/logger.rb index 34c6d4ea5..0cb4c02b4 100644 --- a/core/main/logger.rb +++ b/core/main/logger.rb @@ -40,7 +40,7 @@ module Core raise TypeError, '"Hooked Browser ID" needs to be an integer' unless hb.integer? # logging the new event into the database - @logs.new(:type => from.to_s, :event => event.to_s, :date => time_now, :hooked_browser_id => hb).save + @logs.create(:logtype => from.to_s, :event => event.to_s, :date => time_now, :hooked_browser_id => hb).save! print_debug "Event: #{event}" # if notifications are enabled send the info there too if @notifications diff --git a/core/main/migration.rb b/core/main/migration.rb index 589f52743..ca2a6d968 100644 --- a/core/main/migration.rb +++ b/core/main/migration.rb @@ -27,14 +27,10 @@ module Core def update_commands! config = BeEF::Core::Configuration.instance - db_modules = [] - BeEF::Core::Models::CommandModule.all.each do |mod| - db_modules << mod.name - end + db_modules = BeEF::Core::Models::CommandModule.all.pluck(:name) config.get('beef.module').each do |k, v| - h = { :name => k, :path => "#{v['path']}module.rb" } - BeEF::Core::Models::CommandModule.new(h).save unless db_modules.include? k + BeEF::Core::Models::CommandModule.new(name: k, path: "#{v['path']}module.rb").save! unless db_modules.include? k end BeEF::Core::Models::CommandModule.all.each do |mod| diff --git a/core/main/model.rb b/core/main/model.rb new file mode 100644 index 000000000..0401a78fe --- /dev/null +++ b/core/main/model.rb @@ -0,0 +1,14 @@ +# +# Copyright (c) 2006-2019 Wade Alcorn - wade@bindshell.net +# Browser Exploitation Framework (BeEF) - http://beefproject.com +# See the file 'doc/COPYING' for copying permission +# + +module BeEF +module Core + class Model < ActiveRecord::Base + # Tell ActiveRecord that this is not a model + self.abstract_class = true + end +end +end diff --git a/core/main/models/browserdetails.rb b/core/main/models/browserdetails.rb index cb4f1c4f9..dc35444c8 100644 --- a/core/main/models/browserdetails.rb +++ b/core/main/models/browserdetails.rb @@ -11,20 +11,13 @@ module Models # # For example, the type and version of browser the hooked browsers are using. # - class BrowserDetails + class BrowserDetails < BeEF::Core::Model - include DataMapper::Resource - - storage_names[:default] = 'core_browserdetails' - property :session_id, String, :length => 255, :key => true - property :detail_key, String, :length => 255, :lazy => false, :key => true - property :detail_value, Text, :lazy => false - # # Returns the requested value from the data store # def self.get(session_id, key) - browserdetail = first(:session_id => session_id, :detail_key => key) + browserdetail = self.where(:session_id => session_id, :detail_key => key).first return nil if browserdetail.nil? return nil if browserdetail.detail_value.nil? @@ -35,19 +28,20 @@ module Models # Stores or updates an existing key->value pair in the data store # def self.set(session_id, detail_key, detail_value) - browserdetails = BeEF::Core::Models::BrowserDetails.all( + browserdetails = BeEF::Core::Models::BrowserDetails.where( :session_id => session_id, - :detail_key => detail_key ) - if browserdetails.nil? || browserdetails.empty? + :detail_key => detail_key ).first + if browserdetails.nil? # store the new browser details key/value browserdetails = BeEF::Core::Models::BrowserDetails.new( :session_id => session_id, :detail_key => detail_key, :detail_value => detail_value || '') - result = browserdetails.save + result = browserdetails.save! else # update the browser details key/value - result = browserdetails.update(:detail_value => detail_value || '') + browserdetails.detail_value = detail_value || '' + result = browserdetails.save! print_debug "Browser has updated '#{detail_key}' to '#{detail_value}'" end diff --git a/core/main/models/command.rb b/core/main/models/command.rb index 04e4a83ca..d43cb5917 100644 --- a/core/main/models/command.rb +++ b/core/main/models/command.rb @@ -9,19 +9,11 @@ module Core module Models # @note Table stores the commands that have been sent to the Hooked Browsers. - class Command + class Command < BeEF::Core::Model - include DataMapper::Resource - - storage_names[:default] = 'commands' - - property :id, Serial - property :data, Text - property :creationdate, String, :length => 15, :lazy => false - property :label, Text, :lazy => false - property :instructions_sent, Boolean, :default => false - - has n, :results + has_many :results + has_one :command_module + has_one :hooked_browser # # Save results and flag that the command has been run on the hooked browser @@ -40,22 +32,22 @@ module Models raise TypeError, '"status" needs to be an integer' unless status.integer? # @note get the hooked browser structure and id from the database - hooked_browser = BeEF::Core::Models::HookedBrowser.first(:session => hook_session_id) || nil + hooked_browser = BeEF::Core::Models::HookedBrowser.where(:session => hook_session_id).first || nil raise TypeError, "hooked_browser is nil" if hooked_browser.nil? raise TypeError, "hooked_browser.id is nil" if hooked_browser.id.nil? # @note get the command module data structure from the database - command = first(:id => command_id, :hooked_browser_id => hooked_browser.id) || nil + command = self.where(:id => command_id, :hooked_browser_id => hooked_browser.id).first || nil raise TypeError, "command is nil" if command.nil? # @note create the entry for the results - command.results.new( + BeEF::Core::Models::Result.create( :hooked_browser_id => hooked_browser.id, + :command_id => command.id, :data => result.to_json, :status => status, :date => Time.now.to_i ) - command.save s = show_status(status) log = "Hooked browser [id:#{hooked_browser.id}, ip:#{hooked_browser.ip}]" diff --git a/core/main/models/commandmodule.rb b/core/main/models/commandmodule.rb index 60b0b336d..b35275af8 100644 --- a/core/main/models/commandmodule.rb +++ b/core/main/models/commandmodule.rb @@ -7,22 +7,10 @@ module BeEF module Core module Models - class CommandModule + class CommandModule < BeEF::Core::Model - include DataMapper::Resource + has_many :commands - storage_names[:default] = 'core_commandmodules' - - # @note command module ID - property :id, Serial - - # @note command module name - property :name, Text, :lazy => false - - # @note command module path - property :path, Text, :lazy => false - - has n, :commands end end diff --git a/core/main/models/execution.rb b/core/main/models/execution.rb new file mode 100644 index 000000000..38f361b3d --- /dev/null +++ b/core/main/models/execution.rb @@ -0,0 +1,14 @@ +# +# Copyright (c) 2006-2019 Wade Alcorn - wade@bindshell.net +# Browser Exploitation Framework (BeEF) - http://beefproject.com +# See the file 'doc/COPYING' for copying permission +# + +module BeEF + module Core + module Models # @note Stored info about the execution of the ARE on hooked browsers. + class Execution < BeEF::Core::Model + end + end + end +end diff --git a/core/main/models/hookedbrowser.rb b/core/main/models/hookedbrowser.rb index f5cc3065e..c11d0db41 100644 --- a/core/main/models/hookedbrowser.rb +++ b/core/main/models/hookedbrowser.rb @@ -9,45 +9,11 @@ module Models # # # - class HookedBrowser + class HookedBrowser < BeEF::Core::Model - include DataMapper::Resource - - storage_names[:default] = 'core_hookedbrowsers' - - # @note zombie ID - property :id, Serial - - # @note hooked browser session ID - property :session, Text, :lazy => false - - # @note IP address of the hooked browser - property :ip, Text, :lazy => false - - # @note timestamp first time the browser communicated with BeEF - property :firstseen, String, :length => 15 - - # @note timestamp last time the browser communicated with BeEF - property :lastseen, String, :length => 15 - - # @note HTTP headers sent be the browser to the BeEF server upon first hook - property :httpheaders, Text, :lazy => false - - # @note the domain originating the hook request - property :domain, Text, :lazy => false - - # @note the port on the domain originating the hook request - property :port, Integer, :default => 80 - - # @note number of times the zombie has polled - property :count, Integer, :lazy => false - - # @note if true the HB is used as a tunneling proxy - property :is_proxy, Boolean, :default => false - - has n, :commands - has n, :results - has n, :logs + has_many :commands + has_many :results + has_many :logs # @note Increases the count of a zombie def count! diff --git a/core/main/models/log.rb b/core/main/models/log.rb index 0dd9efbae..2c789ccae 100644 --- a/core/main/models/log.rb +++ b/core/main/models/log.rb @@ -7,17 +7,10 @@ module BeEF module Core module Models - class Log + class Log < BeEF::Core::Model + + has_one :hooked_browser - include DataMapper::Resource - - storage_names[:default] = 'core_logs' - - property :id, Serial - property :type, Text, :lazy => false - property :event, Text, :lazy => false - property :date, DateTime, :lazy => false - property :hooked_browser_id, Text, :lazy => false end end diff --git a/core/main/models/optioncache.rb b/core/main/models/optioncache.rb index 08ed3676b..9289e04ad 100644 --- a/core/main/models/optioncache.rb +++ b/core/main/models/optioncache.rb @@ -7,15 +7,7 @@ module BeEF module Core module Models -class OptionCache - - include DataMapper::Resource - - storage_names[:default] = 'core_optioncache' - - property :id, Serial - property :name, Text - property :value, Text +class OptionCache < BeEF::Core::Model end diff --git a/core/main/models/result.rb b/core/main/models/result.rb index f4f29486f..a78c5ddd7 100644 --- a/core/main/models/result.rb +++ b/core/main/models/result.rb @@ -7,16 +7,10 @@ module BeEF module Core module Models - class Result - - include DataMapper::Resource - - storage_names[:default] = 'core_results' - - property :id, Serial - property :date, String, :length => 15, :lazy => false - property :status, Integer - property :data, Text + class Result < BeEF::Core::Model + + has_one :command + has_one :hooked_browser end diff --git a/core/main/models/rule.rb b/core/main/models/rule.rb new file mode 100644 index 000000000..b6f7030fa --- /dev/null +++ b/core/main/models/rule.rb @@ -0,0 +1,16 @@ +# +# Copyright (c) 2006-2019 Wade Alcorn - wade@bindshell.net +# Browser Exploitation Framework (BeEF) - http://beefproject.com +# See the file 'doc/COPYING' for copying permission +# + +module BeEF + module Core + module Models + # @note Table stores the rules for the Distributed Engine. + class Rule < BeEF::Core::Model + has_many :executions + end + end + end +end diff --git a/core/main/network_stack/websocket/websocket.rb b/core/main/network_stack/websocket/websocket.rb index 69b521f7b..5c9c1d229 100644 --- a/core/main/network_stack/websocket/websocket.rb +++ b/core/main/network_stack/websocket/websocket.rb @@ -108,7 +108,7 @@ module BeEF print_debug("[WebSocket] activeSocket content [#{@@activeSocket}]") hb_session = msg_hash["cookie"] - hooked_browser = BeEF::Core::Models::HookedBrowser.first(:session => hb_session) + hooked_browser = BeEF::Core::Models::HookedBrowser.where(:session => hb_session).first if hooked_browser.nil? print_error '[WebSocket] Fingerprinting not finished yet.' print_more 'ARE rules were not triggered. You may want to trigger them manually via REST API.' @@ -126,7 +126,7 @@ module BeEF # polling zombie unless msg_hash['alive'].nil? - hooked_browser = BeEF::Core::Models::HookedBrowser.first(:session => msg_hash["alive"]) + hooked_browser = BeEF::Core::Models::HookedBrowser.where(:session => msg_hash["alive"]).first # This will happen if you reset BeEF database (./beef -x), # and existing zombies try to connect. These zombies will be ignored, @@ -141,15 +141,15 @@ module BeEF hooked_browser.lastseen = Time.new.to_i hooked_browser.count! - hooked_browser.save + hooked_browser.save! # Check if new modules need to be sent - zombie_commands = BeEF::Core::Models::Command.all(:hooked_browser_id => hooked_browser.id, :instructions_sent => false) + zombie_commands = BeEF::Core::Models::Command.where(:hooked_browser_id => hooked_browser.id, :instructions_sent => false) zombie_commands.each { |command| add_command_instructions(command, hooked_browser) } # Check if there are any ARE rules to be triggered. If is_sent=false rules are triggered are_body = '' - are_executions = BeEF::Core::AutorunEngine::Models::Execution.all(:is_sent => false, :session => hooked_browser.session) + are_executions = BeEF::Core::Models::Execution.where(:is_sent => false, :session => hooked_browser.session) are_executions.each do |are_exec| are_body += are_exec.mod_body are_exec.update(:is_sent => true, :exec_time => Time.new.to_i) diff --git a/core/main/rest/handlers/autorun_engine.rb b/core/main/rest/handlers/autorun_engine.rb index 0e8a008ad..ae2bcaa0d 100644 --- a/core/main/rest/handlers/autorun_engine.rb +++ b/core/main/rest/handlers/autorun_engine.rb @@ -38,7 +38,7 @@ module BeEF get '/rule/delete/:rule_id' do begin rule_id = params[:rule_id] - rule = BeEF::Core::AutorunEngine::Models::Rule.get(rule_id) + rule = BeEF::Core::AutorunEngine::Models::Rule.find(rule_id) rule.destroy { 'success' => true}.to_json rescue => e @@ -53,13 +53,13 @@ module BeEF begin rule_id = params[:rule_id] - online_hooks = BeEF::Core::Models::HookedBrowser.all(:lastseen.gte => (Time.new.to_i - 15)) + online_hooks = BeEF::Core::Models::HookedBrowser.where('lastseen >= ?', (Time.new.to_i - 15)) are = BeEF::Core::AutorunEngine::Engine.instance if online_hooks != nil online_hooks.each do |hb| hb_details = BeEF::Core::Models::BrowserDetails - browser_name = hb_details.get(hb.session, 'browser.name') + browser_name = hb_details.get(hb.session, 'browser.name') browser_version = hb_details.get(hb.session, 'browser.version') os_name = hb_details.get(hb.session, 'host.os.name') os_version = hb_details.get(hb.session, 'host.os.version') diff --git a/core/main/rest/handlers/browserdetails.rb b/core/main/rest/handlers/browserdetails.rb index 3854a9588..626415a73 100644 --- a/core/main/rest/handlers/browserdetails.rb +++ b/core/main/rest/handlers/browserdetails.rb @@ -24,10 +24,10 @@ module BeEF # @note Get all browser details for the specified session # get '/:session' do - hb = BeEF::Core::Models::HookedBrowser.first(:session => params[:session]) + hb = BeEF::Core::Models::HookedBrowser.where(:session => params[:session]).first error 404 if hb.nil? - details = BeEF::Core::Models::BrowserDetails.all(:session_id => hb.session) + details = BeEF::Core::Models::BrowserDetails.where(:session_id => hb.session) error 404 if details.nil? result = [] diff --git a/core/main/rest/handlers/hookedbrowsers.rb b/core/main/rest/handlers/hookedbrowsers.rb index 2acb551ce..edbd3c9db 100644 --- a/core/main/rest/handlers/hookedbrowsers.rb +++ b/core/main/rest/handlers/hookedbrowsers.rb @@ -24,8 +24,8 @@ module BeEF # @note Get online and offline hooked browsers details (like name, version, os, ip, port, ...) # get '/' do - online_hooks = hb_to_json(BeEF::Core::Models::HookedBrowser.all(:lastseen.gte => (Time.new.to_i - 15))) - offline_hooks = hb_to_json(BeEF::Core::Models::HookedBrowser.all(:lastseen.lt => (Time.new.to_i - 15))) + online_hooks = hb_to_json(BeEF::Core::Models::HookedBrowser.where('lastseen >= ?', (Time.new.to_i - 15))) + offline_hooks = hb_to_json(BeEF::Core::Models::HookedBrowser.where('lastseen <= ?', (Time.new.to_i - 15))) output = { 'hooked-browsers' => { @@ -37,33 +37,33 @@ module BeEF end get '/:session/delete' do - hb = BeEF::Core::Models::HookedBrowser.first(:session => params[:session]) + hb = BeEF::Core::Models::HookedBrowser.where(:session => params[:session]).first error 401 unless hb != nil - details = BeEF::Core::Models::BrowserDetails.all(:session_id => hb.session) + details = BeEF::Core::Models::BrowserDetails.where(:session_id => hb.session) details.destroy - logs = BeEF::Core::Models::Log.all(:hooked_browser_id => hb.id) + logs = BeEF::Core::Models::Log.where(:hooked_browser_id => hb.id) logs.destroy - commands = BeEF::Core::Models::Command.all(:hooked_browser_id => hb.id) + commands = BeEF::Core::Models::Command.where(:hooked_browser_id => hb.id) commands.destroy - results = BeEF::Core::Models::Result.all(:hooked_browser_id => hb.id) + results = BeEF::Core::Models::Result.where(:hooked_browser_id => hb.id) results.destroy begin - requester = BeEF::Core::Models::Http.all(:hooked_browser_id => hb.id) + requester = BeEF::Core::Models::Http.where(:hooked_browser_id => hb.id) requester.destroy rescue => e #the requester module may not be enabled end begin - xssraysscans = BeEF::Core::Models::Xssraysscan.all(:hooked_browser_id => hb.id) + xssraysscans = BeEF::Core::Models::Xssraysscan.where(:hooked_browser_id => hb.id) xssraysscans.destroy - xssraysdetails = BeEF::Core::Models::Xssraysdetail.all(:hooked_browser_id => hb.id) + xssraysdetails = BeEF::Core::Models::Xssraysdetail.where(:hooked_browser_id => hb.id) xssraysdetails.destroy rescue => e #the xssraysscan module may not be enabled @@ -96,7 +96,7 @@ module BeEF # Useful if you need to query the API via jQuery.dataTable < 1.10 which is currently used in PhishingFrenzy # get '/pf/online' do - online_hooks = hbs_to_array(BeEF::Core::Models::HookedBrowser.all(:lastseen.gte => (Time.new.to_i - 15))) + online_hooks = hbs_to_array(BeEF::Core::Models::HookedBrowser.where('lastseen >= ?', (Time.new.to_i - 15))) output = { 'aaData' => online_hooks @@ -109,7 +109,7 @@ module BeEF # Useful if you need to query the API via jQuery.dataTable < 1.10 which is currently used in PhishingFrenzy # get '/pf/offline' do - offline_hooks = hbs_to_array(BeEF::Core::Models::HookedBrowser.all(:lastseen.lt => (Time.new.to_i - 15))) + offline_hooks = hbs_to_array(BeEF::Core::Models::HookedBrowser.where('lastseen <= ?', (Time.new.to_i - 15))) output = { 'aaData' => offline_hooks @@ -121,10 +121,10 @@ module BeEF # @note Get all the hooked browser details (plugins enabled, technologies enabled, cookies) # get '/:session' do - hb = BeEF::Core::Models::HookedBrowser.first(:session => params[:session]) + hb = BeEF::Core::Models::HookedBrowser.where(:session => params[:session]).first error 401 unless hb != nil - details = BeEF::Core::Models::BrowserDetails.all(:session_id => hb.session) + details = BeEF::Core::Models::BrowserDetails.where(:session_id => hb.session) result = {} details.each do |property| result[property.detail_key] = property.detail_value @@ -140,16 +140,16 @@ module BeEF os_version = body['os_version'] arch = body['arch'] - hb = BeEF::Core::Models::HookedBrowser.first(:session => params[:session]) + hb = BeEF::Core::Models::HookedBrowser.where(:session => params[:session]).first error 401 unless hb != nil - BeEF::Core::Models::BrowserDetails.first(:session_id => hb.session, :detail_key => 'host.os.name').destroy - BeEF::Core::Models::BrowserDetails.first(:session_id => hb.session, :detail_key => 'host.os.version').destroy + BeEF::Core::Models::BrowserDetails.where(:session_id => hb.session, :detail_key => 'host.os.name').destroy + BeEF::Core::Models::BrowserDetails.where(:session_id => hb.session, :detail_key => 'host.os.version').destroy #BeEF::Core::Models::BrowserDetails.first(:session_id => hb.session, :detail_key => 'Arch').destroy - BeEF::Core::Models::BrowserDetails.new(:session_id => hb.session, :detail_key => 'host.os.name', :detail_value => os).save - BeEF::Core::Models::BrowserDetails.new(:session_id => hb.session, :detail_key => 'host.os.version', :detail_value => os_version).save - BeEF::Core::Models::BrowserDetails.new(:session_id => hb.session, :detail_key => 'Arch', :detail_value => arch).save + BeEF::Core::Models::BrowserDetails.create(:session_id => hb.session, :detail_key => 'host.os.name', :detail_value => os) + BeEF::Core::Models::BrowserDetails.create(:session_id => hb.session, :detail_key => 'host.os.version', :detail_value => os_version) + BeEF::Core::Models::BrowserDetails.create(:session_id => hb.session, :detail_key => 'Arch', :detail_value => arch) # TODO if there where any ARE rules defined for this hooked browser, # after updating OS/arch, force a retrigger of the rule. diff --git a/core/main/rest/handlers/logs.rb b/core/main/rest/handlers/logs.rb index 80c3ee736..9f4bc08c3 100644 --- a/core/main/rest/handlers/logs.rb +++ b/core/main/rest/handlers/logs.rb @@ -24,7 +24,7 @@ module BeEF # @note Get all global logs # get '/' do - logs = BeEF::Core::Models::Log.all() + logs = BeEF::Core::Models::Log.all logs_to_json(logs) end @@ -44,10 +44,10 @@ module BeEF # @note Get hooked browser logs # get '/:session' do - hb = BeEF::Core::Models::HookedBrowser.first(:session => params[:session]) + hb = BeEF::Core::Models::HookedBrowser.where(:session => params[:session]).first error 401 unless hb != nil - logs = BeEF::Core::Models::Log.all(:hooked_browser_id => hb.id) + logs = BeEF::Core::Models::Log.where(:hooked_browser_id => hb.id) logs_to_json(logs) end @@ -62,7 +62,7 @@ module BeEF 'id' => log.id.to_i, 'date' => log.date.to_s, 'event' => log.event.to_s, - 'type' => log.type.to_s, + 'logtype' => log.logtype.to_s, 'hooked_browser_id' => log.hooked_browser_id.to_s } end @@ -84,7 +84,7 @@ module BeEF logs.reverse.each do |log| maker.items.new_item do |item| item.id = log.id.to_s - item.title = "[#{log.type}] #{log.event}" + item.title = "[#{log.logtype}] #{log.event}" item.updated = log.date.to_s end end diff --git a/core/main/rest/handlers/modules.rb b/core/main/rest/handlers/modules.rb index d5d2f8a93..5070afafa 100644 --- a/core/main/rest/handlers/modules.rb +++ b/core/main/rest/handlers/modules.rb @@ -43,7 +43,7 @@ module BeEF end get '/search/:mod_name' do - mod = BeEF::Core::Models::CommandModule.first(:name => params[:mod_name]) + mod = BeEF::Core::Models::CommandModule.where(:name => params[:mod_name]).first result = {} if mod != nil result = {'id' => mod.id} @@ -55,7 +55,7 @@ module BeEF # @note Get the module definition (info, options) # get '/:mod_id' do - cmd = BeEF::Core::Models::CommandModule.get(params[:mod_id]) + cmd = BeEF::Core::Models::CommandModule.find(params[:mod_id]) error 404 unless cmd != nil modk = BeEF::Module.get_key_by_database_id(params[:mod_id]) error 404 unless modk != nil @@ -81,12 +81,12 @@ module BeEF #{"date":"1331637093","data":"{\"data\":\"text=michele\"}"} # get '/:session/:mod_id/:cmd_id' do - hb = BeEF::Core::Models::HookedBrowser.first(:session => params[:session]) + hb = BeEF::Core::Models::HookedBrowser.where(:session => params[:session]).first error 401 unless hb != nil - cmd = BeEF::Core::Models::Command.first(:hooked_browser_id => hb.id, - :command_module_id => params[:mod_id], :id => params[:cmd_id]) + cmd = BeEF::Core::Models::Command.where(:hooked_browser_id => hb.id, + :command_module_id => params[:mod_id], :id => params[:cmd_id]).first error 404 unless cmd != nil - results = BeEF::Core::Models::Result.all(:hooked_browser_id => hb.id, :command_id => cmd.id) + results = BeEF::Core::Models::Result.where(:hooked_browser_id => hb.id, :command_id => cmd.id) error 404 unless results != nil results_hash = {} @@ -137,7 +137,7 @@ module BeEF #{"success":"true","command_id":"not_available"} # post '/:session/:mod_id' do - hb = BeEF::Core::Models::HookedBrowser.first(:session => params[:session]) + hb = BeEF::Core::Models::HookedBrowser.where(:session => params[:session]).first error 401 unless hb != nil modk = BeEF::Module.get_key_by_database_id(params[:mod_id]) error 404 unless modk != nil @@ -198,7 +198,7 @@ module BeEF # run on all hooked browsers currently online? if hb_ids.first =~ /\Aall_online\z/i hb_ids = [] - BeEF::Core::Models::HookedBrowser.all( + BeEF::Core::Models::HookedBrowser.where( :lastseen.gte => (Time.new.to_i - 15)).each {|hb| hb_ids << hb.id } # run on all hooked browsers? elsif hb_ids.first =~ /\Aall\z/i @@ -208,7 +208,7 @@ module BeEF # run modules hb_ids.each do |hb_id| - hb = BeEF::Core::Models::HookedBrowser.first(:id => hb_id) + hb = BeEF::Core::Models::HookedBrowser.find(hb_id) if hb == nil results[hb_id] = 0 next @@ -256,7 +256,7 @@ module BeEF request.body.rewind begin body = JSON.parse request.body.read - hb = BeEF::Core::Models::HookedBrowser.first(:session => body["hb"]) + hb = BeEF::Core::Models::HookedBrowser.where(:session => body["hb"]).first error 401 unless hb != nil results = Hash.new diff --git a/core/main/server.rb b/core/main/server.rb index 4536b1ed5..495f7c202 100644 --- a/core/main/server.rb +++ b/core/main/server.rb @@ -162,7 +162,9 @@ module BeEF # Starts the BeEF http server # def start - @http_server.start + @http_server.start do + use OTR::ActiveRecord::ConnectionManagement + end rescue RuntimeError => e # port is in use raise unless e.message.include? 'no acceptor' diff --git a/core/modules.rb b/core/modules.rb index 4994a121f..b94715ae3 100644 --- a/core/modules.rb +++ b/core/modules.rb @@ -48,7 +48,7 @@ module BeEF # Get all modules currently stored in the database # @return [Array] DataMapper array of all BeEF::Core::Models::CommandModule's in the database def self.get_stored_in_db - BeEF::Core::Models::CommandModule.all(:order => [:id.asc]) + BeEF::Core::Models::CommandModule.all.order(:id) end # Loads all enabled modules diff --git a/core/ruby/print.rb b/core/ruby/print.rb index 4b650e453..428171768 100644 --- a/core/ruby/print.rb +++ b/core/ruby/print.rb @@ -7,14 +7,14 @@ # Function used to print errors to the console # @param [String] s String to be printed def print_error(s) - puts Time.now.localtime.strftime("[%k:%M:%S]")+'[!]'+' '+s + puts Time.now.localtime.strftime("[%k:%M:%S]")+'[!]'+' '+s.to_s BeEF.logger.error s.to_s end # Function used to print information to the console # @param [String] s String to be printed def print_info(s) - puts Time.now.localtime.strftime("[%k:%M:%S]")+'[*]'+' '+s + puts Time.now.localtime.strftime("[%k:%M:%S]")+'[*]'+' '+s.to_s BeEF.logger.info s.to_s end @@ -45,7 +45,7 @@ end # Function used to print successes to the console # @param [String] s String to be printed def print_success(s) - puts Time.now.localtime.strftime("[%k:%M:%S]")+'[+]'+' '+s + puts Time.now.localtime.strftime("[%k:%M:%S]")+'[+]'+' '+s.to_s BeEF.logger.info s.to_s end diff --git a/extensions/admin_ui/controllers/modules/modules.rb b/extensions/admin_ui/controllers/modules/modules.rb index 24bda8505..e1c8c964d 100644 --- a/extensions/admin_ui/controllers/modules/modules.rb +++ b/extensions/admin_ui/controllers/modules/modules.rb @@ -225,10 +225,10 @@ class Modules < BeEF::Extension::AdminUI::HttpController # if dynamic modules are found in the DB, then we don't have yaml config for them # and loading must proceed in a different way. - dynamic_modules = BeEF::Core::Models::CommandModule.all(:path.like => "Dynamic/") + dynamic_modules = BeEF::Core::Models::CommandModule.where('path LIKE ?', 'Dynamic/') if(dynamic_modules != nil) - all_modules = BeEF::Core::Models::CommandModule.all(:order => [:id.asc]) + all_modules = BeEF::Core::Models::CommandModule.all.order(:id) all_modules.each{|dyn_mod| next if !dyn_mod.path.split('/')[1].match(/^metasploit/) command_mod_name = dyn_mod["name"] @@ -257,7 +257,7 @@ class Modules < BeEF::Extension::AdminUI::HttpController def select_command_module command_module_id = @params['command_module_id'] || nil (print_error "command_module_id is nil";return) if command_module_id.nil? - command_module = BeEF::Core::Models::CommandModule.get(command_module_id) + command_module = BeEF::Core::Models::CommandModule.find(command_module_id) key = BeEF::Module.get_key_by_database_id(command_module_id) payload_name = @params['payload_name'] || nil @@ -284,12 +284,12 @@ class Modules < BeEF::Extension::AdminUI::HttpController (print_error "nonce incorrect";return) if @session.get_nonce != nonce # get the browser id - zombie = Z.first(:session => zombie_session) + zombie = Z.where(:session => zombie_session).first (print_error "Zombie is nil";return) if zombie.nil? zombie_id = zombie.id (print_error "Zombie id is nil";return) if zombie_id.nil? - C.all(:command_module_id => command_module_id, :hooked_browser_id => zombie_id).each do |command| + C.where(:command_module_id => command_module_id, :hooked_browser_id => zombie_id).each do |command| commands.push({ 'id' => i, 'object_id' => command.id, @@ -346,7 +346,7 @@ class Modules < BeEF::Extension::AdminUI::HttpController # get params command_id = @params['command_id'] || nil (print_error "Command id is nil";return) if command_id.nil? - command = BeEF::Core::Models::Command.first(:id => command_id.to_i) || nil + command = BeEF::Core::Models::Command.find(command_id.to_i) || nil (print_error "Command is nil";return) if command.nil? # validate nonce nonce = @params['nonce'] || nil @@ -382,11 +382,11 @@ class Modules < BeEF::Extension::AdminUI::HttpController oc.save } - zombie = Z.first(:session => zombie_session) + zombie = Z.where(:session => zombie_session).first (print_error "Zombie is nil";return) if zombie.nil? zombie_id = zombie.id (print_error "Zombie id is nil";return) if zombie_id.nil? - command_module = BeEF::Core::Models::CommandModule.get(command_module_id) + command_module = BeEF::Core::Models::CommandModule.find(command_module_id) if(command_module != nil && command_module.path.match(/^Dynamic/)) dyn_mod_name = command_module.path.split('/').last @@ -423,14 +423,14 @@ class Modules < BeEF::Extension::AdminUI::HttpController # get params command_id = @params['command_id']|| nil (print_error "Command id is nil";return) if command_id.nil? - command = BeEF::Core::Models::Command.first(:id => command_id.to_i) || nil + command = BeEF::Core::Models::Command.find(command_id.to_i) || nil (print_error "Command is nil";return) if command.nil? # get command_module - command_module = BeEF::Core::Models::CommandModule.first(:id => command.command_module_id) + command_module = BeEF::Core::Models::CommandModule.find(command.command_module_id) (print_error "command_module is nil";return) if command_module.nil? - resultsdb = BeEF::Core::Models::Result.all(:command_id => command_id) + resultsdb = BeEF::Core::Models::Result.where(:command_id => command_id) (print_error "Command id result is nil";return) if resultsdb.nil? resultsdb.each{ |result| results.push({'date' => result.date, 'data' => JSON.parse(result.data)}) } @@ -450,10 +450,10 @@ class Modules < BeEF::Extension::AdminUI::HttpController # get params command_id = @params['command_id'] || nil (print_error "Command id is nil";return) if command_id.nil? - command = BeEF::Core::Models::Command.first(:id => command_id.to_i) || nil + command = BeEF::Core::Models::Command.find(command_id.to_i) || nil (print_error "Command is nil";return) if command.nil? - command_module = BeEF::Core::Models::CommandModule.get(command.command_module_id) + command_module = BeEF::Core::Models::CommandModule.find(command.command_module_id) (print_error "command_module is nil";return) if command_module.nil? if(command_module.path.split('/').first.match(/^Dynamic/)) @@ -503,7 +503,7 @@ class Modules < BeEF::Extension::AdminUI::HttpController def dynamic_modules2json(id) command_modules_json = {} - mod = BeEF::Core::Models::CommandModule.first(:id => id) + mod = BeEF::Core::Models::CommandModule.find(id) # if the module id is not in the database return false return {'success' => 'false'}.to_json if(not mod) @@ -525,7 +525,7 @@ class Modules < BeEF::Extension::AdminUI::HttpController def dynamic_payload2json(id, payload_name) command_modules_json = {} - command_module = BeEF::Core::Models::CommandModule.get(id) + command_module = BeEF::Core::Models::CommandModule.find(id) (print_error "Module does not exists";return 'success' => 'false') if command_module.nil? payload_options = BeEF::Module.get_payload_options(command_module.name,payload_name) diff --git a/extensions/autoloader/model.rb b/extensions/autoloader/model.rb index 15ecb9bea..b87a3b3a7 100644 --- a/extensions/autoloader/model.rb +++ b/extensions/autoloader/model.rb @@ -7,19 +7,12 @@ module BeEF module Core module Models -class Autoloading - - include DataMapper::Resource - - storage_names[:default] = 'autoloading' - - property :id, Serial - property :in_use, Boolean - - belongs_to :command +class Autoloading < BeEF::Core::Model + + belongs_to :command end end end -end \ No newline at end of file +end diff --git a/extensions/console/lib/command_dispatcher/core.rb b/extensions/console/lib/command_dispatcher/core.rb index 660fe722b..5ff4b65c4 100644 --- a/extensions/console/lib/command_dispatcher/core.rb +++ b/extensions/console/lib/command_dispatcher/core.rb @@ -150,7 +150,7 @@ class Core 'Hardware' ]) - BeEF::Core::Models::HookedBrowser.all(:lastseen.gte => (Time.new.to_i - 30)).each do |zombie| + BeEF::Core::Models::HookedBrowser.where('lastseen >= ?', (Time.new.to_i - 30)).each do |zombie| tbl << [zombie.id,zombie.ip,BeEF::Core::Models::BrowserDetails.get(zombie.session,"HostName").to_s,BeEF::Core::Models::BrowserDetails.get(zombie.session, 'BrowserName').to_s+"-"+BeEF::Core::Models::BrowserDetails.get(zombie.session, 'BrowserVersion').to_s,BeEF::Core::Models::BrowserDetails.get(zombie.session, 'OsName'),BeEF::Core::Models::BrowserDetails.get(zombie.session, 'Hardware')] end @@ -184,7 +184,7 @@ class Core 'Hardware' ]) - BeEF::Core::Models::HookedBrowser.all(:lastseen.lt => (Time.new.to_i - 30)).each do |zombie| + BeEF::Core::Models::HookedBrowser.where('lastseen < ?', (Time.new.to_i - 30)).each do |zombie| tbl << [zombie.id,zombie.ip,BeEF::Core::Models::BrowserDetails.get(zombie.session,"HostName").to_s,BeEF::Core::Models::BrowserDetails.get(zombie.session, 'BrowserName').to_s+"-"+BeEF::Core::Models::BrowserDetails.get(zombie.session, 'BrowserVersion').to_s,BeEF::Core::Models::BrowserDetails.get(zombie.session, 'OsName'),BeEF::Core::Models::BrowserDetails.get(zombie.session, 'Hardware')] end @@ -213,7 +213,7 @@ class Core end onlinezombies = [] - BeEF::Core::Models::HookedBrowser.all(:lastseen.gt => (Time.new.to_i - 30)).each do |zombie| + BeEF::Core::Models::HookedBrowser.where('lastseen > ?', (Time.new.to_i - 30)).each do |zombie| onlinezombies << zombie.id end @@ -268,7 +268,7 @@ class Core end onlinezombies = [] - BeEF::Core::Models::HookedBrowser.all(:lastseen.gt => (Time.new.to_i - 30)).each do |z| + BeEF::Core::Models::HookedBrowser.where('lastseen > ?' (Time.new.to_i - 30)).each do |z| onlinezombies << z.id end @@ -400,7 +400,7 @@ class Core end offlinezombies = [] - BeEF::Core::Models::HookedBrowser.all(:lastseen.lt => (Time.new.to_i - 30)).each do |zombie| + BeEF::Core::Models::HookedBrowser.where('lastseen < ?', (Time.new.to_i - 30)).each do |zombie| offlinezombies << zombie.id end diff --git a/extensions/console/lib/shellinterface.rb b/extensions/console/lib/shellinterface.rb index aae048126..9c21d1d8a 100644 --- a/extensions/console/lib/shellinterface.rb +++ b/extensions/console/lib/shellinterface.rb @@ -18,8 +18,8 @@ class ShellInterface def settarget(id) begin - self.targetsession = BeEF::Core::Models::HookedBrowser.first(:id => id).session - self.targetip = BeEF::Core::Models::HookedBrowser.first(:id => id).ip + self.targetsession = BeEF::Core::Models::HookedBrowser.find(id).session + self.targetip = BeEF::Core::Models::HookedBrowser.find(id).ip self.targetid = id rescue return nil @@ -28,8 +28,8 @@ class ShellInterface def setofflinetarget(id) begin - self.targetsession = BeEF::Core::Models::HookedBrowser.first(:id => id).session - self.targetip = "(OFFLINE) " + BeEF::Core::Models::HookedBrowser.first(:id => id).ip + self.targetsession = BeEF::Core::Models::HookedBrowser.find(id).session + self.targetip = "(OFFLINE) " + BeEF::Core::Models::HookedBrowser.find(id).ip self.targetid = id rescue return nil @@ -80,10 +80,10 @@ class ShellInterface # if dynamic modules are found in the DB, then we don't have yaml config for them # and loading must proceed in a different way. - dynamic_modules = BeEF::Core::Models::CommandModule.all(:path.like => "Dynamic/") + dynamic_modules = BeEF::Core::Models::CommandModule.where('path LIKE ?', 'Dynamic/') if(dynamic_modules != nil) - all_modules = BeEF::Core::Models::CommandModule.all(:order => [:id.asc]) + all_modules = BeEF::Core::Models::CommandModule.all.order(:id) all_modules.each{|dyn_mod| next if !dyn_mod.path.split('/').first.match(/^Dynamic/) @@ -151,7 +151,7 @@ class ShellInterface commands = [] i = 0 - BeEF::Core::Models::Command.all(:command_module_id => cmdid, :hooked_browser_id => self.targetid).each do |command| + BeEF::Core::Models::Command.where(:command_module_id => cmdid, :hooked_browser_id => self.targetid).each do |command| commands.push({ 'id' => i, 'object_id' => command.id, @@ -167,7 +167,7 @@ class ShellInterface def getindividualresponse(cmdid) results = [] begin - BeEF::Core::Models::Result.all(:command_id => cmdid).each { |result| + BeEF::Core::Models::Result.where(:command_id => cmdid).each { |result| results.push({'date' => result.date, 'data' => JSON.parse(result.data)}) } rescue @@ -380,7 +380,7 @@ class ShellInterface 'results' => [] } @nh = BeEF::Core::Models::NetworkHost - hosts = @nh.all(:hooked_browser_id => self.targetsession) + hosts = @nh.where(:hooked_browser_id => self.targetsession) # add property to summary hash if not hosts.empty? @@ -418,7 +418,7 @@ class ShellInterface 'results' => [] } @ns = BeEF::Core::Models::NetworkService - services = @ns.all(:hooked_browser_id => self.targetsession) + services = @ns.where(:hooked_browser_id => self.targetsession) # add property to summary hash if not services.empty? diff --git a/extensions/demos/html/basic.html b/extensions/demos/html/basic.html index 0b4eaddf2..f2dd3cfcc 100644 --- a/extensions/demos/html/basic.html +++ b/extensions/demos/html/basic.html @@ -7,6 +7,7 @@ --> BeEF Basic Demo +