Potential command injection in `Shell#[]` and `Shell#test`
The Ruby Shell class's bracket and test methods passed the supplied name to send after converting it to an absolute path, so a crafted value could reach a private method such as system and run a shell command. An attacker who could control that argument could execute commands on the host.
- Disclosed after 19 months
As Shell#test and Shell#[] use send when transferring to FileTest, private methods etc. can also be called. Therefore, command injection is possible when a crafted value is passed.
$ irb
irb(main):001:0> `ls xy`
ls: xy: No such file or directory
=> ""
irb(main):002:0> require 'shell'
=> true
irb(main):003:0> sh = Shell.new
=> #<Shell:0x00007fc0c20f2a78>
irb(main):004:0> sh['system', '$(touch xy)']
sh: /private/tmp/: is a directory
=> false
irb(main):005:0> `ls xy`
=> "xy\n"
Since send is executed after the file path is converted to absolute path, it is difficult with instance_eval and open etc, but you can execute it using a subshell.
Impact
It seems almost unlikely that user input is given for the purpose, so it probably will not be affected in most cases. It may be feasible under complex conditions such as combining object injection and other problems.
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 use of send with an attacker-influenced method name and argument, after only converting the path to an absolute path, allowed private methods such as system to be invoked.
Impact
Command execution is possible, but the reporter considers it unlikely that user input reaches this path, so most applications are probably not affected; it may be feasible only in complex conditions such as combined with object injection.
What the attacker needed
Attacker controls the argument to Shell#[] or Shell#test; often needs another flaw such as object injection
How it was found
- Start an interactive Ruby session and confirm a file does not exist.
- Load the shell library and create a Shell instance.
- Call the bracket method with a method name and a crafted value containing a subshell command.
- Check that the file was created, showing the command ran.
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.
A Ruby library method that checks files was forwarding whatever name it was given to another internal method without checking it. Because that forwarding could reach a method that runs shell commands, a specially crafted name could make the program run a command the author never intended. The reporter notes this is hard to reach in practice because the value is normally not user input.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.