Overview
The Nessus scripts automate vulnerability scanning using Tenable Nessus via REST API. These scripts authenticate, launch scans, monitor progress, and export reports in HTML and XML formats.nessus_scan.bat
Launches a Nessus vulnerability scan and generates reports.Parameters
Project name for the scan
Target IP address or range to scan
Nessus authentication username
Nessus authentication password
Nessus server hostname or IP
Nessus server port (typically 8834)
Name of the Nessus scan policy to use
Timestamp for unique file naming
Output directory for reports
Usage
Workflow
- Service Detection - Verifies Nessus service is running
- Authentication - Logs in via
/sessionendpoint - Policy Resolution - Retrieves policy ID and template UUID
- Scan Creation - Creates new scan with target configuration
- Scan Launch - Starts the scan execution
- Progress Monitoring - Polls scan status every 60 seconds
- Report Generation - Exports HTML and XML reports
- Cleanup - Logs out and removes temporary files
API Endpoints Used
| Endpoint | Method | Purpose |
|---|---|---|
/session | POST | Authenticate and get token |
/policies | GET | List available scan policies |
/scans | POST | Create new scan |
/scans/{id}/launch | POST | Launch scan |
/scans/{id} | GET | Get scan status and details |
/scans/{id}/export | POST | Request report export |
/scans/{id}/export/{file}/status | GET | Check export status |
/scans/{id}/export/{file}/download | GET | Download report |
/session | DELETE | Logout |
Authentication Pattern
Scan Configuration
The script creates scans with the following settings:Report Export
Two report formats are generated: HTML Report:Error Handling
- Service not running - Prompts to start Nessus daemon:
/etc/init.d/nessusd start - Authentication failure - Exits if token is null
- Scan paused - Waits and continues monitoring
- Scan canceled - Exits gracefully
- Export failure - Exits if status report is null
Output Files
NessusReport - {Timestamp}.html- HTML formatted reportNessusReport - {Timestamp}.xml- XML/Nessus formatted report
nessus_get_policies.bat
Retrieves available Nessus scan policies for use in scans.Parameters
Nessus server hostname or IP
Nessus server port
Nessus authentication username
Nessus authentication password
Timestamp for temporary file naming
Usage
Implementation
The script retrieves policy names using the Nessus API:Output
Policy names are written to:%TEMP%\nessus_scan_policies_{Timestamp}.txt
Example output:
Error Handling
- Validates service availability before authentication
- Checks credentials and exits with error message if invalid
- Cleans up temporary token files
Notes
- Use retrieved policy names as the
Policy_Nameparameter innessus_scan.bat - The commented line shows how to retrieve scan templates instead of policies