Login Bot
Category: Web
Description
I made a reverse blog where anyone can blog but only I can see it (Opposite of me blogging and everyone seeing). You can post your content with my bot and I'll read it.
Sometimes weird errors happen and the bot gets stuck. I've fixed it now so it should work!
- Junhua
Attachments: dist.zip
Write-up
- Upon analyzing the source code, we discovered that the flag is hidden within the password of the adminaccount.
- We identified an unauthenticated /send_postendpoint that accepts three arguments:title,content,andurl. The first two are required for creating a post, while the third specifies the URL to which theadminwill be redirected after logging in (default is/).
- When the /send_postendpoint is accessed, theadminis redirected tohttp://34.124.157.94:5002/login?next={url}and makes a POST request to the same URL to perform the login. After successful login, theadminis redirected to the specified url before creating our post.
- Initially, we attempted to manipulate the urlparameter to point to our webhook, hoping that the redirection after login would lead to our webhook and exfiltrate the flag. However, we encountered a challenge with theis_safe_url()method, which checks if thenetlocof the host URL matches thenetlocof our webhook URL. Since they are different, it was impossible to satisfy this check.
- Here is the logic of the is_safe_url()method:Text Only 
- Fortunately, we discovered a workaround by prepending a space to our urlinput. When usingurljoin()to join two different domain URLs, it will just return the latter as the joined URL. However a peculiar behavior occurs when the second parameter is prepended with a space, it is not considered a "valid URL" and as a result the function simply appends the second parameter URL to the first parameter URL, without performing any validation.
- By prepending a space to our second parameter, the test_urlbecamehttp://34.124.157.94:5002/ https:/webhook.site/774fac7f-86a1-4682-a2c0-883ea13d0a6a. As a result, bothref_urlandtest_urlhad the same netloc, enabling us to bypass theis_safe_url()check.
- Since the redirect()method after the check was called on oururlinput directly, without being appended with the host URL just like how it was checked, we were able to redirect to any arbitrary URL.
- Armed with this knowledge, we crafted a command to exfiltrate the flag to our webhook URL:
Text Only 
Flag: grey{r3d1recTs_r3Dir3cts_4nd_4ll_0f_th3_r3d1r3ct5}
PS: Unrelated but it is interesting to note the result of urlparse's netloc: https://github.com/python/cpython/issues/102153#issuecomment-1455710285