-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathThreatHunter.py
149 lines (131 loc) · 5.11 KB
/
ThreatHunter.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
import socket
import os
import subprocess
import sys
import platform
import paramiko
import nmap
red = "\033[1;31m"
green = "\033[1;32m"
reset = "\033[0;0m"
# Developer: SirCryptic (NullSecurityTeam)
# Info: ThreatHunter 1.1
os.system('cls' if os.name == 'nt' else 'clear')
banner = '''
_____________ ___________ __ _____
___ __/__ /___________________ __ /___ / / /___ __________ /_____________
__ / __ __ \_ ___/ _ \ __ `/ __/_ /_/ /_ / / /_ __ \ __/ _ \_ ___/
_ / _ / / / / / __/ /_/ // /_ _ __ / / /_/ /_ / / / /_ / __/ /
/_/ /_/ /_//_/ \___/\__,_/ \__/ /_/ /_/ \__,_/ /_/ /_/\__/ \___//_/
'''
print(banner)
def check_firewall(host, port):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5)
result = sock.connect_ex((host, port))
if result == 0:
print(green + "Firewall not detected" + reset)
else:
print(red + "Firewall detected" + reset)
except Exception as e:
print(red + "Error while checking firewall: " + str(e) + reset)
def check_ids(host, port):
try:
response = os.system("hping3 " + host + " -p " + str(port) + " -c 1")
if response == 0:
print(green + "Intrusion Detection System not detected" + reset)
else:
print(red + "Intrusion Detection System detected" + reset)
except Exception as e:
print(red + "Error while checking Intrusion Detection System: " + str(e) + reset)
def check_antivirus(host):
if sys.platform == "win32":
try:
process = subprocess.Popen(['powershell.exe', f'-ComputerName {host}', 'Get-MpComputerStatus'], stdout=subprocess.PIPE)
stdout = process.communicate()[0]
if b"Enabled" in stdout:
print(red + "Antivirus detected" + reset)
else:
print(green + "Antivirus not detected" + reset)
except Exception as e:
print(red + "Error while checking antivirus: " + str(e) + reset)
else:
print("Antivirus check not available on this operating system")
def check_nsg(host, port):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5)
result = sock.connect_ex((host, port))
if result == 0:
print(green + "Network Security Group not detected" + reset)
else:
print(red + "Network Security Group detected" + reset)
except Exception as e:
print(red + "Error while checking Network Security Group: " + str(e) + reset)
def check_ips(host, port):
try:
response = os.system("hping3 " + host + " -p " + str(port) + " -c 5")
if response == 0:
print(green + "Intrusion Prevention System not detected" + reset)
else:
print(red + "Intrusion Prevention System detected" + reset)
except Exception as e:
print(red + "Error while checking Intrusion Prevention System: " + str(e) + reset)
def check_website_os(host):
try:
nm = nmap.PortScanner()
nm.scan(host, arguments='-O')
if 'osclass' in nm[host]:
for osclass in nm[host]['osclass']:
print("Operating System: " + osclass['osfamily'])
else:
print("Operating System: Unknown")
except Exception as e:
print("Error: Unable to scan target")
def check_service(service_name):
try:
service_status = subprocess.run(["systemctl", "is-active", service_name], capture_output=True, text=True)
if "active" in service_status.stdout:
print(service_name, "service is running")
else:
print(service_name, "service is not running")
except Exception as e:
print("Error while checking service:", str(e))
def check_log4js_remote(host, port=22):
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port, timeout=20)
stdin, stdout, stderr = ssh.exec_command("npm list --depth=0")
log4js = stdout.read().decode("utf-8")
if "log4js" in log4js:
print(red + "log4js detected" + reset)
else:
print(green + "log4js not detected" + reset)
ssh.close()
except Exception as e:
print(red + "Error while checking for log4js: " + str(e) + reset)
def use_nameserver():
try:
with open("nameserver.txt", "r") as file:
nameserver = file.read().strip()
except FileNotFoundError:
nameserver = input("Enter nameserver address: ")
with open("nameserver.txt", "w") as file:
file.write(nameserver)
return nameserver
if sys.platform == "win32":
host = use_nameserver()
else:
host = input("Enter hostname or IP address: ")
port = int(input("Enter port number: "))
check_website_os(host)
check_service("ssh")
check_service("httpd")
check_firewall(host, port)
check_ids(host, port)
check_antivirus(host)
check_log4js_remote(host, port=22)
check_nsg(host, port)
check_ips(host, port)