Ruby scripting is a powerful tool used by system administrators and developers to automate tasks and streamline processes on Unix-like systems. However, like any software, ruby scripts can be vulnerable to various security issues, which, if exploited, can lead to privilege escalation and unauthorized access.
Practice
YAML Code Execution
Assume the ruby script can be executed as root with sudo rights. If it use the File.read() method and we controll its input, then the script is vulnerable to arbitrary code execution.
sudo-l (root):/usr/bin/rubysample.rb
Check if we have control over the input of the vulnerable function
File.read(โsample.ymlโ)
If we controll some variables passed to this vulnerables functions, we can inject arbitrary code. here is an example of a malicious sammple.yml file passed to the File.read() function: