ScreenCrack

Description

New screenshot service just dropped! They talk a lot but can they hack it?

URL: https://app.hackthebox.com/challenges/ScreenCrackarrow-up-right

Analysis

The application is able to visit a URL, take a screenshot or show source of the webpage.

ScreenCrack.png

The application is based on Laravel PHP framework.

Let's inspect .env first, this probably is not what the challenge version will have but still.

Next we should inspect routes directory, that's where usually main part of route handling is done.

routes/api.php

routes/web.php

Next we should take a look at Controller classes, because they contain the logic of route handling.

Show Screenshot calls /api/getss and the handler for that is function getSS.View Source calls /api/get-html and the handler for that is function getHtml.

Both calls are POST methods.

To make this calls the url should be valid.

  1. It contains the host (domain)

  2. Should be valid IPv4, but not local address.

  3. Should be a valid domain.

For the screenshot endpoint the url must start with http[s]://.

The FileQueue handles filenames and checks that respective directories exist. For deleteFile system calls are used, this could be entrypoint if we can somehow manipulate filenames, but they are pregenerated from UUID4 and extensions are also hardcoded to png or txt.

The odd thing is there's Redis server running in background, but there's no way to interact with this application. The server is there for a reason and we might need SSRF.

There's 2 more oddities. Why the f*ck is getHtmlResp using curl to get server source and why is getScreenShotResp using file_get_contents to get contents from URL. As a programmer you should try to follow DRY method and this is pure garbage.

Anyway, the getHtmlResp function is not restricting us from using other protocols, but the URLs must have domains inside them (This rules out the file:// protocol).

curlarrow-up-right: A command line tool and library for transferring data with URL syntax, supporting DICT, FILE, FTP, FTPS, GOPHER, GOPHERS, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET, TFTP, WS and WSS.

Now we need to perform SSRF, request is already made for us and we just need to make it work. localhost doesn't work because of Regex pattern, we need an actual domain that can respond to our requests. The curl won't perform redirection by itself so that can't be done.

Payloads from Pravinrp > SSRF payloadsarrow-up-right didn't work as it couldn't bypass valid url function.

Focusing on DNS we can find relative attack: DNS rebindingarrow-up-right is a method of manipulating resolution of domain names that is commonly used as a form of computer attackarrow-up-right.

https://lock.cmpxchg8b.com/rebinder.htmlarrow-up-right (srcarrow-up-right)

ScreenCrack-1.png

Success

ScreenCrack-2.png

https://book.hacktricks.xyz/network-services-pentesting/6379-pentesting-redis#ssrf-talking-to-redisarrow-up-right

This was quite troublesome because turns out gopher protocol was successful, but the curl hangs as it's awaiting new instructions as an interactive service. You need to execute and quit right away so can catch output and end the interaction within 3 seconds so curl doesn't hang.

ScreenCrack-3.png

To make interaction easier I made a script:

Note: Turns out rebinder service uses any IP between A and B, and is random. I chose A: 127.0.0.1 and B: 127.0.0.2 to increase chance of 127.0.0.1~~~

Easy way to root failed (https://book.hacktricks.xyz/network-services-pentesting/6379-pentesting-redis#php-webshellarrow-up-right)

So the queue is controlled by Redis, we have access to Redis and if you remember the files are removed by system call for whatever reason (???) and we can hijack Redis object, modify and pwn the sh*t out it system

Welp first of all we need an serialized object and the easier way I thought of getting it was to make Docker do heavy work since I was running it locally:

Note: The extension can't really be effected because of programming logic, but we can use the filename!

The PoC script does following

  1. Create a dummy object

  2. Pop last item from cache (aka dummy object)

  3. Modify the last item using our serialized payload

  4. Pop the previous request object

  5. Push new malicious object

  6. Show last entry (for verification)

Why are we even deleting objects? Well... the queue worker runs each queue remotely every 10minutes............... (job-runner.sh)

Run the SSRF and wait for fu*king 10minutes and then check on http://<SERVER_IP>/t.php for webshell 🎉

circle-check

Last updated