# Functions for MD5 and SHA1 password encryption use strict; use warnings; no warnings 'redefine'; no warnings 'uninitialized'; our %config; # check_md5() # Returns a perl module name if the needed perl module(s) for MD5 encryption # are not installed, or undef if they are sub check_md5 { # On some systems, the crypt function just works! return undef if (&unix_crypt_supports_md5()); # Try Perl modules eval "use MD5"; if (!$@) { eval "use Digest::MD5"; if ($@) { return "Digest::MD5"; } } return undef; } # encrypt_md5(string, [salt]) # Returns a string encrypted in MD5 format sub encrypt_md5 { my ($passwd, $salt) = @_; my $magic = '$1$'; if ($salt && $salt =~ /^\$1\$([^\$]+)/) { # Extract actual salt from already encrypted password $salt = $1; } if ($salt && $salt !~ /^[a-z0-9\/\.]{8}$/i) { # Non-MD5 salt $salt = undef; } $salt ||= substr(time(), -8); # Use built-in crypt support for MD5, if we can if (&unix_crypt_supports_md5()) { return crypt($passwd, $magic.$salt.'$xxxxxxxxxxxxxxxxxxxxxx'); } # Add the password, magic and salt my $cls = "MD5"; eval "use MD5"; if ($@) { $cls = "Digest::MD5"; eval "use Digest::MD5"; if ($@) { &error("Missing MD5 or Digest::MD5 perl modules"); } } my $ctx = eval "new $cls"; $ctx->add($passwd); $ctx->add($magic); $ctx->add($salt); # Add some more stuff from the hash of the password and salt my $ctx1 = eval "new $cls"; $ctx1->add($passwd); $ctx1->add($salt); $ctx1->add($passwd); my $final = $ctx1->digest(); for(my $pl=length($passwd); $pl>0; $pl-=16) { $ctx->add($pl > 16 ? $final : substr($final, 0, $pl)); } # This piece of code seems rather pointless, but it's in the C code that # does MD5 in PAM so it has to go in! my $j = 0; for(my $i=length($passwd); $i; $i >>= 1) { if ($i & 1) { $ctx->add("\0"); } else { $ctx->add(substr($passwd, $j, 1)); } } $final = $ctx->digest(); # This loop exists only to waste time for(my $i=0; $i<1000; $i++) { my $ctx1 = eval "new $cls"; $ctx1->add($i & 1 ? $passwd : $final); $ctx1->add($salt) if ($i % 3); $ctx1->add($passwd) if ($i % 7); $ctx1->add($i & 1 ? $final : $passwd); $final = $ctx1->digest(); } # Convert the 16-byte final string into a readable form my $rv = $magic.$salt.'$'; my @final = map { ord($_) } split(//, $final); my $l = ($final[ 0]<<16) + ($final[ 6]<<8) + $final[12]; $rv .= &to64($l, 4); $l = ($final[ 1]<<16) + ($final[ 7]<<8) + $final[13]; $rv .= &to64($l, 4); $l = ($final[ 2]<<16) + ($final[ 8]<<8) + $final[14]; $rv .= &to64($l, 4); $l = ($final[ 3]<<16) + ($final[ 9]<<8) + $final[15]; $rv .= &to64($l, 4); $l = ($final[ 4]<<16) + ($final[10]<<8) + $final[ 5]; $rv .= &to64($l, 4); $l = $final[11]; $rv .= &to64($l, 2); return $rv; } # unix_crypt_supports_md5() # Returns 1 if the built-in crypt() function can already do MD5 sub unix_crypt_supports_md5 { my $hash = '$1$A9wB3O18$zaZgqrEmb9VNltWTL454R/'; my $newhash = eval { crypt('test', $hash) }; return $newhash eq $hash; } our @itoa64 = split(//, "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); sub to64 { my ($v, $n) = @_; my $r = ""; while(--$n >= 0) { $r .= $itoa64[$v & 0x3f]; $v >>= 6; } return $r; } sub check_sha1 { eval "use Digest::SHA1"; return undef if (!$@); eval "use Digest::SHA"; return undef if (!$@); return "Digest::SHA"; } # encrypt_sha1(password) # Encrypts a password in SHA1 format sub encrypt_sha1 { my ($pass) = @_; my $sh = eval "use Digest::SHA1 qw(sha1_base64);return sha1_base64(\$pass);"; if ($@) { $sh = eval "use Digest::SHA qw(sha1_base64);return sha1_base64(\$pass);"; } return "{SHA}$sh="; } # encrypt_sha1_hash(password, salt) # Hashes a combined salt+password with SHA1, and returns it in hex. Used on OSX sub encrypt_sha1_hash { my ($pass, $salt) = @_; # XXX not done yet?? } # check_blowfish() # Returns an missing Perl module if blowfish is not available, undef if OK sub check_blowfish { eval "use Crypt::Eksblowfish::Bcrypt"; return $@ ? "Crypt::Eksblowfish::Bcrypt" : undef; } # encrypt_blowfish(password, [salt]) # Returns a string encrypted in blowfish format, suitable for /etc/shadow sub encrypt_blowfish { my ($passwd, $salt) = @_; my ($plain, $base64) = ("", ""); eval "use Crypt::Eksblowfish::Bcrypt"; if ($salt && $salt !~ /^\$2a\$/) { # Invalid salt for Blowfish $salt = undef; } if (!$salt) { # Generate a 22-character base-64 format salt &seed_random(); while(length($base64) < 22) { $plain .= chr(int(rand()*96)+32); $base64 = Crypt::Eksblowfish::Bcrypt::en_base64($plain); } $base64 = substr($base64, 0, 22); $salt = '$2a$'.'08'.'$'.$base64; } return Crypt::Eksblowfish::Bcrypt::bcrypt($passwd, $salt); } # unix_crypt_supports_sha512() # Returns 1 if the built-in crypt() function can already do SHA512 sub unix_crypt_supports_sha512 { my $hash = '$6$Tk5o/GEE$zjvXhYf/dr5M7/jan3pgunkNrAsKmQO9r5O8sr/Cr1hFOLkWmsH4iE9hhqdmHwXd5Pzm4ubBWTEjtMeC.h5qv1'; my $newhash = eval { crypt('test', $hash) }; return $newhash eq $hash; } # check_sha512() # Returns undef if SHA512 hashing is supported, or an error message if not sub check_sha512 { return &unix_crypt_supports_sha512() ? undef : 'Crypt::SHA'; } # encrypt_sha512(password, [salt]) # Hashes a password, possibly with the given salt, with SHA512 sub encrypt_sha512 { my ($passwd, $salt) = @_; $salt ||= '$6$'.substr(time(), -8).'$'; return crypt($passwd, $salt); } # unix_crypt_supports_yescrypt() # Returns 1 if the built-in crypt() function can already do yescrypt sub unix_crypt_supports_yescrypt { my $hash = '$y$j9T$waHytoaqP/CEnKFroGn0S/$fxd5mVc2mBPUc3vv.cpqDckpwrWTyIm2iD4JfnVBi26'; my $newhash = eval { crypt('test', $hash) }; return $newhash eq $hash; } # check_yescrypt() # Returns undef if yescrypt hashing is supported, or an error message if not sub check_yescrypt { return &unix_crypt_supports_yescrypt() ? undef : 'Crypt::NaCl::Sodium'; } # encrypt_yescrypt(password, [salt]) # Hashes a password, possibly with the given salt, with yescrypt sub encrypt_yescrypt { my ($passwd, $salt) = @_; $salt ||= &substitute_pattern('$y$j9T$[A-Z]{4}.[a-zA-Z0-9]{16}.$[a-zA-Z0-9]{14}.[a-zA-Z0-9]{7}/[a-zA-Z0-9]{15}/[a-zA-Z0-9]{4}'); return crypt($passwd, $salt); } # validate_password(password, hash) # Compares a password with a hash to see if they match, returns 1 if so, # 0 otherwise. Tries all supported hashing schemes. sub validate_password { my ($passwd, $hash) = @_; # Classic Unix crypt my $chash = eval { local $main::error_must_die = 1; &unix_crypt($passwd, $hash); }; return 1 if ($chash eq $hash); # MD5 if (!&check_md5()) { my $mhash = &encrypt_md5($passwd, $hash); return 1 if ($mhash eq $hash); } # Blowfish if (!&check_blowfish()) { my $mhash = &encrypt_blowfish($passwd, $hash); return 1 if ($mhash eq $hash); } # SHA512 if (!&check_sha512()) { my $shash = &encrypt_sha512($passwd, $hash); return 1 if ($shash && $shash eq $hash); } # yescrypt if (!&check_yescrypt()) { my $shash = &encrypt_yescrypt($passwd, $hash); return 1 if ($shash && $shash eq $hash); } # Some other hashing, maybe supported by crypt my $ohash = eval { crypt($passwd, $hash) }; return 1 if ($ohash && $ohash eq $hash); return 0; } =head2 is_dictionary_word(word) Returns 1 if some file can be found in a dictionary words file =cut sub is_dictionary_word { my ($word) = @_; $word = lc($word); my @files; if ($config{'dict_file'}) { @files = split(/\s+/, $config{'dict_file'}); } else { @files = ( "/usr/share/dict/words", "/usr/share/dict/linux.words", "/usr/dict/words" ); } foreach my $f (@files) { my $found = 0; my $fh = "WORDS"; &open_readfile($fh, $f); while(<$fh>) { s/#.*//; s/\s//; if (lc($_) eq $word) { $found = 1; last; } } close($fh); return 1 if ($found); } return 0; } 1;
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
images | Folder | 0755 |
|
|
lang | Folder | 0755 |
|
|
CHANGELOG | File | 308 B | 0644 |
|
aix-lib.pl | File | 9.79 KB | 0755 |
|
backup_config.pl | File | 817 B | 0755 |
|
build.cgi | File | 162 B | 0755 |
|
coherent-linux-lib.pl | File | 10.4 KB | 0755 |
|
config-aix | File | 181 B | 0644 |
|
config-coherent-linux | File | 116 B | 0644 |
|
config-debian-linux | File | 120 B | 0644 |
|
config-generic-linux | File | 116 B | 0644 |
|
config-mandrake-linux | File | 116 B | 0644 |
|
config-msc-linux | File | 116 B | 0644 |
|
config-open-linux | File | 117 B | 0644 |
|
config-openSUSE-Linux-15.0-ALL | File | 116 B | 0644 |
|
config-openmamba-linux | File | 116 B | 0644 |
|
config-redhat-linux | File | 116 B | 0644 |
|
config-slackware-linux | File | 116 B | 0644 |
|
config-solaris | File | 167 B | 0644 |
|
config-solaris-8-ALL | File | 199 B | 0644 |
|
config-suse-linux | File | 116 B | 0644 |
|
config-trustix-linux | File | 116 B | 0644 |
|
config-united-linux | File | 116 B | 0644 |
|
config.info | File | 282 B | 0644 |
|
config.info.ca | File | 320 B | 0644 |
|
config.info.cs | File | 321 B | 0644 |
|
config.info.de | File | 321 B | 0644 |
|
config.info.es | File | 277 B | 0644 |
|
config.info.fr | File | 350 B | 0644 |
|
config.info.hu | File | 0 B | 0644 |
|
config.info.nl | File | 290 B | 0644 |
|
config.info.no | File | 297 B | 0644 |
|
config.info.pl | File | 309 B | 0644 |
|
config.info.ru | File | 491 B | 0644 |
|
config.info.sv | File | 132 B | 0644 |
|
config.info.uk | File | 500 B | 0644 |
|
debian-linux-lib.pl | File | 10.19 KB | 0755 |
|
edit_aliases.cgi | File | 1.2 KB | 0755 |
|
edit_client.cgi | File | 1.41 KB | 0755 |
|
edit_ethers.cgi | File | 1.14 KB | 0755 |
|
edit_group.cgi | File | 1.81 KB | 0755 |
|
edit_group_shadow.cgi | File | 1.83 KB | 0755 |
|
edit_hosts.cgi | File | 1.31 KB | 0755 |
|
edit_netgroup.cgi | File | 2.01 KB | 0755 |
|
edit_netmasks.cgi | File | 1.16 KB | 0755 |
|
edit_networks.cgi | File | 1.35 KB | 0755 |
|
edit_passwd.cgi | File | 4.8 KB | 0755 |
|
edit_passwd_shadow.cgi | File | 4.8 KB | 0755 |
|
edit_passwd_shadow_full.cgi | File | 4.8 KB | 0755 |
|
edit_protocols.cgi | File | 1.35 KB | 0755 |
|
edit_rpc.cgi | File | 1.3 KB | 0755 |
|
edit_security.cgi | File | 1.92 KB | 0755 |
|
edit_server.cgi | File | 607 B | 0755 |
|
edit_services.cgi | File | 1.52 KB | 0755 |
|
edit_services2.cgi | File | 1.53 KB | 0755 |
|
edit_switch.cgi | File | 1.74 KB | 0755 |
|
edit_tables.cgi | File | 6.24 KB | 0755 |
|
feedback_files.pl | File | 157 B | 0755 |
|
index.cgi | File | 776 B | 0755 |
|
linux-lib.pl | File | 5.27 KB | 0755 |
|
list_switches.cgi | File | 772 B | 0755 |
|
mandrake-linux-lib.pl | File | 10.38 KB | 0755 |
|
md5-lib.pl | File | 7.58 KB | 0755 |
|
module.info | File | 346 B | 0644 |
|
module.info.af | File | 0 B | 0644 |
|
module.info.af.auto | File | 167 B | 0644 |
|
module.info.ar | File | 0 B | 0644 |
|
module.info.ar.auto | File | 195 B | 0644 |
|
module.info.be | File | 0 B | 0644 |
|
module.info.be.auto | File | 287 B | 0644 |
|
module.info.bg | File | 0 B | 0644 |
|
module.info.bg.auto | File | 250 B | 0644 |
|
module.info.ca | File | 163 B | 0644 |
|
module.info.ca.auto | File | 12 B | 0644 |
|
module.info.cs | File | 28 B | 0644 |
|
module.info.cs.auto | File | 145 B | 0644 |
|
module.info.da | File | 0 B | 0644 |
|
module.info.da.auto | File | 154 B | 0644 |
|
module.info.de | File | 136 B | 0644 |
|
module.info.de.auto | File | 12 B | 0644 |
|
module.info.el | File | 0 B | 0644 |
|
module.info.el.auto | File | 235 B | 0644 |
|
module.info.es | File | 31 B | 0644 |
|
module.info.es.auto | File | 138 B | 0644 |
|
module.info.eu | File | 0 B | 0644 |
|
module.info.eu.auto | File | 164 B | 0644 |
|
module.info.fa | File | 0 B | 0644 |
|
module.info.fa.auto | File | 248 B | 0644 |
|
module.info.fi | File | 0 B | 0644 |
|
module.info.fi.auto | File | 158 B | 0644 |
|
module.info.fr | File | 30 B | 0644 |
|
module.info.fr.auto | File | 141 B | 0644 |
|
module.info.he | File | 0 B | 0644 |
|
module.info.he.auto | File | 170 B | 0644 |
|
module.info.hr | File | 0 B | 0644 |
|
module.info.hr.auto | File | 171 B | 0644 |
|
module.info.hu | File | 34 B | 0644 |
|
module.info.hu.auto | File | 147 B | 0644 |
|
module.info.it | File | 0 B | 0644 |
|
module.info.it.auto | File | 152 B | 0644 |
|
module.info.ja | File | 49 B | 0644 |
|
module.info.ja.auto | File | 226 B | 0644 |
|
module.info.ko | File | 39 B | 0644 |
|
module.info.ko.auto | File | 154 B | 0644 |
|
module.info.lt | File | 0 B | 0644 |
|
module.info.lt.auto | File | 169 B | 0644 |
|
module.info.lv | File | 0 B | 0644 |
|
module.info.lv.auto | File | 169 B | 0644 |
|
module.info.ms | File | 149 B | 0644 |
|
module.info.ms.auto | File | 12 B | 0644 |
|
module.info.mt | File | 0 B | 0644 |
|
module.info.mt.auto | File | 144 B | 0644 |
|
module.info.nl | File | 30 B | 0644 |
|
module.info.nl.auto | File | 130 B | 0644 |
|
module.info.no | File | 29 B | 0644 |
|
module.info.no.auto | File | 117 B | 0644 |
|
module.info.pl | File | 107 B | 0644 |
|
module.info.pl.auto | File | 12 B | 0644 |
|
module.info.pt | File | 0 B | 0644 |
|
module.info.pt.auto | File | 164 B | 0644 |
|
module.info.pt_BR | File | 0 B | 0644 |
|
module.info.pt_BR.auto | File | 173 B | 0644 |
|
module.info.ro | File | 0 B | 0644 |
|
module.info.ro.auto | File | 156 B | 0644 |
|
module.info.ru | File | 41 B | 0644 |
|
module.info.ru.auto | File | 246 B | 0644 |
|
module.info.sk | File | 0 B | 0644 |
|
module.info.sk.auto | File | 165 B | 0644 |
|
module.info.sl | File | 0 B | 0644 |
|
module.info.sl.auto | File | 165 B | 0644 |
|
module.info.sv | File | 31 B | 0644 |
|
module.info.sv.auto | File | 123 B | 0644 |
|
module.info.th | File | 0 B | 0644 |
|
module.info.th.auto | File | 347 B | 0644 |
|
module.info.tr | File | 0 B | 0644 |
|
module.info.tr.auto | File | 169 B | 0644 |
|
module.info.uk | File | 0 B | 0644 |
|
module.info.uk.auto | File | 247 B | 0644 |
|
module.info.ur | File | 0 B | 0644 |
|
module.info.ur.auto | File | 244 B | 0644 |
|
module.info.vi | File | 0 B | 0644 |
|
module.info.vi.auto | File | 217 B | 0644 |
|
module.info.zh | File | 34 B | 0644 |
|
module.info.zh.auto | File | 120 B | 0644 |
|
module.info.zh_TW | File | 37 B | 0644 |
|
module.info.zh_TW.auto | File | 126 B | 0644 |
|
msc-linux-lib.pl | File | 10.38 KB | 0755 |
|
nis-lib.pl | File | 6.02 KB | 0755 |
|
nisupdate.conf | File | 1.94 KB | 0644 |
|
old_edit_passwd_shadow.cgi | File | 4.62 KB | 0755 |
|
old_edit_switch.cgi | File | 1.76 KB | 0755 |
|
old_save_switch.cgi | File | 533 B | 0755 |
|
open-linux-lib.pl | File | 7.89 KB | 0755 |
|
openmamba-linux-lib.pl | File | 10.38 KB | 0755 |
|
redhat-linux-lib.pl | File | 10.38 KB | 0755 |
|
save_aliases.cgi | File | 749 B | 0755 |
|
save_client.cgi | File | 661 B | 0755 |
|
save_ethers.cgi | File | 793 B | 0755 |
|
save_file.cgi | File | 588 B | 0755 |
|
save_group.cgi | File | 945 B | 0755 |
|
save_group_shadow.cgi | File | 1.04 KB | 0755 |
|
save_hosts.cgi | File | 758 B | 0755 |
|
save_netgroup.cgi | File | 1.04 KB | 0755 |
|
save_netmasks.cgi | File | 753 B | 0755 |
|
save_networks.cgi | File | 791 B | 0755 |
|
save_passwd_shadow.cgi | File | 2.36 KB | 0755 |
|
save_protocols.cgi | File | 806 B | 0755 |
|
save_rpc.cgi | File | 746 B | 0755 |
|
save_security.cgi | File | 996 B | 0755 |
|
save_server.cgi | File | 184 B | 0755 |
|
save_services.cgi | File | 775 B | 0755 |
|
save_services2.cgi | File | 776 B | 0755 |
|
save_switch.cgi | File | 932 B | 0755 |
|
slackware-linux-lib.pl | File | 9.91 KB | 0755 |
|
solaris-lib.pl | File | 10.45 KB | 0755 |
|
suse-linux-8.2-lib.pl | File | 11.05 KB | 0755 |
|
suse-linux-9.0-lib.pl | File | 11.05 KB | 0755 |
|
suse-linux-lib.pl | File | 11.88 KB | 0755 |
|
switch-lib.pl | File | 3.08 KB | 0755 |
|
trustix-linux-lib.pl | File | 10.38 KB | 0755 |
|
united-linux-lib.pl | File | 11.05 KB | 0755 |
|