-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscriptscan.py
More file actions
79 lines (54 loc) · 3.17 KB
/
scriptscan.py
File metadata and controls
79 lines (54 loc) · 3.17 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
import nmap
from colorama import Fore
from pyfiglet import Figlet
scanner=nmap.PortScanner()
f=Figlet()
def script_scan():
print(Fore.LIGHTGREEN_EX+f.renderText("SCRIPT SCAN"))
print(Fore.LIGHTGREEN_EX+"This scan uses Nmap's scripting engine to run scripts against the target.")
target=input("Enter the target IP or hostname: ")
script=input("Enter the script to run (e.g., http-enum, smb-os-discovery): ")
print(Fore.RESET)
try:
print(Fore.GREEN+f"Running script '{script}' on target '{target}'...")
print(Fore.RESET)
scanner.scan(target,arguments=f"-sV --script {script} -d")
for host in scanner.all_hosts():
print(Fore.GREEN+"Host:",scanner[host].hostname())
print("State:",scanner[host].state())
print(Fore.RESET)
for proto in scanner[host].all_protocols():
print(Fore.GREEN+"<------------------------>")
print("protocol :",proto)
print(Fore.RESET)
lport = scanner[host][proto].keys()
for port in lport:
print(Fore.GREEN+"port :",port,"state:",scanner[host][proto][port]['state'])
print("name:",scanner[host][proto][port]['name'])
print("product:",scanner[host][proto][port]['product'])
print("version:",scanner[host][proto][port]['version'])
print(Fore.RESET)
try:
print(Fore.GREEN+"extrainfo:",scanner[host][proto][port].get('extrainfo', 'N/A'))
print("\n\n\n")
print(Fore.RESET)
script_res = scanner[host][proto][port].get('script', None)
if script_res:
print(Fore.LIGHTYELLOW_EX+"Script result:")
print(Fore.RESET)
for script_name, output in script_res.items():
print(Fore.GREEN+f"{script_name}: {output}\n")
print(Fore.RESET)
else:
print(Fore.RED+"No script results found for this port.")
print("<------------------------>"+Fore.RESET)
print(Fore.LIGHTRED_EX+"Script scan completed."+Fore.RESET)
except Exception as e:
print(Fore.RED+f"An error occurred while retrieving script results: {e}")
print("<------------------------>"+Fore.RESET)
except nmap.PortScannerError as e:
print(Fore.RED+f"PortScannerError: {e}"+Fore.RESET)
except Exception as e:
print(Fore.RED+f"An error occurred: {e}"+Fore.RESET)
except KeyboardInterrupt:
print(Fore.RED + "Script scan interrupted by user." + Fore.RESET)