While web application testing, I was looking for update email or password update section as well as password reset functionality. Since this feature holds key to the critical vulnerability which can lead to account takeover. Due to private project and criticality of bug, it is not possible to disclose the name of the projects. So we will take example[id].com for understanding the purpose.
Tale-1 #Business Logic Bug in update email with temporary access to the victim’s account can lead to a permanent account takeover.
Explanation:
The password change and email function of an application allow any users to change or reset their password and update email without an administrator intervening. When an email is change application should prompt for the password but in our case due to failed logic, it never did.
So as an impact attacker may able to access complete account and reset user password persistently even after the account is recovered.
Scenario:
Let’s assume Innocent friend: [email protected].
1) Attacker friend 1: [email protected].
2) Hacker: [email protected].
3) Url: https://example1.com/profile
Steps to reproduce:
Note: Physical access temporarily required.
This is the fun part !!!
Let me break it down. This is the bug here. I was checking if the application sends any mail or token to verify the change in an account or not. But it didn’t happen at all. Then I started testing for password reset.
Now click on password reset and enter attackers email i.e. [email protected].
Hacker receives a password reset link on [email protected]. But this account is not associated with any of the accounts.
Click on password reset and change password, but here we still don’t know whose password is changed.
Now try login using hackers email id and updated password
Check email in profile, it is users original email i.e. [email protected]. Afterwards, if [email protected] tries to login using password reset, it will be able to login into [email protected] as well.
While testing password reset I was looking for successful and failed response for registered and non-registered emails. But for any user which was either registered or changed its email using edit email functionality was able to get the password reset link and change the password of the account on which email was saved or edited even once.
So basically what happened is we have three accounts one is the user with [email protected]. Another second account i.e. [email protected] which is a malicious friend and [email protected] which is the hacker. So firstly rotlu changed the email and saved it’s email then again reverts it back to users original email.
Then another third account hacker changes user’s original email to his email and then reverts it back to users original email.
So the total of two malicious entity one friend and other hacker changed the email to their emails and then reverted it back to the user’s original email. So due to failed business logic, all three were able to login into one account through the email in the profile was of a normal user rgmail.
when the attacker saved his email it was saved in the database and mapped with the user’s id. But once it got changed back to user’s again, the application didn’t remove it from the database and now one user id was mapped to two emails or it can be multiple emails here three in our case(I checked that afterwards).
Since it is permanently stored so even if user recovers account by password reset it can be hacked again because anyone could get the password reset after saving the email into a profile and then changing it back to original one. And another failure was hacker used his email to log in to someone else’s account with different email set in the profile, in our case it was rgmail.
Tale-2 #Improper Authentication in the password update field can lead to the permanent account takeover.
In the website, https://example2.com/ there is a password reset function that sends the password reset link to the user’s email. By intercepting the request and then changing email address can allow the attacker to reset another email’s password, thus allowing him to gain full access to the other user’s account.
Scenario:
1) The attacker request a password reset from reset page and obtains the password reset link in his email.
2) By using a web proxy, he tries to reset password but is able to modify his own email to another user’s email and the password reset will be used to reset another email’s password.
3) Done.
Steps to reproduce:
Tale-3 #Improper Authentication in the password reset API can lead to the permanent account takeover.
Password recovery functionalities can result in username enumeration, sensitive information disclosure and password reset vulnerabilities.
The attacker requests a password reset and obtains the valid password reset link in his email. By intercepting, an attacker can use the password reset token and modify his own email to a victim’s email and the same password reset will be used for the victim instead of the attacker.
Scenario:
1) Let’s assume user: [email protected]
2) ABC hacker: [email protected]
3) Url: https://example3.com/password_reset/forgot.html
Steps to reproduce:
This is the most generic scenario once will discover in various vulnerable web applications. It will lead to a complete account takeover.
Tale-4 #Broken access control in the password update field in the profile can lead to the account takeover.
While resetting a password, access control was not in place so I tried resetting password but it required critical auth parameter which was used to validate and update the password for every user.
But this problem was solved due to broken access control, it was easy to fetch user details which hold an auth parameter, which is hexadecimal userid used for creating JWT tokens, cookie and other critical fields received after login.
This auth parameter was sent in PATCH along with a new password, without which it was impossible to reset the password and when wrong auth parameter was entered it showed error: duplicate key for userid : xxxx present.
Scenario:
1) API: https://example4.com/api/users/idxxx
2) Victims Userid taken: 9991
3) Attackers Userid taken: 7777
Steps to reproduce:
Part-1
Part -2
Other than that JWT token was forged to fetch valid user data via API call thus making this attack successful.
Remediation:
https://www.sjoerdlangkemper.nl/2016/09/28/attacking-jwt-authentication/
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH