๐ SQLMap MCP Server (FastMCP)
A Model Context Protocol (MCP) server built with FastMCP that exposes SQLMap CLI tools as MCP functions for automated SQL injection testing and database reconnaissance.
๐ Quick Start
This MCP server offers programmatic access to SQLMap's powerful SQL injection testing capabilities through a standardized interface. It's built with FastMCP for simplicity and ease of use, allowing AI assistants and other MCP clients to perform automated security testing, database enumeration, and vulnerability assessment.
โจ Features
Core SQLMap Capabilities Exposed
-
Basic Scanning
- Detect SQL injection based on URLs.
- Configure test levels and perform risk assessment.
- Support multiple injection techniques.
-
Database Enumeration
- Discover and list databases.
- Enumerate tables within databases.
- Enumerate columns within tables.
- Analyze database schemas.
-
Data Retrieval
- Dump table data with filtering options.
- Extract selective columns.
- Support the WHERE clause for targeted queries.
-
System Information
- Retrieve the database banner.
- Identify the current user.
- Detect the current database.
- Enumerate hostnames.
-
Advanced Access
- Access the file system (read files from the database server).
- Execute operating system commands.
- Inject custom payloads.
-
Advanced Options
- Support proxies.
- Integrate with the Tor network.
- Configure custom User - Agents.
- Support multi - threading.
- Configure request timeouts.
๐ฆ Installation
Prerequisites
- Python 3.13+ (as specified in pyproject.toml)
- FastMCP - Automatically installed via dependencies
- SQLMap - Install via your preferred method:
brew install sqlmap
pip install sqlmap
git clone --depth 1 https://github.com/sqlmapproject/sqlmap.git sqlmap-dev
Setup
-
Clone the repository:
git clone <repository-url>
cd sqlmap-mcp
-
Install dependencies:
uv sync
pip install -e .
-
Verify SQLMap installation:
sqlmap --version
๐ป Usage Examples
Basic Usage
Running the Server
python server.py
MCP Client Configuration
Add this server to your MCP client configuration:
{
"mcpServers": {
"sqlmap": {
"command": "python",
"args": ["/path/to/sqlmap-mcp/server.py"],
"env": {}
}
}
}
Advanced Usage
Available Tools
Tool Name |
Description |
Required Parameters |
Optional Parameters |
sqlmap_help |
Show SQLMap help information. |
advanced (boolean) |
None |
sqlmap_scan_url |
Scan a target URL for SQL injection vulnerabilities. |
url (string) |
data (string), cookie (string), level (integer, 1 - 5), risk (integer, 1 - 3), technique (string) |
sqlmap_enumerate_databases |
Enumerate databases on the target. |
url (string) |
data (string), cookie (string) |
sqlmap_enumerate_tables |
Enumerate tables in a specific database. |
url (string), database (string) |
data (string), cookie (string) |
sqlmap_enumerate_columns |
Enumerate columns in a specific table. |
url (string), database (string), table (string) |
data (string), cookie (string) |
sqlmap_dump_table |
Dump data from a specific table. |
url (string), database (string), table (string) |
columns (string), where (string), limit (integer), data (string), cookie (string) |
sqlmap_get_banner |
Retrieve database banner information. |
url (string) |
data (string), cookie (string) |
sqlmap_get_current_user |
Retrieve current database user. |
url (string) |
data (string), cookie (string) |
sqlmap_get_current_db |
Retrieve current database name. |
url (string) |
data (string), cookie (string) |
sqlmap_read_file |
Read a file from the database server file system. |
url (string), file_path (string) |
data (string), cookie (string) |
sqlmap_execute_command |
Execute an operating system command on the database server. |
url (string), command (string) |
data (string), cookie (string) |
sqlmap_advanced_scan |
Perform advanced SQLMap scan with custom options. |
url (string) |
data (string), cookie (string), user_agent (string), proxy (string), tor (boolean), random_agent (boolean), level (integer, 1 - 5), risk (integer, 1 - 3), technique (string), dbms (string), timeout (integer), threads (integer, 1 - 10) |
Example Usage
Basic URL Scan
{
"name": "sqlmap_scan_url",
"arguments": {
"url": "http://example.com/vuln.php?id=1",
"level": 2,
"risk": 2
}
}
Database Enumeration
{
"name": "sqlmap_enumerate_databases",
"arguments": {
"url": "http://example.com/vuln.php?id=1"
}
}
Advanced Scan with Proxy
{
"name": "sqlmap_advanced_scan",
"arguments": {
"url": "http://example.com/vuln.php?id=1",
"proxy": "http://127.0.0.1:8080",
"level": 3,
"risk": 2,
"threads": 5,
"random_agent": true
}
}
๐ Documentation
Security Considerations
โ ๏ธ Important Note
- Legal Compliance: Only use this tool on systems you own or have explicit permission to test.
- Authorization: Ensure you have proper authorization before performing any security testing.
- Environment Isolation: Use in isolated testing environments to prevent unintended access to production systems.
- Data Protection: Be aware that SQLMap can extract sensitive data from databases.
- Rate Limiting: Implement appropriate rate limiting to avoid overwhelming target systems.
- Logging: Monitor and log all activities for audit purposes.
๐ก Usage Tip
- Test Environment: Always test in a controlled, isolated environment first.
- Documentation: Document all testing activities and results.
- Responsible Disclosure: If vulnerabilities are found, follow responsible disclosure practices.
- Access Control: Restrict access to this MCP server to authorized personnel only.
- Monitoring: Implement monitoring to detect unauthorized usage.
Development
Project Structure
sqlmap-mcp/
โโโ server.py # Main FastMCP server implementation
โโโ pyproject.toml # Project configuration and dependencies
โโโ README.md # This file
โโโ .gitignore # Git ignore rules
Adding New Tools
To add new SQLMap functionality with FastMCP:
- Add a new function decorated with
@app.tool()
- Define the function parameters with proper type hints
- Add a docstring describing the tool's purpose
- Implement the SQLMap command execution logic
Example:
@app.tool()
async def my_new_tool(url: str, param: Optional[str] = None) -> str:
"""Description of what this tool does"""
args = ["-u", url]
if param:
args.extend(["--param", param])
result = await sqlmap_executor.execute_sqlmap(args)
return result.output if result.success else f"Error: {result.error}"
Testing
python server.py
Troubleshooting
Common Issues
- SQLMap not found: Ensure SQLMap is installed and accessible in your PATH.
- Permission denied: Check file permissions and ensure proper access rights.
- Timeout errors: Increase timeout values for complex scans.
- Connection issues: Verify network connectivity and proxy settings.
Debug Mode
Enable debug logging by modifying the server configuration or adding logging statements.
๐ License
This project is licensed under the same license as SQLMap (GPLv2). See the LICENSE file for details.
Acknowledgments
Support
For issues and questions:
- Check the troubleshooting section.
- Review SQLMap documentation.
- Open an issue on the project repository.
โ ๏ธ Important Note
This tool is for educational and authorized security testing purposes only. Users are responsible for ensuring they have proper authorization before using this tool on any system.