-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnessus.py
More file actions
63 lines (56 loc) · 2.09 KB
/
Copy pathnessus.py
File metadata and controls
63 lines (56 loc) · 2.09 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
import os
import sys
import requests
import json
import uuid
url = "https://192.168.4.208:8834"
username = "nessus"
scan_name = "name7"
target = "192.168.42.3"
def get_nessus_token(url, username, scan_name, target):
scan_found = False
url_token = f"{url}/session"
data = {"username": "nessus", "password": "technet24"}
#print(data)
response = requests.post(url_token, json=data, verify=False)
token = json.loads(response.text)["token"]
print(token)
url_scan = f"{url}/scans"
#print(url_scan)
headers = {"X-Cookie": f"token={token}"}
print(headers)
response_scan = requests.get(url_scan, headers=headers, verify=False)
scans = response_scan.json()["scans"]
for scan in scans:
if scan["name"] == scan_name:
scan_id = scan["id"]
url_launch = f"https://192.168.4.208:8834/scans/{scan_id}/launch"
response = requests.post(url_launch, headers=headers, verify=False)
if response.status_code == 200:
print("Lunch scan by id: status code",response.status_code)
return response.json()
else:
print(f"Error: Scan lunch failed!, {response.json()}")
sys.exit(1)
scan_found = True
break
if not scan_found:
print("Start Create New Scan ")
url_create = "https://192.168.4.208:8834/scans"
headers_create = {
"X-Cookie": f"token={token}",
"Content-Type": "application/json"
}
payload = {
"uuid": "ab4bacd2-05f6-425c-9d79-3ba3940ad1c24e51e1f403febe40",
"settings": {
"name": scan_name,
"text_targets": target,
"policy_id": 61,
"launch": "ON_DEMAND"
}
}
print(payload)
response_create = requests.post(url_create, headers=headers_create,json=payload ,verify=False)
print(response_create.json())
get_nessus_token(url, username, scan_name, target)