forked from xaitax/CVE-2024-6387_Check
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCVE-2024-6387_Check.py
229 lines (189 loc) · 6.93 KB
/
CVE-2024-6387_Check.py
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
#!/usr/bin/env python3
import socket
import argparse
import ipaddress
import threading
import time
from queue import Queue
from concurrent.futures import ThreadPoolExecutor
VERSION = "0.5"
BLUE = "\033[94m"
GREEN = "\033[92m"
RED = "\033[91m"
ORANGE = "\033[33m"
ENDC = "\033[0m"
progress_lock = threading.Lock()
progress_counter = 0
total_hosts = 0
def display_banner():
banner = rf"""
{BLUE}
_________ _________ ___ ___ .__
_______ ____ ___________ ____ / _____// _____// | \|__| ____ ____
\_ __ \_/ __ \ / ___\_ __ \_/ __ \ \_____ \ \_____ \/ ~ \ |/ _ \ / \
| | \/\ ___// /_/ > | \/\ ___/ / \/ \ Y / ( <_> ) | \
|__| \___ >___ /|__| \___ >_______ /_______ /\___|_ /|__|\____/|___| /
\/_____/ \/ \/ \/ \/ \/
CVE-2024-6387 Vulnerability Checker
v{VERSION} / Alex Hagenah / @xaitax / [email protected]
{ENDC}
"""
print(banner)
def get_ssh_sock(ip, port, timeout):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(timeout)
try:
sock.connect((ip, port))
return sock
except:
sock.close()
return None
def get_ssh_banner(sock):
try:
banner = sock.recv(1024).decode(errors='ignore').strip()
sock.close()
return banner
except Exception as e:
return str(e)
def check_vulnerability(ip, port, timeout, result_queue):
global progress_counter
sshsock = get_ssh_sock(ip, port, timeout)
if not sshsock:
result_queue.put((ip, port, 'closed', "Port closed"))
with progress_lock:
progress_counter += 1
return
banner = get_ssh_banner(sshsock)
if "SSH-2.0" not in banner:
result_queue.put(
(ip, port, 'failed', f"Failed to retrieve SSH banner: {banner}"))
with progress_lock:
progress_counter += 1
return
if "SSH-2.0-OpenSSH" not in banner:
result_queue.put((ip, port, 'unknown', f"(banner: {banner})"))
with progress_lock:
progress_counter += 1
return
vulnerable_versions = [
'SSH-2.0-OpenSSH_1',
'SSH-2.0-OpenSSH_2',
'SSH-2.0-OpenSSH_3',
'SSH-2.0-OpenSSH_4.0',
'SSH-2.0-OpenSSH_4.1',
'SSH-2.0-OpenSSH_4.2',
'SSH-2.0-OpenSSH_4.3',
'SSH-2.0-OpenSSH_4.4',
'SSH-2.0-OpenSSH_8.5',
'SSH-2.0-OpenSSH_8.6',
'SSH-2.0-OpenSSH_8.7',
'SSH-2.0-OpenSSH_8.8',
'SSH-2.0-OpenSSH_8.9',
'SSH-2.0-OpenSSH_9.0',
'SSH-2.0-OpenSSH_9.1',
'SSH-2.0-OpenSSH_9.2',
'SSH-2.0-OpenSSH_9.3',
'SSH-2.0-OpenSSH_9.4',
'SSH-2.0-OpenSSH_9.5',
'SSH-2.0-OpenSSH_9.6',
'SSH-2.0-OpenSSH_9.7'
]
excluded_versions = [
'SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.10',
'SSH-2.0-OpenSSH_9.3p1 Ubuntu-3ubuntu3.6',
'SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu13.3',
'SSH-2.0-OpenSSH_9.3p1 Ubuntu-1ubuntu3.6',
'SSH-2.0-OpenSSH_9.2p1 Debian-2+deb12u3',
'SSH-2.0-OpenSSH_8.4p1 Debian-5+deb11u3'
]
if any(version in banner for version in vulnerable_versions) and banner not in excluded_versions:
result_queue.put((ip, port, 'vulnerable', f"(running {banner})"))
else:
result_queue.put((ip, port, 'not_vulnerable', f"(running {banner})"))
with progress_lock:
progress_counter += 1
def process_ip_list(ip_list_file):
ips = []
try:
with open(ip_list_file, 'r') as file:
ips.extend(file.readlines())
except IOError:
print(f"❌ [-] Could not read file: {ip_list_file}")
return [ip.strip() for ip in ips]
def main():
global total_hosts
display_banner()
parser = argparse.ArgumentParser(
description="Check if servers are running a vulnerable version of OpenSSH (CVE-2024-6387).")
parser.add_argument(
"targets", nargs='*', help="IP addresses, domain names, file paths containing IP addresses, or CIDR network ranges.")
parser.add_argument("--port", type=int, default=22,
help="Port number to check (default: 22).")
parser.add_argument("-t", "--timeout", type=float, default=1.0,
help="Connection timeout in seconds (default: 1 second).")
parser.add_argument(
"-l", "--list", help="File containing a list of IP addresses to check.")
args = parser.parse_args()
targets = args.targets
port = args.port
timeout = args.timeout
ips = []
if args.list:
ips.extend(process_ip_list(args.list))
for target in targets:
try:
with open(target, 'r') as file:
ips.extend(file.readlines())
except IOError:
if '/' in target:
try:
network = ipaddress.ip_network(target, strict=False)
ips.extend([str(ip) for ip in network.hosts()])
except ValueError:
print(f"❌ [-] Invalid CIDR notation: {target}")
else:
ips.append(target)
result_queue = Queue()
total_hosts = len(ips)
max_workers = 100
with ThreadPoolExecutor(max_workers=max_workers) as executor:
futures = [executor.submit(check_vulnerability, ip.strip(
), port, timeout, result_queue) for ip in ips]
while any(future.running() for future in futures):
with progress_lock:
print(f"\rProgress: {
progress_counter}/{total_hosts} hosts scanned", end="")
time.sleep(1)
for future in futures:
future.result()
print(f"\rProgress: {progress_counter}/{total_hosts} hosts scanned")
total_scanned = len(ips)
closed_ports = 0
unknown = []
not_vulnerable = []
vulnerable = []
while not result_queue.empty():
ip, port, status, message = result_queue.get()
if status == 'closed':
closed_ports += 1
elif status == 'unknown':
unknown.append((ip, message))
elif status == 'vulnerable':
vulnerable.append((ip, message))
elif status == 'not_vulnerable':
not_vulnerable.append((ip, message))
else:
print(f"⚠️ [!] Server at {ip}:{port} is {message}")
print(f"\n🛡️ Servers not vulnerable: {len(not_vulnerable)}\n")
for ip, msg in not_vulnerable:
print(f" [+] Server at {GREEN}{ip}{ENDC} {msg}")
print(f"\n🚨 Servers likely vulnerable: {len(vulnerable)}\n")
for ip, msg in vulnerable:
print(f" [+] Server at {RED}{ip}{ENDC} {msg}")
print(f"\n⚠️ Servers with unknown SSH version: {len(unknown)}\n")
for ip, msg in unknown:
print(f" [+] Server at {ORANGE}{ip}{ENDC} {msg}")
print(f"\n🔒 Servers with port {port} closed: {closed_ports}")
print(f"\n📊 Total scanned targets: {total_scanned}\n")
if __name__ == "__main__":
main()