Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: tests

on:
push:
pull_request:

permissions:
contents: read

jobs:
pytest:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.9", "3.13"]
exclude:
# GitHub's Ubuntu 26.04 image has no Python 3.9 build; 3.9 is still tested on Windows.
- os: ubuntu-latest
python-version: "3.9"
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: ${{ matrix.python-version }}
- run: python -m pip install -r requirements-dev.txt
- run: python -m pytest
20 changes: 20 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Contributing

Issues and pull requests are welcome.

## Setup

```bash
python -m venv venv
venv\Scripts\activate # Linux/macOS: source venv/bin/activate
pip install -r requirements-dev.txt
pytest
```

## Ground rules

- Run `pytest` before you send a change. Add a test for any bug you fix; the tests in `tests/` show the style (small synthetic `.nessus` files built in code).
- Never commit real scan files or output. `.gitignore` already excludes `*.nessus`, `*.csv` and `*.xlsx`. Use synthetic data in tests.
- The 106-column list lives in one place, `nessus_common.py`. If you add a field, add it there, then update the SQL types in `nessus_to_sql.py`, the field list in the README, and the column count checks in the tests.
- Scripts take paths on the command line. The file pickers are only a fallback when no path is given, and tests must never open one.
- Plain, direct wording in docs and messages.
93 changes: 63 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ A collection of Python scripts for processing and converting Tenable Nessus vuln
| `nessus_to_csv.py` | Convert .nessus files to CSV |
| `nessus_to_xlsx.py` | Convert .nessus files to formatted Excel (.xlsx) |
| `nessus_to_sql.py` | Import .nessus files into SQL Server |
| `nessus_common.py` | Shared parser and column list used by the three converters. Keep it next to them. |

All conversion scripts support multiple input files, automatic duplicate removal, progress tracking, and performance metrics.
All three converters accept files or folders on the command line, support multiple input files, remove duplicate findings, and print performance metrics. Each also has a file-picker fallback that runs only when you give no path.

## Requirements

- Python 3.9+
- A graphical display (tkinter file dialogs require a desktop environment or X11 forwarding)
- A graphical display only if you run a converter with no path (tkinter file dialogs need a desktop environment or X11 forwarding)

```bash
pip install -r requirements.txt
```

| Dependency | Used By |
|------------|---------|
| `psutil` | All scripts (performance metrics) |
| `psutil` | The converters (performance metrics) |
| `requests` | `tenable_scan_retrieval.py` (Tenable.io API) |
| `openpyxl` | `nessus_to_xlsx.py` (Excel output) |
| `pyodbc` | `nessus_to_sql.py` (SQL Server via ODBC Driver 18) |
Expand All @@ -34,52 +35,70 @@ pip install -r requirements.txt
`nessus_to_sql.py` requires:
- Windows with ODBC Driver 18 for SQL Server installed
- Windows Authentication (Trusted Connection) to the target SQL Server
- Permissions to create tables and insert data
- Permission to insert data and to create tables: the import log (always) and the findings table (if you ask the script to create it)

## Usage

Exit codes for the converters: `0` success, `1` nothing could be converted (bad usage, no files, or every file failed), `2` output was written but at least one file could not be read. A file that fails to parse is skipped and listed at the end.

### Download Scans from Tenable.io

```bash
python tenable_scan_retrieval.py
python tenable_scan_retrieval.py # pick scans from a list
python tenable_scan_retrieval.py --all # every scan, no prompts
python tenable_scan_retrieval.py --scan-id 12 --scan-id 34
python tenable_scan_retrieval.py --all --output-dir D:\scans
```

1. Enter your API credentials (find them in Tenable.io: Settings > My Account > API Keys)
2. Select scans to download (single number, comma-separated, or "all")
3. Files are saved in a date-organized directory: `Year/MM-MonthName/Week-XX/`
1. Provide your API credentials (Tenable.io: Settings > My Account > API Keys). Set `TENABLE_ACCESS_KEY` and `TENABLE_SECRET_KEY`, or type them at the prompt. The secret key is not shown as you type.
2. Select scans: with no options, enter a single number, comma-separated numbers, or "all". `--all` and `--scan-id` skip the prompt.
3. Files are saved as `<scan name>-<scan id>.nessus` in `Year/MM-MonthName/Week-XX/` under `--output-dir` (default: the current folder). Year and week are both ISO values, so 2027-01-01 goes in `2026/01-January/Week-53`.

Every request has a timeout (10 s to connect, 60 s to read). A rate-limited request (HTTP 429) is retried up to 3 times. Each download goes to a `.part` file and is renamed only when complete; the size is checked against `Content-Length` unless the response is compressed, where that length does not apply. Each scan's export is polled every 5 seconds for up to 900 seconds. Use `--export-timeout SECONDS` and `--poll-interval SECONDS` to change that for very large scans. To use another Tenable cloud, set `TENABLE_URL` (https only), for example `https://fedcloud.tenable.com`. The exit code is `1` if any selected scan failed.

### Convert to CSV

```bash
python nessus_to_csv.py
python nessus_to_csv.py -o findings.csv scan1.nessus scan2.nessus
python nessus_to_csv.py -o findings.csv D:\scans # folders are searched recursively
python nessus_to_csv.py # no path: file pickers
```

1. Choose file selection (1) or folder selection (2)
2. Select .nessus files or folder
3. Choose output location
4. Produces a UTF-8 CSV with 106 columns
Produces a CSV with 106 columns, UTF-8 with a byte order mark so Excel reads non-ASCII text correctly. Without `-o` the output is `nessus_conversion.csv` in the current folder. The CSV is written to a temporary file first, so a run where every input fails does not overwrite an existing CSV.

### Convert to Excel

```bash
python nessus_to_xlsx.py
python nessus_to_xlsx.py -o findings.xlsx D:\scans
python nessus_to_xlsx.py # no path: file pickers
```

1. Select one or more .nessus files
2. Choose output location
3. Produces a formatted Excel workbook with alternating row colors, table filters, and TableStyleMedium2 styling
Produces a formatted Excel workbook with alternating row colors, table filters, and TableStyleMedium2 styling.

- An Excel cell holds at most 32,767 characters. A longer value (usually Plugin Output) is cut, ends with `[truncated, original was N characters]`, and the script prints how many cells were cut. Use the CSV script when you need the full text.
- A sheet holds at most 1,048,576 rows. A larger input stops with an error; split it or use the CSV script.

### Import to SQL Server

```bash
python nessus_to_sql.py
python nessus_to_sql.py D:\scans --server sqlserver.example.com --database Scans --table nessus_findings --create-table
python nessus_to_sql.py D:\scans # prompts for server, database and table
python nessus_to_sql.py D:\scans --dry-run # print the SQL and row count, no connection
```

1. Select folder containing .nessus files
2. Enter SQL Server address (e.g., `localhost`, `10.10.30.20`, `server.domain.com`)
3. Select database and table from interactive menus
4. Table is auto-created if it doesn't exist
5. Data is inserted in batches of 500,000 rows for memory efficiency
1. Give a folder or files (or none, to get a folder picker).
2. Give the server, database and table on the command line, or answer the prompts. The table menu lists the existing `dbo` tables and a "Create a new table" choice that asks for a name.
3. An existing table must already have all the script's columns, or the script stops before inserting. To create a table, use `--create-table` with `--table NAME`, or choose it in the menu. The findings table has no unique key, so no finding is ever dropped for looking like another one (compliance checks, for instance, share a plugin ID, host and port and differ only in their text). The script skips a row only when all 106 columns equal an earlier row in the same run.
4. Next to the findings table the script keeps `<table>_import_log` (created on first use, for existing tables too, so the login needs permission to create it). It records each imported file's base name, its SHA-256 and its row count. A file whose name and SHA-256 are already logged is skipped, so running the same folder twice adds nothing. A file with the same name but different content is imported again in full, and the same content under a different name is a separate import (the `file_path` value differs). Delete a row from the log to force a file to be imported again.
5. Each file is imported in one transaction together with its log row, in batches of 500,000 rows. If a batch fails, nothing from that file is kept, it is not logged, and the run stops. The closing message counts rows inserted by this run, files imported and files skipped.

Tables built by the old version of this script (before this change) have `VARCHAR(150)` columns for `cwe`, `bid`, `mskb` and the other reference columns, and `NVARCHAR(4000)` for `cve`. A finding with many references makes the joined text longer than that, and SQL Server then rejects the whole batch with "String or binary data would be truncated". When you point the script at such a table it prints a warning with the `ALTER TABLE ... ALTER COLUMN ... NVARCHAR(MAX)` statements for the narrow columns. Run those once, or import into a new table. The column check looks at names only, not types.

The `file_path` column holds the file's base name (for example `scan1.nessus`), not a full path. The CSV and Excel outputs call the same value File Name.

The connection uses Windows Authentication and validates the server certificate. If your server uses a self-signed certificate, install it as trusted. `--trust-server-certificate` accepts any certificate, which lets someone in the network path impersonate the server, so use it only on a network you control.

Dates are read in Python and sent as dates, empty numbers and dates are stored as NULL, and text columns are `NVARCHAR`, so non-Latin text is stored as is. This script has been tested against a fake connection only; it has not been run against a real SQL Server.

## Extracted Data Fields (106 per finding)

Expand All @@ -90,7 +109,7 @@ python nessus_to_sql.py
- IP Address, MAC Address, Virtual MAC Address
- Hostname, NetBIOS Name, FQDN, RDNS
- System Type, Operating System (name, family, confidence, detection method)
- CPE (Common Platform Enumeration)
- CPE (Common Platform Enumeration): the finding's own CPE from its plugin, not the host-level OS CPE

### Vulnerability Details
- Plugin ID, Plugin Family, Plugin Name
Expand All @@ -113,6 +132,8 @@ python nessus_to_sql.py
- Bug IDs: BID, EDB-ID, CEA-ID, CERT
- IAVA, IAVB, IAVT, ICSA, TRA

When a finding lists the same kind of reference more than once (two CWEs, several MSKB numbers), all of them are kept, joined with `, `.

### Exploit Intelligence
- Exploit Available, Exploitability Ease, Exploit Code Maturity
- Framework availability: Metasploit, Canvas, Core Impact
Expand All @@ -129,20 +150,32 @@ python nessus_to_sql.py

</details>

## Platform Notes
Newer Nessus fields (such as CVSS v4 and EPSS) are not extracted.

## Notes

- **Spreadsheet safety**: in CSV and Excel output, a text cell that starts with `=`, `+`, `-` or `@` (or a tab or carriage return) gets a leading `'` so Excel does not run it as a formula. Plugin output and hostnames come from scanned hosts, so they can contain anything. Plain numbers such as `-5` are left alone. The leading `'` is visible in the cell; strip it if you load the CSV into something other than Excel.
- **Duplicate removal**: the CSV, Excel and SQL scripts drop a row only when all 106 columns match another row. The file name is one of the columns, so the same finding in two differently named files is kept. Rows stay in the order they appear in the input.
- **Memory**: each host is released after it is read and only one file's rows are held at a time, but a single very large file is still held in memory as rows.
- **Windows-optimized**: the SQL script uses Windows Authentication (Trusted Connection). The memory metric uses `peak_wset` on Windows and falls back to `rss` on Linux/macOS.
- **API credentials**: read from the environment or prompted at runtime, never stored to disk.

## Tests

```bash
pip install -r requirements-dev.txt
pytest
```

- **GUI required**: All scripts use tkinter file dialogs for file/folder selection. They will not work over SSH without X11 forwarding or on headless servers.
- **Windows-optimized**: The SQL script uses Windows Authentication (Trusted Connection). The memory metric uses `peak_wset` on Windows and falls back to `rss` on Linux/macOS.
- **API credentials**: Prompted at runtime, never stored to disk.
- **Duplicate removal**: CSV and XLSX scripts automatically deduplicate findings before writing output.
The tests build small synthetic `.nessus` files and run the scripts through their command-line interface, so no scan data, GUI, SQL Server or Tenable account is needed.

## License

MIT License. See [LICENSE](LICENSE) for details.

## Contributing

Contributions, issues, and feature requests are welcome.
Contributions, issues, and feature requests are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md).

## Disclaimer

Expand Down
Loading
Loading