From 3f6dc0e9631a2a80e73d22e3af1a8eb3a6314475 Mon Sep 17 00:00:00 2001 From: adfoster-r7 Date: Wed, 12 Jun 2024 13:24:07 +0100 Subject: [PATCH] Update Rails 7.1 support --- app/models/mdm/event.rb | 6 +++++- app/models/mdm/listener.rb | 6 +++++- app/models/mdm/loot.rb | 6 +++++- app/models/mdm/macro.rb | 12 ++++++++++-- app/models/mdm/nexpose_console.rb | 8 ++++++-- app/models/mdm/note.rb | 8 ++++++-- app/models/mdm/profile.rb | 6 +++++- app/models/mdm/session.rb | 8 ++++++-- app/models/mdm/task.rb | 18 +++++++++++++++--- app/models/mdm/user.rb | 8 ++++++-- app/models/mdm/web_form.rb | 8 ++++++-- app/models/mdm/web_page.rb | 12 ++++++++++-- app/models/mdm/web_site.rb | 8 ++++++-- app/models/mdm/web_vuln.rb | 8 ++++++-- 14 files changed, 97 insertions(+), 25 deletions(-) diff --git a/app/models/mdm/event.rb b/app/models/mdm/event.rb index 74c9d18f..3007369e 100755 --- a/app/models/mdm/event.rb +++ b/app/models/mdm/event.rb @@ -72,7 +72,11 @@ class Mdm::Event < ApplicationRecord # {#name}-specific information about this event. # # @return [Hash] - serialize :info, coder: MetasploitDataModels::Base64Serializer.new + if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1 + serialize :info, coder: MetasploitDataModels::Base64Serializer.new + else + serialize :info, MetasploitDataModels::Base64Serializer.new + end # # Validations diff --git a/app/models/mdm/listener.rb b/app/models/mdm/listener.rb index 4fc38785..a20fedd8 100755 --- a/app/models/mdm/listener.rb +++ b/app/models/mdm/listener.rb @@ -69,7 +69,11 @@ class Mdm::Listener < ApplicationRecord # Options used to spawn this listener. # # @return [Hash] - serialize :options, coder: MetasploitDataModels::Base64Serializer.new + if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1 + serialize :options, coder: MetasploitDataModels::Base64Serializer.new + else + serialize :options, MetasploitDataModels::Base64Serializer.new + end # # Validations diff --git a/app/models/mdm/loot.rb b/app/models/mdm/loot.rb index 5913c334..ce225278 100755 --- a/app/models/mdm/loot.rb +++ b/app/models/mdm/loot.rb @@ -140,7 +140,11 @@ class Mdm::Loot < ApplicationRecord # Serializations # - serialize :data, coder: MetasploitDataModels::Base64Serializer.new + if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1 + serialize :data, coder: MetasploitDataModels::Base64Serializer.new + else + serialize :data, MetasploitDataModels::Base64Serializer.new + end private diff --git a/app/models/mdm/macro.rb b/app/models/mdm/macro.rb index 99ac6182..f8e0cd46 100755 --- a/app/models/mdm/macro.rb +++ b/app/models/mdm/macro.rb @@ -39,12 +39,20 @@ class Mdm::Macro < ApplicationRecord # # @return [ArrayObject}>] Array of action hashes. Each action hash is have key :module with value # of an {Mdm::Module::Detail#fullname} and and key :options with value of options used to the run the module. - serialize :actions, coder: MetasploitDataModels::Base64Serializer.new + if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1 + serialize :actions, coder: MetasploitDataModels::Base64Serializer.new + else + serialize :actions, MetasploitDataModels::Base64Serializer.new + end # Preference for this macro, shared across all actions. # # @return [Hash] - serialize :prefs, coder: MetasploitDataModels::Base64Serializer.new + if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1 + serialize :prefs, coder: MetasploitDataModels::Base64Serializer.new + else + serialize :prefs, MetasploitDataModels::Base64Serializer.new + end # The maximum number of seconds that this macro is allowed to run. # diff --git a/app/models/mdm/nexpose_console.rb b/app/models/mdm/nexpose_console.rb index 507891bc..7b61d4e2 100755 --- a/app/models/mdm/nexpose_console.rb +++ b/app/models/mdm/nexpose_console.rb @@ -89,7 +89,11 @@ class Mdm::NexposeConsole < ApplicationRecord # List of sites known to Nexpose. # # @return [Array] Array of site names. - serialize :cached_sites, coder: MetasploitDataModels::Base64Serializer.new + if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1 + serialize :cached_sites, coder: MetasploitDataModels::Base64Serializer.new + else + serialize :cached_sites, MetasploitDataModels::Base64Serializer.new + end # # Validations @@ -113,7 +117,7 @@ class Mdm::NexposeConsole < ApplicationRecord # # @return [void] def strip_protocol - self.address.gsub!(/^http(s)*:\/\//i,'') unless self.address.nil? + self.address.gsub!(/^http(s)*:\/\//i,'') unless self.address.nil? end Metasploit::Concern.run(self) diff --git a/app/models/mdm/note.rb b/app/models/mdm/note.rb index 91afb053..da4b1c29 100755 --- a/app/models/mdm/note.rb +++ b/app/models/mdm/note.rb @@ -1,6 +1,6 @@ # Data gathered or derived from the {#host} or {#service} such as its {#ntype fingerprint}. class Mdm::Note < ApplicationRecord - + # # Associations # @@ -107,7 +107,11 @@ class Mdm::Note < ApplicationRecord # Serializations # - serialize :data, coder: ::MetasploitDataModels::Base64Serializer.new + if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1 + serialize :data, coder: ::MetasploitDataModels::Base64Serializer.new + else + serialize :data, ::MetasploitDataModels::Base64Serializer.new + end private diff --git a/app/models/mdm/profile.rb b/app/models/mdm/profile.rb index af78d77c..3e282229 100755 --- a/app/models/mdm/profile.rb +++ b/app/models/mdm/profile.rb @@ -38,7 +38,11 @@ class Mdm::Profile < ApplicationRecord # Global settings. # # @return [Hash] - serialize :settings, coder: MetasploitDataModels::Base64Serializer.new + if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1 + serialize :settings, coder: MetasploitDataModels::Base64Serializer.new + else + serialize :settings, MetasploitDataModels::Base64Serializer.new + end Metasploit::Concern.run(self) end diff --git a/app/models/mdm/session.rb b/app/models/mdm/session.rb index 0740e086..6b213649 100755 --- a/app/models/mdm/session.rb +++ b/app/models/mdm/session.rb @@ -1,7 +1,7 @@ # A session opened on a {#host} using an {#via_exploit exploit} and controlled through a {#via_payload payload} to # connect back to the local host using meterpreter or a cmd shell. class Mdm::Session < ApplicationRecord - + # # Associations # @@ -172,7 +172,11 @@ class Mdm::Session < ApplicationRecord # Serializations # - serialize :datastore, coder: ::MetasploitDataModels::Base64Serializer.new + if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1 + serialize :datastore, coder: ::MetasploitDataModels::Base64Serializer.new + else + serialize :datastore, ::MetasploitDataModels::Base64Serializer.new + end # Returns whether the session can be upgraded to a meterpreter session from a shell session on Windows. # diff --git a/app/models/mdm/task.rb b/app/models/mdm/task.rb index 190cbe1f..a3d285aa 100755 --- a/app/models/mdm/task.rb +++ b/app/models/mdm/task.rb @@ -130,17 +130,29 @@ class Mdm::Task < ApplicationRecord # Options passed to `#module`. # # @return [Hash] - serialize :options, coder: MetasploitDataModels::Base64Serializer.new + if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1 + serialize :options, coder: MetasploitDataModels::Base64Serializer.new + else + serialize :options, MetasploitDataModels::Base64Serializer.new + end # Result of task running. # # @return [Hash] - serialize :result, coder: MetasploitDataModels::Base64Serializer.new + if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1 + serialize :result, coder: MetasploitDataModels::Base64Serializer.new + else + serialize :result, MetasploitDataModels::Base64Serializer.new + end # Settings used to configure this task outside of the {#options module options}. # # @return [Hash] - serialize :settings, coder: MetasploitDataModels::Base64Serializer.new + if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1 + serialize :settings, coder: MetasploitDataModels::Base64Serializer.new + else + serialize :settings, MetasploitDataModels::Base64Serializer.new + end # # Instance Methods diff --git a/app/models/mdm/user.rb b/app/models/mdm/user.rb index 15896b76..4ceda773 100755 --- a/app/models/mdm/user.rb +++ b/app/models/mdm/user.rb @@ -1,7 +1,7 @@ # A user of metasploit-framework or metasploit-pro. class Mdm::User < ApplicationRecord extend MetasploitDataModels::SerializedPrefs - + # # Associations # @@ -109,7 +109,11 @@ class Mdm::User < ApplicationRecord # Hash of user preferences # # @return [Hash] - serialize :prefs, coder: MetasploitDataModels::Base64Serializer.new + if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1 + serialize :prefs, coder: MetasploitDataModels::Base64Serializer.new + else + serialize :prefs, MetasploitDataModels::Base64Serializer.new + end # @!attribute time_zone # User's preferred time zone. diff --git a/app/models/mdm/web_form.rb b/app/models/mdm/web_form.rb index caf5c970..1c4cfef3 100755 --- a/app/models/mdm/web_form.rb +++ b/app/models/mdm/web_form.rb @@ -1,6 +1,6 @@ # A filled-in form on a {#web_site}. class Mdm::WebForm < ApplicationRecord - + # # Associations # @@ -46,7 +46,11 @@ class Mdm::WebForm < ApplicationRecord # Parameters submitted in this form. # # @return [Array>] - serialize :params, coder: MetasploitDataModels::Base64Serializer.new + if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1 + serialize :params, coder: MetasploitDataModels::Base64Serializer.new + else + serialize :params, MetasploitDataModels::Base64Serializer.new + end Metasploit::Concern.run(self) end diff --git a/app/models/mdm/web_page.rb b/app/models/mdm/web_page.rb index b1ef090b..3159f76c 100755 --- a/app/models/mdm/web_page.rb +++ b/app/models/mdm/web_page.rb @@ -81,12 +81,20 @@ class Mdm::WebPage < ApplicationRecord # Headers sent from server. # # @return [Hash{String => String}] - serialize :headers, coder: MetasploitDataModels::Base64Serializer.new + if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1 + serialize :headers, coder: MetasploitDataModels::Base64Serializer.new + else + serialize :headers, MetasploitDataModels::Base64Serializer.new + end # Cookies sent from server. # # @return [Hash{String => String}] - serialize :cookie, coder: MetasploitDataModels::Base64Serializer.new + if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1 + serialize :cookie, coder: MetasploitDataModels::Base64Serializer.new + else + serialize :cookie, MetasploitDataModels::Base64Serializer.new + end Metasploit::Concern.run(self) end diff --git a/app/models/mdm/web_site.rb b/app/models/mdm/web_site.rb index 0aca3a33..296065f3 100755 --- a/app/models/mdm/web_site.rb +++ b/app/models/mdm/web_site.rb @@ -1,6 +1,6 @@ # A Web Site running on a {#service}. class Mdm::WebSite < ApplicationRecord - + # # Associations # @@ -60,7 +60,11 @@ class Mdm::WebSite < ApplicationRecord # @!attribute [rw] options # @todo Determine format and purpose of Mdm::WebSite#options. - serialize :options, coder: ::MetasploitDataModels::Base64Serializer.new + if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1 + serialize :options, coder: ::MetasploitDataModels::Base64Serializer.new + else + serialize :options, ::MetasploitDataModels::Base64Serializer.new + end # # Instance Methods diff --git a/app/models/mdm/web_vuln.rb b/app/models/mdm/web_vuln.rb index 50a3ffae..32027338 100755 --- a/app/models/mdm/web_vuln.rb +++ b/app/models/mdm/web_vuln.rb @@ -11,7 +11,7 @@ # end # end class Mdm::WebVuln < ApplicationRecord - + # # CONSTANTS # @@ -141,7 +141,11 @@ class Mdm::WebVuln < ApplicationRecord # Parameters sent as part of request # # @return [Array] Array of parameter key value pairs - serialize :params, coder: MetasploitDataModels::Base64Serializer.new(:default => DEFAULT_PARAMS) + if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1 + serialize :params, coder: MetasploitDataModels::Base64Serializer.new(:default => DEFAULT_PARAMS) + else + serialize :params, MetasploitDataModels::Base64Serializer.new(:default => DEFAULT_PARAMS) + end # # Methods