Challenge 2 – Login
The starting point for all users.Rate limited to avoid brute force attacks.
Last updated
The starting point for all users.Rate limited to avoid brute force attacks.
Last updated
Login pages are the user's starting point in many web apps. They collect username/email and password and create user sessions if they are valid.
Let us look at a sample login page flow:
There is an obvious flaw here. Let us review it:
Tom is an attacker
Tom wants to break into Jerry’s account
Tom gets account does not exist error
Tom gets invalid password error for all of them
Then Tom tries jerry as the password and Boom! Tom just logged in to the portal as Jerry
The above scenario is a major headache for all login pages. These types of attacks are known as dictionary or brute force attacks. There are multiple ways to protect login pages from brute force attacks - captchas, delays, account lockouts, generic error messages etc.
What happens if we revise the current login page design with account lockouts. If the user is not able to login successfully within a few tries, the portal will lock the user’s account.
As you can see, the account lockout is achieved by storing the number of failed login attempts on the server side. For every failed login attempt, the app will increment the counter. If the value exceeds a certain point, for example 3, the portal will lock the account.
The high-level steps are:
User enters the correct username but the wrong password.
Portal increases the failed login attempt count to 1.
User enters the wrong password again.
Portal increases the failed login attempt count to 2.
User enters the wrong password one more time.
Failed login attempt count reaches 3.
The portal locks out the user out of their account.
Sounds good? Let us verify this in our lab:
Open your browser
Navigate to the login page
Enter abcd as the password
Click on the Login button a few times
Initially, you will get an error message that goes Login failed
After a few tries, you will see a different error message - Your account is locked out
You have been locked out of the user account
Now, change the password from abcd to tom
Click on the login button again
The system will not allow you to login even with the correct password because the account is locked
What if we perform all these login attempts in a single try before the server updates the failed login attempt counter on the database? Let us check that theory.
By default, TimeGap Theory will lock the user account on the third wrong attempt. In order to successfully test our attack, we would need more than three browser windows. That kind of spoils the fun, doesn’t it? Let us reduce the maximum failed attempt to 1. This way, we just need two browser windows to test.
On your browser, navigate to the Settings page
Change the login attempt count to 1
Click on the Save button
Stay on the Settings page, we need to do one more thing
Time to slow down TimeGap Theory:
Change the Main wait to 5 seconds
Click on the Save button
Now, TimeGap Theory will wait 5 seconds before every database write operation. This write operation includes failed login attempts values.
Preparation Phase
Open two browsers side by side (Use a private/incognito window if you do not have two browsers).
On both the browsers:
Navigate to the login page
Click on the second user button this time - this will fill the form with details of the user Jerry
Alright, the preparation is done. Here comes the exploitation phase.
Exploitation Phase
Click on the Login button on the first browser
In the second browser quickly also click on the Login button
Post-exploitation Phase
Wait for both the browsers to complete the request
You should see the login attempt was successful on the second browser
Check the user login attempt count is greater than 1. Phew
If you check your score, you should see you have 100 points
Before moving on, revert the delay to 0 on the settings page
There is no way we can perform a brute force attack like this in real life. You cannot call the webmaster and ask them to delay the server. Browser Dev Tools to the rescue again.
First, we need a valid fetch request:
Open your browser (Chrome or Firefox)
Navigate to the login page
Click on any of the user buttons
Open up dev tools by pressing F12 on the browser
On Windows, you can use Ctrl + Shift + I
On Mac, you can use Cmd + Shift + I
On the login page, click on the Submit button
On the browser dev tools, click on the Network tab
Right click on the login.php request
Click on Copy > Copy as fetch
Paste this in the Console tab of the browser dev tools. It should like the following:
It is okay if you see a request with some more elements. We trimmed down the unwanted portions to make it look clean.
But that’s just one request.
We are talking about brute forcing here. We need a minimum of 5 for this simulation.
Copy and paste the fetch request without pressing the Enter key. However, it is a good practice to separate each request with a comma. Let us do that.
We also changed the password value in each request. The first four requests have the wrong password. The last request has the correct password.
Before running this new command, we need to clear the slate. It involves three simple steps:
Ensure that there is no delay
Go to TimeGap Theory > Settings
Set the Main wait to 0
Refresh the user accounts.
Go to TimeGap Theory > Admin
Click on Create Default Users
Clear your current score.
Go to TimeGap Theory > Score
Click on the Clear button
Alright, our slate is clear. Let us execute the attack now:
Enter the combined fetch requests on the Console tab of browser dev tools
Press the Enter key
Go to the Network tab of the browser
See if you can find an index.php file
Right click on it and select open in a new tab
You are logged in
If you want to see which password was correct, you can check which request showed true in the Console tab
Go to TimeGap Theory > Score
You should have got 100 points for completing the Login challenge
What is the business impact of such an attack? Depending on how the app is designed, there are several possibilities:
A legitimate user may keep getting their account compromised despite changing their passwords
Attackers may compromise the admin functionalities of web apps
Let us summarize what we completed:
The login page rate limits the login attempts by locking the account
You analyzed this behavior by locking out one account
You slowed down the system and bypassed the business logic
You bypassed the business logic by using browser dev tools
Now you know how TOC/TOU security issues can affect login pages
Tom tries , , etc
Tom tries
Tom gets invalid password error. This means there is a user account with as user name
Tom tries logging into the portal with and 1,2,3,a,b,c etc. as the password
Enter as the username