r/programminghorror • u/SirBackrooms • Sep 22 '26
PHP A website with millions of users was generating their "secret" password reset codes like this for two decades. The algorithm was open to the public due to a failed open-source effort the company launched in the early 2010s. Fixed a few days ago.
2.1k
Upvotes
464
u/Kinexity Sep 22 '26
What's the problem exactly? Is it about the range of rand? Or is time in microseconds not coarse enough?
327
u/lurebat Sep 22 '26 edited Sep 22 '26
Mmm, one code per microsecond So if you attack someone by requesting a reset on their email, and the response comes back in 30ms, it means there are only 30000 options of passwords.
Let's be charitable and say the give you only 5 attempts per code, that still means 1/6 chance of guessing correctly.Infinite attempts.62
u/Responsible_Royal_98 Sep 22 '26
I’ve seen worse. I know a site that just base64 encodes your email and uses that as the “authentication” token for the password reset link. If you realize what’s going on it removes all guesswork in taking over an arbitrary account.
97
u/DenyCasio Sep 22 '26
I exploited a similar feature of some gambling bots in oldschool runescape. They would output their calculation time in the chat and the number you "rolled" when playing. So i wrote a program that would tell me when to accept a trade to get a win. It worked about 80 percent of the time. I couldn't tell if it was lag, or seeded losses to ensure the house didn't lose too much money.
They changed their bots shortly after to not output verbose info.
5
u/Hottage [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Sep 22 '26
Okay it looks gross and deterministic but is it actually an issue?
You'd have to know the exact microsecond that the request was made (including any minute time variance on the server) to be able to exploit this.
The most egregious part of this code would be the keyspace only being 10,000 wide.
As an example:
If you miscalculate the attack time by even one microsecond:
If anything the issue these days would be that you could throw a few hundred requests at the validation endpoint in a second or two to try and brute force it.
18
u/NightmareJoker2 Sep 22 '26
Well, at least it’s not as bad as Facebook. They generate a code and store it until it is used or revoked, and simply resend the same code if you make a reset request again.
I receive multiple requests daily, because someone keeps wanting to steal my username.
7
u/EdelWhite Sep 22 '26
Meh it's probably fine. Definitely random enough to deter script kiddies. Would do nothing against a targeted attack tho.
4
u/Single-Virus4935 Sep 23 '26
Two things would make this secure:
Best to combine both so even if one of the two is broken/leaked it is still not brutforceable.
7
u/darksteelsteed Sep 22 '26
So the first bit of the srand being based off timestamp in usec. You request a password reset email. You look at your own clocks time. You then apply the algorithm using different seeds by taking your own clock back or forth microsecond at a time until you get a match. Your search space will be maybe a 5 min window in either direction. So that is 600 million md5 combinations to try. Trivial on your gpu to brute force ... or you just use rainbow tables because its md5. Then you sync your clock with that info to match the servers clock. Then you can issue password recovery requests and since you now have the same time as the server your search space is radically reduced to only a couple of million tries. You can even Then go further and fingerprint the servers timing to narrow this further until you can literally generate password reset codes without needing to receive the emails at all. That is why this code is not secure
1
u/ElectricalPrice3189 Sep 27 '26
Only 10k possible codes, or am I reading things incorrectly?
0
u/Gammelkebab Sep 22 '26
So am i reading this code correctly? row 1 does nothing, row 2 takes a rnd 4 digit nr and the 3rd row reduces the resulting String to the 2nd to 6th digit. But the nr ends after 4 digits? i m confus
1
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Sep 23 '26
What does multiplying by 1 million accomplish?
1
u/hypnokev Sep 23 '26
I love this. I can’t even tell you about the worst one I found on an IoT pentest. Suffice to say I defeated their AES-128 encryption solution that day, and it took just under 1,000,000 guesses. Impressed this one requires fewer.
1
u/DT-Sodium Sep 23 '26
Even if you forget how the rand is seeded, what's still only 10k passwords to brute-force through.
1
u/JerryAtom Sep 23 '26
PHP programmers, it explains a lot
1
u/M4elstr0m__ Sep 24 '26
I see two issues: the code, and the PHP lang itself (just kidding dont hit me)
1
u/AmazingGrinder Sep 24 '26
"A website" and it's Wikidot, current hosting of multiple popular international projects like SCP Foundation.
1
u/CondiMesmer Sep 25 '26
I mean it's probably good enough for most real world stuff. It'd be pretty hard to exploit, even if it's deterministic.
1
u/binarywork8087 Sep 25 '26
sorry but if it works dont touch it and if it is very well developed it is just ok
1
u/binarywork8087 Sep 25 '26
this is that obscurity problem now I got it
1
u/binarywork8087 Sep 25 '26
the problem is md5, is it?, too flawed these days....
1
u/Crazo7924 Oct 20 '26
I think no one asked the real question:
Which website was affected?
1
u/MurkyWar2756 echo "Sub Mod" && :(){ :|:& };: Sep 22 '26
Now that is a horror.
1
u/AdditionalTerm732 Sep 22 '26
Nobody: ... Absolutely nobody: ... The dev: Forgets the admin password, deletes the entire website in frustration, completely forgetting the password was literally open-source on GitHub for 10 years.
1
u/Memw1 Sep 22 '26
First you gotta know if in the second you choose someone decided to reset their password, then you need to test every microsecond possibly getting you ratelimited.
1
u/Medium-Head5014 Sep 23 '26
Better i would not say but a huge improvement over the previous one, that one was making a mess, i think its on par with fable 5.1 from what Ive seen today
0
u/empwilli Sep 22 '26
Is the fact that its not really seeded at random really an issue? I feel that without proper rate limiting or similar the 17895680 options can easily be brute forced. Even simpler if I focus on the 2 or 3 char long codes.
2
u/obeythelobster Sep 23 '26
Would it be secure with a fixed seed at start-up for all requests + a salt?
0
u/[deleted] Sep 22 '26
[deleted] — view deleted comment