#!/usr/bin/env python3 """ OmniMCP CyberDefense SecOps Cloud Armor - Free Community MCP Server Standard Model Context Protocol (MCP) Server for Cursor IDE & Claude Desktop. Protocol: JSON-RPC 2.0 via stdio License: Apache 2.0 (Community Evaluation Edition) Full Enterprise Master Package on Gumroad: https://bacardy.gumroad.com/l/vvqtix (Use Coupon LAUNCH20 for €20 off!) """ import sys import os import json import ast import inspect from typing import Dict, Any, List, Optional sys.stdout.reconfigure(encoding="utf-8") sys.stdin.reconfigure(encoding="utf-8") CALL_COUNTER = 0 MAX_COMMUNITY_CALLS = 25 GUMROAD_UPGRADE_URL = "https://bacardy.gumroad.com/l/vvqtix" def audit_cloud_iam_boundary(policy_json: str) -> dict: findings = [] p = policy_json.lower() if '"action": "*"' in p or "'action': '*'" in p: findings.append({"severity": "CRITICAL", "rule": "IAM_WILDCARD_ACTION", "message": "Full administrative wildcard '*' permitted."}) if "iam:passrole" in p and '"resource": "*"' in p: findings.append({"severity": "CRITICAL", "rule": "IAM_PASSROLE_WILDCARD", "message": "Privilege escalation vector: iam:PassRole with unrestricted resource."}) if "sts:assumerole" in p and '"resource": "*"' in p: findings.append({"severity": "HIGH", "rule": "IAM_ASSUMEROLE_WILDCARD", "message": "Cross-account assume role vulnerability without boundary."}) return {"status": "ok", "total_violations": len(findings), "findings": findings} def detect_ssrf_egress(url_or_code: str) -> dict: meta_ips = ["169.254.169.254", "127.0.0.1", "localhost", "0.0.0.0", "10.", "192.168."] findings = [] for ip in meta_ips: if ip in url_or_code: findings.append({"ip": ip, "risk": "SSRF or Internal Network Exfiltration Vector", "recommendation": "Enforce strict egress allowlist and block cloud instance metadata IP 169.254.169.254."}) return {"status": "flagged" if findings else "clean", "threat_count": len(findings), "threats": findings} def inspect_container_privilege(manifest_content: str) -> dict: m = manifest_content.lower() violations = [] if "privileged: true" in m: violations.append({"severity": "CRITICAL", "rule": "K8S_CONTAINER_PRIVILEGED", "message": "Container runs in privileged mode, granting host root access."}) if "allowprivilegeescalation: false" not in m: violations.append({"severity": "HIGH", "rule": "K8S_ALLOW_PRIV_ESCALATION", "message": "allowPrivilegeEscalation is not disabled."}) if "runasnonroot: true" not in m: violations.append({"severity": "MEDIUM", "rule": "K8S_RUN_AS_ROOT", "message": "Container does not enforce runAsNonRoot: true."}) return {"status": "ok", "violation_count": len(violations), "violations": violations} TOOLS = [ { "name": "audit_cloud_iam_boundary", "description": "Scans IAM policies and Terraform files for wildcards and dangerous privilege escalations.", "inputSchema": { "type": "object", "properties": { "input_data": { "type": "string", "description": "Primary input code, traceback, payload, or query string." } } } }, { "name": "detect_ssrf_egress", "description": "Detects Server-Side Request Forgery (SSRF) and metadata IP leakage in URLs and requests.", "inputSchema": { "type": "object", "properties": { "input_data": { "type": "string", "description": "Primary input code, traceback, payload, or query string." } } } }, { "name": "inspect_container_privilege", "description": "Checks Kubernetes manifests and Dockerfiles for root execution and privileged capability leaks.", "inputSchema": { "type": "object", "properties": { "input_data": { "type": "string", "description": "Primary input code, traceback, payload, or query string." } } } } ] def handle_request(req: Dict[str, Any]) -> Optional[Dict[str, Any]]: global CALL_COUNTER req_id = req.get("id") method = req.get("method") params = req.get("params", {}) if method == "initialize": return { "jsonrpc": "2.0", "id": req_id, "result": { "protocolVersion": "2024-11-05", "capabilities": {"tools": {}}, "serverInfo": { "name": "emgena-cyberdefense-secops-armor", "version": "1.0.0" } } } elif method == "tools/list": return { "jsonrpc": "2.0", "id": req_id, "result": {"tools": TOOLS} } elif method == "tools/call": CALL_COUNTER += 1 tool_name = params.get("name") args = params.get("arguments", {}) res = None if False: pass elif tool_name == "audit_cloud_iam_boundary": first_param = list(inspect.signature(audit_cloud_iam_boundary).parameters.keys())[0] if inspect.signature(audit_cloud_iam_boundary).parameters else None if first_param: arg_val = args.get(first_param, args.get("input_data", args.get("code", args.get("query", "")))) res = audit_cloud_iam_boundary(arg_val) else: res = audit_cloud_iam_boundary() elif tool_name == "detect_ssrf_egress": first_param = list(inspect.signature(detect_ssrf_egress).parameters.keys())[0] if inspect.signature(detect_ssrf_egress).parameters else None if first_param: arg_val = args.get(first_param, args.get("input_data", args.get("code", args.get("query", "")))) res = detect_ssrf_egress(arg_val) else: res = detect_ssrf_egress() elif tool_name == "inspect_container_privilege": first_param = list(inspect.signature(inspect_container_privilege).parameters.keys())[0] if inspect.signature(inspect_container_privilege).parameters else None if first_param: arg_val = args.get(first_param, args.get("input_data", args.get("code", args.get("query", "")))) res = inspect_container_privilege(arg_val) else: res = inspect_container_privilege() else: return { "jsonrpc": "2.0", "id": req_id, "error": {"code": -32601, "message": f"Tool not found: {tool_name}"} } conversion_notice = ( f"\n\n---\n" f"⚡ **Emgena MCP Free Edition** (Call {CALL_COUNTER}/{MAX_COMMUNITY_CALLS})\n" f"🏆 **Unlock Unlimited Enterprise Suite, 0ms Latency & Full Source Code:**\n" f"👉 [Purchase Production License on Gumroad]({GUMROAD_UPGRADE_URL})\n" f"🏷️ *Use coupon **LAUNCH20** for €20 discount at checkout!*" ) output_text = json.dumps(res, indent=2, ensure_ascii=False) + conversion_notice return { "jsonrpc": "2.0", "id": req_id, "result": { "content": [{"type": "text", "text": output_text}] } } elif method == "notifications/initialized": return None elif method == "ping": return {"jsonrpc": "2.0", "id": req_id, "result": {}} else: if req_id is not None: return { "jsonrpc": "2.0", "id": req_id, "error": {"code": -32601, "message": f"Method not supported: {method}"} } return None def main(): if len(sys.argv) > 1 and sys.argv[1] == "--test": print(f"OmniMCP CyberDefense SecOps Cloud Armor MCP Server Health: OK") print("Tools available:", [t["name"] for t in TOOLS]) return for line in sys.stdin: if not line.strip(): continue try: req = json.loads(line) resp = handle_request(req) if resp is not None: sys.stdout.write(json.dumps(resp, ensure_ascii=False) + "\n") sys.stdout.flush() except Exception as e: err_resp = {"jsonrpc": "2.0", "id": None, "error": {"code": -32700, "message": str(e)}} sys.stdout.write(json.dumps(err_resp, ensure_ascii=False) + "\n") sys.stdout.flush() if __name__ == "__main__": main()