T09 · Insecure Skill Coding Practices
- Location
scripts/script.sh:220- Finding
User-Controlled Log Path Permits Path Traversal and Symlink-Directed Writes
- Content
View full analysis
/dev/null | awk -v pat="$name" 'NR>1 && $6 ~ pat') echo "[$ts] process=$name matches=$count" >> "$logfile" if [[ $count -gt 0 ]]; then echo "$entries" >> "$logfile" ``` ### Technical Analysis The `log` command accepts a process name from the command line and inserts it directly into a filesystem path: ```bash local logfile="$LOG_DIR/${name}.log" ``` Although shell quoting prevents command substitution and shell metacharacter injection, it does not prevent path traversal. The value is not checked for path separators, `..` components, absolute-path behavior, or other unsafe pathname content. A crafted process name can therefore cause the resolved log destination to leave `~/.procmon`, subject to the automatically appended `.log` suffix. The subsequent `>>` redirections also follow symbolic links. If an attacker can create or replace a predictable entry such as `~/.procmon/node.log` with a symlink, invoking `procmon log node` appends data to the symlink target. The code does not verify that the destination is a regular file, that it is not a symbolic link, or that its canonical path remains inside the intended log directory. ### Attack Path A path-traversal exploitation path is: 1. An attacker influences the argument passed to `procmon log`, such as by supplying a name containing `../` path components. 2. ProcMon constructs `"$HOME/.procmon/${name}.log"` without validating or canonicalizing the name. 3. Filesystem path resol ...[truncated 1616 chars]- Remediation
View remediation
