T09 · Insecure Skill Coding Practices
- Location
scripts/share.sh:33- Finding
Predictable Shared Temporary Log Exposes the Bearer Token
- Content
View full analysis
/tmp/share-$PORT.log 2>&1 & PID=$! # Wait for server to start sleep 1 # Extract link from log if [[ -f /tmp/share-$PORT.log ]]; then LINK=$(grep "Link:" /tmp/share-$PORT.log | sed -E 's/^.*Link:[[:space:]]*//') ``` ### Technical Analysis The server writes its output, including the complete token-bearing share URL, to a predictable file named `/tmp/share-.log`. The port defaults to `8888` and is incremented sequentially when occupied, making the resulting path easy to predict. The script does not create the file securely, enforce restrictive permissions, verify ownership, or reject symbolic links. Shell redirection follows an existing symbolic link. Consequently: - The share token can be exposed to other local users if the caller's umask creates a broadly readable file, as commonly occurs with a `022` umask. - A local attacker may pre-create a file at the predictable path and monitor it if the server process can write to it. - A local attacker may pre-create a symbolic link and cause the shell redirection to overwrite or append to another file writable by the invoking user. - Token-bearing logs remain in `/tmp` after the link is returned. The token is the primary authorization credential for accessing the shared file. Disclosure therefore allows an attacker who can reach the service from an accepted local or RFC1918 address to download the file. ### Attack Path 1. The attacker predicts that the script will use port `8888`, or identifies the sequentially selected port. 2. The attacker monitors or pre-creates `/tmp/share-8888.log`; alternatively, the attacker places a symbolic link at that path. 3. A user invokes `share.sh`. 4. The shell writes the server output, including `http://- Remediation
View remediation
