-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCVE_2021_21985.py
121 lines (99 loc) · 3.76 KB
/
CVE_2021_21985.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" This script check the CVE-2021-21985 vulnerability and patch. """
###################
# This script check the CVE-2021-21985 vulnerability and patch.
# Copyright (C) 2021 Maurice Lambert
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
###################
print(
"""
CVE_2021_21985 Copyright (C) 2021 Maurice Lambert
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.
"""
)
from ssl import SSLContext, create_default_context, CERT_NONE
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen
from json.decoder import JSONDecodeError
from json import loads, dumps
from sys import argv, exit
def create_ssl_context() -> SSLContext:
"""Create a SSLContext without hostname check and certification."""
context = create_default_context()
context.check_hostname = False
context.verify_mode = CERT_NONE
return context
if len(argv) == 1:
print(
"USAGE: CVE_2021_21985.py <IP or hostname server 1> <IP or hostname server 2> <IP or hostname server ...>"
)
exit(1)
targets = argv[1:]
print("Start scan...")
data = dumps(
{
"methodInput": [
{"type": "ClusterComputeResource", "value": None, "serverGuid": None}
]
}
).encode()
headers = {
"User-Agent": "Mozilla/5.0 (compatible; vCenter)",
"Content-Type": "application/json",
}
for target in targets:
# print(f"Scan {target}")
try:
response = urlopen(
Request(
f"https://{target}/ui/h5-vsan/rest/proxy/service/com.vmware.vsan.client.services.capability.VsanCapabilityProvider/getClusterCapabilityData",
data=data,
headers=headers,
),
context=create_ssl_context(),
)
except HTTPError as e:
response = e
except URLError as e:
print(f"ERROR on {target}: reason: {e.reason}")
continue
# print(f"Status code: {response.status}")
if response.status == 200:
try:
content = loads(response.read())
except JSONDecodeError:
print(f"ERROR on {target}: content response is not JSON.")
continue
else:
if "result" in content.keys():
print(f" [-] {target} is vulnerable")
elif "error" in content.keys():
print(
f" [!] {target} is probably vulnerable (get a JSON response error)"
)
elif response.status == 401:
print(f" [+] {target} is patched")
# breakpoint()
elif response.status == 503:
print(f" [!] {target} is probably not vulnerable (get a HTTP error code 503)")
elif response.status == 404:
print(
f" [!] {target} is probably not vulnerable (vulnerable ressource is not available)"
)
else:
print(
f' [!] {target} return a HTTP error code "{response.status} {response.reason}" (Not Implemented)'
)
print("End.")