T05 · Unauthorized Access and Privilege Escalation
Error
- Location
- scripts/start_server.py:17
- Finding
- Unauthenticated directory server listens on all network interfaces<![CDATA[ ## Vulnerability Details **File Location**: `scripts/start_server.py:17-28, 52-65` **Vulnerability Type**: Public unauthenticated file exposure **Risk Level**: High ### Vulnerable Code ```python parser.add_argument("directory", help="要分享的文件目录路径") parser.add_argument("--port", type=int, default=4000, help="服务器端口(默认: 4000)") parser.add_argument("--daemon", action="store_true", help="后台运行") parser.add_argument("--bind", default="0.0.0.0", help="绑定地址(默认: 0.0.0.0)") args = parser.parse_args() # 检查目录是否存在 if not os.path.isdir(args.directory): print(f"❌ 错误:目录不存在: {args.directory}") sys.exit(1) # 切换到目标目录 os.chdir(args.directory) ``` ```python # 显示下载链接 print("\n📥 下载链接:") print(f" 主页: http://{args.bind}:{args.port}/") print(f" (如果从外部访问,请使用服务器公网IP)") print("="*60) # 构建命令 cmd = [ sys.executable, "-m", "http.server", str(args.port), "--bind", args.bind ] ``` ### Technical Analysis The server uses Python's built-in `http.server` module to expose the selected directory. It binds to `0.0.0.0` by default, making it reachable through every network interface, and it implements no authentication, authorization, expiring links, source-address restrictions, or file allowlist. The only path validation verifies that the supplied path is a directory. It does not reject sensitive locations such as a home directory, workspace root, source repository, configuration directory, or filesystem root. Python's standard directory server also provides directory listings when no index page is present and serves files recursively beneath the selected root. Although public file sharing is the declared purpose of the Skill, public exposure is enabled by default rather than through an explicit opt-in. This violates least-privilege principles and makes an operator path-selection error immediately network-accessible. ### Attack Path 1. An operator invokes the Skill with a directory containing both intended downloads and sensitive files, or mistakenly selects ...[truncated 1029 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Change the default bind address to `127.0.0.1`. 2. Require an explicit option such as `--public` before permitting a non-loopback bind address. 3. Display the resolved directory and require interactive confirmation before public exposure. 4. Reject dangerous sharing roots by default, including `/`, user home directories, workspace roots, and known credential or configuration directories. 5. Copy explicitly selected files into a newly created, restricted staging directory instead of serving an arbitrary existing directory tree. 6. Disable directory listings and expose only an allowlist of intended files. 7. Add authentication or cryptographically random, short-lived download tokens. 8. Support expiration and automatic server shutdown after a configured time or download count. 9. Run the server under a dedicated unprivileged account with access only to staged files. 10. Log access without recording credentials or sensitive query parameters. ]]>
