SmbHash(3)
π NAME π
Okay so bestie, this is Crypt::SmbHash: a Perl-only implementation of lanman and nt md4 hash functions, for use in Samba style smbpasswd entries. The page header is SmbHash(3), and the manual name is User Contributed Perl Documentation β consider that little name tag folded in near the top π«Ά.
β¨ SYNOPSIS β¨
use Crypt::SmbHash;
ntlmgen SCALAR, LMSCALAR, NTSCALAR;
That's the whole opening vibe: load the module, then call ntlmgen with three scalars π
.
π¦ DESCRIPTION π¦
This module generates Lanman and NT MD4 style password hashes, using perl-only code for portability. It's here to help with the administration of Samba style systems, no cap.
In the Samba distribution, authentication is referred to a private smbpasswd file. Entries have similar forms to the following:
username:unixuid:LM:NT
Where LM and NT are one-way password hashes of the same password. Iconic but also very much a βhandle with careβ situation π₯.
ntlmgen generates the hashes given in the first argument, and places the result in the second and third arguments.
Example: to generate a smbpasswd entry, go like this:
#!/usr/local/bin/perl
use Crypt::SmbHash;
$username = $ARGV[0];
$password = $ARGV[1];
if ( !$password ) {
print "Not enough arguments\n";
print "Usage: $0 username password\n";
exit 1;
}
$uid = (getpwnam($username))[2];
my ($login,undef,$uid) = getpwnam($ARGV[0]);
ntlmgen $password, $lm, $nt;
printf "%s:%d:%s:%s:[%-11s]:LCT-%08X\n", $login, $uid, $lm, $nt, "U", time;
ntlmgen returns returns β yes, the double βreturnsβ is canon here, we're not editing the icon π β the hash values in a list context, so the alternative method of using it is:
( $lm, $nt ) = ntlmgen $password;
The functions lmhash and nthash are used by ntlmgen to generate the hashes, and are available when requested:
use Crypt::SmbHash qw(lmhash nthash)
$lm = lmhash($pass);
$nt = nthash($pass);
If Encoding is available (part of perl-5.8), the $pass argument to ntlmgen, lmhash and nthash must be a perl string. In double use, this:
use Crypt::SmbHash qw(ntlmgen lmhash nthash);
use Encode;
( $lm, $nt ) = ntlmgen decode('iso-8859-1', $pass);
$lm = lmhash(decode_utf8($pass), $pwenc);
$nt = nthash(decode_utf8($pass));
The $pwenc parameter to lmhash() is optional and defaults to 'iso-8859-1'. It specifies the encoding to which the password is encoded before hashing πΈ.
π MD4 π
The algorithm used in nthash requires the md4 algorithm. This algorithm is included in this module for completeness, but because it is written in all-perl code ( rather than in C ), it's not very quick π.
However, if you have the Digest::MD4 module installed, Crypt::SmbHash will try to use that module instead, making it much faster π₯.
A simple test compared calling nthash without Digest::MD4 installed, and with, this showed that using nthash on a system with Digest::MD4 installed proved to be over 90 times faster. Obsessed with the glow-up, honestly π.
π AUTHOR π
Ported from Samba by Benjamin Kuit <lt>bj@it.uts.edu.au<gt>.
Samba is Copyright(C) Andrew Tridgell 1997-1998.
Because this module is a direct port of code within the Samba distribution, it follows the same license, that is:
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
perl v5.42.0, dated 2019-11-11 β that's the source/version and date sign-off, mwah πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Crypt-SmbHash 0.12-bp160.1.1 Β· Artistic-1.0 OR GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms