forked from h2g2bob/ipp-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_vulnerability.py
44 lines (39 loc) · 1.26 KB
/
check_vulnerability.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
import subprocess
def get_lines_list(output: str):
lines_list = []
lines_str = output.split("\n")
for line_str in lines_str:
line = []
for word in line_str.split(" "):
if word != "":
line.append(word)
if line and line[0] != "udp":
continue
if line:
lines_list.append(line)
return lines_list
def check_cups_browsed_version():
try:
result = subprocess.run(
["netstat", "-anu"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
if result.returncode == 0:
is_vulnerable = False
local_add = "0.0.0.0:631"
foreign_add = "0.0.0.0:*"
lines_list = get_lines_list(result.stdout.strip())
for line in lines_list:
if line[3] == local_add and line[4] == foreign_add:
is_vulnerable = True
print("You are vulnerable!")
if not is_vulnerable:
print("You are NOT vulnerable.")
else:
print(f"Error: {result.stderr.strip()}")
except FileNotFoundError:
print("net-tool is not installed.")
if __name__ == "__main__":
check_cups_browsed_version()