-
Notifications
You must be signed in to change notification settings - Fork 3
/
parser.js
899 lines (772 loc) · 28.4 KB
/
parser.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
"use strict";
// Boot stuff when DOM is loaded
$(function () {
// Bootstrap
console.group('Parser');
console.log('DOM Loaded.');
console.groupEnd();
// Loading XML content
// Using jquery to be quick as it's already needed by Fomantic-UI
var Report = {
converted: null,
url: '',
settings: {
'debug': true,
'dialogTimeout': 4000,
'materialize': (typeof Materialize !== 'undefined' ? true : false),
'fomantic-ui': (typeof $.site.settings !== 'undefined' ? true : false),
'semantic-ui': (typeof $.site.settings !== 'undefined' ? true : false)
},
createDialog: function (message, type) {
if (!message) {
if (Report.settings.materialize === true) {
// TODO: Add support for dialog types
Materialize.toast('The "message" argument must be defined.', Report.settings.dialogTimeout, 'rounded');
}
else if (Report.settings["fomantic-ui"] === true || Report.settings["semantic-ui"] === true) {
$('body').toast({
title: 'Error',
class: 'error',
displayTime: Report.settings.dialogTimeout,
showProgress: 'bottom',
classProgress: 'red',
message: 'The "message" argument must be defined.'
});
}
else {
alert('The "message" argument must be defined.');
}
}
else {
if (Report.settings.materialize === true) {
Materialize.toast(message, Report.settings.dialogTimeout, 'rounded');
}
else if (Report.settings["fomantic-ui"] === true || Report.settings["semantic-ui"] === true) {
$('body').toast({
title: (typeof type !== undefined ? (type === 'error' ? 'Error' : 'Info') : ''),
class: (typeof type !== undefined ? (type === 'error' ? 'error' : 'success') : ''),
displayTime: Report.settings.dialogTimeout,
showProgress: 'bottom',
classProgress: (typeof type !== undefined ? (type === 'error' ? 'orange' : 'teal') : 'blue'),
// classProgress: 'orange',
message: message
});
}
else {
alert(message);
}
}
},
fetch: function (url, container) {
if (url && url === '') {
Report.createDialog("The URL argument must be defined!", 'error');
}
else if (container && container === undefined) {
Report.createDialog("The HTML container must be defined!", 'error');
}
else {
$.ajax({
type: "GET",
url: url,
crossDomain: true,
headers: { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Headers': '*' },
// headers: { 'Access-Control-Allow-Origin': window.location.href },
dataType: "xml"
}).done(function(response) {
Report.hidePreloader();
Report.createDialog("XML report loaded.", 'success');
if (Report.settings.debug === true) {
console.info('Got XML Document:', response);
}
var x2js = new X2JS();
var jsonObj = x2js.xml2json(response);
Report.converted = jsonObj;
if (typeof jsonObj === 'object') {
if (Report.settings.debug === true) {
console.info('Got JSON Object:', jsonObj);
console.info('Building HTML...');
}
Report.build(jsonObj, container);
Report.createDialog("XML report converted.", 'success');
}
}).fail(function(jqXHR) {
Report.hide();
Report.createDialog("Can't fetch the XML report!", 'error');
if (Report.settings.debug === true) {
console.error("Can't fetch the XML report!", jqXHR);
}
});
}
},
parseFile: function (data, container) {
if (data && data === '') {
Report.createDialog("The data argument must be defined!", 'error');
}
else if (container && container === undefined) {
Report.createDialog("The HTML container must be defined!", 'error');
}
else {
Report.hidePreloader();
Report.createDialog("XML report loaded.", 'success');
if (Report.settings.debug === true) {
console.info('Got XML data:', data);
}
var x2js = new X2JS();
var jsonObj = x2js.xml2json(data);
Report.converted = jsonObj;
if (typeof jsonObj === 'object') {
if (Report.settings.debug === true) {
console.info('Got JSON Object:', jsonObj);
console.info('Building HTML...');
}
Report.build(jsonObj, container);
Report.createDialog("XML report parsed.", 'success');
}
}
},
parseString: function (data, container) {
if (data && data === '') {
Report.createDialog("The data argument must be defined!", 'error');
}
else if (container && container === undefined) {
Report.createDialog("The HTML container must be defined!", 'error');
}
else {
Report.hidePreloader();
Report.createDialog("XML report loaded.", 'success');
if (Report.settings.debug === true) {
console.info('Got XML data:', data);
}
var x2js = new X2JS();
var jsonObj = x2js.xml_str2json(data);
Report.converted = jsonObj;
if (typeof jsonObj === 'object') {
if (Report.settings.debug === true) {
console.info('Got JSON Object:', jsonObj);
console.info('Building HTML...');
}
Report.build(jsonObj, container);
Report.createDialog("XML report parsed.", 'success');
}
}
},
// Escape special characters by encoding them into HTML entities
// https://stackoverflow.com/a/46685127
escapeHtml: function (str) {
var div = document.createElement('div');
div.innerText = str;
return div.innerHTML;
},
show: function () {
if (Report.settings.debug === true) {
console.info('Showing report container...');
}
// Components.report.show();
Report.showPreloader();
},
hide: function () {
if (Report.settings.debug === true) {
console.info('Hiding report container...');
}
Report.hidePreloader();
// Components.report.hide();
},
showPreloader: function () {
if (Report.settings.debug === true) {
console.info('Showing preloader...');
}
// Framework.progressBar.eq(0).show('slow');
},
hidePreloader: function () {
if (Report.settings.debug === true) {
console.info('Hidding preloader...');
}
// Framework.progressBar.eq(0).hide('slow');
},
readFile: function (file, container) {
var reader = new FileReader();
reader.onload = function (event) {
if (Report.settings.debug === true) {
console.info('File loaded.', event);
}
Report.parseXml(event.target.result, container);
}
reader.onerror = function (event) {
Report.hide();
Report.createDialog("Can't load the XML file.", 'error');
if (Report.settings.debug === true) {
console.error("Can't load the XML file.", event);
}
}
if (Report.settings.debug === true) {
console.info('Reading given XML file:', file);
}
reader.readAsText(file);
},
updateFileSize: function (fileList, display) {
// Taken from Mozilla MDN and modified for this project
// https://developer.mozilla.org/en-US/docs/Web/API/File/Using_files_from_web_applications#Example_Showing_file(s)_size
var nBytes = 0,
oFiles = fileList,
nFiles = oFiles.length;
for (var nFileId = 0; nFileId < nFiles; nFileId++) {
nBytes += oFiles[nFileId].size;
}
var sOutput = nBytes + " bytes";
// optional code for multiples approximation
for (var aMultiples = ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"], nMultiple = 0, nApprox = nBytes / 1024; nApprox > 1; nApprox /= 1024, nMultiple++) {
sOutput = nApprox.toFixed(3) + " " + aMultiples[nMultiple] + " (" + nBytes + " bytes)";
}
// end of optional code
// display values
if (display && display === true) {
document.getElementById("fileNum").innerHTML = nFiles;
document.getElementById("fileSize").innerHTML = sOutput;
}
// dirty addition
document.getElementById("report-upload-details").style.display = 'block';
},
check: function () {
if (Report.settings.debug === true) {
console.info('Browser:', window.location);
}
var safeEnv = true;
if (window.location.protocol === 'file:') {
safeEnv = false;
}
return safeEnv;
},
build: function (obj, container) {
if (!container) {
Report.createDialog("Container not defined.");
if (Report.settings.debug === true) {
console.error("Container not defined.");
}
return false;
}
else {
container = $(container);
if (Report.settings.debug === true) {
console.info('Got container:', container);
}
}
if (!obj) {
Report.createDialog("Object not defined.");
if (Report.settings.debug === true) {
console.error("Object not defined.");
}
return false;
}
else {
// Generate the HTML with the parse function
Report.generate(obj.nmaprun, container);
// Call UI convertion hooks
Report.convertionHooks();
}
},
generate: function (data, container) {
var html;
// Main Container (can't be inverted because of 'styled' class)
html = '<div class="ui styled fluid accordion">';
html += '<div class="active title">';
html += '<i class="dropdown icon"></i>';
html += data._args;
html += '</div>';
// Start Content
html += '<div class="active content">';
// Report Table
html += '<table class="ui celled inverted table">';
html += '<thead>';
html += '<tr>';
html += '<th>IP</th>';
html += '<th>MAC</th>';
html += '<th>Hostname</th>';
html += '<th>Ports</th>';
html += '<th>Start</th>';
html += '<th>End</th>';
html += '<th>Elapsed (seconds)</th>';
html += '<th>Status</th>';
html += '</tr>';
html += '</thead>';
html += '<tbody>';
if (Array.isArray(data.host)) {
for (let index = 0; index < data.host.length; index++) {
const scannedHost = data.host[index];
console.log(scannedHost);
html += '<tr>';
// IP
html += '<td>' + (
Array.isArray(scannedHost.address)
? scannedHost.address[0]._addr
: scannedHost.address._addr
) + '</td>';
// MAC
html += '<td>' + (
Array.isArray(scannedHost.address) && scannedHost.address.length > 1
? scannedHost.address[1]._addr
: 'N/A'
) + '</td>';
// Hostname
html += '<td><a href="#!" onclick="$(\'.ui.modal\').modal(\'show\');">' + (
Array.isArray(scannedHost.hostnames.hostname)
? scannedHost.hostnames.hostname[0]._name
: scannedHost.hostnames.hostname._name
) + '</a></td>';
// Port(s)
html += '<td class="center aligned"><a href="#!" onclick="$(\'.ui.modal\').modal(\'show\');">' + (
Array.isArray(scannedHost.ports.port)
? scannedHost.ports.port.length
: scannedHost.ports.port._portid + '/' + scannedHost.ports.port._protocol + ' (' + scannedHost.ports.port.service._name + ')'
) + '</a></td>';
// Date start
html += '<td>' + data._startstr + '</td>';
// Date end
html += '<td>' + data.runstats.finished._timestr + '</td>';
// Time elapsed
html += '<td class="center aligned">' + data.runstats.finished._elapsed + '</td>';
// Exit status
html += '<td>' + data.runstats.finished._exit + '</td>';
html += '</tr>';
}
}
else {
const scannedHost = data.host;
console.log(scannedHost);
html += '<tr>';
// IP
html += '<td>' + (
Array.isArray(scannedHost.address)
? scannedHost.address[0]._addr
: scannedHost.address._addr
) + '</td>';
// MAC
html += '<td>' + (
Array.isArray(scannedHost.address) && scannedHost.address.length > 1
? scannedHost.address[1]._addr
: 'N/A'
) + '</td>';
// Hostname
html += '<td><a href="#!" onclick="$(\'.ui.modal.ports\').modal(\'show\');">' + (
Array.isArray(scannedHost.hostnames.hostname)
? scannedHost.hostnames.hostname[0]._name
: scannedHost.hostnames.hostname._name
) + '</a></td>';
// Port(s)
html += '<td class="center aligned"><a href="#!" onclick="$(\'.ui.modal.ports\').modal(\'show\');">' + (
Array.isArray(scannedHost.ports.port)
? scannedHost.ports.port.length
: scannedHost.ports.port._portid + '/' + scannedHost.ports.port._protocol + ' (' + scannedHost.ports.port.service._name + ')'
) + '</a></td>';
// Date start
html += '<td>' + data._startstr + '</td>';
// Date end
html += '<td>' + data.runstats.finished._timestr + '</td>';
// Time elapsed
html += '<td class="center aligned">' + data.runstats.finished._elapsed + '</td>';
// Exit status
html += '<td>' + data.runstats.finished._exit + '</td>';
html += '</tr>';
}
html += '</tbody>';
html += '</table>';
// End Content
html += '</div>';
// Scan details modal
html += '<div class="ui inverted modal ports">';
html += '<div class="header">Scan details</div>';
html += '<div class="content">';
html += '<table class="ui celled inverted table">';
html += '<thead>';
html += '<tr>';
html += '<th>Port</th>';
html += '<th>Scripts</th>';
html += '<th>State</th>';
html += '<th>Service</th>';
html += '<th>Method</th>';
html += '<th>TTL</th>';
html += '<th>Product</th>';
html += '</tr>';
html += '</thead>';
html += '<tbody>';
if (Array.isArray(data.host.ports.port)) {
for (let index = 0; index < data.host.ports.port.length; index++) {
const scannedPort = data.host.ports.port[index];
console.log(scannedPort);
html += '<tr>';
html += '<td>' + scannedPort._portid + ' (' + scannedPort._protocol + ')</td>';
if (scannedPort.script) {
html += '<td><a href="#!" onclick="$(\'.ui.modal.scripts.' + scannedPort._portid + '\').modal(\'show\');">';
html += (Array.isArray(scannedPort.script)
? scannedPort.script.length
: (typeof scannedPort.script === 'object' && scannedPort.script.hasOwnProperty('_id')
? 1
: 0)
);
html += '</a></td>';
}
else {
html += '<td>0</td>';
}
html += '<td>' + scannedPort.state._state + '</td>';
html += '<td>' + scannedPort.service._name + '</td>';
html += '<td>' + scannedPort.state._reason + '</td>';
html += '<td>' + scannedPort.state._reason_ttl + '</td>';
if (scannedPort.service._product && scannedPort.service._version) {
html += '<td>' + scannedPort.service._product + ' ' + scannedPort.service._version + '</td>';
}
else if (scannedPort.service._product && !scannedPort.service._version) {
html += '<td>' + scannedPort.service._product + '</td>';
}
else if (scannedPort.service._extrainfo && scannedPort.service._extrainfo !== "access denied") {
html += '<td>' + scannedPort.service._extrainfo + '</td>';
}
else {
html += '<td>' + scannedPort.service._name + '</td>';
}
html += '</tr>';
}
}
else {
const scannedPort = data.host.ports.port;
console.log(scannedPort);
html += '<tr>';
html += '<td>' + scannedPort._portid + ' (' + scannedPort._protocol + ')</td>';
if (scannedPort.script) {
html += '<td><a href="#!" onclick="$(\'.ui.modal.scripts.' + scannedPort._portid + '\').modal(\'show\');">';
html += (Array.isArray(scannedPort.script)
? scannedPort.script.length
: (typeof scannedPort.script === 'object' && scannedPort.script.hasOwnProperty('_id')
? 1
: 0)
);
html += '</a></td>';
}
else {
html += '<td>N/A</td>';
}
html += '<td>' + scannedPort.state._state + '</td>';
html += '<td>' + scannedPort.service._name + '</td>';
html += '<td>' + scannedPort.state._reason + '</td>';
html += '<td>' + scannedPort.state._reason_ttl + '</td>';
if (scannedPort.service._product && scannedPort.service._version) {
html += '<td>' + scannedPort.service._product + ' ' + scannedPort.service._version + '</td>';
}
else if (scannedPort.service._product && !scannedPort.service._version) {
html += '<td>' + scannedPort.service._product + '</td>';
}
else if (scannedPort.service._extrainfo && scannedPort.service._extrainfo !== "access denied") {
html += '<td>' + scannedPort.service._extrainfo + '</td>';
}
else {
html += '<td>' + scannedPort.service._name + '</td>';
}
html += '</tr>';
}
html += '</tbody>';
html += '</table>';
html += '</div>';
html += '<div class="actions">';
html += '<div class="ui ok green inverted button">Close</div>';
// html += '<div class="ui cancel button">Cancel</div>';
html += '</div>';
html += '</div>';
// Scripts details modal
if (Array.isArray(data.host.ports.port)) {
for (let indexA = 0; indexA < data.host.ports.port.length; indexA++) {
if (data.host.ports.port[indexA].script) {
html += '<div class="ui inverted fullscreen modal scripts ' + data.host.ports.port[indexA]._portid + '">';
html += '<div class="header">Script executed on port (' + data.host.ports.port[indexA]._portid + ')</div>';
html += '<div class="scrolling content">';
html += '<table class="ui celled inverted table">';
html += '<thead>';
html += '<tr>';
html += '<th>Id</th>';
html += '<th>Output</th>';
html += '</tr>';
html += '</thead>';
html += '<tbody>';
if (Array.isArray(data.host.ports.port[indexA].script)) {
for (let indexB = 0; indexB < data.host.ports.port[indexA].script.length; indexB++) {
const scannedPortScript = data.host.ports.port[indexA].script[indexB];
console.log(scannedPortScript);
html += '<tr>';
html += '<td>' + scannedPortScript._id + '</td>';
switch (scannedPortScript._id) {
case 'vulners':
html += '<td>';
if (scannedPortScript.table.table) {
// Set firt entry for thead / tfoot
const scannedPortScriptVulnersFirst = scannedPortScript.table.table[0];
html += '<table class="ui fixed single line striped celled inverted table">';
html += '<thead>';
html += '<tr>';
// Get a consistent table header as the order is imposible to predict
for (let indexC = 0; indexC < scannedPortScriptVulnersFirst.elem.length; indexC++) {
const scannedPortScriptVulnersHeader = scannedPortScriptVulnersFirst.elem[indexC];
html += '<th>' + scannedPortScriptVulnersHeader._key + '</th>';
}
html += '</tr>';
html += '</thead>';
html += '<tbody>';
for (let indexD = 0; indexD < scannedPortScript.table.table.length; indexD++) {
const scannedPortScriptVulners = scannedPortScript.table.table[indexD];
html += '<tr>';
for (let indexE = 0; indexE < scannedPortScriptVulners.elem.length; indexE++) {
const scannedPortScriptVulnersKey = scannedPortScriptVulners.elem[indexE];
if (scannedPortScriptVulnersKey._key === 'type') {
html += '<td>' + scannedPortScriptVulnersKey.__text + '</td>';
}
else if (scannedPortScriptVulnersKey._key === 'id') {
scannedPortScriptVulners.elem.forEach(element => {
if (element._key === 'type') {
switch (element.__text) {
case 'exploitpack':
scannedPortScriptVulnersKey.__url = 'https://vulners.com/exploitpack/';
break;
case 'exploitdb':
scannedPortScriptVulnersKey.__url = 'https://vulners.com/exploitdb/';
break;
case 'cve':
scannedPortScriptVulnersKey.__url = 'https://vulners.com/cve/';
break;
case 'canvas':
scannedPortScriptVulnersKey.__url = 'https://vulners.com/canvas/';
break;
case 'packetstorm':
scannedPortScriptVulnersKey.__url = 'https://vulners.com/packetstorm/';
break;
case 'metasploit':
scannedPortScriptVulnersKey.__url = 'https://vulners.com/metasploit/';
break;
case 'zdt':
scannedPortScriptVulnersKey.__url = 'https://vulners.com/zdt/';
break;
default:
scannedPortScriptVulnersKey.__url = null;
break;
}
}
});
if (typeof scannedPortScriptVulnersKey.__url !== null) {
html += '<td><a href="' + scannedPortScriptVulnersKey.__url + scannedPortScriptVulnersKey.__text + '" target="_blank">' + scannedPortScriptVulnersKey.__text + '</a></td>';
}
else {
html += '<td>' + scannedPortScriptVulnersKey.__text + '</td>';
}
}
else {
html += '<td>' + scannedPortScriptVulnersKey.__text + '</td>';
}
}
html += '</tr>';
}
html += '</tbody>';
html += '<tfoot>';
html += '<tr>';
// Get a consistent table header as the order is imposible to predict
for (let indexC = 0; indexC < scannedPortScriptVulnersFirst.elem.length; indexC++) {
const scannedPortScriptVulnersFooter = scannedPortScriptVulnersFirst.elem[indexC];
html += '<td style="font-weight: bold;">' + scannedPortScriptVulnersFooter._key + '</td>';
}
html += '</tr>';
html += '</tfoot>';
html += '</table>';
}
html += '</td>';
break;
case 'ssh-hostkey':
html += '<td>';
if (scannedPortScript.table) {
// Set firt entry for thead / tfoot
const scannedPortScriptSSHFirst = scannedPortScript.table[0];
html += '<table class="ui fixed single line striped celled inverted table">';
html += '<thead>';
html += '<tr>';
// Get a consistent table header as the order is imposible to predict
for (let indexC = 0; indexC < scannedPortScriptSSHFirst.elem.length; indexC++) {
const scannedPortScriptSSHHeader = scannedPortScriptSSHFirst.elem[indexC];
html += '<th>' + scannedPortScriptSSHHeader._key + '</th>';
}
html += '</tr>';
html += '</thead>';
html += '<tbody>';
for (let indexD = 0; indexD < scannedPortScript.table.length; indexD++) {
const scannedPortScriptSSH = scannedPortScript.table[indexD];
html += '<tr>';
for (let indexE = 0; indexE < scannedPortScriptSSH.elem.length; indexE++) {
const scannedPortScriptSSHKey = scannedPortScriptSSH.elem[indexE];
if (scannedPortScriptSSHKey._key === 'key') {
html += '<td class="tooltipped" data-inverted="true" data-position="bottom right" title="' + scannedPortScriptSSHKey.__text + '">' + scannedPortScriptSSHKey.__text + '</td>';
}
else {
html += '<td>' + scannedPortScriptSSHKey.__text + '</td>';
}
}
html += '</tr>';
}
html += '</tbody>';
html += '<tfoot>';
html += '<tr>';
// Get a consistent table header as the order is imposible to predict
for (let indexC = 0; indexC < scannedPortScriptSSHFirst.elem.length; indexC++) {
const scannedPortScriptSSHFooter = scannedPortScriptSSHFirst.elem[indexC];
html += '<td style="font-weight: bold;">' + scannedPortScriptSSHFooter._key + '</td>';
}
html += '</tr>';
html += '</tfoot>';
html += '</table>';
}
html += '</td>';
break;
default:
html += '<td>' + scannedPortScript._output + '</td>';
break;
}
html += '</tr>';
}
}
else {
const scannedPortScript = data.host.ports.port[indexA].script;
console.log(scannedPortScript);
html += '<tr>';
html += '<td>' + scannedPortScript._id + '</td>';
switch (scannedPortScript._id) {
case 'dns-nsid':
html += '<td>';
if (scannedPortScript.elem) {
html += '<table class="ui fixed single line celled inverted table">';
html += '<thead>';
html += '<tr>';
// Get a consistent table header as the order is imposible to predict
for (let indexB = 0; indexB < scannedPortScript.elem.length; indexB++) {
const scannedPortScriptDNSHeader = scannedPortScript.elem[indexB];
html += '<th>' + scannedPortScriptDNSHeader._key + '</th>';
}
html += '</tr>';
html += '</thead>';
html += '<tbody>';
html += '<tr>';
for (let indexC = 0; indexC < scannedPortScript.elem.length; indexC++) {
const scannedPortScriptDNSKey = scannedPortScript.elem[indexC];
if (scannedPortScriptDNSKey._key === 'key') {
html += '<td class="tooltipped" data-inverted="true" data-position="bottom center" title="' + scannedPortScriptDNSKey.__text + '">' + scannedPortScriptDNSKey.__text + '</td>';
}
else {
html += '<td>' + scannedPortScriptDNSKey.__text + '</td>';
}
}
html += '</tr>';
html += '</tbody>';
/* html += '<tfoot>';
html += '<tr>';
// Get a consistent table header as the order is imposible to predict
for (let indexB = 0; indexB < scannedPortScript.elem.length; indexB++) {
const scannedPortScriptDNSFooter = scannedPortScript.elem[indexB];
html += '<td style="font-weight: bold;">' + scannedPortScriptDNSFooter._key + '</td>';
}
html += '</tr>';
html += '</tfoot>'; */
html += '</table>';
}
html += '</td>';
break;
default:
html += '<td>' + scannedPortScript._output + '</td>';
break;
}
html += '</tr>';
}
html += '</tbody>';
html += '</table>';
html += '</div>';
html += '<div class="actions">';
html += '<div class="ui ok green inverted button">Close</div>';
// html += '<div class="ui cancel button">Cancel</div>';
html += '</div>';
html += '</div>';
}
}
}
else {
if (data.host.ports.port.script) {
html += '<div class="ui inverted fullscreen modal scripts ' + data.host.ports.port._portid + '">';
html += '<div class="header">Script executed on port (' + data.host.ports.port._portid + ')</div>';
html += '<div class="scrolling content">';
html += '<table class="ui celled inverted table">';
html += '<thead>';
html += '<tr>';
html += '<th>Id</th>';
html += '<th>Output</th>';
html += '</tr>';
html += '</thead>';
html += '<tbody>';
if (Array.isArray(data.host.ports.port.script)) {
for (let index = 0; index < data.host.ports.port.script.length; index++) {
const scannedPortScript = data.host.ports.port.script[index];
console.log(scannedPortScript);
html += '<tr>';
html += '<td>' + scannedPortScript._id + '</td>';
html += '<td>' + scannedPortScript._output + '</td>';
html += '</tr>';
}
}
else {
const scannedPortScript = data.host.ports.port.script;
console.log(scannedPortScript);
html += '<tr>';
html += '<td>' + scannedPortScript._id + '</td>';
html += '<td>' + scannedPortScript._output + '</td>';
html += '</tr>';
}
html += '</tbody>';
html += '</table>';
html += '</div>';
html += '<div class="actions">';
html += '<div class="ui ok green inverted button">Close</div>';
// html += '<div class="ui cancel button">Cancel</div>';
html += '</div>';
html += '</div>';
}
}
// End Container
html += '</div>';
// Clean previous container content
container.html('');
// Remove existing modals
container.remove('.ui.modal');
// Assign HTML code to container
container.html(html);
},
convertionHooks: function () {
if (Report.settings["fomantic-ui"] === true || Report.settings["semantic-ui"] === true) {
// Refresh accordions
$('.ui.accordion').accordion('refresh');
// Refresh disabled links
$('a[href="#!"]').on('click', function(event) {
event.preventDefault();
});
// Refresh modals
$('.ui.modal').modal('refresh');
// Refresh tooltips
$('.tooltipped').popup();
}
},
getStructure: function () {
console.group('Parser');
console.info('Config:', Report);
console.groupEnd();
},
toObject: function () {
return Report.converted;
},
toJSON: function () {
return JSON.stringify(Report.converted);
}
};
// Display state of the main oject
if (Report.settings.debug === true) {
Report.getStructure();
}
// Store to the global window object
window.Report = Report;
});