From d588c56391700219cd23c80852f7c2b8003d2258 Mon Sep 17 00:00:00 2001 From: Ben Passmore Date: Tue, 8 Oct 2019 16:15:55 +1000 Subject: [PATCH] Refactored models to use ActiveRecord --- core/main/models/browserdetails.rb | 9 +------ core/main/models/command.rb | 14 ++-------- core/main/models/commandmodule.rb | 16 ++---------- core/main/models/hookedbrowser.rb | 42 +++--------------------------- core/main/models/log.rb | 13 +++------ core/main/models/optioncache.rb | 10 +------ core/main/models/result.rb | 11 +------- 7 files changed, 14 insertions(+), 101 deletions(-) diff --git a/core/main/models/browserdetails.rb b/core/main/models/browserdetails.rb index cb4f1c4f9..907e90031 100644 --- a/core/main/models/browserdetails.rb +++ b/core/main/models/browserdetails.rb @@ -11,15 +11,8 @@ 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 # diff --git a/core/main/models/command.rb b/core/main/models/command.rb index 04e4a83ca..995e4ecc4 100644 --- a/core/main/models/command.rb +++ b/core/main/models/command.rb @@ -9,19 +9,9 @@ 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 # # Save results and flag that the command has been run on the hooked browser 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/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..2128450fd 100644 --- a/core/main/models/result.rb +++ b/core/main/models/result.rb @@ -7,16 +7,7 @@ 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 end