-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpentest_mcp.py
More file actions
42 lines (33 loc) · 1.48 KB
/
pentest_mcp.py
File metadata and controls
42 lines (33 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from mcp.server.fastmcp import FastMCP, Context
import logging
from tools.nmap import run_nmap
from tools.gobuster import run_gobuster
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger("security-tools-mcp")
# Create MCP server
mcp = FastMCP("PentestMCP")
# Register tools
mcp.tool()(run_nmap)
mcp.tool()(run_gobuster)
def validate_input(input_str: str) -> bool:
"""Basic validation to help prevent command injection"""
# Disallow dangerous characters
dangerous_chars = [';', '&', '|', '>', '<', '`', '$', '(', ')', '{', '}', '\\']
return not any(char in input_str for char in dangerous_chars)
def validate_options(options: str) -> bool:
"""Validate command-line options"""
# Disallow dangerous characters
dangerous_chars = [';', '&', '|', '>', '<', '`', '$', '(', ')', '{', '}', '\\']
return not any(char in options for char in dangerous_chars)
def validate_wordlist(wordlist: str) -> bool:
"""Validate wordlist path"""
# Only allow wordlists in specific directories
allowed_prefixes = ["/usr/share/wordlists/", "/opt/wordlists/"]
dangerous_chars = [';', '&', '|', '>', '<', '`', '$', '(', ')', '{', '}', '\\']
return (
any(wordlist.startswith(prefix) for prefix in allowed_prefixes) and
not any(char in wordlist for char in dangerous_chars)
)
if __name__ == "__main__":
logger.info("Starting Pentest MCP Server")
mcp.run(transport='stdio')