Skip to main content
Glama
Kali Linux MCP Server

Kali Linux MCP Server

by taguianas
README.md
# šŸ”“ Kali Linux MCP Server

**Run professional penetration testing tools through natural language using AI.**

A Docker-based MCP (Model Context Protocol) server that wraps Kali Linux security tools and exposes them to AI clients like Claude Code, Cursor, and any MCP-compatible application. Simply ask "scan this target for open ports" and let AI handle the rest.

[![Docker](https://img.shields.io/badge/Docker-Containerized-2496ED?logo=docker&logoColor=white)](https://www.docker.com/)
[![MCP](https://img.shields.io/badge/MCP-Protocol-00A67E?logo=anthropic&logoColor=white)](https://modelcontextprotocol.io/)
[![Kali Linux](https://img.shields.io/badge/Kali_Linux-Security-557C94?logo=kalilinux&logoColor=white)](https://www.kali.org/)
[![Python](https://img.shields.io/badge/Python-3.11+-3776AB?logo=python&logoColor=white)](https://python.org/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

---

## Overview

This project bridges the gap between AI assistants and real security tools. Instead of switching between terminals, remembering complex command flags, and manually parsing scan output, you simply describe what you want in plain English and the AI executes professional-grade security tools on your behalf.

Built with FastMCP 3.x and running inside a Kali Linux Docker container, the server exposes 18+ security tools as MCP endpoints that any compatible AI client can call.

## Demo

> **You:** "Scan scanme.nmap.org for open ports"
>
> **Claude Code:** *Calls nmap_scan tool with target "scanme.nmap.org"*
>
> **Result:**

| Port | State | Service |
|------|-------|---------|
| 22/tcp | Open | SSH |
| 53/tcp | Open | DNS |
| 80/tcp | Open | HTTP |
| 9929/tcp | Open | Nping Echo |
| 31337/tcp | Open | Elite |

*5 open ports found on scanme.nmap.org (45.33.32.156) in 4.27 seconds*

## Features

**18+ Security Tools** wrapped as MCP endpoints, organized by category:

**Network Scanning** : nmap full scan, quick scan (top 100 ports), vulnerability scan with NSE scripts, OS detection

**Web Application Testing** : Nikto web server scanner, Dirb directory brute-forcer, WPScan for WordPress vulnerability detection and enumeration

**SQL Injection** : SQLMap automated detection and database dumping

**Exploit Research** : SearchSploit for querying the Exploit Database, with detailed exploit viewing

**Reconnaissance** : WHOIS lookups, DNS record queries via dig, banner grabbing with netcat, SMB enumeration with enum4linux

**Password Testing** : Hydra brute-force testing for SSH, FTP, HTTP and other services

**Meta** : Built-in tool listing with descriptions for all available tools

## Architecture

```
+------------------+         HTTP (Streamable)         +------------------------+
|                  |  --------------------------------> |                        |
|   AI Client      |    MCP Protocol over HTTP         |   Docker Container     |
|                  |    POST /mcp                      |   (Kali Linux)         |
|  - Claude Code   |  <-------------------------------- |                        |
|  - Cursor        |         JSON-RPC 2.0              |  +------------------+  |
|  - Any MCP       |                                   |  | FastMCP Server   |  |
|    Client        |                                   |  | (Python 3.11)    |  |
|                  |                                   |  +--------+---------+  |
+------------------+                                   |           |            |
                                                       |  +--------v---------+  |
                                                       |  | Security Tools   |  |
                                                       |  |                  |  |
                                                       |  | nmap   nikto     |  |
                                                       |  | sqlmap  dirb     |  |
                                                       |  | wpscan  hydra    |  |
                                                       |  | searchsploit     |  |
                                                       |  | whois  dig  nc   |  |
                                                       |  | enum4linux       |  |
                                                       |  +------------------+  |
                                                       +------------------------+
                                                           Port 8000 (SSE/HTTP)
```

**How it works:**

1. The AI client sends a natural language request (e.g., "scan this target")
2. The AI interprets the request and calls the appropriate MCP tool with parameters
3. The FastMCP server receives the JSON-RPC call and dispatches it to the corresponding Python function
4. The Python function sanitizes input, executes the Kali Linux tool via subprocess, and captures the output
5. Results are returned through the MCP protocol back to the AI client
6. The AI formats and presents the results in a readable way

## Project Structure

```
kali-mcp-server/
ā”œā”€ā”€ kali_server.py              # Main MCP server with all tool definitions
ā”œā”€ā”€ run_sse.py                  # SSE/HTTP transport launcher
ā”œā”€ā”€ Dockerfile                  # Kali Linux container with all tools installed
ā”œā”€ā”€ requirements.txt            # Python dependencies (FastMCP, MCP SDK)
ā”œā”€ā”€ custom.yaml                 # Docker MCP Toolkit catalog configuration
ā”œā”€ā”€ claude_desktop_config.json  # Claude Desktop configuration template
ā”œā”€ā”€ .mcp.json                   # Claude Code project-level MCP config
ā”œā”€ā”€ README.md                   # This file
└── LICENSE                     # MIT License
```

## Prerequisites

Before you begin, make sure you have:

- **Docker Desktop** installed and running ([download here](https://docs.docker.com/desktop/))
- **An MCP-compatible AI client** such as Claude Code, Cursor, or any client supporting the MCP protocol
- **Git** for cloning the repository

## Installation

### Step 1: Clone the repository

```bash
git clone https://github.com/taguianas/kali-mcp-server.git
cd kali-mcp-server
```

### Step 2: Build the Docker image

```bash
docker build -t kali-mcp-server .
```

This pulls the official Kali Linux rolling image and installs all security tools. The build takes a few minutes on the first run.

### Step 3: Run the MCP server

```bash
docker run -d \
  --name kali-mcp \
  --privileged \
  --user root \
  -p 8000:8000 \
  kali-mcp-server
```

The `--privileged` flag is required because tools like nmap need raw socket access for SYN scans, OS detection, and other low-level network operations.

### Step 4: Verify the server is running

```bash
# Check the container is up
docker ps | grep kali

# Check the logs
docker logs kali-mcp

# You should see:
# INFO: Uvicorn running on http://0.0.0.0:8000
```

### Step 5: Test the MCP endpoint

```bash
curl -s -X POST http://localhost:8000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}'
```

You should receive a JSON response containing the server capabilities and tool list.

## Connecting to AI Clients

### Claude Code (CLI)

```bash
claude mcp add -s user --transport http kali-linux http://localhost:8000/mcp
```

Verify the connection:

```bash
claude mcp list
# Should show: kali-linux: http://localhost:8000/mcp (HTTP) - Connected
```

### Claude Code (Desktop App)

Create a `.mcp.json` file in your project directory:

```json
{
  "mcpServers": {
    "kali-linux": {
      "type": "http",
      "url": "http://localhost:8000/mcp"
    }
  }
}
```

Then start a new session in the Claude Code desktop app.

### Cursor IDE

Add to your Cursor MCP settings (`~/.cursor/mcp.json`):

```json
{
  "mcpServers": {
    "kali-linux": {
      "transport": "http",
      "url": "http://localhost:8000/mcp"
    }
  }
}
```

### Any MCP Client

The server exposes a standard MCP endpoint at `http://localhost:8000/mcp` using the Streamable HTTP transport. Any client supporting MCP over HTTP can connect.

## Usage Examples

Once connected to your AI client, just ask in natural language:

| What you say | What happens |
|---|---|
| "Scan scanme.nmap.org for open ports" | Runs `nmap -F -T4 scanme.nmap.org` |
| "Run a vulnerability scan on 10.0.0.5" | Runs `nmap -sV --script=vuln 10.0.0.5` |
| "Detect the OS on 192.168.1.1" | Runs `nmap -O -sV 192.168.1.1` |
| "Scan this web server with nikto: http://target.com" | Runs `nikto -h http://target.com` |
| "Find hidden directories on http://target.com" | Runs `dirb http://target.com` |
| "Check this WordPress site for vulnerable plugins" | Runs `wpscan --url http://target.com --enumerate vp` |
| "Test http://target.com/page?id=1 for SQL injection" | Runs `sqlmap -u <url> --batch` |
| "Search for Apache 2.4 exploits" | Runs `searchsploit apache 2.4` |
| "Do a WHOIS lookup on google.com" | Runs `whois google.com` |
| "Get DNS records for example.com" | Runs `dig example.com ANY` |
| "List all available tools" | Shows the complete tool catalog |

## Managing the Server

```bash
# Start the server
docker start kali-mcp

# Stop the server
docker stop kali-mcp

# Restart the server
docker restart kali-mcp

# View logs
docker logs kali-mcp --tail 50

# Remove and recreate
docker rm -f kali-mcp
docker run -d --name kali-mcp --privileged --user root -p 8000:8000 kali-mcp-server
```

## Security Considerations

**Input Sanitization:** All user inputs are sanitized before being passed to system commands. The `sanitize_input()` function strips dangerous shell metacharacters including `;`, `&`, `|`, backticks, `$`, parentheses, braces, redirects, and newlines. This prevents command injection attacks through the MCP interface.

**Parameter Validation:** Each tool validates its required parameters and returns clear error messages when inputs are missing or invalid.

**Authorized Use Only:** This tool must only be used against systems you own or have explicit written authorization to test.

## Tech Stack

| Component | Technology |
|---|---|
| Base Image | Kali Linux Rolling |
| MCP Framework | FastMCP 3.1.x |
| MCP SDK | mcp 1.26.x |
| HTTP Server | Uvicorn |
| Language | Python 3.11+ |
| Container | Docker |
| Transport | Streamable HTTP (MCP) |

## Legal Disclaimer

This tool is provided for **educational and authorized security testing purposes only**. You must only use these tools against systems that you own or have explicit written permission to test. Unauthorized access to computer systems is illegal under laws including the Computer Fraud and Abuse Act (CFAA), the EU Directive on Attacks Against Information Systems, and applicable national legislation.

The authors are not responsible for any misuse or damage caused by this software.

## Contributing

Contributions are welcome! Feel free to:

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/new-tool`)
3. Add your changes
4. Submit a Pull Request

Ideas for contributions: adding new tools (Gobuster, Masscan, Metasploit integration), adding output formatters, adding authentication for the MCP endpoint, or creating a web dashboard.

## Author

**Anas TAGUI**

- GitHub: [@taguianas](https://github.com/taguianas)

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

## Acknowledgments

- [NetworkChuck](https://www.youtube.com/@NetworkChuck) for the Docker MCP tutorial that inspired this project
- [Anthropic](https://anthropic.com) for the Model Context Protocol
- [Docker](https://docker.com) for the containerization platform
- [Kali Linux](https://kali.org) for the security tools distribution
- The open-source security community for the individual tools (nmap, nikto, sqlmap, etc.)