Intelligent Ducky Script classifier and organizer for BadUSB payloads using keyword detection and AI-powered categorization.
- Ducky Script Validation: Detects valid BadUSB scripts using keyword matching
- Multi-Level Classification:
- Pattern-based detection (fast)
- AI-powered classification via Ollama (accurate)
- Automatic fallback to "unassigned" category
- Batch Processing: Recursively processes entire directory structures
- Collision Handling: Auto-renames files with duplicate names
- Comprehensive Logging: Detailed file and console logging with statistics
- Error Resilience: Graceful error handling for malformed files
- Python 3.8+
- Ollama (optional, for AI classification)
cd Bad_USB_Classifier
pip install -r requirements.txtFor AI-powered classification, install Ollama:
# https://ollama.ai
ollama pull qwen2.5:3bpython classify_badusb.py <directory_path>
# or, with keyword-only classification (no Ollama calls, no pass 2):
python classify_badusb.py <directory_path> --no-ollamapython classify_badusb.py ./badusb_samplesOutput structure:
badusb_samples/
├── classified_badusb/
│ ├── exfiltration/
│ ├── phishing/
│ ├── remote_access/
│ ├── credentials/
│ └── unassigned/
└── classification.log
# Clone (or `git pull` if already cloned) every repo listed in url.txt
python classify_badusb.py --urls url.txt --output ./badusb_repos
# Search GitHub/Reddit for new source repos not yet in url.txt (dry-run)
python discover_repos.py
# ...and append the ones you want to keep:
python discover_repos.py --writepayload_setup_agent.py scans an already-classified folder, detects scripts
that need a value (Discord webhook, Telegram bot/chat id, attacker IP/port,
email, [placeholder] values...), and interactively fills them in — guiding
you through creating a Discord webhook from scratch if you don't have one
yet. See badusb_pipeline.py at the repo root for
the one-command version that chains classification and enrichment together.
python payload_setup_agent.py ./badusb_samples/classified_badusb.txt- Text-based scripts.duck- Ducky Script format.ds- Ducky Script variant
exfiltration, PassVault, remote_access, CartmanSong, general, phishing, ReverseShell, Chrome2Discord, iMessageExfil, prank, Telegram, credentials, incident_response, quackberry, Text2Speech, destructive, Mimikatz, ransom, web2Discord, EmailAndTextMessage, MOAB, execution, mobile, recon
- Validation Phase: Verifies file contains valid Ducky Script keywords
- Detection Phase: Searches for topic keywords in content
- Classification Phase: If no match, queries Ollama for AI classification
- Organization Phase: Moves files to appropriate category folder
Classification logs are saved to classification.log with:
- Timestamp
- Log level (INFO, DEBUG, ERROR)
- Processing status and details
Edit these constants in classify_badusb.py:
OLLAMA_MODEL = "qwen2.5:3b" # Change AI model
VALID_KEYWORDS = {...} # Modify Ducky Script keywords
TOPICS = [...] # Add/remove categories
SUPPORTED_EXTENSIONS = {".txt", ...} # Change file types- Pattern Detection: ~10-50ms per file
- AI Classification: ~500-1000ms per file (depends on content size)
- Batch Processing: 100+ files/minute on typical hardware
- Requires Ollama running locally for AI classification
- Large files (>10MB) may timeout during AI classification
- Accuracy depends on script quality and keyword presence
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/improvement) - Commit changes (
git commit -am 'Add feature') - Push to branch (
git push origin feature/improvement) - Open a Pull Request
Areas for contribution:
- Additional classification categories
- Support for more script formats (AutoIt, AutoHotkey)
- Performance optimizations
- Test coverage
- Documentation improvements
MIT License - See LICENSE file
This tool was inspired by and references:
- Flipper Zero - Multi-tool device for security professionals
- BadUSB Research - Concept and security implications
- Ducky Script Documentation - Official script syntax
- Flipper Zero BadUSB community payloads and research
This tool is designed for authorized security testing, research, and defensive purposes only. Users are responsible for legal compliance when working with BadUSB payloads.
Developed as part of Bad_Usb_Forge suite for security automation and analysis.
For issues, questions, or feature requests: Open an issue on GitHub