XF 1.5 Xenforo Password Blob to SHA256

Dretax

Member
I am trying to compare the specified password to the one in the database.

AFAIK Xenforo does: SHA256(SHA256(pw) + XenforoSalt)
https://github.com/Contex/XenAPI/blob/master/net/xenapi/XenAPI/api.php

I am not really a web developer, but how would I go ahead and encrypt the specific string to the one I received?
As I see this php reads the specific blob file, and then converts it to a base64 string.

But how does It converts my specified password to that exact string? I am trying to implement It to lua specifically but any other language examples can come good.

This sql query gives me back the blob and userid i need, but I still do not know how to make the same string from a password output:
SQL:
SELECT `data`, `user_id` FROM `xf_user_authenticate` WHERE `user_id` = (SELECT `user_id` FROM `xf_user_field_value` WHERE `field_value` = 'username') LIMIT 1
 
Last edited:
I have never worked with Auth, but look at XF\Authentication\Core

esspecially getPasswordHash() and createHash()

Maybe that helps.
 
I have never worked with Auth, but look at XF\Authentication\Core

esspecially getPasswordHash() and createHash()

Maybe that helps.
That only creates the hash, but not the blob's hash as I have seen. @Jake Bunce might be able to help me out regarding this issue, because I think that mysql query isnt the best either.
 
XenForo will use the best encryption it has available to it, usually this will be bcrypt, it will only fallback to lower methods such as sha if the better ones are unavailable.
 
XenForo will use the best encryption it has available to it, usually this will be bcrypt, it will only fallback to lower methods such as sha if the better ones are unavailable.
We have a winner here. Correct, my db stores bcrypt. That is being stored as a blob file which I can read.
Question is how many maximum number of rounds does xenforo perform with bcrypt?
I got a similar starting hash with 3 so I assume It's different. I need to know that inorder to get the same hash.
 
1522678392462.webp

That's awfully weird, the hash seems to be 10, the tester says they match, but I do not receive the same output?
 
Have you included the salt?
Uhh. I forgot.
But I added It, still got a wrong bcrypt. I even tried brypting the brypt.

Took the salt from:
library/Xenforo/application.php
globalSalt variable.

Ahha...
I was unfamiliar with bcrypt. Seems like the value is changing all the time, so It needs a specific testing method that can verify if the hash is the same.

Edit:
Confirmed, implementation is successful. All i need now is a correct sql query to find the userid by username.
 
Last edited:
Alright I sticked with
SELECT `data`, `user_id` FROM `xf_user_authenticate` WHERE `user_id` = (SELECT `user_id` FROM `xf_user` WHERE `username` = '??') LIMIT 1

Also, I noticed that Xenforo is using $2a$ blowfishes for bcrypt. Why is that? I am stuck a bit on the API I am using, and trying to counter It atm, but also would like to know if there is any way to solve this for xenforo, like to use $2y$ hashes.

"Note that only the prefix $2y$ is supported (older prefixes can cause security issues). "
Seems weirdo to me?

Edit: https://github.com/mabako/mta_bcrypt Solved with an extension. Thanks for all the help.
 
Last edited:
Uhh. I forgot.
But I added It, still got a wrong bcrypt. I even tried brypting the brypt.

Took the salt from:
library/Xenforo/application.php
globalSalt variable.

Ahha...
I was unfamiliar with bcrypt. Seems like the value is changing all the time, so It needs a specific testing method that can verify if the hash is the same.

Edit:
Confirmed, implementation is successful. All i need now is a correct sql query to find the userid by username.
$globalSalt is used for user email confirmation links and proxy hashes. This is to ensure two XF sites don't generate the same email confirmation link for the same email. This salt is not used for password encryption.

Alright I sticked with
SELECT `data`, `user_id` FROM `xf_user_authenticate` WHERE `user_id` = (SELECT `user_id` FROM `xf_user` WHERE `username` = '??') LIMIT 1

Also, I noticed that Xenforo is using $2a$ blowfishes for bcrypt. Why is that? I am stuck a bit on the API I am using, and trying to counter It atm, but also would like to know if there is any way to solve this for xenforo, like to use $2y$ hashes.

"Note that only the prefix $2y$ is supported (older prefixes can cause security issues). "
Seems weirdo to me?

Edit: https://github.com/mabako/mta_bcrypt Solved with an extension. Thanks for all the help.

All prefixes will work. Due to security bugs in earlier PHP's implementation of bcrypt some people suggested using a new prefix to differentiate hashes generated with the fixed algorithm from problematic hashes. See this StackOverflow answer for details.

XF by default uses 10 iterations (this is a changeable config in XenForo_Application, but changing this would cause earlier password hashes to be invalid when attempting to compare I believe)
 
Last edited:
XF by default uses 10 iterations (this is a changeable config in XenForo_Application, but changing this would cause earlier password hashes to be invalid when attempting to compare I believe)
I haven't tested this, but it shouldn't (and if it does, it's fairly easily resolvable). The cost factor is part of the encryption hash, so older hashes with a different cost factor should function fine. All the necessary data to verify the hash is saved in the database.

e.g., cost factor 10: $2a$10$7PmAac2EOziqp6edo6OJt.7Nm/FNbB8wHMJ35y8JrWV0FyMJft3tu
cost factor 12: $2a$12$u0fxtZ72A6KED.7gASy8Mu5O/FAvc5SEI5MjKhe0qRRZDBiX.FVRC

Emphasis on $10 and $12.
 
Top Bottom