/
custom.js
2533 lines (2343 loc) · 92.7 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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function checkall(clickchk, relChkbox) {
var checker = $('#' + clickchk);
var multichk = $('.' + relChkbox);
checker.click(function() {
multichk.prop('checked', $(this).prop('checked'));
});
}
function multiCheck(tb_var) {
tb_var.on("change", ".chk-parent", function() {
var e = $(this).closest("table").find("td:first-child .child-chk"),
a = $(this).is(":checked");
$(e).each(function() {
a ? ($(this).prop("checked", !0), $(this).closest("tr").addClass("active")) : ($(this).prop("checked", !1), $(this).closest("tr").removeClass("active"))
})
}),
tb_var.on("change", "tbody tr .new-control", function() {
$(this).parents("tr").toggleClass("active")
})
}
function GetIEVersion() {
var sAgent = window.navigator.userAgent;
var Idx = sAgent.indexOf("MSIE");
// If IE, return version number.
if (Idx > 0) return parseInt(sAgent.substring(Idx + 5, sAgent.indexOf(".", Idx)));
// If IE 11 then look for Updated user agent string.
else if (!!navigator.userAgent.match(/Trident\/7\./)) return 11;
else return 0; //It is not IE
}
function truncate(str, n) {
return (str.length > n) ? str.substr(0, n - 1) + '…' : str;
};
function return_str_if_not_null(val) {
return val ? val : '';
}
// 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 can not be undone.",
icon: '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({
icon: 'error',
title: 'Oops! Unable to delete the scheduled task!'
})
})
}
}])
}
function change_scheduled_task_status(id, checkbox) {
if (checkbox.checked) {
text_msg = 'Schedule Scan Started';
} else {
text_msg = 'Schedule Scan Stopped';
}
Snackbar.show({
text: text_msg,
pos: 'top-right',
duration: 2500
});
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")
}
})
}
// splits really long strings into multiple lines
// Souce: https://stackoverflow.com/a/52395960
function split_into_lines(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 (data) {
var badge = `<span class='badge badge-soft-` + 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;
}
return '';
}
function get_severity_badge(severity) {
switch (severity) {
case 'Info':
return "<span class='badge badge-soft-primary'> INFO </span>";
break;
case 'Low':
return "<span class='badge badge-low'> LOW </span>";
break;
case 'Medium':
return "<span class='badge badge-soft-warning'> MEDIUM </span>";
break;
case 'High':
return "<span class='badge badge-soft-danger'> HIGH </span>";
break;
case 'Critical':
return "<span class='badge badge-critical'> CRITICAL </span>";
break;
case 'Unknown':
return "<span class='badge badge-soft-info'> UNKNOWN </span>";
default:
return "";
}
}
// 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 = "../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!",
icon: '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({
icon: 'error',
title: 'Oops! Unable to delete Delete scan results!'
})
})
}
}])
}
function delete_all_screenshots() {
const delAPI = "../scan/delete/screenshots/";
swal.queue([{
title: 'Are you sure you want to delete all Screenshots?',
text: "You won't be able to revert this!",
icon: '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({
icon: '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) {
hide_all_tooltips();
const instance = tippy(document.querySelector(btn));
instance.setContent(message);
instance.show();
setTimeout(function() {
instance.hide();
}, 500);
}
function hide_all_tooltips() {
$(".tooltip").tooltip("hide");
}
function get_response_time_text(response_time) {
if (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>`;
}
return '';
}
function parse_technology(data, color, scan_id = null, domain_id=null) {
var badge = `<span data-toggle="tooltip" title="Technology" class='badge-link badge badge-soft-` + color + ` mt-1 me-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}, domain_id=null)">` + data[key]['name'] + "</span>";
} else if (domain_id) {
data_with_span += badge + ` onclick="get_tech_details('${data[key]['name']}', scan_id=null, domain_id=domain_id)">` + 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-soft-warning m-1 bs-tooltip' title="CDN IP Address">`;
} else {
var badge = `<span class='badge badge-soft-primary 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-success text-strike";
} else {
checkbox.parentNode.parentNode.parentNode.classList.remove("table-success");
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,
icon: '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({
icon: 'error',
title: 'Target does not has team_handle to send report to.'
})
} else if (data.status == 201) {
swal.insertQueueStep({
icon: 'success',
title: 'Vulnerability report successfully submitted to hackerone.'
})
} else if (data.status == 400) {
swal.insertQueueStep({
icon: 'error',
title: 'Invalid Report.'
})
} else if (data.status == 401) {
swal.insertQueueStep({
icon: 'error',
title: 'Hackerone authentication failed.'
})
} else if (data.status == 403) {
swal.insertQueueStep({
icon: 'error',
title: 'API Key forbidden by Hackerone.'
})
} else if (data.status == 423) {
swal.insertQueueStep({
icon: 'error',
title: 'Too many requests.'
})
}
}).catch(function() {
swal.insertQueueStep({
icon: 'error',
title: 'Oops! Unable to send vulnerability report to hackerone, check your target team_handle or hackerone configurarions!'
})
})
}
}])
}
function get_interesting_subdomains(target_id, scan_history_id) {
if (target_id) {
url = `/api/listInterestingEndpoints/?target_id=${target_id}&format=datatables`;
non_orderable_targets = [0, 1, 2, 3];
} else if (scan_history_id) {
url = `/api/listInterestingSubdomains/?scan_id=${scan_history_id}&format=datatables`;
non_orderable_targets = [];
}
var interesting_subdomain_table = $('#interesting_subdomains').DataTable({
"drawCallback": function(settings, start, end, max, total, pre) {
// if no interesting subdomains are found, hide the datatable and show no interesting subdomains found badge
if (this.fnSettings().fnRecordsTotal() == 0) {
$('#interesting_subdomain_div').empty();
// $('#interesting_subdomain_div').append(`<div class="card-header bg-primary py-3 text-white">
// <div class="card-widgets">
// <a href="#" data-toggle="remove"><i class="mdi mdi-close"></i></a>
// </div>
// <h5 class="card-title mb-0 text-white"><i class="mdi mdi-fire-alert me-2"></i>Interesting subdomains could not be identified</h5>
// </div>
// <div id="cardCollpase4" class="collapse show">
// <div class="card-body">
// reNgine could not identify any interesting subdomains. You can customize interesting subdomain keywords <a href="/scanEngine/interesting/lookup/">from here</a> and this section would be automatically updated.
// </div>
// </div>`);
} else {
// show nav bar
$('.interesting-tab-show').removeAttr('style');
$('#interesting_subdomain_alert_count').html(`${this.fnSettings().fnRecordsTotal()} Interesting Subdomains`)
$('#interesting_subdomain_count_badge').empty();
$('#interesting_subdomain_count_badge').html(`<span class="badge badge-soft-primary me-1">${this.fnSettings().fnRecordsTotal()}</span>`);
}
},
"oLanguage": {
"oPaginate": {
"sPrevious": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-left"><line x1="19" y1="12" x2="5" y2="12"></line><polyline points="12 19 5 12 12 5"></polyline></svg>',
"sNext": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-right"><line x1="5" y1="12" x2="19" y2="12"></line><polyline points="12 5 19 12 12 19"></polyline></svg>'
},
"sInfo": "Showing page _PAGE_ of _PAGES_",
"sSearch": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>',
"sSearchPlaceholder": "Search...",
"sLengthMenu": "Results : _MENU_",
},
"processing": true,
"dom": "<'dt--top-section'<'row'<'col-12 col-sm-6 d-flex justify-content-sm-start justify-content-center'f><'col-12 col-sm-6 d-flex justify-content-sm-end justify-content-center'l>>>" + "<'table-responsive'tr>" + "<'dt--bottom-section d-sm-flex justify-content-sm-between text-center'<'dt--pages-count mb-sm-0 mb-3'i><'dt--pagination'p>>",
"destroy": true,
"bInfo": false,
"stripeClasses": [],
'serverSide': true,
"ajax": url,
"order": [
[3, "desc"]
],
"lengthMenu": [5, 10, 20, 50, 100],
"pageLength": 10,
"columns": [{
'data': 'name'
}, {
'data': 'page_title'
}, {
'data': 'http_status'
}, {
'data': 'content_length'
}, {
'data': 'http_url'
}, {
'data': 'technologies'
}, ],
"columnDefs": [{
"orderable": false,
"targets": non_orderable_targets
}, {
"targets": [4],
"visible": false,
"searchable": false,
}, {
"targets": [5],
"visible": false,
"searchable": true,
}, {
"className": "text-center",
"targets": [2]
}, {
"render": function(data, type, row) {
tech_badge = '';
if (row['technologies']) {
// tech_badge = `</br>` + parse_technology(row['technologies'], "primary", outline=true, scan_id=null);
}
if (row['http_url']) {
return `<a href="` + row['http_url'] + `" class="text-primary" target="_blank">` + data + `</a>` + tech_badge;
}
return `<a href="https://` + data + `" class="text-primary" target="_blank">` + data + `</a>` + tech_badge;
},
"targets": 0
}, {
"render": function(data, type, row) {
// display badge based on http status
// green for http status 2XX, orange for 3XX and warning for everything else
if (data >= 200 && data < 300) {
return "<span class='badge badge-pills badge-soft-success'>" + data + "</span>";
} else if (data >= 300 && data < 400) {
return "<span class='badge badge-pills badge-soft-warning'>" + data + "</span>";
} else if (data == 0) {
// datatable throws error when no data is returned
return "";
}
return `<span class='badge badge-pills badge-soft-danger'>` + data + `</span>`;
},
"targets": 2,
}, ],
});
}
function get_interesting_endpoint(target_id, scan_history_id) {
var non_orderable_targets = [];
if (target_id) {
url = `/api/listInterestingEndpoints/?target_id=${target_id}&format=datatables`;
// non_orderable_targets = [0, 1, 2, 3];
} else if (scan_history_id) {
url = `/api/listInterestingEndpoints/?scan_id=${scan_history_id}&format=datatables`;
// non_orderable_targets = [0, 1, 2, 3];
}
$('#interesting_endpoints').DataTable({
"drawCallback": function(settings, start, end, max, total, pre) {
if (this.fnSettings().fnRecordsTotal() == 0) {
$('#interesting_endpoint_div').remove();
} else {
$('.interesting-tab-show').removeAttr('style');
$('#interesting_endpoint_alert_count').html(`, ${this.fnSettings().fnRecordsTotal()} Interesting Endpoints`)
$('#interesting_endpoint_count_badge').empty();
$('#interesting_endpoint_count_badge').html(`<span class="badge badge-soft-primary me-1">${this.fnSettings().fnRecordsTotal()}</span>`);
}
},
"oLanguage": {
"oPaginate": {
"sPrevious": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-left"><line x1="19" y1="12" x2="5" y2="12"></line><polyline points="12 19 5 12 12 5"></polyline></svg>',
"sNext": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-right"><line x1="5" y1="12" x2="19" y2="12"></line><polyline points="12 5 19 12 12 19"></polyline></svg>'
},
"sInfo": "Showing page _PAGE_ of _PAGES_",
"sSearch": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>',
"sSearchPlaceholder": "Search...",
"sLengthMenu": "Results : _MENU_",
},
"processing": true,
"dom": "<'dt--top-section'<'row'<'col-12 col-sm-6 d-flex justify-content-sm-start justify-content-center'f><'col-12 col-sm-6 d-flex justify-content-sm-end justify-content-center'l>>>" + "<'table-responsive'tr>" + "<'dt--bottom-section d-sm-flex justify-content-sm-between text-center'<'dt--pages-count mb-sm-0 mb-3'i><'dt--pagination'p>>",
'serverSide': true,
"destroy": true,
"bInfo": false,
"ajax": url,
"order": [
[3, "desc"]
],
"lengthMenu": [5, 10, 20, 50, 100],
"pageLength": 10,
"columns": [{
'data': 'http_url'
}, {
'data': 'page_title'
}, {
'data': 'http_status'
}, {
'data': 'content_length'
}, ],
"columnDefs": [{
"orderable": false,
"targets": non_orderable_targets
}, {
"className": "text-center",
"targets": [2]
}, {
"render": function(data, type, row) {
var url = split_into_lines(data, 70);
return "<a href='" + data + "' target='_blank' class='text-primary'>" + url + "</a>";
},
"targets": 0
}, {
"render": function(data, type, row) {
// display badge based on http status
// green for http status 2XX, orange for 3XX and warning for everything else
if (data >= 200 && data < 300) {
return "<span class='badge badge-pills badge-soft-success'>" + data + "</span>";
} else if (data >= 300 && data < 400) {
return "<span class='badge badge-pills badge-soft-warning'>" + data + "</span>";
} else if (data == 0) {
// datatable throws error when no data is returned
return "";
}
return `<span class='badge badge-pills badge-soft-danger'>` + data + `</span>`;
},
"targets": 2,
}, ],
});
}
function get_important_subdomains(target_id, scan_history_id) {
var url = `/api/querySubdomains/?only_important&no_lookup_interesting&format=json`;
if (target_id) {
url += `&target_id=${target_id}`;
} else if (scan_history_id) {
url += `&scan_id=${scan_history_id}`;
}
$.getJSON(url, function(data) {
$('#important-count').empty();
$('#important-subdomains-list').empty();
if (data['subdomains'].length > 0) {
$('#important-count').html(`<span class="badge badge-soft-primary ms-1 me-1">${data['subdomains'].length}</span>`);
for (var val in data['subdomains']) {
subdomain = data['subdomains'][val];
div_id = 'important_' + subdomain['id'];
$("#important-subdomains-list").append(`
<div id="${div_id}">
<p>
<span id="subdomain_${subdomain['id']}"> ${subdomain['name']}
<span class="">
<a href="javascript:;" data-clipboard-action="copy" class="m-1 float-end badge-link text-info copyable text-primary" data-toggle="tooltip" data-placement="top" title="Copy Subdomain!" data-clipboard-target="#subdomain_${subdomain['id']}">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather feather-copy"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg></span>
</a>
</span>
</p>
</div>
<hr />
`);
}
} else {
$('#important-count').html(`<span class="badge badge-soft-primary ms-1 me-1">0</span>`);
$('#important-subdomains-list').append(`<p>No subdomains markerd as important!</p>`);
}
$('.bs-tooltip').tooltip();
});
}
function mark_important_subdomain(row, subdomain_id) {
if (row) {
parentNode = row.parentNode.parentNode.parentNode.parentNode;
if (parentNode.classList.contains('table-danger')) {
parentNode.classList.remove('table-danger');
} else {
parentNode.className = "table-danger";
}
}
var data = {'subdomain_id': subdomain_id}
const subdomainImpApi = "/api/toggle/subdomain/important/";
if ($("#important_subdomain_" + subdomain_id).length == 0) {
$("#subdomain-" + subdomain_id).prepend(`<span id="important_subdomain_${subdomain_id}"></span>`);
setTooltip("#subdomain-" + subdomain_id, 'Marked Important!');
} else {
$("#important_subdomain_" + subdomain_id).remove();
setTooltip("#subdomain-" + subdomain_id, 'Marked Un-Important!');
}
return fetch(subdomainImpApi, {
method: 'POST',
credentials: "same-origin",
headers: {
"X-CSRFToken": getCookie("csrftoken"),
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
}
function delete_scan(id) {
const delAPI = "../delete/scan/" + id;
swal.queue([{
title: 'Are you sure you want to delete this scan history?',
text: "You won't be able to revert this!",
icon: '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({
icon: 'error',
title: 'Oops! Unable to delete the scan history!'
})
})
}
}]);
}
function stop_scan(scan_id=null, subscan_id=null, reload_scan_bar=true, reload_location=false) {
const stopAPI = "/api/action/stop/scan/";
if (scan_id) {
var data = {'scan_id': scan_id}
}
else if (subscan_id) {
var data = {'subscan_id': subscan_id}
}
swal.queue([{
title: 'Are you sure you want to stop this scan?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Stop',
padding: '2em',
showLoaderOnConfirm: true,
preConfirm: function() {
return fetch(stopAPI, {
method: 'POST',
credentials: "same-origin",
body: JSON.stringify(data),
headers: {
"X-CSRFToken": getCookie("csrftoken"),
"Content-Type": 'application/json',
}
}).then(function(response) {
return response.json();
}).then(function(data) {
// TODO Look for better way
if (data.status) {
Snackbar.show({
text: 'Scan Successfully Aborted.',
pos: 'top-right',
duration: 1500
});
if (reload_scan_bar) {
getScanStatusSidebar();
}
if (reload_location) {
window.location.reload();
}
} else {
Snackbar.show({
text: 'Oops! Could not abort the scan. ' + data.message,
pos: 'top-right',
duration: 1500
});
}
}).catch(function() {
swal.insertQueueStep({
icon: 'error',
title: 'Oops! Unable to stop the scan'
})
})
}
}])
}
function extractContent(s) {
var span = document.createElement('span');
span.innerHTML = s;
return span.textContent || span.innerText;
};
function delete_datatable_rows(table_id, rows_id, show_snackbar = true, snackbar_title) {
// this function will delete the datatables rows after actions such as delete
// table_id => datatable_id with #
// rows_ids: list/array => list of all numerical ids to delete, to maintain consistency
// rows id will always follow this pattern: datatable_id_row_n
// show_snackbar = bool => whether to show snackbar or not!
// snackbar_title: str => snackbar title if show_snackbar = True
var table = $(table_id).DataTable();
for (var row in rows_id) {
table.row(table_id + '_row_' + rows_id[row]).remove().draw();
}
Snackbar.show({
text: snackbar_title,
pos: 'top-right',
duration: 1500,
actionTextColor: '#fff',
backgroundColor: '#e7515a',
});
}
function delete_subscan(subscan_id) {
// This function will delete the sunscans using rest api
// Supported method: POST
const delAPI = "/api/action/rows/delete/";
var data = {
'type': 'subscan',
'rows': [subscan_id]
}
swal.queue([{
title: 'Are you sure you want to delete this subscan?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Delete',
padding: '2em',
showLoaderOnConfirm: true,
preConfirm: function() {
return fetch(delAPI, {
method: 'POST',
credentials: "same-origin",
headers: {
"X-CSRFToken": getCookie("csrftoken"),
"Content-Type": "application/json"
},
body: JSON.stringify(data)
}).then(function(response) {
return response.json();
}).then(function(response) {
if (response['status']) {
delete_datatable_rows('#subscan_history_table', [subscan_id], show_snackbar = true, '1 Subscan Deleted!')
}
}).catch(function() {
swal.insertQueueStep({
icon: 'error',
title: 'Oops! Unable to delete the scan history!'
})
})
}
}])
}
function show_subscan_results(subscan_id) {
// This function will popup a modal and show the subscan results
// modal being used is from base
var api_url = '/api/fetch/results/subscan/?format=json';
var data = {
'subscan_id': subscan_id
};
Swal.fire({
title: 'Fetching Results...'
});
swal.showLoading();
fetch(api_url, {
method: 'POST',
credentials: "same-origin",
headers: {
"X-CSRFToken": getCookie("csrftoken"),
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}).then(response => response.json()).then(function(response) {
console.log(response);
swal.close();
if (response['subscan']['status'] == -1) {
swal.fire("Error!", "Scan has not yet started! Please wait for other scans to complete...", "warning", {
button: "Okay",
});
return;
} else if (response['subscan']['status'] == 1) {
swal.fire("Error!", "Scan is in progress! Please come back later...", "warning", {
button: "Okay",
});
return;
}
$('#xl-modal-title').empty();
$('#xl-modal-content').empty();
$('#xl-modal-footer').empty();
var task_name = '';
if (response['subscan']['task'] == 'port_scan') {
task_name = 'Port Scan';
} else if (response['subscan']['task'] == 'vulnerability_scan') {
task_name = 'Vulnerability Scan';
} else if (response['subscan']['task'] == 'fetch_url') {
task_name = 'EndPoint Gathering';
} else if (response['subscan']['task'] == 'dir_file_fuzz') {
task_name = 'Directory and Files Fuzzing';
}
$('#xl-modal_title').html(`${task_name} Results on ${response['subscan']['subdomain_name']}`);
var scan_status = '';
var badge_color = 'danger';
if (response['subscan']['status'] == 0) {
scan_status = 'Failed';
} else if (response['subscan']['status'] == 2) {
scan_status = 'Successful';
badge_color = 'success';
} else if (response['subscan']['status'] == 3) {
scan_status = 'Aborted';
} else {
scan_status = 'Unknown';
}
$('#xl-modal-content').append(`<div>Scan Status: <span class="badge bg-${badge_color}">${scan_status}</span></div>`);
console.log(response);
$('#xl-modal-content').append(`<div class="mt-1">Engine Used: <span class="badge bg-primary">${htmlEncode(response['subscan']['engine'])}</span></div>`);
if (response['result'].length > 0) {
if (response['subscan']['task'] == 'port_scan') {
$('#xl-modal-content').append(`<div id="port_results_li"></div>`);
for (var ip in response['result']) {
var ip_addr = response['result'][ip]['address'];
var id_name = `ip_${ip_addr}`;
$('#port_results_li').append(`<h5>IP Address: ${ip_addr}</br></br>${response['result'][ip]['ports'].length} Ports Open</h5>`);
$('#port_results_li').append(`<ul id="${id_name}"></ul>`);
for (var port_obj in response['result'][ip]['ports']) {
var port = response['result'][ip]['ports'][port_obj];
var port_color = 'primary';
if (port["is_uncommon"]) {
port_color = 'danger';
}
$('#port_results_li ul').append(`<li><span class="ms-1 mt-1 me-1 badge badge-soft-${port_color}">${port['number']}</span>/<span class="ms-1 mt-1 me-1 badge badge-soft-${port_color}">${port['service_name']}</span>/<span class="ms-1 mt-1 me-1 badge badge-soft-${port_color}">${port['description']}</span></li>`);
}
}
$('#xl-modal-footer').append(`<span class="text-danger">* Uncommon Ports</span>`);
} else if (response['subscan']['task'] == 'vulnerability_scan') {
render_vulnerability_in_xl_modal(vuln_count = response['result'].length, subdomain_name = response['subscan']['subdomain_name'], result = response['result']);
} else if (response['subscan']['task'] == 'fetch_url') {
render_endpoint_in_xlmodal(endpoint_count = response['result'].length, subdomain_name = response['subscan']['subdomain_name'], result = response['result']);
} else if (response['subscan']['task'] == 'dir_file_fuzz') {
if (response['result'][0]['directory_files'].length == 0) {
$('#xl-modal-content').append(`
<div class="alert alert-info mt-2" role="alert">
<i class="mdi mdi-alert-circle-outline me-2"></i> ${task_name} could not fetch any results.
</div>
`);
} else {
render_directories_in_xl_modal(response['result'][0]['directory_files'].length, response['subscan']['subdomain_name'], response['result'][0]['directory_files']);
}
}
} else {
$('#xl-modal-content').append(`
<div class="alert alert-info mt-2" role="alert">
<i class="mdi mdi-alert-circle-outline me-2"></i> ${task_name} could not fetch any results.
</div>
`);
}
$('#modal_xl_scroll_dialog').modal('show');
$("body").tooltip({
selector: '[data-toggle=tooltip]'
});
});
}
function get_http_status_badge(data) {
if (data >= 200 && data < 300) {
return "<span class='badge badge-soft-success'>" + data + "</span>";
} else if (data >= 300 && data < 400) {
return "<span class='badge badge-soft-warning'>" + data + "</span>";