Samba Password Hash Algorithm

Sorry let me rephrase. The pincode is not. Password is different. Sorry.

You need password? That is for GQL functions I’m pretty sure. It’s tied to applications.

Are you sure you’re not thinking of PIN? PINs are indeed not encrypted (although they should be) but passwords are. Passwords are used for API access. I also want to use it for my web app so employees can experience SSO.

1 Like

User passwords stored as one way hashes.

I figured that, but I was wondering what the hashing algorithm was. For example: bcrypt.

Oh hmm I don’t think Emre ever discussed that.

Is it perhaps ms sql’s built in PWDENCRYPT() function?

That is all I can find

I suppose there’s no access to the code for the Verify() method? Maybe it’s base64 like the comment says. That would be very insecure…

Looks like the prepended data “$SPHASH$V1$” is used to identify the password version, perhaps for future releases, backward compatibility, etc. The data is removed via the Replace() method and then the remaining data is split at the remaining $ which gives an array of [10000,hash…]. Now I’m wondering what the 10000 means haha.

1 Like

10000 is the amount of iterations the cipher is applied to the input string. 10000 is the min for PBKDF2.

If you’re working with PHP you can use a .Net library via dotnet.

Hi Thanks Memo. I see there’s a hash_pbkdf2 function for php. I’m having trouble translating the C# to php though. Specifically how the SaltSize variable is derived and the Array.Copy method (5 arguments?).

I’m running php on a LAMP stack so I can’t use the dotnet dll.

I tried looking at some sample code and I can’t make heads or tails of how to check the C# hashed password.

When it comes to the cryptological stuff I don’t really understand what it’s all doing with all the byte array stuff. Maybe one day.

I had an inkling the dotnet in php was windows only but I’ve never used it, just remember reading about it.

May I recommend StackOverflow… :laughing: =]

Yeah I think I can get it figured out. I need to know the SaltSize variable. It seems to be outside of the code snippet from Samba’s Verify() method.

salt size is 16

Ok, I’m getting closer. Do you know HashSize and the hash algorithm?

Here’s my function so far:

<?php
// SambaPOS's prepended data to password hash
define("PW_VER_STRING", '$SPHASH$V1$');
define("SALT_SIZE", 16);

$hash_pw = '$SPHASH$V1$10000$s9jDG3+SOfSnTcb/BQScxGnUR58kr3UxZg9GirPrkBQ6yVAD';
echo pw_verify("SomePassword", $hash_pw);

function pw_verify($pw, $hash)
{
    // Get rid of version data
    $hash = str_replace(PW_VER_STRING, "", $hash);

    // Split hash into iterations, hash
    list($iter, $hash64) = explode("$", $hash);

    // Base64 decode hash
    $hashBytes = base64_decode($hash64);
    $salt = array_slice(array_values(unpack('C*', $hashBytes)), 0, SALT_SIZE);
    print_r($salt);
}
?>

Here is PHP’s equiv. of the C# class:

hash_pbkdf2 ( string $algo , string $password , string $salt , int $iterations [, int $length = 0 [, bool $binary = FALSE ]] ) : string

hash size is 20

and as you can see by the php function, the algorithm is PBKDF2 (according to RFC 2898)

Hmm, i don’t know if that’s it. the function has an argument “hash_algo”. Here is a list of supported algorithms from php.net:

Array
(
    [0] => md2
    [1] => md4
    [2] => md5
    [3] => sha1
    [4] => sha224
    [5] => sha256
    [6] => sha384
    [7] => sha512/224
    [8] => sha512/256
    [9] => sha512
    [10] => sha3-224
    [11] => sha3-256
    [12] => sha3-384
    [13] => sha3-512
    [14] => ripemd128
    [15] => ripemd160
    [16] => ripemd256
    [17] => ripemd320
    [18] => whirlpool
    [19] => tiger128,3
    [20] => tiger160,3
    [21] => tiger192,3
    [22] => tiger128,4
    [23] => tiger160,4
    [24] => tiger192,4
    [25] => snefru
    [26] => snefru256
    [27] => gost
    [28] => gost-crypto
    [29] => adler32
    [30] => crc32
    [31] => crc32b
    [32] => crc32c
    [33] => fnv132
    [34] => fnv1a32
    [35] => fnv164
    [36] => fnv1a64
    [37] => joaat
    [38] => haval128,3
    [39] => haval160,3
    [40] => haval192,3
    [41] => haval224,3
    [42] => haval256,3
    [43] => haval128,4
    [44] => haval160,4
    [45] => haval192,4
    [46] => haval224,4
    [47] => haval256,4
    [48] => haval128,5
    [49] => haval160,5
    [50] => haval192,5
    [51] => haval224,5
    [52] => haval256,5
)

I would try md5 or sha1 (I’m leaning towards the latter seeing as Emre mentioned maybe using sha256)