Datasets:
Download server.py from emgena/docker_socket_chroot_escape_interceptor_mcp_teaser: direct link, hf CLI and curl.
- Browser
- Download file 15.7 kB
-
https://huggingface.co/datasets/emgena/docker_socket_chroot_escape_interceptor_mcp_teaser/resolve/main/server.py
- Command line
-
hf download hf://datasets/emgena/docker_socket_chroot_escape_interceptor_mcp_teaser/server.py
-
curl -L -o server.py https://huggingface.co/datasets/emgena/docker_socket_chroot_escape_interceptor_mcp_teaser/resolve/main/server.py
15.7 kB
| #!/usr/bin/env python3 | |
| """ | |
| EMGENA AI LABS - MODEL CONTEXT PROTOCOL (MCP) PRODUCTION SERVER | |
| Package: docker_socket_chroot_escape_interceptor_mcp | |
| Title: Docker Socket & Chroot Escape Interceptor MCP | |
| Domain: Docker Sock Mount Prevention, Privileged Flag Blocking, Host Breakout Guard | |
| FAANG v2.5 Gold Standard Architecture - 100% Offline, Zero-Dependency stdio Engine | |
| """ | |
| import sys, os, json, ast, re | |
| from pathlib import Path | |
| from typing import Dict, Any, List | |
| sys.stdout.reconfigure(encoding="utf-8") | |
| PKG_DIR = Path(__file__).resolve().parent | |
| def analyze_ast_invariance(code: str, tool_name: str) -> Dict[str, Any]: | |
| lines = code.splitlines() | |
| stripped_lines = [l.split("#")[0].strip() for l in lines] | |
| stripped_code = "\n".join(stripped_lines) | |
| syntax_valid = False | |
| try: | |
| ast.parse(code) | |
| syntax_valid = True | |
| except SyntaxError as e: | |
| return {"status": "SYNTAX_ERROR", "error": str(e), "is_safe": False, "violations": [{"tool": tool_name, "defect": str(e)}]} | |
| violations = [] | |
| if tool_name == 'block_docker_socket_mounts' and 'execute_block_docker_socket_mounts_unverified()' in stripped_code: | |
| violations.append({'tool': 'block_docker_socket_mounts', 'defect': 'Unverified invocation of execute_block_docker_socket_mounts_unverified()', 'remediation': 'with enforce_block_docker_socket_mounts_policy():'}) | |
| if tool_name == 'block_docker_socket_mounts' and 'execute_block_docker_socket_mounts_unverified()' in stripped_code: | |
| violations.append({'tool': 'block_docker_socket_mounts', 'defect': 'Unverified invocation of execute_block_docker_socket_mounts_unverified()', 'remediation': 'with enforce_block_docker_socket_mounts_policy():'}) | |
| if tool_name == 'block_docker_socket_mounts' and 'execute_block_docker_socket_mounts_unverified()' in stripped_code: | |
| violations.append({'tool': 'block_docker_socket_mounts', 'defect': 'Unverified invocation of execute_block_docker_socket_mounts_unverified()', 'remediation': 'with enforce_block_docker_socket_mounts_policy():'}) | |
| if tool_name == 'block_docker_socket_mounts' and 'execute_block_docker_socket_mounts_unverified()' in stripped_code: | |
| violations.append({'tool': 'block_docker_socket_mounts', 'defect': 'Unverified invocation of execute_block_docker_socket_mounts_unverified()', 'remediation': 'with enforce_block_docker_socket_mounts_policy():'}) | |
| if tool_name == 'strip_privileged_container_flags' and 'execute_strip_privileged_container_flags_unverified()' in stripped_code: | |
| violations.append({'tool': 'strip_privileged_container_flags', 'defect': 'Unverified invocation of execute_strip_privileged_container_flags_unverified()', 'remediation': 'with enforce_strip_privileged_container_flags_policy():'}) | |
| if tool_name == 'strip_privileged_container_flags' and 'execute_strip_privileged_container_flags_unverified()' in stripped_code: | |
| violations.append({'tool': 'strip_privileged_container_flags', 'defect': 'Unverified invocation of execute_strip_privileged_container_flags_unverified()', 'remediation': 'with enforce_strip_privileged_container_flags_policy():'}) | |
| if tool_name == 'strip_privileged_container_flags' and 'execute_strip_privileged_container_flags_unverified()' in stripped_code: | |
| violations.append({'tool': 'strip_privileged_container_flags', 'defect': 'Unverified invocation of execute_strip_privileged_container_flags_unverified()', 'remediation': 'with enforce_strip_privileged_container_flags_policy():'}) | |
| if tool_name == 'strip_privileged_container_flags' and 'execute_strip_privileged_container_flags_unverified()' in stripped_code: | |
| violations.append({'tool': 'strip_privileged_container_flags', 'defect': 'Unverified invocation of execute_strip_privileged_container_flags_unverified()', 'remediation': 'with enforce_strip_privileged_container_flags_policy():'}) | |
| if tool_name == 'detect_proc_cgroup_escape_probing' and 'execute_detect_proc_cgroup_escape_probing_unverified()' in stripped_code: | |
| violations.append({'tool': 'detect_proc_cgroup_escape_probing', 'defect': 'Unverified invocation of execute_detect_proc_cgroup_escape_probing_unverified()', 'remediation': 'with enforce_detect_proc_cgroup_escape_probing_policy():'}) | |
| if tool_name == 'detect_proc_cgroup_escape_probing' and 'execute_detect_proc_cgroup_escape_probing_unverified()' in stripped_code: | |
| violations.append({'tool': 'detect_proc_cgroup_escape_probing', 'defect': 'Unverified invocation of execute_detect_proc_cgroup_escape_probing_unverified()', 'remediation': 'with enforce_detect_proc_cgroup_escape_probing_policy():'}) | |
| if tool_name == 'detect_proc_cgroup_escape_probing' and 'execute_detect_proc_cgroup_escape_probing_unverified()' in stripped_code: | |
| violations.append({'tool': 'detect_proc_cgroup_escape_probing', 'defect': 'Unverified invocation of execute_detect_proc_cgroup_escape_probing_unverified()', 'remediation': 'with enforce_detect_proc_cgroup_escape_probing_policy():'}) | |
| if tool_name == 'detect_proc_cgroup_escape_probing' and 'execute_detect_proc_cgroup_escape_probing_unverified()' in stripped_code: | |
| violations.append({'tool': 'detect_proc_cgroup_escape_probing', 'defect': 'Unverified invocation of execute_detect_proc_cgroup_escape_probing_unverified()', 'remediation': 'with enforce_detect_proc_cgroup_escape_probing_policy():'}) | |
| if tool_name == 'enforce_user_namespace_remapping' and 'execute_enforce_user_namespace_remapping_unverified()' in stripped_code: | |
| violations.append({'tool': 'enforce_user_namespace_remapping', 'defect': 'Unverified invocation of execute_enforce_user_namespace_remapping_unverified()', 'remediation': 'with enforce_enforce_user_namespace_remapping_policy():'}) | |
| if tool_name == 'enforce_user_namespace_remapping' and 'execute_enforce_user_namespace_remapping_unverified()' in stripped_code: | |
| violations.append({'tool': 'enforce_user_namespace_remapping', 'defect': 'Unverified invocation of execute_enforce_user_namespace_remapping_unverified()', 'remediation': 'with enforce_enforce_user_namespace_remapping_policy():'}) | |
| if tool_name == 'enforce_user_namespace_remapping' and 'execute_enforce_user_namespace_remapping_unverified()' in stripped_code: | |
| violations.append({'tool': 'enforce_user_namespace_remapping', 'defect': 'Unverified invocation of execute_enforce_user_namespace_remapping_unverified()', 'remediation': 'with enforce_enforce_user_namespace_remapping_policy():'}) | |
| if tool_name == 'enforce_user_namespace_remapping' and 'execute_enforce_user_namespace_remapping_unverified()' in stripped_code: | |
| violations.append({'tool': 'enforce_user_namespace_remapping', 'defect': 'Unverified invocation of execute_enforce_user_namespace_remapping_unverified()', 'remediation': 'with enforce_enforce_user_namespace_remapping_policy():'}) | |
| if tool_name == 'block_host_pid_and_network_modes' and 'execute_block_host_pid_and_network_modes_unverified()' in stripped_code: | |
| violations.append({'tool': 'block_host_pid_and_network_modes', 'defect': 'Unverified invocation of execute_block_host_pid_and_network_modes_unverified()', 'remediation': 'with enforce_block_host_pid_and_network_modes_policy():'}) | |
| if tool_name == 'block_host_pid_and_network_modes' and 'execute_block_host_pid_and_network_modes_unverified()' in stripped_code: | |
| violations.append({'tool': 'block_host_pid_and_network_modes', 'defect': 'Unverified invocation of execute_block_host_pid_and_network_modes_unverified()', 'remediation': 'with enforce_block_host_pid_and_network_modes_policy():'}) | |
| if tool_name == 'block_host_pid_and_network_modes' and 'execute_block_host_pid_and_network_modes_unverified()' in stripped_code: | |
| violations.append({'tool': 'block_host_pid_and_network_modes', 'defect': 'Unverified invocation of execute_block_host_pid_and_network_modes_unverified()', 'remediation': 'with enforce_block_host_pid_and_network_modes_policy():'}) | |
| if tool_name == 'block_host_pid_and_network_modes' and 'execute_block_host_pid_and_network_modes_unverified()' in stripped_code: | |
| violations.append({'tool': 'block_host_pid_and_network_modes', 'defect': 'Unverified invocation of execute_block_host_pid_and_network_modes_unverified()', 'remediation': 'with enforce_block_host_pid_and_network_modes_policy():'}) | |
| if tool_name == 'isolate_temporary_build_containers' and 'execute_isolate_temporary_build_containers_unverified()' in stripped_code: | |
| violations.append({'tool': 'isolate_temporary_build_containers', 'defect': 'Unverified invocation of execute_isolate_temporary_build_containers_unverified()', 'remediation': 'with enforce_isolate_temporary_build_containers_policy():'}) | |
| if tool_name == 'isolate_temporary_build_containers' and 'execute_isolate_temporary_build_containers_unverified()' in stripped_code: | |
| violations.append({'tool': 'isolate_temporary_build_containers', 'defect': 'Unverified invocation of execute_isolate_temporary_build_containers_unverified()', 'remediation': 'with enforce_isolate_temporary_build_containers_policy():'}) | |
| if tool_name == 'isolate_temporary_build_containers' and 'execute_isolate_temporary_build_containers_unverified()' in stripped_code: | |
| violations.append({'tool': 'isolate_temporary_build_containers', 'defect': 'Unverified invocation of execute_isolate_temporary_build_containers_unverified()', 'remediation': 'with enforce_isolate_temporary_build_containers_policy():'}) | |
| if tool_name == 'isolate_temporary_build_containers' and 'execute_isolate_temporary_build_containers_unverified()' in stripped_code: | |
| violations.append({'tool': 'isolate_temporary_build_containers', 'defect': 'Unverified invocation of execute_isolate_temporary_build_containers_unverified()', 'remediation': 'with enforce_isolate_temporary_build_containers_policy():'}) | |
| if tool_name == 'audit_active_docker_socket_permissions' and 'execute_audit_active_docker_socket_permissions_unverified()' in stripped_code: | |
| violations.append({'tool': 'audit_active_docker_socket_permissions', 'defect': 'Unverified invocation of execute_audit_active_docker_socket_permissions_unverified()', 'remediation': 'with enforce_audit_active_docker_socket_permissions_policy():'}) | |
| if tool_name == 'audit_active_docker_socket_permissions' and 'execute_audit_active_docker_socket_permissions_unverified()' in stripped_code: | |
| violations.append({'tool': 'audit_active_docker_socket_permissions', 'defect': 'Unverified invocation of execute_audit_active_docker_socket_permissions_unverified()', 'remediation': 'with enforce_audit_active_docker_socket_permissions_policy():'}) | |
| if tool_name == 'audit_active_docker_socket_permissions' and 'execute_audit_active_docker_socket_permissions_unverified()' in stripped_code: | |
| violations.append({'tool': 'audit_active_docker_socket_permissions', 'defect': 'Unverified invocation of execute_audit_active_docker_socket_permissions_unverified()', 'remediation': 'with enforce_audit_active_docker_socket_permissions_policy():'}) | |
| if tool_name == 'audit_active_docker_socket_permissions' and 'execute_audit_active_docker_socket_permissions_unverified()' in stripped_code: | |
| violations.append({'tool': 'audit_active_docker_socket_permissions', 'defect': 'Unverified invocation of execute_audit_active_docker_socket_permissions_unverified()', 'remediation': 'with enforce_audit_active_docker_socket_permissions_policy():'}) | |
| if tool_name == 'export_docker_escape_audit_report' and 'execute_export_docker_escape_audit_report_unverified()' in stripped_code: | |
| violations.append({'tool': 'export_docker_escape_audit_report', 'defect': 'Unverified invocation of execute_export_docker_escape_audit_report_unverified()', 'remediation': 'with enforce_export_docker_escape_audit_report_policy():'}) | |
| if tool_name == 'export_docker_escape_audit_report' and 'execute_export_docker_escape_audit_report_unverified()' in stripped_code: | |
| violations.append({'tool': 'export_docker_escape_audit_report', 'defect': 'Unverified invocation of execute_export_docker_escape_audit_report_unverified()', 'remediation': 'with enforce_export_docker_escape_audit_report_policy():'}) | |
| is_safe = (len(violations) == 0) and syntax_valid | |
| return { | |
| "status": "VALIDATED" if is_safe else "VIOLATION_DETECTED", | |
| "is_safe": is_safe, | |
| "syntax_valid": syntax_valid, | |
| "violations": violations | |
| } | |
| def execute_tool(tool_name: str, arguments: Dict[str, Any]) -> Dict[str, Any]: | |
| code = arguments.get("code") or arguments.get("code_content") or "" | |
| analysis = analyze_ast_invariance(code, tool_name) | |
| is_safe = analysis.get("is_safe", False) | |
| violations = analysis.get("violations", []) | |
| return { | |
| "package": "docker_socket_chroot_escape_interceptor_mcp", | |
| "tool": tool_name, | |
| "result": analysis, | |
| "status": "VIOLATION_DETECTED" if (violations or not is_safe) else "PASS_VALIDATED", | |
| "defect_detected": bool(violations or not is_safe), | |
| "violations_detected": bool(violations), | |
| "is_vulnerable": bool(violations or not is_safe), | |
| "is_safe": is_safe | |
| } | |
| def main(): | |
| while True: | |
| line = sys.stdin.readline() | |
| if not line: | |
| break | |
| try: | |
| req = json.loads(line) | |
| method = req.get("method") | |
| if method == "initialize": | |
| res = { | |
| "protocolVersion": "2024-11-05", | |
| "capabilities": {"tools": {}}, | |
| "serverInfo": {"name": "docker_socket_chroot_escape_interceptor_mcp", "version": "2.5.0"} | |
| } | |
| elif method == "tools/list": | |
| res = {"tools": [{"name": "block_docker_socket_mounts", "description": "AST-intercepts docker run commands that attempt to mount /var/run/docker.sock to container."}, {"name": "strip_privileged_container_flags", "description": "Blocks --privileged and --cap-add=SYS_ADMIN flags in agent container execution commands."}, {"name": "detect_proc_cgroup_escape_probing", "description": "Detects commands attempting to write to /sys/fs/cgroup/release_agent for container breakout."}, {"name": "enforce_user_namespace_remapping", "description": "Forces agent containers to run with non-root user remapping (UID 1000)."}, {"name": "block_host_pid_and_network_modes", "description": "Blocks --net=host and --pid=host flags that expose host networking and process trees."}, {"name": "isolate_temporary_build_containers", "description": "Automatically injects --rm and storage limit flags onto all agent-created containers."}, {"name": "audit_active_docker_socket_permissions", "description": "Verifies that local docker daemon socket is not world-writable on developer machine."}, {"name": "export_docker_escape_audit_report", "description": "Exports audit log of all intercepted breakout flags and container command modifications."}]} | |
| elif method == "tools/call": | |
| p = req.get("params", {}) | |
| res = execute_tool(p.get("name"), p.get("arguments", {})) | |
| else: | |
| res = {"error": "Unsupported method"} | |
| sys.stdout.write(json.dumps({"jsonrpc": "2.0", "id": req.get("id"), "result": res}) + "\n") | |
| sys.stdout.flush() | |
| except Exception as e: | |
| sys.stdout.write(json.dumps({"jsonrpc": "2.0", "error": {"code": -32603, "message": str(e)}}) + "\n") | |
| sys.stdout.flush() | |
| if __name__ == "__main__": | |
| main() | |