-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab.js
More file actions
1556 lines (1359 loc) · 72.4 KB
/
lab.js
File metadata and controls
1556 lines (1359 loc) · 72.4 KB
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
// lab.js - Alpha-Tech Advanced Hacking Lab Simulation
// Client-side educational tool for cybersecurity practice (SIMULATED)
// Author: Generated/merged for Alpha-Tech lab
// Notes: This file intentionally simulates behavior for training/demo purposes.
// Do NOT use these tools against systems without explicit authorization.
(function() {
'use strict';
// ---------- Global Variables ----------
let currentTool = 'terminal';
let commandHistory = [];
let historyIndex = 0;
let scanInterval;
let sniffInterval;
let crackInterval;
let bruteInterval;
let vulnScanInterval;
let traceInterval;
// DOM Elements (grab lazily on init)
let terminalInput;
let terminalOutput;
let consoleLog;
// ---------- Utility Functions ----------
function escapeHtml(s) {
if (!s) return '';
return s.replace(/[&<>"']/g, m => ({
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
}[m]));
}
function addLogEntry(message, type = 'info') {
if (!consoleLog) return;
const now = new Date();
const timeString = `[${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}:${now.getSeconds().toString().padStart(2, '0')}]`;
const logEntry = document.createElement('div');
logEntry.className = 'log-entry';
logEntry.innerHTML = `
<span class="log-time">${timeString}</span>
<span class="log-${type}">${escapeHtml(message)}</span>
`;
consoleLog.appendChild(logEntry);
consoleLog.scrollTop = consoleLog.scrollHeight;
}
function copyToClipboard(elementId) {
// Copies the contents of a textarea inside result container elementId
const container = document.getElementById(elementId);
if (!container) return;
const textarea = container.querySelector('textarea');
if (!textarea) return;
textarea.select();
try {
document.execCommand('copy');
addLogEntry('Copied to clipboard', 'success');
// Friendly UI feedback
const prev = textarea.style.border;
textarea.style.border = '2px solid #00cc99';
setTimeout(() => textarea.style.border = prev, 600);
} catch (e) {
addLogEntry('Copy to clipboard failed', 'error');
}
}
// Small helper to load an image from an <input type="file">
function loadImageFromFile(file) {
return new Promise((res, rej) => {
const img = new Image();
const reader = new FileReader();
reader.onload = e => {
img.onload = () => res(img);
img.onerror = rej;
img.src = e.target.result;
};
reader.onerror = rej;
reader.readAsDataURL(file);
});
}
// ---------- Initialization Functions ----------
function initTabs() {
document.querySelectorAll('.tabs').forEach(tabSystem => {
const tabs = tabSystem.querySelectorAll('.tab');
// derive tabId by parent element id (e.g., scanner-window -> scanner)
const tabId = tabSystem.parentElement.id.replace('-window', '');
tabs.forEach(tab => {
tab.addEventListener('click', function() {
// Remove active class from all tabs in this system
tabSystem.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
// Add active class to clicked tab
this.classList.add('active');
// Hide all tab contents inside this tool window
document.querySelectorAll(`#${tabId}-window .tab-content`).forEach(content => {
content.classList.remove('active');
});
// Show selected tab content
const tabName = this.getAttribute('data-tab');
const content = document.getElementById(tabName);
if (content) content.classList.add('active');
});
});
});
}
function initToolSwitching() {
const toolButtons = document.querySelectorAll('.tool-btn');
const toolWindows = document.querySelectorAll('.tool-window');
toolButtons.forEach(button => {
button.addEventListener('click', function() {
// Remove active class from all buttons and windows
toolButtons.forEach(btn => btn.classList.remove('active'));
toolWindows.forEach(w => w.classList.remove('active'));
// Add active class to clicked button
this.classList.add('active');
currentTool = this.getAttribute('data-tool');
// Show corresponding window
const win = document.getElementById(`${currentTool}-window`);
if (win) win.classList.add('active');
// Focus on terminal if switching to it
if (currentTool === 'terminal' && terminalInput) {
terminalInput.focus();
}
// Add log entry
addLogEntry(`Switched to ${currentTool} tool`, 'info');
});
});
}
// ---------- Terminal Functions ----------
function processCommand(command) {
let output = '';
switch (command.toLowerCase()) {
case 'help':
output = `Available commands:\n
- help: Show this help message
- scan: Start network scan
- crack: Launch password cracker
- vuln: Run vulnerability scan
- sqli: Test for SQL injection
- xss: Test for XSS
- trace: Run traceroute
- firewall: Test firewall
- exploits: Browse exploit database
- clear: Clear terminal
- whoami: Show current user
- ifconfig: Show network interfaces
- menu: Show available tools`;
break;
case 'menu':
output = `Available tools:\n
- Network Scanner
- Packet Sniffer
- Password Cracker
- Vulnerability Scanner
- Firewall Tester
- SQL Injection Tester
- XSS Tester
- Exploit Database
- Traceroute
Type 'help' for command reference`;
break;
case 'scan':
output = `Starting network scan... (simulated)`;
const scannerBtn = document.querySelector('[data-tool="scanner"]');
if (scannerBtn) scannerBtn.click();
startNetworkScan();
break;
case 'crack':
output = `Launching password cracker...`;
const crackerBtn = document.querySelector('[data-tool="cracker"]');
if (crackerBtn) crackerBtn.click();
break;
case 'vuln':
output = `Starting vulnerability scan...`;
const vulnBtn = document.querySelector('[data-tool="vulnscan"]');
if (vulnBtn) vulnBtn.click();
startVulnerabilityScan();
break;
case 'sqli':
output = `Launching SQL injection tester...`;
const sqliBtn = document.querySelector('[data-tool="sqli"]');
if (sqliBtn) sqliBtn.click();
break;
case 'xss':
output = `Launching XSS tester...`;
const xssBtn = document.querySelector('[data-tool="xss"]');
if (xssBtn) xssBtn.click();
break;
case 'trace':
output = `Starting traceroute...`;
const traceBtn = document.querySelector('[data-tool="traceroute"]');
if (traceBtn) traceBtn.click();
startTraceroute();
break;
case 'firewall':
output = `Testing firewall...`;
const fwBtn = document.querySelector('[data-tool="firewall"]');
if (fwBtn) fwBtn.click();
break;
case 'exploits':
output = `Browsing exploit database...`;
const expBtn = document.querySelector('[data-tool="exploit"]');
if (expBtn) expBtn.click();
break;
case 'clear':
if (terminalOutput) terminalOutput.innerHTML = '';
return;
case 'whoami':
output = 'root';
break;
case 'ifconfig':
output = `eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255
ether 08:00:27:ab:cd:ef txqueuelen 1000 (Ethernet)
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0`;
break;
case '':
return;
default:
output = `Command not found: ${escapeHtml(command)}\nType 'help' for available commands`;
}
if (terminalOutput) {
// preserve newlines
terminalOutput.innerHTML += `<div style="white-space:pre-wrap">${escapeHtml(output)}</div><br>`;
terminalOutput.scrollTop = terminalOutput.scrollHeight;
}
}
function initTerminal() {
if (!terminalInput) return;
terminalInput.addEventListener('keydown', function(e) {
if (e.key === 'ArrowUp') {
// Navigate command history up
if (historyIndex > 0) {
historyIndex--;
this.value = commandHistory[historyIndex];
}
e.preventDefault();
} else if (e.key === 'ArrowDown') {
// Navigate command history down
if (historyIndex < commandHistory.length - 1) {
historyIndex++;
this.value = commandHistory[historyIndex];
} else {
historyIndex = commandHistory.length;
this.value = '';
}
e.preventDefault();
} else if (e.key === 'Enter') {
const command = this.value.trim();
this.value = '';
if (command) {
// Add to command history
commandHistory.push(command);
historyIndex = commandHistory.length;
// Add command to output
if (terminalOutput) {
terminalOutput.innerHTML += `<span class="terminal-prompt">root@alpha-lab:~#</span> ${escapeHtml(command)}<br>`;
}
// Process command
processCommand(command);
// Scroll to bottom
const termEl = document.getElementById('terminal');
if (termEl) termEl.scrollTop = termEl.scrollHeight;
}
}
});
}
// ---------- Network Scanner Functions ----------
function startNetworkScan() {
const scanRangeEl = document.getElementById('scan-range');
const scanRange = (scanRangeEl && scanRangeEl.value) ? scanRangeEl.value : '192.168.1.0/24';
const scanResults = document.getElementById('scan-results');
if (!scanResults) return;
scanResults.innerHTML = `<div class="log-info">Scanning network ${escapeHtml(scanRange)}... (This may take a few seconds)</div>`;
addLogEntry(`Starting network scan on ${scanRange}`, 'info');
// Simulate network scan
let progress = 0;
scanInterval = setInterval(() => {
progress += 10;
if (progress < 100) {
scanResults.innerHTML = `<div class="log-info">Scanning network ${escapeHtml(scanRange)}... ${progress}% complete</div>`;
} else {
clearInterval(scanInterval);
const devices = [
{ ip: '192.168.1.1', mac: '00:1A:2B:3C:4D:5E', hostname: 'router', os: 'Linux' },
{ ip: '192.168.1.2', mac: '00:1A:2B:3C:4D:5F', hostname: 'server', os: 'Ubuntu 20.04' },
{ ip: '192.168.1.100', mac: '08:00:27:AB:CD:EF', hostname: 'workstation', os: 'Windows 10' },
{ ip: '192.168.1.101', mac: '08:00:27:GH:IJ:KL', hostname: 'printer', os: 'Embedded' }
];
scanResults.innerHTML = '';
devices.forEach(device => {
const deviceElement = document.createElement('div');
deviceElement.className = 'device-item';
deviceElement.innerHTML = `
<div>
<strong>${escapeHtml(device.hostname)}</strong>
<div class="device-ip">IP: ${escapeHtml(device.ip)}</div>
<div class="device-mac">MAC: ${escapeHtml(device.mac)}</div>
</div>
<div>OS: ${escapeHtml(device.os)}</div>
`;
scanResults.appendChild(deviceElement);
});
addLogEntry('Network scan completed. Found 4 devices.', 'success');
}
}, 300);
}
function stopNetworkScan() {
clearInterval(scanInterval);
const scanResults = document.getElementById('scan-results');
if (scanResults) scanResults.innerHTML += '<div class="log-warning">Scan stopped by user</div>';
addLogEntry('Network scan stopped', 'warning');
}
function startPortScan() {
const targetEl = document.getElementById('scan-target');
const target = (targetEl && targetEl.value) ? targetEl.value : '192.168.1.1';
const scanTypeEl = document.getElementById('scan-type');
const scanType = (scanTypeEl && scanTypeEl.value) ? scanTypeEl.value : 'quick';
let ports = [];
if (scanType === 'quick') {
ports = [21, 22, 23, 25, 53, 80, 110, 139, 143, 443, 445, 3389];
} else if (scanType === 'full') {
// Simulate top ports for demo
ports = [21, 22, 23, 25, 53, 80, 110, 139, 143, 443, 445, 3389, 8080, 8443];
} else if (scanType === 'custom') {
const customPorts = document.getElementById('custom-ports').value || '';
ports = customPorts.split(',').map(p => parseInt(p.trim())).filter(p => !isNaN(p));
}
const portResults = document.getElementById('port-scan-results');
if (!portResults) return;
portResults.innerHTML = `<div class="log-info">Scanning ports on ${escapeHtml(target)}...</div>`;
addLogEntry(`Starting port scan on ${target}`, 'info');
let scannedPorts = 0;
const totalPorts = ports.length;
let openPorts = [];
const portScanInterval = setInterval(() => {
if (scannedPorts < totalPorts) {
const port = ports[scannedPorts];
const isOpen = Math.random() > 0.7; // 30% chance port is "open"
if (isOpen) {
let service = '';
switch (port) {
case 22:
service = 'SSH';
break;
case 80:
service = 'HTTP';
break;
case 443:
service = 'HTTPS';
break;
case 3389:
service = 'RDP';
break;
default:
service = 'Unknown';
}
openPorts.push({ port, service });
portResults.innerHTML += `<div class="log-success">Port ${port}/tcp open - ${service}</div>`;
} else {
portResults.innerHTML += `<div class="log-info">Port ${port}/tcp closed</div>`;
}
scannedPorts++;
const progress = Math.floor((scannedPorts / totalPorts) * 100);
const portTab = document.querySelector('#port-scan .tab');
if (portTab) portTab.textContent = `Port Scan (${progress}%)`;
} else {
clearInterval(portScanInterval);
portResults.innerHTML += `<div class="log-info">Scan completed. ${openPorts.length} ports open.</div>`;
const portTab = document.querySelector('#port-scan .tab');
if (portTab) portTab.textContent = 'Port Scan';
addLogEntry(`Port scan completed on ${target}. Found ${openPorts.length} open ports.`, 'success');
}
}, 500);
}
// ---------- Packet Sniffer Functions ----------
function startPacketSniffing() {
const ifaceEl = document.getElementById('sniff-interface');
const iface = (ifaceEl && ifaceEl.value) ? ifaceEl.value : 'eth0';
const packetList = document.getElementById('packet-list');
if (!packetList) return;
packetList.innerHTML = '<div class="log-info">Starting packet capture on ' + escapeHtml(iface) + '...</div>';
addLogEntry(`Starting packet capture on ${iface}`, 'info');
const packetTypes = [
{ type: 'TCP', src: '192.168.1.100:51234', dst: '142.250.190.46:443', info: 'HTTPS' },
{ type: 'DNS', src: '192.168.1.100:53', dst: '8.8.8.8:53', info: 'Standard query A google.com' },
{ type: 'ARP', src: '192.168.1.100', dst: '192.168.1.1', info: 'Who has 192.168.1.1? Tell 192.168.1.100' },
{ type: 'ICMP', src: '192.168.1.100', dst: '8.8.8.8', info: 'Echo (ping) request' },
{ type: 'HTTP', src: '192.168.1.100:51235', dst: '104.16.85.20:80', info: 'GET / HTTP/1.1' }
];
let packetCount = 0;
sniffInterval = setInterval(() => {
packetCount++;
const packetType = packetTypes[Math.floor(Math.random() * packetTypes.length)];
const packetElement = document.createElement('div');
packetElement.className = 'packet';
packetElement.innerHTML = `
<div class="packet-header">${escapeHtml(packetType.type)} Packet #${packetCount}</div>
<div>From: ${escapeHtml(packetType.src)} → To: ${escapeHtml(packetType.dst)}</div>
<div>${escapeHtml(packetType.info)}</div>
`;
packetList.prepend(packetElement);
if (packetCount % 10 === 0) {
addLogEntry(`Captured ${packetCount} packets on ${iface}`, 'info');
}
}, 800);
}
function stopPacketSniffing() {
clearInterval(sniffInterval);
const packetList = document.getElementById('packet-list');
if (packetList) packetList.innerHTML += '<div class="log-warning">Packet capture stopped</div>';
addLogEntry('Packet capture stopped', 'warning');
}
function clearPackets() {
const packetList = document.getElementById('packet-list');
if (packetList) packetList.innerHTML = '';
addLogEntry('Cleared packet list', 'info');
}
function analyzeTraffic() {
const analysisDiv = document.getElementById('traffic-analysis');
if (!analysisDiv) return;
analysisDiv.innerHTML = '<div class="log-info">Analyzing captured traffic...</div>';
setTimeout(() => {
analysisDiv.innerHTML = `
<div class="log-success">Traffic Analysis Results:</div>
<div>Total packets: 42</div>
<div>Protocol distribution:</div>
<div>- TCP: 28 (66.7%)</div>
<div>- UDP: 8 (19.0%)</div>
<div>- ICMP: 4 (9.5%)</div>
<div>- Other: 2 (4.8%)</div>
<div class="log-warning">Potential issues detected:</div>
<div>- Unencrypted HTTP traffic found</div>
<div>- Suspicious port scanning activity detected</div>
`;
addLogEntry('Traffic analysis completed', 'success');
}, 1500);
}
// ---------- Password Cracker Functions ----------
function startHashCracking() {
const hashInputEl = document.getElementById('hash-input');
const hashInput = (hashInputEl && hashInputEl.value) ? hashInputEl.value.trim() : '';
const hashType = document.getElementById('hash-type').value;
const attackMode = document.getElementById('attack-mode').value;
const crackResults = document.getElementById('crack-results');
if (!crackResults) return;
if (!hashInput) {
crackResults.innerHTML = '<div class="log-error">Please enter a hash to crack</div>';
addLogEntry('Hash cracking failed - no hash provided', 'error');
return;
}
crackResults.innerHTML = '<div class="log-info">Attempting to crack hash using ' + escapeHtml(attackMode) + ' attack...</div>';
addLogEntry(`Starting ${attackMode} attack on ${hashType} hash`, 'info');
const commonPasswords = {
'5f4dcc3b5aa765d61d8327deb882cf99': 'password',
'7c6a180b36896a0a8c02787eeafb0e4c': 'password1',
'6cb75f652a9b52798eb6cf2201057c73': 'password123',
'd8578edf8458ce06fbc5bb76a58c5ca4': 'qwerty',
'5a105e8b9d40e1329780d62ea2265d8a': 'test',
'b1b3773a05c0ed0176787a4f1574ff0075f7521e': 'letmein',
'7110eda4d09e062aa5e4a390b0a572ac0d2c0220': '1234',
'b0399d2029f64d445bd131ffaa399a42d2f8e7dc': 'admin'
};
let attempts = 0;
crackInterval = setInterval(() => {
attempts++;
crackResults.innerHTML = `<div class="log-info">Attempt ${attempts}: Testing password candidate...</div>`;
if (attempts % 10 === 0) {
addLogEntry(`Hash cracking in progress - attempt ${attempts}`, 'info');
}
if (commonPasswords[hashInput.toLowerCase()]) {
clearInterval(crackInterval);
const password = commonPasswords[hashInput.toLowerCase()];
crackResults.innerHTML = `
<div class="log-success">Hash cracked successfully after ${attempts} attempts!</div>
<div>Hash: ${escapeHtml(hashInput)}</div>
<div>Type: ${escapeHtml(hashType.toUpperCase())}</div>
<div class="log-warning">Password: ${escapeHtml(password)}</div>
<div class="log-info">This password is extremely weak and commonly used</div>
<button class="btn" id="show-security-tips">
<i class="fas fa-shield-alt"></i> View Security Recommendations
</button>
`;
addLogEntry(`Successfully cracked ${hashType} hash: ${password}`, 'success');
// attach security tips handler
document.getElementById('show-security-tips').addEventListener('click', showPasswordSecurityTips);
} else if (attempts > 30) {
clearInterval(crackInterval);
crackResults.innerHTML = `
<div class="log-error">Failed to crack hash after ${attempts} attempts</div>
<div>Hash: ${escapeHtml(hashInput)}</div>
<div>Type: ${escapeHtml(hashType.toUpperCase())}</div>
<div>This hash is not in our dictionary database</div>
<div class="log-info">The password may be stronger or use a different algorithm</div>
`;
addLogEntry(`Failed to crack ${hashType} hash after ${attempts} attempts`, 'warning');
}
}, 200);
}
function stopHashCracking() {
clearInterval(crackInterval);
const crackResults = document.getElementById('crack-results');
if (crackResults) crackResults.innerHTML += '<div class="log-warning">Hash cracking stopped by user</div>';
addLogEntry('Hash cracking stopped', 'warning');
}
function showPasswordSecurityTips() {
const tips = [
'Use a password manager to generate and store unique passwords.',
'Use long passphrases (12+ characters) with mixed character sets.',
'Enable multi-factor authentication (MFA) wherever possible.',
'Salt and slow-hash user passwords on the server using bcrypt/argon2.',
'Monitor for reused passwords and exposed credentials.'
].join('\n\n');
alert('Security Recommendations:\n\n' + tips);
}
function generateWordlist() {
const baseWord = document.getElementById('base-word').value.trim() || 'password';
// rules are not interpreted in this simulation beyond being present
const wordlistOutput = document.getElementById('wordlist-output');
if (!wordlistOutput) return;
wordlistOutput.innerHTML = '<div class="log-info">Generating wordlist based on rules...</div>';
addLogEntry('Generating wordlist', 'info');
setTimeout(() => {
const variations = [
baseWord,
baseWord + '123',
baseWord + '!',
baseWord + '2020',
baseWord + '2021',
baseWord.charAt(0).toUpperCase() + baseWord.slice(1),
baseWord + '@',
baseWord + '1',
baseWord + '2',
baseWord + '3',
baseWord + '123!',
baseWord + '123@',
baseWord + '123#',
baseWord.toUpperCase(),
baseWord.split('').reverse().join(''), // Reverse the word
baseWord + baseWord, // Duplicate
baseWord + 'abc',
baseWord + 'xyz'
];
const uniqueVariations = [...new Set(variations)];
wordlistOutput.innerHTML = `
<div class="log-success">Generated wordlist with ${uniqueVariations.length} unique entries:</div>
<div style="max-height: 300px; overflow-y: auto; border: 1px solid #444; padding: 10px; margin-top: 10px;">
`;
uniqueVariations.forEach(word => {
wordlistOutput.innerHTML += `<div>${escapeHtml(word)}</div>`;
});
wordlistOutput.innerHTML += `</div>`;
addLogEntry(`Generated wordlist with ${uniqueVariations.length} variations`, 'success');
}, 1000);
}
function startBruteForce() {
const charset = document.getElementById('charset').value || 'abcdefghijklmnopqrstuvwxyz';
const minLength = parseInt(document.getElementById('min-length').value) || 4;
const maxLength = parseInt(document.getElementById('max-length').value) || 6;
const bruteResults = document.getElementById('brute-results');
if (!bruteResults) return;
bruteResults.innerHTML = '<div class="log-info">Starting brute force attack...</div>';
addLogEntry(`Starting brute force attack with charset: ${charset}`, 'info');
let attempts = 0;
bruteInterval = setInterval(() => {
attempts++;
// Generate a random attempt for simulation
let currentAttempt = '';
const currentLength = Math.floor(Math.random() * (maxLength - minLength + 1)) + minLength;
for (let i = 0; i < currentLength; i++) {
currentAttempt += charset.charAt(Math.floor(Math.random() * charset.length));
}
bruteResults.innerHTML = `<div class="log-info">Attempt ${attempts}: Testing "${escapeHtml(currentAttempt)}"</div>`;
if (attempts % 10 === 0) {
addLogEntry(`Brute force in progress - attempt ${attempts}`, 'info');
}
if (charset.includes('t') && charset.includes('e') && charset.includes('s') &&
currentAttempt === 'test' && attempts > 5) {
clearInterval(bruteInterval);
bruteResults.innerHTML += `
<div class="log-success">Password found after ${attempts} attempts!</div>
<div class="log-warning">Password: test</div>
<div class="log-info">This is a very weak password</div>
`;
addLogEntry('Brute force attack successful! Password: test', 'success');
} else if (attempts > 100) {
clearInterval(bruteInterval);
bruteResults.innerHTML += `
<div class="log-error">Stopped after ${attempts} attempts</div>
<div>No password found with current parameters</div>
<div class="log-info">This suggests the password may be longer or uses characters not in the selected charset</div>
`;
addLogEntry(`Brute force stopped after ${attempts} attempts`, 'warning');
}
}, 300);
}
function stopBruteForce() {
clearInterval(bruteInterval);
const bruteResults = document.getElementById('brute-results');
if (bruteResults) bruteResults.innerHTML += '<div class="log-warning">Brute force attack stopped by user</div>';
addLogEntry('Brute force attack stopped', 'warning');
}
// ---------- Vulnerability Scanner Functions ----------
function startVulnerabilityScan() {
const target = document.getElementById('vuln-target').value || 'http://testphp.vulnweb.com';
const scanProfile = document.getElementById('vuln-scan-profile').value;
const vulnResults = document.getElementById('vuln-scan-results');
if (!vulnResults) return;
vulnResults.innerHTML = `<div class="log-info">Starting ${escapeHtml(scanProfile)} scan on ${escapeHtml(target)}...</div>`;
addLogEntry(`Starting ${scanProfile} vulnerability scan on ${target}`, 'info');
let progress = 0;
vulnScanInterval = setInterval(() => {
progress += 5;
if (progress < 100) {
vulnResults.innerHTML = `<div class="log-info">Scanning ${escapeHtml(target)}... ${progress}% complete</div>`;
} else {
clearInterval(vulnScanInterval);
const vulnerabilities = [
{ title: 'SQL Injection Vulnerability', severity: 'High', description: 'The application appears vulnerable to SQL injection attacks in the login form.', solution: 'Use prepared statements and parameterized queries.', cvss: '9.8', reference: 'CWE-89' },
{ title: 'Cross-Site Scripting (XSS)', severity: 'Medium', description: 'Reflected XSS vulnerability found in search parameter.', solution: 'Implement proper output encoding and input validation.', cvss: '6.1', reference: 'CWE-79' },
{ title: 'Outdated Software', severity: 'Medium', description: 'Apache 2.2.15 detected (End of Life). Multiple known vulnerabilities.', solution: 'Upgrade to a supported version of Apache.', cvss: '5.9', reference: 'CVE-2017-3169' },
{ title: 'Missing Security Headers', severity: 'Low', description: 'Missing X-XSS-Protection and Content-Security-Policy headers.', solution: 'Implement proper security headers in web server configuration.', cvss: '3.7', reference: 'OWASP-ASVS' },
{ title: 'Information Disclosure', severity: 'Low', description: 'Server version information disclosed in HTTP headers.', solution: 'Configure server to not disclose version information.', cvss: '3.5', reference: 'CWE-200' }
];
vulnResults.innerHTML = `
<div class="log-success">Scan completed. Found ${vulnerabilities.length} vulnerabilities.</div>
<div class="log-info">Scan duration: ~2 minutes (simulated)</div>
<div class="log-warning">Vulnerabilities found:</div>
`;
vulnerabilities.forEach(vuln => {
const vulnElement = document.createElement('div');
vulnElement.className = 'vulnerability-item';
vulnElement.innerHTML = `
<div class="vuln-title">[${escapeHtml(vuln.severity)}] ${escapeHtml(vuln.title)}</div>
<div class="vuln-desc">${escapeHtml(vuln.description)}</div>
<div><strong>CVSS Score:</strong> ${escapeHtml(vuln.cvss)}/10</div>
<div><strong>Reference:</strong> ${escapeHtml(vuln.reference)}</div>
<div><strong>Solution:</strong> ${escapeHtml(vuln.solution)}</div>
`;
vulnResults.appendChild(vulnElement);
});
vulnResults.innerHTML += `
<div class="log-info">Remediation Summary:</div>
<div class="result-box">
<strong>Critical Actions:</strong><br>
- Fix SQL injection vulnerability immediately<br>
- Implement XSS protection<br>
- Update Apache server<br><br>
<strong>Recommended Actions:</strong><br>
- Add security headers<br>
- Disable server version disclosure<br>
- Implement WAF protection<br>
- Regular security scanning
</div>
<button class="btn" id="export-vuln-report">
<i class="fas fa-file-pdf"></i> Export Vulnerability Report
</button>
`;
// Add export functionality (simulated)
const exportBtn = document.getElementById('export-vuln-report');
if (exportBtn) {
exportBtn.addEventListener('click', function() {
addLogEntry('Exported vulnerability report', 'success');
alert('Vulnerability report exported successfully (simulated)\n\nFile: vulnerability_report.pdf');
});
}
addLogEntry(`Vulnerability scan completed. Found ${vulnerabilities.length} issues.`, 'success');
}
}, 300);
}
function stopVulnerabilityScan() {
clearInterval(vulnScanInterval);
const vulnResults = document.getElementById('vuln-scan-results');
if (vulnResults) vulnResults.innerHTML += '<div class="log-warning">Vulnerability scan stopped by user</div>';
addLogEntry('Vulnerability scan stopped', 'warning');
}
// ---------- SQL Injection Functions (SIMULATED) ----------
function testSQLInjection() {
const url = document.getElementById('sqli-url').value || 'http://testphp.vulnweb.com/artists.php?artist=1';
const technique = document.getElementById('sqli-technique').value;
const sqliResults = document.getElementById('sqli-results');
if (!sqliResults) return;
sqliResults.innerHTML = '<div class="log-info">Testing for SQL injection using ' + escapeHtml(technique) + ' technique...</div>';
addLogEntry(`Testing for SQL injection at ${url} using ${technique} technique`, 'info');
setTimeout(() => {
let isVulnerable = false;
let payload = '';
switch (technique) {
case 'error-based':
isVulnerable = true;
payload = "artist=1'";
break;
case 'boolean':
isVulnerable = true;
payload = "artist=1 AND 1=1";
break;
case 'time':
isVulnerable = false;
payload = "artist=1; WAITFOR DELAY '0:0:5'--";
break;
case 'union':
isVulnerable = true;
payload = "artist=1 UNION SELECT 1,2,3,4,5,6,7,8--";
break;
}
if (isVulnerable) {
sqliResults.innerHTML = `
<div class="log-success">Vulnerability found (simulated)!</div>
<div>URL: ${escapeHtml(url)}</div>
<div>Technique: ${escapeHtml(technique)}</div>
<div class="log-warning">Successful payload: ${escapeHtml(payload)}</div>
<div>The application appears vulnerable to ${escapeHtml(technique)} SQL injection (simulated).</div>
`;
addLogEntry(`SQL injection vulnerability found using ${technique} technique`, 'success');
} else {
sqliResults.innerHTML = `
<div class="log-error">No vulnerability detected</div>
<div>URL: ${escapeHtml(url)}</div>
<div>Technique: ${escapeHtml(technique)}</div>
<div>The application does not appear vulnerable to ${escapeHtml(technique)} SQL injection (simulated).</div>
`;
addLogEntry(`No SQL injection vulnerability found using ${technique} technique`, 'warning');
}
}, 1500);
}
function exploitSQLInjection() {
const url = document.getElementById('sqli-url').value || 'http://testphp.vulnweb.com/artists.php?artist=1';
const sqliResults = document.getElementById('sqli-results');
if (!sqliResults) return;
sqliResults.innerHTML = '<div class="log-info">Attempting to exploit SQL injection (simulated)...</div>';
addLogEntry(`Attempting to exploit SQL injection at ${url}`, 'info');
setTimeout(() => {
sqliResults.innerHTML = `
<div class="log-success">Exploit successful (simulated)!</div>
<div>Database type: MySQL</div>
<div>Current user: root@localhost</div>
<div>Current database: acuart</div>
<div class="log-warning">Use the 'Dump Data' button to extract database contents (simulated)</div>
`;
addLogEntry('SQL injection exploit successful (simulated)', 'success');
}, 2000);
}
function dumpDatabase() {
const sqliResults = document.getElementById('sqli-results');
if (!sqliResults) return;
sqliResults.innerHTML = '<div class="log-info">Dumping database contents (simulated)...</div>';
addLogEntry('Starting database dump (simulated)', 'info');
setTimeout(() => {
sqliResults.innerHTML = `
<div class="log-success">Database dump complete (simulated)</div>
<div>Tables found:</div>
<div>- artists</div>
<div>- carts</div>
<div>- categories</div>
<div>- featured</div>
<div>- guestbook</div>
<div>- pictures</div>
<div>- users</div>
<div class="log-warning">Sample data from users table (simulated):</div>
<table class="table">
<tr><th>id</th><th>uname</th><th>pass</th><th>email</th><th>address</th><th>country</th></tr>
<tr><td>1</td><td>test</td><td>test</td><td>test@test.com</td><td>123 Test St</td><td>US</td></tr>
<tr><td>2</td><td>admin</td><td>5f4dcc3b5aa765d61d8327deb882cf99</td><td>admin@test.com</td><td>456 Admin Ave</td><td>UK</td></tr>
<tr><td>3</td><td>john</td><td>7c6a180b36896a0a8c02787eeafb0e4c</td><td>john@example.com</td><td>789 User Rd</td><td>CA</td></tr>
<tr><td>4</td><td>jane</td><td>6cb75f652a9b52798eb6cf2201057c73</td><td>jane@example.com</td><td>321 Customer Ln</td><td>AU</td></tr>
</table>
<div class="log-info">Total records: 4 (simulated)</div>
<div class="log-warning">Sensitive data detected: Password hashes should be properly hashed with salt</div>
<button class="btn" id="export-data">
<i class="fas fa-download"></i> Export Data as CSV
</button>
`;
addLogEntry('Database dump completed (simulated)', 'success');
// Add export functionality (simulated)
const exportBtn = document.getElementById('export-data');
if (exportBtn) {
exportBtn.addEventListener('click', function() {
addLogEntry('Exported database data as CSV (simulated)', 'success');
alert('Data exported successfully (simulated)\n\nIn a real environment, this would download a CSV file containing the database contents.');
});
}
}, 2500);
}
// ---------- XSS Tester (SIMULATED) ----------
function testXSS() {
const url = document.getElementById('xss-url').value || 'http://testphp.vulnweb.com/search.php?test=query';
const payloads = (document.getElementById('xss-payloads').value || '').split('\n').filter(p => p.trim());
const xssResults = document.getElementById('xss-results');
if (!xssResults) return;
xssResults.innerHTML = '<div class="log-info">Testing for XSS vulnerabilities (simulated)...</div>';
addLogEntry(`Testing for XSS at ${url} with ${payloads.length} payloads`, 'info');
setTimeout(() => {
let vulnerablePayloads = [];
payloads.forEach(payload => {
if (payload.includes('script') || payload.includes('onerror') || payload.includes('onload')) {
vulnerablePayloads.push(payload);
}
});
if (vulnerablePayloads.length > 0) {
xssResults.innerHTML = `
<div class="log-success">XSS vulnerabilities found (simulated)!</div>
<div>URL: ${escapeHtml(url)}</div>
<div>Vulnerable payloads:</div>
`;
vulnerablePayloads.forEach(payload => {
xssResults.innerHTML += `<div class="log-warning">- ${escapeHtml(payload)}</div>`;
});
xssResults.innerHTML += `<div>The application appears vulnerable to XSS attacks (simulated).</div>`;
addLogEntry(`Found ${vulnerablePayloads.length} XSS vulnerabilities`, 'success');
} else {
xssResults.innerHTML = `
<div class="log-error">No XSS vulnerabilities detected</div>
<div>URL: ${escapeHtml(url)}</div>
<div>The application does not appear vulnerable to the tested XSS payloads (simulated).</div>
`;
addLogEntry('No XSS vulnerabilities found', 'warning');
}
}, 2000);
}
function scanDOM() {
const xssResults = document.getElementById('xss-results');
if (!xssResults) return;
xssResults.innerHTML = '<div class="log-info">Analyzing DOM for potential XSS vectors (simulated)...</div>';
addLogEntry('Starting DOM analysis for XSS', 'info');
setTimeout(() => {
xssResults.innerHTML = `
<div class="log-success">DOM analysis complete</div>
<div>Potential XSS vectors found:</div>
<div class="log-warning">- document.write() with user input</div>
<div class="log-warning">- innerHTML with user input</div>
<div class="log-warning">- jQuery.html() with user input</div>
<div>Recommendations:</div>
<div>- Use textContent instead of innerHTML</div>
<div>- Implement proper output encoding</div>
<div>- Use Content Security Policy (CSP)</div>
`;
addLogEntry('DOM analysis completed', 'success');
}, 1800);
}
// ---------- Traceroute (SIMULATED) ----------
function startTraceroute() {
const target = document.getElementById('trace-target').value || 'google.com';
const traceResults = document.getElementById('trace-results');
if (!traceResults) return;
traceResults.innerHTML = '<div class="log-info">Tracing route to ' + escapeHtml(target) + '...</div>';
addLogEntry(`Starting traceroute to ${target}`, 'info');
const hops = [
{ ip: '192.168.1.1', time1: '1.2 ms', time2: '1.5 ms', time3: '1.3 ms', host: 'router.home' },
{ ip: '10.20.30.1', time1: '12.5 ms', time2: '11.8 ms', time3: '12.1 ms', host: 'gateway.isp.net' },
{ ip: '203.0.113.45', time1: '15.3 ms', time2: '14.9 ms', time3: '15.7 ms', host: 'core-router.isp.net' },
{ ip: '198.51.100.22', time1: '20.1 ms', time2: '19.8 ms', time3: '20.5 ms', host: 'border-router.google.com' },
{ ip: '172.217.16.14', time1: '22.5 ms', time2: '21.9 ms', time3: '22.3 ms', host: 'google.com' }
];
let hopIndex = 0;
traceInterval = setInterval(() => {
if (hopIndex < hops.length) {
const hop = hops[hopIndex];
const hopElement = document.createElement('div');
hopElement.className = 'hop-item';
hopElement.innerHTML = `
<span class="hop-number">${hopIndex + 1}</span>
<span>${escapeHtml(hop.host)} [${escapeHtml(hop.ip)}]</span>
<span>${escapeHtml(hop.time1)} ${escapeHtml(hop.time2)} ${escapeHtml(hop.time3)}</span>
`;
traceResults.appendChild(hopElement);
hopIndex++;
} else {
clearInterval(traceInterval);
traceResults.innerHTML += '<div class="log-success">Trace complete.</div>';
addLogEntry(`Traceroute to ${target} completed`, 'success');
}
}, 1000);
}
function stopTraceroute() {