T09 · Insecure Skill Coding Practices
- Location
scripts/script.sh:48- Finding
Unsafe Archive Extraction May Write Outside the Intended Destination
- Content
View full analysis
[output-dir]}" local outdir="${2:-.}" [ ! -f "$archive" ] && die "File not found: $archive" local compress="" case "$archive" in *.tar.gz|*.tgz) compress="z" ;; *.tar.bz2|*.tbz2) compress="j" ;; *.tar.xz|*.txz) compress="J" ;; *.tar) compress="" ;; esac mkdir -p "$outdir" tar -x${compress}vf "$archive" -C "$outdir" 2>&1 | while IFS= read -r line; do echo " - $line" done ``` ### Technical Analysis The extraction command processes every archive entry without first validating member names or symbolic and hard-link targets. A malicious archive may contain absolute paths, parent-directory traversal components such as `../`, or links that redirect subsequent writes outside the selected output directory. Some `tar` implementations and versions provide partial default protections, but the script does not explicitly enforce or verify those protections. It therefore treats implementation-dependent behavior as a security boundary and provides no post-extraction containment check. ### Attack Path 1. An attacker constructs an archive containing traversal paths, absolute paths, or entries associated with unsafe symbolic or hard links. 2. The attacker convinces a user or agent to process the archive with: ```bash scripts/script.sh extract malicious.tar output ``` 3. `cmd_extract` creates the destination and passes the unvalidated archive directly to `tar`. 4. If the installed `tar` implementation accepts the crafted entries or link behavior, extraction writes outside `output`. 5. Files accessible to the process can be created or overwritten. ### Impact Assessment Successful exploitation can create o ...[truncated 564 chars]- Remediation
View remediation
