2FA broken logic

Abdullah Hamza
6 min readJul 19, 2024

--

To access the lab visit the following link:

This lab’s two-factor authentication is vulnerable due to its flawed logic. To solve the lab, access Carlos’s account page.

  • Your credentials: wiener:peter
  • Victim’s username: carlos

You also have access to the email server to receive your 2FA verification code.

Click on the given button to access the lab:

On the Lab’s homepage we can see “My account” option. Let’s click on that to attempt login.

Lab homepage

Let’s login using correct credentials of wiener to capture the login request using burp.

login using wiener’s credentials

As soon as we log in, we are asked to enter 4 digit security code.

security code option

We have “email client” button on top of the page. Click on it to access the email.

Email client server

On Email client page we can see the security code provided is 1490.

security code received on mail

Let’s enter that security code and login.

login with security code

We are successfully logged in as wiener.

logged in as wiener

Let’s see the login requests in burp HTTP history. We can see three login requests captured by burp suite. Right click and send these requests one by one to repeater.

login requests captured by burp

In repeater tab we can see the first login (POST) request. It has the username and password of wiener.

First login POST request

The second login (GET) request has a session token and it verifies the username entered. It has the username of wiener and it gets the 4 digit security code for that specific username which was sent to email of wiener.

second login GET request for 4 digit security code

The third login (POST) request has the security code entered for wiener and it logs in to the wiener’s account.

third login POST request with 4 digit security code

Let’s remove the session token from second request and send that to check the response of server.

The server responds by displaying a window asking us to enter the 4-digit security code for the user “wiener”. It indicates that the application can proceed further without validating session token.

altering second login GET request

Next, we will send the third request multiple times without the session token to check if the account lock mechanism is activated on the application. We observed that no account lock mechanism is implemented.

So we can brute force 4 digit security code for victim carlos.

checking account lock mechanism

To brute force the security code, we first need to send the 4-digit security code to the victim’s email. For example, to send the security code for the user “carlos,” we need to send the second request with the victim’s username as shown in the image below:

GET request sent for getting security code of victim

After sending the request, we can see the response asking for the 4-digit security code of “carlos.” This indicates that the server has sent the 4-digit code to the victim’s email. Now, we can attempt brute force on security code.

Response of the GET request

To Brute force security code we will send the third request that contains mfa-code to intruder.

In intruder position tab select Attack type to Sniper. Click on “Clear §” to remove all the automatic payload positions. Highlight the value of the mfa-codeparameter.

Click on “Add §” to mark this value as a payload position. It will be surrounded by § symbols.

Adding payload position to the request

Navigate to the “Payloads” tab in Intruder. you can see the Payload tab in the intruder section as shown below.

In the “Payloads” section, make sure “Payload set 1” is selected, corresponding to the position you marked.

Under “Payload type”, select “Brute forcer”.

Under “Payload settings,” remove all characters other than digits from the character set. Set the length to 4 for both the Min length and Max length parameters.

Now that we have set all the payloads click on “start attack” button.

Payload configuration for brute force attack

Burp Suite will start sending requests with each payload in our list and display the results in the Intruder tab.

Brute force results in intruder tab

In results we can differentiate requests on basis of Status code and one of the requests returns status code 302. We can see the mfa-code entered in the request.

Request with 302 status code

When we view the response to this request, we can see the session cookie included in the response. We can use this cookie to bypass 2FA.

Response of unique request

Navigate to Wiener’s account page. Right-click on the page and select “Inspect.”

Go to the “Application” tab and select “Cookies.” In the cookies section, paste the session cookies of “carlos” that we copied from the Intruder results. Right-click and delete any existing cookies.

Changing session cookies in browser

Now, remove anything in the URL that comes after my-account as shown in the image below and reload the page.

Changing url

And based on session cookies we are logged in as “carlos” and the lab is also marked as solved.

Congratulations! The walkthrough of Eighth authentication lab finishes here.

You can see walkthrough of Ninth lab by clicking the following link:

--

--

Abdullah Hamza
Abdullah Hamza

Written by Abdullah Hamza

Developer | CEH | Penetration Tester | Red Team

No responses yet