T09 · Insecure Skill Coding Practices
Error
- Location
- clash-switch.sh:15
- Finding
- Hardcoded Clash Controller Credential<![CDATA[ ## Vulnerability Details **File Location**: `clash-switch.sh:15-17` and `clash-switch.sh:369-375`; duplicated in `clash-switch-v2.sh:16-18` **Vulnerability Type**: Hardcoded secret and credential disclosure **Risk Level**: High ### Vulnerable Code ```bash # 配置变量 CLASH_API="http://127.0.0.1:58871" CLASH_SECRET="6434ff5a-5b0f-4598-99ec-83ca96c77167" PROXY_URL="http://127.0.0.1:7890" ``` The original script also prints the credential in its help output: ```bash 配置: Clash API: ${CLASH_API} 代理地址: ${PROXY_URL} 控制密钥: ${CLASH_SECRET} ``` The enhanced script contains the same embedded credential: ```bash CLASH_API="http://127.0.0.1:58871" CLASH_SECRET="6434ff5a-5b0f-4598-99ec-83ca96c77167" PROXY_URL="http://127.0.0.1:7890" ``` ### Technical Analysis A reusable Clash API bearer credential is embedded directly in two distributed shell scripts. The secret is transmitted in the `Authorization` header when accessing the Clash controller and is additionally disclosed in the original script's help output. Anyone who can read the project files, package contents, shell history, support logs, or help output can recover the credential. If a Clash installation retains this credential and its external controller is reachable, the exposed value can authorize proxy enumeration and routing changes. ### Attack Path 1. An attacker downloads the public package or obtains a local copy of the scripts. 2. The attacker extracts the hardcoded `CLASH_SECRET`. 3. The attacker locates a Clash controller configured with that credential, such as an externally exposed controller or one reachable from the same host or network. 4. The attacker sends authenticated requests to `/proxies` to enumerate proxy groups and nodes. 5. The attacker issues authenticated `PUT` requests to change active proxy selections and influence the victim's network routing. ### Impact Assessment The credential grants the level of control exposed by the Clash external-controller API. Confirmed scr ...[truncated 287 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove the embedded credential from both shell scripts and rotate it immediately wherever it has been used. 2. Read the secret from `CLASH_SECRET` or a dedicated configuration file rather than source code. 3. If a configuration file is used, require ownership by the executing user and permissions no broader than `0600`. 4. Remove the secret from all help, status, diagnostic, and log output. 5. Prevent accidental commits with secret-scanning hooks and CI checks. 6. Bind the Clash controller to loopback unless remote administration is explicitly required. 7. Use a unique credential per installation rather than a shared package-level default. ]]>
