An advanced Python application for automatically scanning USB drives when connected to Ubuntu systems using ClamAV antivirus engine. Features a modern GUI interface with real-time feedback and comprehensive reporting.
- Automatic Detection: Monitors USB ports and automatically detects removable storage devices
- Real-time Scanning: Uses ClamAV engine for thorough virus scanning
- Safe Quarantine: Safely isolates detected threats for review and recovery
- Multiple File Systems: Supports VFAT, NTFS, exFAT, EXT3, and EXT4
- Modern GUI Interface: Intuitive graphical interface with real-time status updates
- Progress Indicators: Visual progress bars and status messages
- Detailed Device Info: Shows device vendor, model, file system, and capacity
- Comprehensive Logging: Both GUI log display and file-based logging
- Scan Reports: Detailed JSON reports saved to USB device and desktop
- Auto-start Service: Optional systemd service for automatic startup
- Desktop Integration: Desktop shortcut for manual launching
- Security Hardened: Runs with minimal required privileges
- Error Handling: Robust error handling and recovery mechanisms
- OS: Ubuntu 20.04 LTS or newer (tested on Ubuntu 24.04)
- Python: Python 3.8 or newer
- Desktop: X11-based desktop environment (GNOME, XFCE, etc.)
- Privileges: Sudo access for initial setup
# System packages
sudo apt install python3 python3-pip python3-pyudev python3-tk clamav clamav-daemon freshclam dbus-x11
# Python packages
pip3 install pyudev==0.24.1-
Clone the repository:
git clone https://github.com/yourusername/usb-virus-scanner.git cd usb-virus-scanner -
Run the setup script:
chmod +x setup.sh ./setup.sh
-
Test the installation:
python3 usb_scanner.py
The setup script will:
- Install all required dependencies
- Configure ClamAV with proper permissions
- Update virus definitions
- Optionally install as a system service
- Create a desktop shortcut
If you prefer manual installation:
sudo apt update
sudo apt install python3 python3-pip python3-pyudev python3-tk clamav clamav-daemon freshclam dbus-x11pip3 install --user pyudev==0.24.1# Stop freshclam service temporarily
sudo systemctl stop clamav-freshclam
# Update virus definitions
sudo freshclam
# Restart and enable freshclam
sudo systemctl enable clamav-freshclam
sudo systemctl start clamav-freshclamecho "$USER ALL=(ALL) NOPASSWD: /usr/bin/clamscan, /usr/bin/freshclam" | sudo tee /etc/sudoers.d/usb-scannerchmod +x usb_scanner.pypython3 usb_scanner.pyDouble-click the "USB Virus Scanner" icon on your desktop.
The scanner now maintains a quarantine system for safely isolating detected threats:
# List quarantined files
./manage.sh quarantine list
# Restore a file from quarantine (use with caution!)
./manage.sh quarantine restore <filename>
# Delete a specific quarantined file
./manage.sh quarantine delete <filename>
# Delete all quarantined files
./manage.sh quarantine delete allQuarantined files are stored at ~/.local/share/usb-scanner/quarantine with metadata about their origin.
If installed as a service:
# Start service
sudo systemctl start usb-scanner.service
# Stop service
sudo systemctl stop usb-scanner.service
# Check status
sudo systemctl status usb-scanner.service
# View logs
journalctl -u usb-scanner.service -fThe application features a modern dark-themed GUI with:
- Status Panel: Real-time status updates and progress indicators
- Device Information: Detailed info about connected USB devices
- Scan Log: Scrollable log with timestamps and color-coded messages
- Control Buttons: Clear log and exit functions
- π΅ Blue: Waiting for device or normal operation
- π‘ Yellow: Device mounting or definition updates
- π Orange: Scanning in progress
- π’ Green: Scan completed successfully
- π΄ Red: Threats found or errors occurred
The scanner generates detailed reports in JSON format containing:
{
"timestamp": "2025-06-05T10:30:00",
"device_info": {
"vendor": "SanDisk",
"model": "Ultra USB 3.0",
"fs_type": "vfat",
"label": "MYDRIVE"
},
"mount_point": "/media/user/MYDRIVE",
"scan_duration": "0:02:15",
"threats_found": 2,
"infected_files": [
"/media/user/MYDRIVE/suspicious_file.exe: Malware.Win32.Trojan.12345 FOUND"
],
"quarantine_location": "/home/user/.local/share/usb-scanner/quarantine",
"action_taken": "quarantined",
"exit_code": 1
}Reports are saved to:
- USB device root directory (preferred)
- Desktop as backup location
This scanner is designed for dedicated testing/scanning systems, not daily-use workstations:
- Run on isolated systems that can be rebuilt if compromised
- Use dedicated scanning stations for unknown USB devices
- Regularly backup the scanning system configuration
The scanner requires specific sudo permissions for:
clamscan: Virus scanning with removal capabilitiesfreshclam: Virus definition updates
These are configured with NOPASSWD to avoid interrupting automated scans.
The scanner needs read/write access to:
- USB mount points (for scanning and report writing)
/var/log(for logging)- User home directory (for backup reports)
"ClamAV not found" error:
sudo apt install clamav
which clamscan # Should return /usr/bin/clamscan"Cannot run clamscan with sudo" error:
# Check sudoers configuration
sudo visudo -f /etc/sudoers.d/usb-scanner
# Should contain: username ALL=(ALL) NOPASSWD: /usr/bin/clamscan, /usr/bin/freshclamGUI doesn't appear:
# Check if X11 forwarding is enabled
echo $DISPLAY # Should show :0 or similar
xauth list # Should show X11 authentication entriesDevice not detected:
# Check if device appears in system
lsblk
dmesg | tail -20
# Ensure USB device has a supported file systemPermission denied on USB device:
# Check mount options
mount | grep /media
# Device might be mounted read-only or with noexecCheck these locations for diagnostic information:
- Application log:
/var/log/usb_scanner.log - System journal:
journalctl -u usb-scanner.service - ClamAV logs:
/var/log/clamav/ - Detailed scan log:
/tmp/clamscan_detailed.log
Run with verbose output:
python3 -u usb_scanner.pyThe scanner automatically updates virus definitions on startup and periodically through the freshclam service.
Manual update:
sudo freshclamcd usb-virus-scanner
git pull origin main
# Restart service if running
sudo systemctl restart usb-scanner.service- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
This software is provided "as is" without warranty. While it uses industry-standard ClamAV engine, no antivirus solution is 100% effective. Always:
- Keep virus definitions updated
- Use multiple security layers
- Scan unknown devices on isolated systems
- Maintain regular backups
For issues and questions:
- Check the troubleshooting section above
- Search existing GitHub issues
- Create a new issue with:
- Ubuntu version
- Python version
- Error messages
- Steps to reproduce
Version: 2.1.1
Last Updated: June 9, 2025
Tested On: Ubuntu 24.04 LTS