Gateway

Web Exploitation (nginx misconfig)

given a web link with the source code. First we see the web

nothing much to see here. Then I proceed to analyze the source code

ignore the py files, those are my scripts. Anyway as you can see, we are given a Dockerfile and an nginx conf file.

Dockerfile:

we see here it is an openresty image with nginx conf

nginx.conf:

from here we see that the '/flag' and '/password' file is read and assigned to 'u' and 'v' variable. Then the 'flag' is closed and both files are removed. Keep in my mind that 'password' has not been closed, which will enable us to read the file descriptor to read the contents. As for the 'flag' we have to read it in memory.

here we see we can do Path Traversal cause of Off-By-Slash nginx misconfig, https://medium.com/@_sharathc/unveiling-the-off-by-one-slash-vulnerability-in-nginx-configurations-c05b3b7b7c1earrow-up-right this article explains it good.

but we can't access it remotely cause we will be blocked by access_by_lua_block unless it is from localhost.

then we see here there's a gateway to access /static from /download but there are a lot of restrictions.

finally we see a /read endpoint. Basically this endpoint will require a X-Password Header to access a filename which we defined by X-Filename. Then we can specify where the bytes start and the range of bytes using X-Start and X-Length.

Now for the exploit part. First we use path traversal to find the password file. We can use /download endpoint but it got so much restrictions, which turns out there's a way to bypass all of the restrictions. How? by giving so much arguments until it can't handle the arguments.

here it is stated that the maximum request arguments is 100. So using thsi script we make 100 request arguments then add the filename

it worked! now we just have to read the fd where password is located. We know the password is located in /proc/self/fd/6 from container debugging.

and as we can see the password text are all asterisks, which means it contain /download filename restrictions. we can bypass this by only retrieve 1 byte at a time. My script:

when we run the script, we got the password:

Password: passthepasswordisdontlookbehindpasswordsomethingiswatching

Now after we got the password we can access /read endpoint. first we see /proc/self/maps to see the memory layout

we see /dev/zero is located in 0x7faf57b10000, now we can use offset with /proc/self/mem to dump memory

and we got the flag

Flag: hacktoday{g4t3w4y_m1sc0nf1gur4t10n_c0z_tr0ubl3}

Last updated