T07 · Tool Hijacking and Spoofing
Error
- Location
- SKILL.md:139
- Finding
- Predictable Shared Temporary Executable Allows Local Tool Hijacking## Vulnerability Details **File Location**: `SKILL.md`, lines 139–170 **Vulnerability Type**: Predictable executable path and unsafe temporary-file handling **Risk Level**: High ### Vulnerable Code ```bash # Test if Screen Recording permission is granted (background screenshot available) /tmp/safari_wid 2>/dev/null && echo "BACKGROUND_SCREENSHOT=true" || echo "BACKGROUND_SCREENSHOT=false" # Compile the helper once per session (if not already compiled) if [ ! -f /tmp/safari_wid ]; then cat > /tmp/safari_wid.swift << 'SWIFT' import CoreGraphics import Foundation let options: CGWindowListOption = [.optionOnScreenOnly, .excludeDesktopElements] guard let windowList = CGWindowListCopyWindowInfo(options, kCGNullWindowID) as? [[String: Any]] else { exit(1) } for window in windowList { guard let owner = window[kCGWindowOwnerName as String] as? String, owner == "Safari", let layer = window[kCGWindowLayer as String] as? Int, layer == 0, let wid = window[kCGWindowNumber as String] as? Int else { continue } print(wid) exit(0) } exit(1) SWIFT swiftc /tmp/safari_wid.swift -o /tmp/safari_wid fi # Capture Safari window in background (no activation needed) WID=$(/tmp/safari_wid) screencapture -l "$WID" -o -x /tmp/safari_screenshot.png ``` ### Technical Analysis The documented workflow creates, caches, and executes a helper using the globally predictable path `/tmp/safari_wid`. More critically, it executes that path before validating or compiling it. The later check only verifies whether the path is a regular file: ```bash if [ ! -f /tmp/safari_wid ]; then ``` It does not verify that the file was created by the current process, is owned by the current user, has safe permissions, contains the expected program, or is not controlled by another local process. If a malicious executable already exists at that path, compilation is skipped and the untrusted file is executed both during capability detection and while obtaining th ...[truncated 1517 chars]
- Remediation
- ## Remediation Suggestions 1. Create a unique private working directory rather than using fixed paths: ```bash WORKDIR=$(mktemp -d "${TMPDIR:-/tmp}/safari-control.XXXXXX") || exit 1 chmod 700 "$WORKDIR" trap 'rm -rf "$WORKDIR"' EXIT HUP INT TERM SOURCE="$WORKDIR/safari_wid.swift" HELPER="$WORKDIR/safari_wid" SCREENSHOT="$WORKDIR/safari_screenshot.png" ``` 2. Compile and execute only the helper created during the current run. Do not treat a preexisting executable as a trusted cache. 3. Use restrictive permissions and a restrictive `umask`, such as `umask 077`, before creating files. 4. If caching is required, place the helper in a user-owned private cache directory and validate its ownership, permissions, file type, and cryptographic hash before execution. 5. Reject symbolic links and avoid check-then-use logic. Open or create files atomically where possible. 6. Store screenshots under the private working directory instead of the predictable `/tmp/safari_screenshot.png` path. 7. Ensure cleanup occurs through a shell `trap`, including on interruption or failure.
