Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/extensions/social_engineering/rest/socialengineering.rb
1874 views
1
#
2
# Copyright (c) 2006-2026 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 Extension
9
module SocialEngineering
10
class SEngRest < 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
# Example: curl -H "Content-Type: application/json; charset=UTF-8" -d json_body
23
# -X POST http://127.0.0.1:3000/api/seng/clone_page?token=851a937305f8773ee82f5259e792288cdcb01cd7
24
#
25
# Example json_body:
26
# {
27
# "url": "https://accounts.google.com/ServiceLogin?service=mail&continue=https://mail.google.com/mail/"
28
# "mount": "/gmail",
29
# "dns_spoof": true
30
# }
31
post '/clone_page' do
32
request.body.rewind
33
begin
34
body = JSON.parse request.body.read
35
uri = body['url']
36
mount = body['mount']
37
use_existing = body['use_existing']
38
dns_spoof = body['dns_spoof']
39
40
if !uri.nil? && !mount.nil?
41
if (uri =~ URI::DEFAULT_PARSER.make_regexp).nil? # invalid URI
42
print_error 'Invalid URI'
43
halt 401
44
end
45
46
unless mount[%r{^/}] # mount needs to start with /
47
print_error 'Invalid mount (need to be a relative path, and start with / )'
48
halt 401
49
end
50
51
web_cloner = BeEF::Extension::SocialEngineering::WebCloner.instance
52
success = web_cloner.clone_page(uri, mount, use_existing, dns_spoof)
53
54
if success
55
result = {
56
'success' => true,
57
'mount' => mount
58
}.to_json
59
else
60
result = {
61
'success' => false
62
}.to_json
63
halt 500
64
end
65
end
66
rescue StandardError
67
print_error 'Invalid JSON input passed to endpoint /api/seng/clone_page'
68
error 400 # Bad Request
69
end
70
end
71
end
72
end
73
end
74
end
75
76