A comprehensive API security monitoring and testing platform that provides real-time detection of various attack vectors and allows security professionals to test their APIs against multiple security threats.
- SQL Injection detection with pattern matching
- XSS (Cross-Site Scripting) detection
- Path Traversal protection
- Command Injection detection
- NoSQL Injection detection
- LDAP Injection detection
- XML External Entity (XXE) detection
- Rate Limiting and DDoS protection
- Add custom APIs for security testing
- Configure HTTP methods (GET, POST, PUT, DELETE, PATCH)
- Set custom headers and authentication
- Define body templates with payload placeholders
- Select specific attack types to test against each API
- Individual and bulk attack testing
- Real-time metrics and statistics
- Live abuse event logging
- Attack test results visualization
- Custom API management interface
- Export functionality for compliance
- FastAPI backend with async support
- Custom middleware for request interception
- In-memory storage for custom APIs and test results
- Prometheus metrics integration
- Modern HTML5/CSS3 dashboard with responsive design
- Python 3.11+
- pip package manager
- Clone the repository
git clone <repository-url>
cd api-abuse-detection- Install dependencies
pip install -r requirements.txt- Run the application
python main.py- Access the dashboard
- Open your browser and navigate to
http://localhost:8000 - The API documentation is available at
http://localhost:8000/api/docs
- Open your browser and navigate to
- Build and run with Docker Compose
docker-compose up -d- Access the application
- Dashboard:
http://localhost:8000 - Prometheus:
http://localhost:9090 - Grafana:
http://localhost:3000(admin/admin)
- Dashboard:
-
Navigate to the dashboard at
http://localhost:8000 -
Fill in the API details:
- Name: Descriptive name for your API
- Description: Optional description
- URL: Full endpoint URL
- Method: HTTP method (GET, POST, PUT, DELETE, PATCH)
- Headers: Custom headers in JSON format (optional)
- Body Template: Request body with
{{payload}}placeholder (optional) - Attack Types: Select which attacks to test against
-
Click "Add API" to save
curl -X POST "http://localhost:8000/api/test-attack" \
-H "Content-Type: application/json" \
-d '{
"api_id": "your_api_id",
"attack_type": "sql_injection",
"custom_payload": "custom_payload_here"
}'curl -X POST "http://localhost:8000/api/test-all-attacks/your_api_id" \
-H "Content-Type: application/json" \
-d '{
"attack_types": ["sql_injection", "xss", "path_traversal"]
}'| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Main dashboard interface |
/api/custom-apis |
POST | Create custom API |
/api/custom-apis |
GET | List all custom APIs |
/api/custom-apis/{id} |
GET | Get specific custom API |
/api/custom-apis/{id} |
PUT | Update custom API |
/api/custom-apis/{id} |
DELETE | Delete custom API |
/api/test-attack |
POST | Test specific attack |
/api/test-all-attacks/{id} |
POST | Test all attacks |
/api/attack-history |
GET | Get test results |
/api/metrics |
GET | Get system metrics |
/health |
GET | Health check |
Create a .env file in the root directory:
# Application
DEBUG=false
SECRET_KEY=your-secret-key-change-in-production
# Rate Limiting
RATE_LIMIT_PER_MINUTE=100
RATE_LIMIT_PER_HOUR=1000
# Security
MAX_PAYLOAD_LENGTH=10000
# Monitoring
ENABLE_METRICS=true
LOG_LEVEL=INFOThe system uses regex patterns to detect various attack types. You can customize these patterns in app/core/detection.py:
self.patterns = {
"sql_injection": [
r"(\b(union|select|insert|update|delete|drop|create|alter|exec|execute)\b)",
# Add your custom patterns here
],
# ... other attack types
}The system exposes Prometheus metrics at /metrics:
http_requests_total: Total HTTP requests by method, endpoint, and statushttp_request_duration_seconds: Request duration histogramssecurity_attacks_detected_total: Attack detections by typesecurity_requests_blocked_total: Blocked requests by reasonapi_tests_run_total: API tests executedcustom_apis_total: Number of custom APIs
Import the provided Grafana dashboard to visualize:
- Request rates and response times
- Security event trends
- API test results
- System performance metrics
# Install test dependencies
pip install pytest pytest-asyncio
# Run tests
pytest tests/The system includes:
- Unit tests for detection modules
- Integration tests for API endpoints
- Frontend functionality testing
- Attack simulation validation
- Set production environment variables
export DEBUG=false
export SECRET_KEY=your-production-secret-key- Use a production WSGI server
pip install gunicorn
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker- Set up reverse proxy (nginx)
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}# Build production image
docker build -t api-abuse-detection:latest .
# Run with production settings
docker run -d \
-p 8000:8000 \
-e DEBUG=false \
-e SECRET_KEY=your-production-key \
--name api-abuse-detection \
api-abuse-detection:latest- Rate Limiting: Configurable per-minute and per-hour limits
- Payload Validation: Maximum payload size limits
- Pattern Detection: Regex-based attack detection
- Security Headers: Automatic security header injection
- Isolated Testing: Tests run against external APIs only
- No Local Execution: Attack payloads never execute locally
- Audit Logging: All test activities are logged
- Configurable Patterns: Safe, customizable detection rules
- Request Processing: < 10ms average
- Attack Detection: < 5ms average
- Concurrent Users: 1000+ simultaneous connections
- Memory Usage: < 100MB typical
- Use connection pooling for external API calls
- Implement caching for frequently accessed data
- Monitor memory usage and implement cleanup
- Use async operations for I/O-bound tasks
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Install development dependencies
pip install -r requirements-dev.txt
# Set up pre-commit hooks
pre-commit install
# Run linting
flake8 app/
black app/This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: Check the API docs at
/api/docs - Issues: Report bugs on GitHub Issues
- Discussions: Join community discussions
If you're getting rate limit errors, adjust the limits in your .env file:
RATE_LIMIT_PER_MINUTE=200
RATE_LIMIT_PER_HOUR=2000Customize detection patterns in app/core/detection.py to reduce false positives.
- Monitor memory usage
- Check external API response times
- Implement caching if needed
- Machine Learning Detection: AI-powered attack detection
- Advanced Analytics: Detailed security insights
- Integration APIs: Webhook support and third-party integrations
- Mobile App: Native mobile dashboard
- Multi-tenant Support: Organization and user management
- v1.0.0: Initial release with core functionality
- v1.1.0: Enhanced detection patterns and performance improvements
- v1.2.0: Advanced analytics and reporting features
Built with ❤️ for the security community
This tool is designed for legitimate security testing purposes only. Always ensure you have proper authorization before testing any APIs.