-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnour
60 lines (50 loc) · 2.06 KB
/
nour
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
import nmap
import json
import time
import sys
from nessrest import ness6rest
nessus_dict = {}
index = 1
nm_tcp_options = '-Pn -sV -sC'
nm_udp_options = '-sU -Pn --top-ports 100 -sV -sC'
nm_scan = nmap.PortScanner()
# Make sure scan_dict is defined
for ip_scan in scan_dict.keys():
ip_list = scan_dict[ip_scan].split(',')
for ip_val in ip_list:
nessus_dict[index] = {}
nessus_dict[index]['name'] = ip_scan
nessus_dict[index]['ip'] = ip_val
port_list = [] # Initialize port_list at the beginning of each loop
try:
data_tcp = nm_scan.scan(str(ip_val), arguments=nm_tcp_options)
for ports in data_tcp['scan'][str(ip_val)]['tcp'].keys():
if ports not in port_list:
port_list.append(str(ports))
except Exception as e:
print("Exception: " + str(e))
try:
data_udp = nm_scan.scan(str(ip_val), arguments=nm_udp_options)
for ports in data_udp['scan'][str(ip_val)]['udp'].keys():
if ports not in port_list:
port_list.append(str(ports))
except Exception as e:
print("Exception: " + str(e))
nessus_dict[index]['ports'] = ','.join(port_list)
index += 1
print(nessus_dict) # Changed to print function
scan = ness6rest.Scanner(url="https://localhost:8834", login="nour", password="nour", insecure=True)
scan.policy_set('policy_name')
for keys in nessus_dict.keys():
try:
scan.policy_limit_ports(ports=nessus_dict[keys]['ports'])
scan.scan_add(targets=nessus_dict[keys]['ip'], name=nessus_dict[keys]['name'] + nessus_dict[keys]['ip'])
scan.scan_run()
scan._scan_status()
time.sleep(60)
scan_data = scan.download_scan(export_format="csv")
file_nessus = 'final_scan_' + str(time.time()) + '.csv'
with open(file_nessus, 'w') as scan_file: # Use context manager for file handling
scan_file.write(scan_data)
except Exception as e:
print("Exception: " + str(e)) # Print exception for debugging