T09 · Insecure Skill Coding Practices
- Location
SKILL.md:29- Finding
Predictable shared temporary files permit symlink-based file overwrite
- Content
View full analysis
/tmp/net-diag.json ``` Add `--speed` to include a bandwidth test (adds ~20s): ```bash python3 scripts/diagnose.py --speed > /tmp/net-diag.json ``` Skip traceroute or MTU if time-constrained: ```bash python3 scripts/diagnose.py --no-traceroute --no-mtu > /tmp/net-diag.json ``` ### 2. Compare against history (if available) ```bash python3 scripts/history.py --compare /tmp/net-diag.json > /tmp/net-history.json ``` The same predictable history file is subsequently consumed when generating a report: ```bash python3 scripts/report.py /tmp/net-diag.json --history-compare /tmp/net-history.json ``` ### Technical Analysis `/tmp` is normally writable by every local user. Although its sticky bit prevents users from deleting each other's files, it does not prevent an attacker from creating an unused predictable filename before the victim does. Shell output redirection opens the destination while following symbolic links and ordinarily truncates an existing target. The workflow does not securely create the files, verify their ownership or type, use exclusive creation, or place them in a private directory. Consequently, a local attacker can pre-create `/tmp/net-diag.json` or `/tmp/net-history.json` as a symbolic link to another file writable by the victim. The issue is in the documented execution workflow rather than the Python subprocess calls. The flagged `subprocess.run` invocation at `scripts/diagnose.py:42-43` is only a fixed localhost `ping` capability probe and is not a reverse shell. ### Attack Path 1. An attacker with access to the same host predicts that the victim will follow the documented Net Detective wo ...[truncated 1543 chars]- Remediation
View remediation
"$diag_file" python3 scripts/history.py --compare "$diag_file" > "$history_file" python3 scripts/report.py "$diag_file" --history-compare "$history_file" ``` Additional hardening measures: 1. Document that the workflow must not be run with `sudo` or another elevated account. 2. Set a restrictive umask, such as `umask 077`, before creating files containing local network metadata. 3. If scripts gain direct output-file support, create files atomically using exclusive creation and mode `0600`. 4. Validate that any existing destination is a regular file owned by the current user and reject symbolic links. 5. Delete temporary diagnostics promptly after report generation unless the user explicitly chooses to retain them. 6. Prefer a user-private runtime directory, such as `$XDG_RUNTIME_DIR`, when available. ]]>
