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.
attackerControlledFile.txtalways be a regular file? If it can be changed to a symlink or FIFO then there's a fairly straightforward DOS involving/dev/urand, which would also probably cripple any cryptographic code that an application on the same box might run. I'll type this up into a "proper" answer if it can be a symlink, but if not then I won't bother. – ymbirtt Jun 07 '19 at 08:47catcommand and subprocess would terminate because the shell's buffer would fill up very quickly. The subsequentechowould do nothing because it would be operating on an empty string, not a string with an infinite (or even non-zero) size. – forest Jun 08 '19 at 03:10attackerControlledFile.txtis a plain text document that describes (alleged) evidence that someone high up in the company is diddling IT Guy's wife, with the intent of creating strife that will lead to IT Guy quitting and opening a job position that Attacker can then apply for? (You did say something about "regardless of how unlikely it would be" =P) – Steve-O Jun 09 '19 at 14:30