/
custom.js
472 lines (428 loc) · 11.6 KB
/
custom.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
// seperate hostname and url
// Referenced from https://stackoverflow.com/questions/736513/how-do-i-parse-a-url-into-hostname-and-path-in-javascript
function getParsedURL(url) {
var parser = new URL(url);
return parser.pathname+parser.search;
};
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
// Source: https://portswigger.net/web-security/cross-site-scripting/preventing#encode-data-on-output
function htmlEncode(str){
return String(str).replace(/[^\w. ]/gi, function(c){
return '&#'+c.charCodeAt(0)+';';
});
}
// Source: https://portswigger.net/web-security/cross-site-scripting/preventing#encode-data-on-output
function jsEscape(str){
return String(str).replace(/[^\w. ]/gi, function(c){
return '\\u'+('0000'+c.charCodeAt(0).toString(16)).slice(-4);
});
}
function deleteScheduledScan(id)
{
const delAPI = "../delete/scheduled_task/"+id;
swal.queue([{
title: 'Are you sure you want to delete this?',
text: "This action is irreversible.",
type: 'warning',
showCancelButton: true,
confirmButtonText: 'Delete',
padding: '2em',
showLoaderOnConfirm: true,
preConfirm: function() {
return fetch(delAPI, {
method: 'POST',
credentials: "same-origin",
headers: {
"X-CSRFToken": getCookie("csrftoken")
}
})
.then(function (response) {
return response.json();
})
.then(function(data) {
// TODO Look for better way
return location.reload();
})
.catch(function() {
swal.insertQueueStep({
type: 'error',
title: 'Oops! Unable to delete the scheduled task!'
})
})
}
}])
}
function change_scheduled_task_status(id)
{
const taskStatusApi = "../toggle/scheduled_task/"+id;
return fetch(taskStatusApi, {
method: 'POST',
credentials: "same-origin",
headers: {
"X-CSRFToken": getCookie("csrftoken")
}
})
}
function change_vuln_status(id)
{
const vulnStatusApi = "../toggle/vuln_status/"+id;
return fetch(vulnStatusApi, {
method: 'POST',
credentials: "same-origin",
headers: {
"X-CSRFToken": getCookie("csrftoken")
}
})
}
function change_subdomain_status(id)
{
const subdomainStatusApi = "../toggle/subdomain_status/"+id;
return fetch(subdomainStatusApi, {
method: 'POST',
credentials: "same-origin",
headers: {
"X-CSRFToken": getCookie("csrftoken")
}
})
}
// truncate the long string and put ... in the end
function truncate(source, size) {
return source.length > size ? source.slice(0, size - 1) + "…" : source;
}
// splits really long strings into multiple lines
// Souce: https://stackoverflow.com/a/52395960
function split(str, maxWidth) {
const newLineStr = "</br>";
done = false;
res = '';
do {
found = false;
// Inserts new line at first whitespace of the line
for (i = maxWidth - 1; i >= 0; i--) {
if (test_white_space(str.charAt(i))) {
res = res + [str.slice(0, i), newLineStr].join('');
str = str.slice(i + 1);
found = true;
break;
}
}
// Inserts new line at maxWidth position, the word is too long to wrap
if (!found) {
res += [str.slice(0, maxWidth), newLineStr].join('');
str = str.slice(maxWidth);
}
if (str.length < maxWidth)
done = true;
} while (!done);
return res + str;
}
function test_white_space(x) {
const white = new RegExp(/^\s$/);
return white.test(x.charAt(0));
};
// span values function will seperate the values by comma and put badge around it
function parse_comma_values_into_span(data, color, outline=null)
{
if(outline)
{
var badge = `<span class='badge badge-pill outline-badge-`+color+` m-1'>`;
}
else {
var badge = `<span class='badge badge-pill badge-`+color+` m-1'>`;
}
var data_with_span ="";
data.split(/\s*,\s*/).forEach(function(split_vals) {
data_with_span+=badge + split_vals + "</span>";
});
return data_with_span;
}
// Source: https://stackoverflow.com/a/54733055
function typingEffect(words, id, i) {
let word = words[i].split("");
var loopTyping = function() {
if (word.length > 0) {
let elem = document.getElementById(id);
elem.setAttribute('placeholder', elem.getAttribute('placeholder') + word.shift());
} else {
deletingEffect(words, id, i);
return false;
};
timer = setTimeout(loopTyping, 150);
};
loopTyping();
};
function deletingEffect(words, id, i) {
let word = words[i].split("");
var loopDeleting = function() {
if (word.length > 0) {
word.pop();
document.getElementById(id).setAttribute('placeholder', word.join(""));
} else {
if (words.length > (i + 1)) {
i++;
} else {
i = 0;
};
typingEffect(words, id, i);
return false;
};
timer = setTimeout(loopDeleting, 90);
};
loopDeleting();
};
function fullScreenDiv(id, btn){
let fullscreen = document.querySelector(id);
let button = document.querySelector(btn);
document.fullscreenElement && document.exitFullscreen() || document.querySelector(id).requestFullscreen()
fullscreen.setAttribute("style","overflow:auto");
}
function get_randid(){
return '_' + Math.random().toString(36).substr(2, 9);
}
function delete_all_scan_results()
{
const delAPI = "../start_scan/delete/scan_results/";
swal.queue([{
title: 'Are you sure you want to delete all scan results?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonText: 'Delete',
padding: '2em',
showLoaderOnConfirm: true,
preConfirm: function() {
return fetch(delAPI, {
method: 'POST',
credentials: "same-origin",
headers: {
"X-CSRFToken": getCookie("csrftoken")
}
})
.then(function (response) {
return response.json();
})
.then(function(data) {
// TODO Look for better way
return location.reload();
})
.catch(function() {
swal.insertQueueStep({
type: 'error',
title: 'Oops! Unable to delete Delete scan results!'
})
})
}
}])
}
function delete_all_screenshots()
{
const delAPI = "../start_scan/delete/screenshots/";
swal.queue([{
title: 'Are you sure you want to delete all Screenshots?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonText: 'Delete',
padding: '2em',
showLoaderOnConfirm: true,
preConfirm: function() {
return fetch(delAPI, {
method: 'POST',
credentials: "same-origin",
headers: {
"X-CSRFToken": getCookie("csrftoken")
}
})
.then(function (response) {
return response.json();
})
.then(function(data) {
// TODO Look for better way
return location.reload();
})
.catch(function() {
swal.insertQueueStep({
type: 'error',
title: 'Oops! Unable to delete Empty Screenshots!'
})
})
}
}])
}
function load_image_from_url(src, append_to_id){
img = document.createElement('img');
img.src = src;
img.style.width = '100%';
document.getElementById(append_to_id).appendChild(img);
}
function setTooltip(btn, message) {
$(btn).tooltip('hide')
.attr('data-original-title', message)
.tooltip('show');
}
function hideTooltip(btn) {
setTimeout(function() {
$(btn).tooltip('hide');
}, 1000);
}
function get_response_time_text(response_time){
var text_color = 'danger';
if (response_time < 0.5){
text_color = 'success'
}
else if (response_time >= 0.5 && response_time < 1){
text_color = 'warning'
}
return `<span class="text-${text_color}">${response_time.toFixed(4)}s</span>`;
}
function parse_technology(data, color, outline=null, scan_id=null)
{
if(outline)
{
var badge = `<span class='badge-link badge badge-pill outline-badge-`+color+` m-1'`;
}
else {
var badge = `<span class='badge-link badge badge-pill badge-`+color+` m-1'`;
}
var data_with_span ="";
for (var key in data){
if (scan_id){
data_with_span += badge + ` onclick="get_tech_details('${data[key]['name']}', ${scan_id})">` + data[key]['name'] + "</span>";
}
else{
data_with_span += badge + ` onclick="get_tech_details('${data[key]['name']}')">` + data[key]['name'] + "</span>";
}
}
return data_with_span;
}
// span values function will seperate the values by comma and put badge around it
function parse_ip(data, cdn){
if (cdn)
{
var badge = `<span class='badge badge-pill outline-badge-warning m-1 bs-tooltip' title="CDN IP Address">`;
}
else{
var badge = `<span class='badge badge-pill outline-badge-info m-1'>`;
}
var data_with_span ="";
data.split(/\s*,\s*/).forEach(function(split_vals) {
data_with_span+=badge + split_vals + "</span>";
});
return data_with_span;
}
//to remove the image element if there is no screenshot captured
function removeImageElement(element)
{
element.parentElement.remove();
}
// https://stackoverflow.com/a/18197341/9338140
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
function vuln_status_change(checkbox, id)
{
if (checkbox.checked) {
checkbox.parentNode.parentNode.parentNode.className = "table-secondary text-strike";
}
else {
checkbox.parentNode.parentNode.parentNode.classList.remove("table-secondary");
checkbox.parentNode.parentNode.parentNode.classList.remove("text-strike");
}
change_vuln_status(id);
}
function report_hackerone(vulnerability_id, severity){
message = ""
if (severity == 'Info' || severity == 'Low' || severity == 'Medium') {
message = "We do not recommended sending this vulnerability report to hackerone due to the severity, do you still want to report this?"
}
else{
message = "This vulnerability report will be sent to Hackerone.";
}
const vulnerability_report_api = "../../api/vulnerability/report/?vulnerability_id=" + vulnerability_id;
swal.queue([{
title: 'Reporting vulnerability to hackerone',
text: message,
type: 'warning',
showCancelButton: true,
confirmButtonText: 'Report',
padding: '2em',
showLoaderOnConfirm: true,
preConfirm: function() {
return fetch(vulnerability_report_api, {
method: 'GET',
credentials: "same-origin",
headers: {
"X-CSRFToken": getCookie("csrftoken")
}
})
.then(function (response) {
return response.json();
})
.then(function(data) {
console.log(data.status)
if (data.status == 111) {
swal.insertQueueStep({
type: 'error',
title: 'Target does not has team_handle to send report to.'
})
}
else if (data.status == 201) {
swal.insertQueueStep({
type: 'success',
title: 'Vulnerability report successfully submitted to hackerone.'
})
}
else if (data.status == 400) {
swal.insertQueueStep({
type: 'error',
title: 'Invalid Report.'
})
}
else if (data.status == 401) {
swal.insertQueueStep({
type: 'error',
title: 'Hackerone authentication failed.'
})
}
else if (data.status == 403) {
swal.insertQueueStep({
type: 'error',
title: 'API Key forbidden by Hackerone.'
})
}
else if (data.status == 423) {
swal.insertQueueStep({
type: 'error',
title: 'Too many requests.'
})
}
})
.catch(function() {
swal.insertQueueStep({
type: 'error',
title: 'Oops! Unable to send vulnerability report to hackerone, check your target team_handle or hackerone configurarions!'
})
})
}
}])
}