2FA code can be reused
The two-factor authentication code could be reused after the time step changed because the library compared the consumed time step with the current time step instead of the matched one. An attacker who obtained a code through phishing or shoulder surfing could log in again with the same code.
GitLab
Originally disclosed on GitLab
- Fixed in 21 months
- Disclosed after 21 months
HackerOne report #762578 by shaicoleman on 2019-12-20, assigned to @dcouture:
Summary
The 2FA code, which should only be used once, can be reused.
Steps to reproduce
- Login with 2FA, e.g. with timecode 123456
- Wait for the next time code to change on the authenticator
- Login with 2FA, with the same timecode, e.g. 123456
Impact
Loss of protection of the 2FA, in cases of phishing sites or shoulder surfing.
What is the current bug behavior?
The bug is in rotp v2 which is a dependency of the devise-two-factor gem.
It is fixed in the latest version of the gem.
The problem is that the verify_with_drift doesn't return the matched timestep, it compares instead the consumed timestep with the current timestep.
When the next timestep arrives, verify_with_drift still works with a reused 2FA code, and the consumed_timestep is compared to current timestep, which allows the 2FA code to be reused.
Also the current behaviour allows a new timestep to be older than the old timestep.
What is the expected correct behavior?
- verify_with_drift should return the timestep of the matched timestep, and compare the consumed timestep to that.
- After a 2FA login, it shouldn't allow an older timestep to be reused, e.g. if the authenticator shows:
111111 and then 222222. If I log in with 222222, it shouldn't allow someone at the same time to log in with 111111 (e.g. in case of the shoulder surfing), this is because it checks that the consumed timestep is different, it should check that it's newer. (this is a separate vulnerability, but less serious).
Impact
Loss of protection of 2FA
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the library's verification function compared the consumed time step with the current time step rather than the time step that actually matched the code, so a reused code still passed after the time step advanced.
Impact
The protection of 2FA is lost in cases such as phishing sites or shoulder surfing, because a stolen code can be reused.
What the attacker needed
Attacker obtains a valid 2FA code; victim's account uses time-based 2FA
The fix
The library should return the matched time step and compare the consumed time step to it; older time steps should also be rejected.
How it was found
- Log in with 2FA using a time-based code.
- Wait until the authenticator generates the next code.
- Log in again with 2FA using the same previous code.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Two-factor authentication (2FA) adds a second step to login, often a six-digit code from an app that changes every 30 seconds. Normally each code should work only once. Here, the system allowed the same code to be used again later, so someone who saw or stole the code could log in as the victim.
What is Account takeover?
Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.