T07 · Tool Hijacking and Spoofing
- Location
scripts/wellness_push.py:33- Finding
Working-Directory-Relative Subprocess Allows Local Tool Hijacking
- Content
View full analysis
str: cmd = [ sys.executable, "scripts/wellness_digest.py", "--date", args.date, "--tz", args.tz, "--render", args.render, "--channel", args.channel, ] for p in args.inputs: cmd += ["--in", p] if args.use_bridge: cmd += ["--use-bridge", "--bridge-dir", args.bridge_dir] if args.out: cmd += ["--out", args.out] res = subprocess.run(cmd, capture_output=True, text=True) ``` ### Technical Analysis The subprocess command identifies `wellness_digest.py` using the relative path `scripts/wellness_digest.py`. Python resolves that path against the caller's current working directory, not against the directory containing the legitimate `wellness_push.py` file. Although list-form invocation avoids shell metacharacter injection, it does not prevent executable or script substitution. If the helper is invoked while the current working directory is controlled by another user, a malicious file at `scripts/wellness_digest.py` will be executed instead of the intended sibling script. ### Attack Path 1. An attacker gains write access to a directory from which the victim may invoke `wellness_push.py`. 2. The attacker creates a malicious `scripts/wellness_digest.py` beneath that directory. 3. The victim invokes the legitimate `wellness_push.py` by absolute path or through an automation while retaining the attacker-controlled directory as the current working directory. 4. `subprocess.run()` resolves `scripts/wellness_digest.py` from that current directory. 5. The malicious Python file executes with the victim's account privileges. ### Impact Assessment Successful exploitation results in arbitrary local c ...[truncated 281 chars]- Remediation
View remediation
