Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/core/main/rest/handlers/logs.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
module Rest
10
class Logs < BeEF::Core::Router::Router
11
config = BeEF::Core::Configuration.instance
12
13
before do
14
error 401 unless params[:token] == config.get('beef.api_token')
15
halt 401 unless BeEF::Core::Rest.permitted_source?(request.ip)
16
headers 'Content-Type' => 'application/json; charset=UTF-8',
17
'Pragma' => 'no-cache',
18
'Cache-Control' => 'no-cache',
19
'Expires' => '0'
20
end
21
22
#
23
# @note Get all global logs
24
#
25
get '/' do
26
logs = BeEF::Core::Models::Log.all
27
logs_to_json(logs)
28
end
29
30
#
31
# @note Get all global logs
32
#
33
get '/rss' do
34
logs = BeEF::Core::Models::Log.all
35
headers 'Content-Type' => 'text/xml; charset=UTF-8',
36
'Pragma' => 'no-cache',
37
'Cache-Control' => 'no-cache',
38
'Expires' => '0'
39
logs_to_rss logs
40
end
41
42
#
43
# @note Get hooked browser logs
44
#
45
get '/:session' do
46
hb = BeEF::Core::Models::HookedBrowser.where(session: params[:session]).first
47
error 401 if hb.nil?
48
49
logs = BeEF::Core::Models::Log.where(hooked_browser_id: hb.id)
50
logs_to_json(logs)
51
end
52
53
private
54
55
def logs_to_json(logs)
56
logs_json = []
57
count = logs.length
58
59
logs.each do |log|
60
logs_json << {
61
'id' => log.id.to_i,
62
'date' => log.date.to_s,
63
'event' => log.event.to_s,
64
'logtype' => log.logtype.to_s,
65
'hooked_browser_id' => log.hooked_browser_id.to_s
66
}
67
end
68
69
unless logs_json.empty?
70
{
71
'logs_count' => count,
72
'logs' => logs_json
73
}.to_json
74
end
75
end
76
77
def logs_to_rss(logs)
78
rss = RSS::Maker.make('atom') do |maker|
79
maker.channel.author = 'BeEF'
80
maker.channel.updated = Time.now.to_s
81
maker.channel.about = 'https://beefproject.com/'
82
maker.channel.title = 'BeEF Event Logs'
83
84
logs.reverse.each do |log|
85
maker.items.new_item do |item|
86
item.id = log.id.to_s
87
item.title = "[#{log.logtype}] #{log.event}"
88
item.updated = log.date.to_s
89
end
90
end
91
end
92
rss.to_s
93
end
94
end
95
end
96
end
97
end
98
99