schollz/croc path traversal
Description
A malicious sender can delete arbitrary files (and empty directories) on a receiver's machine (anywhere the receiving user has permission ofc) by sending a file named croc-marked-files.txt. croc uses that exact filename in the current working directory as its internal "delete these temp files on exit" list, and deletes every path it contains without any validation. Because a received file with that name lands in the receiver's working directory (the default receive location), the incoming file becomes the deletion list, and its contents are fully attacker-controlled. Deletion runs automatically when the transfer completes and also on Ctrl-C.
Details
Two functions in src/utils/utils.go implement a cleanup mechanism for temporary files:
const crocRemovalFile = "croc-marked-files.txt"a fixed, relative path resolved against the current working directory.RemoveMarkedFiles()opens that file and runsos.Remove(line)for every line, with no path validation and no confinement to the working directory, so absolute paths and../traversal are honored.
RemoveMarkedFiles() is invoked on normal exit (main.go:45) and on SIGINT/Ctrl-C (main.go:51) after any receive.
The receiver writes incoming top-level files into the current working directory (FolderRemote = "./"), and the name croc-marked-files.txt passes utils.ValidFileName (it is an ordinary basename with no separators).
As a result, a sender who sends a file named croc-marked-files.txt whose contents are a newline-separated list of victim paths causes those paths to be deleted on the receiver when croc exits.
Relevant code:
src/utils/utils.go:crocRemovalFile,MarkFileForRemoval,RemoveMarkedFilesmain.go:45andmain.go:51: cleanup invocation- receive path writes top-level files to the CWD
The paths are taken verbatim from attacker-controlled file content, so this is External Control of File Name or Path used in a delete operation, combined with Path Traversal (absolute / ../).
PoC
Using a local relay (nothing leaves the machine). On UNIX the code phrase is passed via CROC_SECRET.
- Attacker crafts and sends the payload:
mkdir -p /tmp/attacker && cd /tmp/attacker
printf 'secret.txt\n../victim-sibling.txt\n/tmp/absolute-target.txt\n' > croc-marked-files.txt
croc send croc-marked-files.txt- Victim receives into a directory containing valuable files:
mkdir -p /tmp/victim && cd /tmp/victim
echo A > secret.txt # relative (CWD)
echo B > /tmp/victim-sibling.txt # wait: place at ../ target
echo C > /tmp/absolute-target.txt # absolute
CROC_SECRET=<SECRET> croc --yes- On completion,
secret.txt, the../target, and the absolute-path target
are all deleted. The same occurs if the receiver presses Ctrl-C after the file has arrived.
Verified: CWD-relative, ../ traversal (escapes the receive directory), and absolute paths all delete; deletion is attributable solely to the receiver.
Impact
A peer you are receiving from can delete arbitrary files and empty directories owned by the receiving user (e.g. ~/.ssh/authorized_keys, dotfiles, documents, project files). It triggers on normal completion (silently with --yes)
This far exceeds the expected "receive a file into this folder" trust boundary.
Impact escalation -> Remote Code Execution (The Arbitrary File Deletion vulnerability can be chained)
The same primitive (a sender fully controls the basename, dotfiles included, and content of files written into the receive directory) escalates to code execution when the victim receives into their home directory:
- Bypass the overwrite prompt (uses the deletion bug above). Transfer 1 sends
croc-marked-files.txtwhose contents list the victim's existing shell-init file (e.g..bashrc). On exit,RemoveMarkedFiles()deletes it.
<img width="1546" height="292" alt="image" src="github.com/
- Plant a malicious init file. Transfer 2 sends a file named
.bashrcBecause the original was deleted, no overwrite prompt will fire
<img width="1436" height="364" alt="image" src="github.com/
- Dilevery : The victim runs
CROC_SECRET=<SECRET> croc … --yestwice ( the first transfer (croc-marked-files.txt) deletes~/.bashrcon exit, and the second writes the attacker's malicious~/.bashrcwith no overwrite prompt.
<img width="1570" height="368" alt="image" src="github.com/
- Execution. The attacker's code runs as the victim on the next shell / login (for a server, on the next SSH login).
<img width="1438" height="238" alt="image" src="github.com/
Important: the victim must run croc from $HOME so its .bashrc gets replaced (received writes are confined to the working-directory subtree; the delete is not confined and accepts absolute/.. paths), two transfers must be accepted (silent with --yes; otherwise the filenames appear in the accept prompt)