Imagine the following code:
ATTACKERDATA="$(cat attackerControlledFile.txt)"
echo "${ATTACKERDATA}"
An attacker can, through whatever arbitrary process, modify the contents of attackerControlledFile.txt
to anything they desire. The content can be ASCII, UTF-8, Binary, etc. Anything is fine. The machine also assumes that it is infinitely fast, so even an extremely large file of multiple terrabytes would be read and printed immediately.
Is it possible for an attacker, regardless of how unlikely it would be, to exploit this somehow by modifying the content of attackerControlledFile.txt
? "Somehow" refers to things like:
- This code only works in
bash
- This code requires the output to be printed onto a specific terminal emulator
- Etc.
Everything else assumes a reasonably sane system. This means that answers such as "If echo
is an attacker-controlled binary that's actually malware" does not count, as the existence of malware is not exactly "reasonably sane". Answers that would require a specific software or version of that software to be present do count, as long as that software was not made for the purpose of exploitation.
A similar question asks Is it possible to use the Linux “echo” command maliciously?, but the accepted answer is actually about a flaw in the design of a web application. Furthermore, it requires the attacker to be able to do redirects, which as far as I know, this construct cannot do.