module BeEF
module Core
module Models
class Command < BeEF::Core::Model
has_many :results
has_one :command_module
has_one :hooked_browser
def self.save_result(hook_session_id, command_id, command_friendly_name, result, status)
raise TypeError, '"hook_session_id" needs to be a string' unless hook_session_id.is_a?(String)
raise TypeError, '"command_id" needs to be an integer' unless command_id.is_a?(Integer)
raise TypeError, '"command_friendly_name" needs to be a string' unless command_friendly_name.is_a?(String)
raise TypeError, '"result" needs to be a hash' unless result.is_a?(Hash)
raise TypeError, '"status" needs to be an integer' unless status.is_a?(Integer)
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?
command = where(id: command_id, hooked_browser_id: hooked_browser.id).first || nil
raise TypeError, 'command is nil' if command.nil?
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
)
s = show_status(status)
log = "Hooked browser [id:#{hooked_browser.id}, ip:#{hooked_browser.ip}]"
log += " has executed instructions (status: #{s}) from command module [cid:#{command_id},"
log += " mod: #{command.command_module_id}, name:'#{command_friendly_name}']"
BeEF::Core::Logger.instance.register('Command', log, hooked_browser.id)
print_info log
true
end
def self.show_status(status)
case status
when -1
'ERROR'
when 1
'SUCCESS'
else
'UNKNOWN'
end
end
end
end
end
end