Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/extensions/xssrays/handler.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
module BeEF
7
module Extension
8
module Xssrays
9
class Handler < BeEF::Core::Router::Router
10
XS = BeEF::Core::Models::Xssraysscan
11
XD = BeEF::Core::Models::Xssraysdetail
12
HB = BeEF::Core::Models::HookedBrowser
13
14
get '/' do
15
# verify if the request contains the hook token
16
# raise an error if it's null or not found in the DB
17
beef_hook = params[:hbsess] || nil
18
19
if beef_hook.nil? || HB.where(session: beef_hook).first.nil?
20
print_error '[XSSRAYS] Invalid beef hook ID: the hooked browser cannot be found in the database'
21
return
22
end
23
24
# verify the specified ray ID is valid
25
rays_scan_id = params[:raysid] || nil
26
if rays_scan_id.nil? || !BeEF::Filters.nums_only?(rays_scan_id)
27
print_error '[XSSRAYS] Invalid ray ID'
28
return
29
end
30
31
case params[:action]
32
when 'ray'
33
# we received a ray
34
parse_rays(rays_scan_id)
35
when 'finish'
36
# we received a notification for finishing the scan
37
finalize_scan(rays_scan_id)
38
else
39
# invalid action
40
print_error '[XSSRAYS] Invalid action'
41
return
42
end
43
44
headers 'Pragma' => 'no-cache',
45
'Cache-Control' => 'no-cache',
46
'Expires' => '0',
47
'Access-Control-Allow-Origin' => '*',
48
'Access-Control-Allow-Methods' => 'POST,GET'
49
end
50
51
# parse incoming rays: rays are verified XSS, as the attack vector is calling back BeEF when executed.
52
def parse_rays(rays_scan_id)
53
xssrays_scan = XS.find(rays_scan_id)
54
hooked_browser = HB.where(session: params[:hbsess]).first
55
56
if xssrays_scan.nil?
57
print_error '[XSSRAYS] Invalid scan'
58
return
59
end
60
61
xssrays_detail = XD.new(
62
hooked_browser_id: hooked_browser.session,
63
vector_name: params[:n],
64
vector_method: params[:m],
65
vector_poc: params[:p],
66
xssraysscan_id: xssrays_scan.id
67
)
68
xssrays_detail.save
69
70
print_info("[XSSRAYS] Scan id [#{xssrays_scan.id}] received ray [ip:#{hooked_browser.ip}], hooked origin [#{hooked_browser.domain}]")
71
print_debug("[XSSRAYS] Ray info: \n #{request.query_string}")
72
end
73
74
# finalize the XssRays scan marking the scan as finished in the db
75
def finalize_scan(rays_scan_id)
76
xssrays_scan = BeEF::Core::Models::Xssraysscan.find(rays_scan_id)
77
78
if xssrays_scan.nil?
79
print_error '[XSSRAYS] Invalid scan'
80
return
81
end
82
83
xssrays_scan.update(is_finished: true, scan_finish: Time.now)
84
print_info("[XSSRAYS] Scan id [#{xssrays_scan.id}] finished at [#{xssrays_scan.scan_finish}]")
85
end
86
end
87
end
88
end
89
end
90
91