Skip to main content

Overview

The Database module (modules/database.py) provides SQLite-based data persistence for all scan results. It manages five normalized tables storing scans, ports, vulnerabilities, web findings, and exploit attempts.

Database Class

Defined at database.py:12, this class handles all database operations.

Initialization

database.py:13-20
string
default:"database/autopentestx.db"
Path to SQLite database file

Database Schema

AutoPentestX uses a normalized schema with five tables:

scans Table

Stores scan metadata and overall results.
database.py:42-55
Fields:
  • id: Unique scan identifier (auto-increment)
  • target: IP address or domain scanned
  • scan_date: Timestamp when scan started
  • os_detection: Detected operating system
  • scan_duration: Total scan time in seconds
  • total_ports: Ports scanned count
  • open_ports: Open ports discovered
  • vulnerabilities_found: Total vulnerabilities
  • risk_score: Overall risk level (CRITICAL/HIGH/MEDIUM/LOW)
  • status: Scan status (completed/failed/interrupted)

ports Table

Stores discovered open ports and services.
database.py:57-69

vulnerabilities Table

Stores general vulnerabilities and CVEs.
database.py:71-86

web_vulnerabilities Table

Stores web-specific vulnerabilities from Nikto/SQLMap.
database.py:101-111

exploits Table

Stores exploitation attempt results.
database.py:88-100

CRUD Operations

Insert Operations

insert_scan()

Creates a new scan entry and returns the scan ID.
database.py:120-135

insert_port()

database.py:155-170

insert_vulnerability()

database.py:172-195

Update Operations

update_scan()

Updates scan record with results.
database.py:137-153

Query Operations

get_scan_by_id()

database.py:230-245

get_ports_for_scan()

database.py:247-260

get_vulnerabilities_for_scan()

database.py:262-275

Usage Example

Error Handling

The Database module handles these common errors:
Returns error if database file cannot be created or accessed.
Returns None instead of crashing if insert fails.
SQLite enforces foreign key constraints. Ensure scan_id exists before inserting related records.

Database Maintenance

Backup

Vacuum

Clear Old Scans

Database Queries

Common SQL queries for data analysis

Configuration

Database settings and options

PDF Reports

How reports retrieve data from database

Workflow

Phase 1: Database initialization