219 words
1 minute
Ignite CTF 2023 Writeup - Nghinx

This machine CTF demonstrates how LFI and misconfiguration in the default Nginx config can lead to machine or even account takeover.


Challenge Details#

  • Challenge Name: Nghinx
  • Challenge Type: Machine
  • Difficulty: Medium
  • Points: 100
  • Description:
    “We never been hacked, we probably have the most secure app so far.”

Initial Enumeration#

When accessing the machine URL, we’re greeted with a blog homepage:

blog-page

Clicking on “My first blog” redirects us to a .txt file, which throws an error:

error-page

Let’s try removing the path from the redirection and access /etc/passwd:

etc-passwd

We get a readable response. Attempting /etc/shadow fails due to permission issues:

permission-error

Nginx Configuration Enumeration#

Given the challenge name, we suspect this is running Nginx. Trying to access /etc/nginx/nginx.conf doesn’t help:

config-file

However, reading /etc/nginx/sites-available/default gives us valuable information:

default-nginx

Nginx Configuration Snippet#

server {
listen 80;
location ~ ^/ttydremote(.*)$ {
proxy_pass http://127.0.0.1:7681/$1;
auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/.htpasswd;
}
...
}

This tells us /ttydremote is protected by basic auth using /etc/nginx/.htpasswd.

Cracking Credentials#

We read the .htpasswd file and extract the hashed credentials:

htpasswd

Use Hashcat to crack the hash:

Terminal window
sudo hashcat -m 1600 hash.txt /home/Ignite/Desktop/Tool/rockyou.txt

And we get:

  • Username: username
  • Password: password

cracked-password

Gaining Access#

Accessing /ttydremote prompts for credentials. We use the cracked ones:

auth-login

Now we’re inside the system as a low-privileged user.

Privilege Escalation#

Running sudo -l reveals we can execute ansible-playbook with sudo:

sudo-l

Check GTFOBins for escalation steps:

gtfobin

Execute the suggested commands, gain a root shell, and grab the flag.

Final Flag#

We navigate to /root and retrieve the flag:

Flag{QCFAb2I1MlNaY1lld2dyUElDMVNIeU5sZz09ZjU0MjhiMmZlN2MwZmViOA==}

flag


We are done great job everyone! 👏

Ignite CTF 2023 Writeup - Nghinx
https://blog.hanzalaghayasabbasi.com/posts/ignite-ctf-machine-nghinx/
Author
Hanzala Ghayas Abbasi
Published at
2023-12-19
License
CC BY-NC-SA 4.0