-
Notifications
You must be signed in to change notification settings - Fork 6
/
CVE-2021-4034_Finder.py
96 lines (66 loc) · 2.64 KB
/
CVE-2021-4034_Finder.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
#!/usr/bin/python3
import apt
import csv
def check_ubuntu(dist):
if "20.04" in dist[1]:
return "0.105-26ubuntu1.2"
elif "21.10" in dist[1]:
return "0.105-31ubuntu0.1"
elif "18.04" in dist[1]:
return "0.105-20ubuntu0.18.04.6"
def check_debian(dist):
if "stretch" in dist[1]:
return "0.105-18+deb9u2"
elif "buster" in dist[1]:
return "0.105-25+deb10u1"
elif "bullseye" in dist[1]:
return "0.105-31+deb11u1"
# Return True is vulnerable, False if not
def check_deb_varients(dist):
cache = apt.cache.Cache()
cache.open()
pkg = cache["policykit-1"]
pkg_ver = pkg.installed.version
fixed_ver = None
if "Ubuntu" in dist[0]:
fixed_ver = check_ubuntu(dist)
elif "Debian" in dist[0]:
fixed_ver = check_debian(dist)
return pkg_ver < fixed_ver
# Credits: https://github.com/markkuleinio/python-get-distro/blob/master/get_distro.py
def find_distro():
RELEASE_DATA = {}
with open("/etc/os-release") as f:
reader = csv.reader(f, delimiter="=")
for row in reader:
if row:
RELEASE_DATA[row[0]] = row[1]
if RELEASE_DATA["ID"] in ["debian", "raspbian"]:
with open("/etc/debian_version") as f:
DEBIAN_VERSION = f.readline().strip()
major_version = DEBIAN_VERSION.split(".")[0]
version_split = RELEASE_DATA["VERSION"].split(" ", maxsplit=1)
if version_split[0] == major_version:
# Just major version shown, replace it with the full version
RELEASE_DATA["VERSION"] = " ".join([DEBIAN_VERSION] + version_split[1:])
return (RELEASE_DATA["NAME"], RELEASE_DATA["VERSION"])
def main():
banner = """---> PwnKit-Hunter <---
This test is currently working on Debian (stretch, buster, and bullseye) and Ubuntu (18.04, 20.04, 21.10) only
If your distro is not on this list, please check the apropriate advisory, and update your system soon.
For RedHat distros we suggest the following mitigation: https://access.redhat.com/security/vulnerabilities/RHSB-2022-001#Mitigation"""
print(banner)
print()
dist = find_distro()
if "Ubuntu" in dist[0] or "Debian" in dist[0]:
print("[*] Test started")
is_vuln = False
is_vuln = check_deb_varients(dist)
if is_vuln:
print("[-] Your polkit package is vulnerable.\nUpdate it using: apt install policykit-1")
else:
print("[+] Your polkit package is not vulnerable. Keep being secure")
else:
print("[-] This test is currently working on Debian and Ubuntu only.")
if __name__ == "__main__":
main()