OS Command Injection in '/lib/un.rb -- Utilities to replace common UNIX commands in Makefiles etc'
The wait_writable utility in Ruby's un.rb library passed filenames to a shell command without sanitising them, so a filename containing shell metacharacters was executed as a command. An attacker able to control a filename could run arbitrary commands in environments that use these Ruby core utilities.
- Triaged in 4 days
- Disclosed after 3 months
If the wait_writable command receives a list of files with a command in the name of one of them, it will be executed.
PoC
$ touch \|\ touch\ evil.txt
$ ls
'| touch evil.txt'
$ ruby -run -e wait_writable -- -w 1 -v *
$ ls
evil.txt '| touch evil.txt'
The vulnerability has the same severity as https://hackerone.com/reports/651518 . The fix, respectively, is the same: open -> File.open.
Impact
An attacker can use this problem to execute arbitrary commands in environments that uses ruby coreutilities.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the utility passed user-controlled filenames into a shell invocation (via `open`) instead of using `File.open`, so shell metacharacters in a filename were interpreted as commands.
Impact
An attacker could execute arbitrary commands in environments that use Ruby core utilities, though this depends on being able to place a crafted filename where the utility will process it.
What the attacker needed
Ability to control a filename processed by the utility; utility run with a wildcard or crafted argument
How it was found
- Create a file whose name contains a pipe followed by a command.
- List the directory to confirm the file exists.
- Run the wait_writable utility with a wildcard so the crafted filename is passed as an argument.
- List the directory again and observe the extra file created by the executed command.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Some programs build a command line as text and hand it to the operating system to run. If a filename is dropped into that text without being escaped, characters like a pipe can make the system run a second command instead of just naming a file. Here a file whose name contained a pipe caused a separate command to run when the utility was pointed at it.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.