Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/core/main/logger.rb
1154 views
1
#
2
# Copyright (c) 2006-2025 Wade Alcorn - [email protected]
3
# Browser Exploitation Framework (BeEF) - https://beefproject.com
4
# See the file 'doc/COPYING' for copying permission
5
#
6
7
module BeEF
8
module Core
9
class Logger
10
include Singleton
11
12
# Constructor
13
def initialize
14
@logs = BeEF::Core::Models::Log
15
@config = BeEF::Core::Configuration.instance
16
17
# if notifications are enabled create a new instance
18
notifications_enabled = @config.get('beef.extension.notifications.enable')
19
@notifications = BeEF::Extension::Notifications::Notifications unless notifications_enabled == false or notifications_enabled.nil?
20
end
21
22
#
23
# Registers a new event in the logs
24
# @param [String] from The origin of the event (i.e. Authentication, Hooked Browser)
25
# @param [String] event The event description
26
# @param [Integer] hb The id of the hooked browser affected (default = 0 if no HB)
27
#
28
# @return [Boolean] True if the register was successful
29
#
30
def register(from, event, hb = 0)
31
# type conversion to enforce standards
32
hb = hb.to_i
33
34
# get time now
35
time_now = Time.now
36
37
# arguments type checking
38
raise TypeError, "'from' is #{from.class}; expected String" unless from.is_a?(String)
39
raise TypeError, "'event' is #{event.class}; expected String" unless event.is_a?(String)
40
raise TypeError, "'hb' hooked browser ID is #{hb.class}; expected Integer" unless hb.is_a?(Integer)
41
42
# logging the new event into the database
43
@logs.create(logtype: from.to_s, event: event.to_s, date: time_now, hooked_browser_id: hb).save!
44
print_debug "Event: #{event}"
45
# if notifications are enabled send the info there too
46
@notifications.new(from, event, time_now, hb) if @notifications
47
48
true
49
end
50
51
@logs
52
end
53
end
54
end
55
56