diff --git a/extensions/webrtc/api/hook.rb b/extensions/webrtc/api/hook.rb index cbe4176b2..9132ab080 100644 --- a/extensions/webrtc/api/hook.rb +++ b/extensions/webrtc/api/hook.rb @@ -29,7 +29,7 @@ module BeEF rtcmanagementoutput = [] # Get all RTCSignals for this browser - BeEF::Core::Models::Rtcsignal.all(:target_hooked_browser_id => hb.id, :has_sent => "waiting").each { |h| + BeEF::Core::Models::Rtcsignal.where(:target_hooked_browser_id => hb.id, :has_sent => "waiting").each { |h| # output << self.requester_parse_db_request(h) rtcsignaloutput << h.signal h.has_sent = "sent" @@ -37,7 +37,7 @@ module BeEF } # Get all RTCManagement messages for this browser - BeEF::Core::Models::Rtcmanage.all(:hooked_browser_id => hb.id, :has_sent => "waiting").each {|h| + BeEF::Core::Models::Rtcmanage.where(:hooked_browser_id => hb.id, :has_sent => "waiting").each {|h| rtcmanagementoutput << h.message h.has_sent = "sent" h.save diff --git a/extensions/webrtc/models/rtcmanage.rb b/extensions/webrtc/models/rtcmanage.rb index 027149711..c64a61ba1 100644 --- a/extensions/webrtc/models/rtcmanage.rb +++ b/extensions/webrtc/models/rtcmanage.rb @@ -9,18 +9,8 @@ module Models # # Table stores the queued up JS commands for managing the client-side webrtc logic. # - class Rtcmanage < ActiveRecord::Base - attribute :id, :Serial - - # The hooked browser id - attribute :hooked_browser_id, :Text, :lazy => false - - # The message - attribute :message, :Text, :lazy => true - - # Boolean value to say if the signal has been sent to the target peer - attribute :has_sent, :Text, :lazy => false, :default => "waiting" - + class Rtcmanage < BeEF::Core::Model + # Starts the RTCPeerConnection process, establishing a WebRTC connection between the caller and the receiver def self.initiate(caller, receiver, verbosity = false) stunservers = BeEF::Core::Configuration.instance.get("beef.extension.webrtc.stunservers") @@ -29,25 +19,25 @@ module Models # Add the beef.webrtc.start() JavaScript call into the Rtcmanage table - this will be picked up by the browser on next hook.js poll # This is for the Receiver r = BeEF::Core::Models::Rtcmanage.new(:hooked_browser_id => receiver, :message => "beef.webrtc.start(0,#{caller},JSON.stringify(#{turnservers}),JSON.stringify(#{stunservers}),#{verbosity});") - r.save + r.save! # This is the same beef.webrtc.start() JS call, but for the Caller r = BeEF::Core::Models::Rtcmanage.new(:hooked_browser_id => caller, :message => "beef.webrtc.start(1,#{receiver},JSON.stringify(#{turnservers}),JSON.stringify(#{stunservers}),#{verbosity});") - r.save + r.save! end # Advises a browser to send an RTCDataChannel message to its peer # Similar to the initiate method, this loads up a JavaScript call to the beefrtcs[peerid].sendPeerMsg() function call def self.sendmsg(from, to, message) r = BeEF::Core::Models::Rtcmanage.new(:hooked_browser_id => from, :message => "beefrtcs[#{to}].sendPeerMsg('#{message}');") - r.save + r.save! end # Gets the browser to run the beef.webrtc.status() JavaScript function # This JS function will return it's values to the /rtcmessage handler def self.status(id) r = BeEF::Core::Models::Rtcmanage.new(:hooked_browser_id => id, :message => "beef.webrtc.status(#{id});") - r.save + r.save! end end diff --git a/extensions/webrtc/models/rtcmodulestatus.rb b/extensions/webrtc/models/rtcmodulestatus.rb index c294c6582..618a480f4 100644 --- a/extensions/webrtc/models/rtcmodulestatus.rb +++ b/extensions/webrtc/models/rtcmodulestatus.rb @@ -13,27 +13,10 @@ module Models # - class Rtcmodulestatus < ActiveRecord::Base - attribute :id, :Serial - - # The hooked browser id - attribute :hooked_browser_id, :Text, :lazy => false - - # The hooked browser's IP - attribute :hooked_browser_ip, :Text, :lazy => false - - # The target hooked browser id - attribute :target_hooked_browser_id, :Text, :lazy => false - - # The command module ID - attribute :command_module_id, :Text, :lazy => false - - # The status field - attribute :status, :Text, :lazy => true - - # Timestamps - attribute :created_at, DateTime - attribute :updated_at, DateTime + class Rtcmodulestatus < BeEF::Core::Model + + belongs_to :hooked_browser + belongs_to :command_module end diff --git a/extensions/webrtc/models/rtcsignal.rb b/extensions/webrtc/models/rtcsignal.rb index 63ba6e1d1..594d5085e 100644 --- a/extensions/webrtc/models/rtcsignal.rb +++ b/extensions/webrtc/models/rtcsignal.rb @@ -9,21 +9,9 @@ module Models # # Table stores the webrtc signals from a hooked_browser, directed to a target_hooked_browser # - class Rtcsignal < ActiveRecord::Base - attribute :id, :Serial + class Rtcsignal < BeEF::Core::Model - # The hooked browser id - attribute :hooked_browser_id, :Text, :lazy => false - - # The target hooked browser id - attribute :target_hooked_browser_id, :Text, :lazy => false - - # The WebRTC signal to submit. In clear text. - attribute :signal , :Text, :lazy => true - - # Boolean value to say if the signal has been sent to the target peer - attribute :has_sent, :Text, :lazy => false, :default => "waiting" - + belongs_to :hooked_browser end diff --git a/extensions/webrtc/models/rtcstatus.rb b/extensions/webrtc/models/rtcstatus.rb index 3e8d798cf..4d8968dca 100644 --- a/extensions/webrtc/models/rtcstatus.rb +++ b/extensions/webrtc/models/rtcstatus.rb @@ -13,28 +13,9 @@ module Models # - class Rtcstatus < ActiveRecord::Base - attribute :id, :Serial - - # The hooked browser id - attribute :hooked_browser_id, :Text, :lazy => false - - # The hooked browser's IP - # property :hooked_browser_ip, Text, :lazy => false - - # The target hooked browser id - attribute :target_hooked_browser_id, :Text, :lazy => false - - # The target hooked browser's IP - # property :target_hooked_browser_ip, Text, :lazy => false - - # The status field - attribute :status, :Text, :lazy => true - - # Timestamps - attribute :created_at, DateTime - attribute :updated_at, DateTime + class Rtcstatus < BeEF::Core::Model + belongs_to :hooked_browser end diff --git a/extensions/webrtc/rest/webrtc.rb b/extensions/webrtc/rest/webrtc.rb index 06c7b23a3..8b410f0a9 100644 --- a/extensions/webrtc/rest/webrtc.rb +++ b/extensions/webrtc/rest/webrtc.rb @@ -177,7 +177,7 @@ module BeEF begin id = params[:id] - events = BeEF::Core::Models::Rtcstatus.all(:hooked_browser_id => id) + events = BeEF::Core::Models::Rtcstatus.where(:hooked_browser_id => id) events_json = [] count = events.length @@ -227,7 +227,7 @@ module BeEF begin id = params[:id] - events = BeEF::Core::Models::Rtcmodulestatus.all(:hooked_browser_id => id) + events = BeEF::Core::Models::Rtcmodulestatus.where(:hooked_browser_id => id) events_json = [] count = events.length @@ -301,13 +301,13 @@ module BeEF raise InvalidParamError, 'message' if message.nil? if message === "!gostealth" - stat = BeEF::Core::Models::Rtcstatus.first(:hooked_browser_id => fromhb.to_i, :target_hooked_browser_id => tohb.to_i) || nil + stat = BeEF::Core::Models::Rtcstatus.where(:hooked_browser_id => fromhb.to_i, :target_hooked_browser_id => tohb.to_i).first || nil unless stat.nil? stat.status = "Selected browser has commanded peer to enter stealth" stat.updated_at = Time.now stat.save end - stat2 = BeEF::Core::Models::Rtcstatus.first(:hooked_browser_id => tohb.to_i, :target_hooked_browser_id => fromhb.to_i) || nil + stat2 = BeEF::Core::Models::Rtcstatus.where(:hooked_browser_id => tohb.to_i, :target_hooked_browser_id => fromhb.to_i).first || nil unless stat2.nil? stat2.status = "Peer has commanded selected browser to enter stealth" stat2.updated_at = Time.now @@ -382,8 +382,7 @@ module BeEF # Find the module, modify it, send it to be executed on the tohb # Validate the command module by ID - command_module = BeEF::Core::Models::CommandModule.first( - :id => cmdid) + command_module = BeEF::Core::Models::CommandModule.find(cmdid) error 404 if command_module.nil? error 404 if command_module.path.nil?