Why Root Permissions Are Required
AutoPentestX uses Nmap for network scanning, which requires root (sudo) privileges for several scan techniques:
SYN Scans (-sS) Raw packet manipulation requires root access to create custom TCP packets
OS Detection (-O) Low-level network probes need raw socket access
Service Detection (-sV) Some service fingerprinting techniques require privileged ports
Raw Sockets Direct network interface access is restricted to root user
Without sudo , Nmap falls back to TCP connect scans (-sT), which are slower, noisier, and easier to detect. You may also get incomplete results.
Common Permission Errors
Error Message: [ ! ] OS Detection failed: Permission denied
nmap.nmap.PortScannerError: 'nmap returned:
You requested a scan type which requires root privileges.'
Cause: Running AutoPentestX without sudo privileges.Solution: Run the entire script with sudo: sudo python3 main.py -t 192.168.1.100
Or using the wrapper script: sudo ./autopentestx.sh 192.168.1.100
If using a virtual environment: # Activate venv first
source venv/bin/activate
# Then run with sudo
sudo python3 main.py -t 192.168.1.100
The virtual environment must be activated before running sudo, or use the full path: sudo /home/user/AutoPentestX/venv/bin/python3 main.py -t 192.168.1.100
For automated scanning, configure passwordless sudo for Nmap:
Add exception for Nmap
Add this line at the end: username ALL= ( ALL ) NOPASSWD: /usr/bin/nmap
Replace username with your actual username.
Save and test
Should run without asking for password. Security Risk : Only use passwordless sudo in controlled lab environments, never on production systems.
Error Messages: PermissionError: [Errno 13] Permission denied: 'reports/'
sqlite3.OperationalError: unable to open database file
OSError: [Errno 13] Permission denied: 'logs/autopentestx.log'
Cause: Insufficient write permissions for output directories.Solution:
Check current permissions
ls -la reports/ logs/ database/
Fix directory permissions
# Make directories writable
chmod 755 reports/ logs/ database/ exploits/
# If needed, change ownership
sudo chown -R $USER : $USER reports/ logs/ database/ exploits/
Recreate directories if missing
mkdir -p reports logs database exploits
chmod 755 reports/ logs/ database/ exploits/
Verify fix
# Test write access
touch reports/test.txt && rm reports/test.txt && echo "✓ Write access OK"
The install.sh script automatically creates these directories with proper permissions. Re-run it if directories are missing.
Script Execution Permission
Error Message: bash: ./install.sh: Permission denied
bash: ./autopentestx.sh: Permission denied
bash: ./main.py: Permission denied
Cause: Execute bit not set on shell scripts or Python files.Solution: # Make scripts executable
chmod +x install.sh
chmod +x autopentestx.sh
chmod +x main.py
chmod -R 755 modules/
# Verify
ls -lh * .sh * .py
Alternative: Run explicitly with interpreter:bash install.sh
python3 main.py -t 192.168.1.100
Virtual Environment Permission Issues
Error Message: PermissionError: [Errno 13] Permission denied: '/home/user/AutoPentestX/venv/bin/pip'
Could not install packages due to an EnvironmentError
Cause: Virtual environment created with wrong ownership (often happens when using sudo).Solution:
Recreate WITHOUT sudo
# IMPORTANT: Don't use sudo here!
python3 -m venv venv
Activate and install packages
source venv/bin/activate
pip install -r requirements.txt
Fix ownership if needed
# Only if venv was created with sudo
sudo chown -R $USER : $USER venv/
NEVER create virtual environments with sudo . This causes permission conflicts and security issues.
Understanding Sudo and AutoPentestX
When Sudo is Required
Required
Not Required
Optional
These operations REQUIRE sudo: ✅ Full system scans with SYN scanning sudo python3 main.py -t 192.168.1.100
✅ OS detection and fingerprinting sudo python3 main.py -t example.com
✅ Raw packet manipulation sudo nmap -sS -O 192.168.1.100
✅ Installing system packages sudo apt-get install nmap nikto sqlmap
These operations DON’T need sudo: ❌ Creating virtual environment python3 -m venv venv # No sudo!
❌ Installing Python packages in venv pip install -r requirements.txt # No sudo!
❌ Accessing reports and logs cat reports/AutoPentestX_Report_ * .pdf
❌ Querying the database sqlite3 database/autopentestx.db
Reduced functionality without sudo: ⚠️ TCP connect scans (slower, less stealthy) # Will work but use -sT instead of -sS
python3 main.py -t 192.168.1.100
⚠️ Limited OS detection # Falls back to TTL-based detection
python3 main.py -t 192.168.1.100
You can run AutoPentestX without sudo, but many features will be disabled or degraded.
Security Best Practices
Principle of Least Privilege Only use sudo when necessary. Don’t run entire sessions as root. # Good
sudo python3 main.py -t 192.168.1.100
# Bad
sudo su
python3 main.py -t 192.168.1.100
Verify Commands Always review what you’re running with sudo # Check script content first
cat install.sh
# Then run with sudo
./install.sh
Limit Sudo Scope Use sudoers file to grant specific permissions # Only allow Nmap with sudo
username ALL= ( ALL ) NOPASSWD: /usr/bin/nmap
Audit Sudo Usage Review sudo logs regularly # Check sudo history
cat /var/log/auth.log | grep sudo
journalctl -u sudo
Docker Alternative (No Sudo Required)
If you want to avoid sudo permission issues entirely, consider running AutoPentestX in Docker:
FROM kalilinux/kali-rolling
RUN apt-get update && apt-get install -y \
python3 python3-pip nmap nikto sqlmap metasploit-framework
WORKDIR /autopentestx
COPY . .
RUN pip3 install -r requirements.txt
ENTRYPOINT [ "python3" , "main.py" ]
# Build container with root access
docker build -t autopentestx .
# Run without sudo on host (container has root inside)
docker run --rm autopentestx -t 192.168.1.100
Docker containers run with root privileges by default, so Nmap gets the permissions it needs without requiring sudo on your host system.
Checking Current Permissions
Use these commands to diagnose permission issues:
# Check if you're root
whoami
id
# Check sudo access
sudo -v
# View sudo permissions
sudo -l
# Check directory permissions
ls -la reports/ logs/ database/
# Check file ownership
stat reports/ logs/ database/
# View ACLs (if applicable)
getfacl reports/
# Test Nmap with sudo
sudo nmap -sS localhost
# Test write permissions
touch reports/test.txt && rm reports/test.txt
# Test database access
sqlite3 database/autopentestx.db "SELECT 1;"
Troubleshooting Checklist
Before asking for help with permission issues, verify:
Running with sudo
sudo python3 main.py -t 192.168.1.100
✅ Using sudo for network scanning
Directories exist
mkdir -p reports logs database exploits
✅ All required directories created
Correct ownership
ls -la | grep -E "reports|logs|database|exploits"
✅ Directories owned by your user
Scripts executable
chmod +x install.sh autopentestx.sh main.py
✅ Execute permissions set
Venv not root-owned
✅ Virtual environment owned by your user, not root