I want to use a Python Script to access Nessus API and start a scanning . I have installed my Nessus service on my Ubuntu Virtual Machine https://127.0.0.1:8834 , here is my code (I hide my accesskey and secretkey):
import json
import warnings
from urllib3.exceptions import InsecureRequestWarning
# Specify the Nessus API endpoint and credentials
nessus_url = "https://127.0.0.1:8834"
access_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
secret_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Specify the target for the scan
target = "140.113.199.245"
# Define the scan policy
policy_id = 1
# Specify the scan name
scan_name = "Scan"
# Specify the scan template
template = "web-app"
# Define the headers for the API request
headers = {
"X-ApiKeys": f"accessKey={access_key};secretKey={secret_key}",
"Content-type": "application/json"
}
# Create the request body for the scan
request_body = {
"settings": {
"name": scan_name,
"description": "",
"policy_id": policy_id,
"text_targets": target,
"template": template
}
}
#requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
# /opt/nessus/com/nessus/CA/cacert.pem
# Send the API request to start the scan
with warnings.catch_warnings():
warnings.simplefilter("ignore")
response = requests.post(f"{nessus_url}/scans", headers=headers, data=json.dumps(request_body), verify = "/opt/nessus/com/nessus/CA/cacert.pem",stream = True,timeout=30)
# Print the response
print(response.text)
and after I run this Script, error occur as below:
requests.exceptions.ChunkedEncodingError:
("Connection broken: ConnectionResetError(104, 'Connection reset by peer')"
ConnectionResetError(104, 'Connection reset by peer'))
What is this error and how can I fix this ?