The following post by 0xb0b is licensed under CC BY 4.0
Recon
We start with an Nmap scan and find two open ports. Port 22 on which we have SSH available and port 80 on which a web server is running whose index page appears to be a login page.
If we visit the index page, we see the login screen, which requires a captcha to be filled in as well as a username and password.
We intercept any login request and see that the data we transmit has been encrypted.
As the challenge says “when crypto interferes, automate.” So let's do this. We should log in with the admin user and our task is now to write a script that executes a brute-force and can perform the captcha requests.
Script using Selenium
Selenium is suitable for this. Selenium is an open-source automation tool used for testing web applications across different browsers and platforms by simulating user interactions.
This challenge is a follow-up room to a walkthrough room that deals with exactly this:
We are also told that we should limit the wordlist used to the first 100 entries from rockyou.txt:
Note: Use the first 100 lines of rockyou.txt
We follow the instructions of the walkthorugh and thus also receive the scripot to be applied directly. We use selenium for browser automation and PIL and pytesseract for the image processing.
We use Selenium WebDriver which controls the Chrome browser for automation, selenium_stealth to prevent bot detection and fake_useragent to generate realistic browser fingerprints to avoid detection.
We implement a retry in case of captcha misinterpretation to avoid accidentally skipping passwords.
After we run the script we eventually retrive the flag.
It may not work straight away, and might need to be rerun again. This may be due to Selenium itself. Since this phenomenon did not occur with the following alternative script.
Script Without Browser Automation
An alternative script could be created to execute the request directly, rather than via browser automation. This is possible in this case, as we have the encryption keys available and simulating a valid browser is unnecessary, as there appears to be no detection in place.
The encryption of the data we enter is carried out locally. The script for this can be found in script.js.
Here we find the key material to carry out the encryption ourselves in our script.
Furthermore, we can retrieve the captcha directly via capthca.php for further processing.
Next, we wirte a script using requests. Fetching the CSRF token is necessary here, since we do not simulate a browser.
After execution...
... we retrieve the valid credentials of admin.
With those we are able to login and retrieve the flag.