Secret Hitler Account Takeover
The password reset endpoint passed user-supplied JSON objects directly into MongoDB queries, allowing query operators to be injected. An attacker could take over any non-staff account by crafting a username that matched both a reset token they controlled and the victim's account.
robertchen.cc
Published on robertchen.cc
This is an account takeover attack I discovered on the open source Secret Hitler game.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The application passed user-controlled objects directly into MongoDB queries without validating that the values were strings, enabling NoSQL operator injection.
Impact
An attacker could take over any non-staff account, but staff accounts were protected by a hardcoded check.
What the attacker needed
Ability to create an account; ability to send crafted JSON requests
The fix
The vulnerability can be mitigated by disabling JSON parsing so that request body values are not interpreted as objects.
How it was found
- Create an account with a username that sorts very high alphabetically, such as a long string of z characters.
- Request a password reset for that account to generate a valid reset token.
- Send a password reset request where the username is a MongoDB operator that selects accounts greater than or equal to the victim's username, and the token is an operator that matches any token.
- The reset token from the attacker's account satisfies the token check, and the user lookup returns the victim's account, allowing the password to be reset.
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 write-up has not been written yet. The Original tab links to the source.
The game's password reset form expected simple text values, but it also accepted special database instructions. By sending a crafted request, an attacker could make the database pick a different account than intended and reset its password. This let them log in as other players, except staff accounts which were protected.
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.