[Chugalug] silly perl one liner to randomize passwords

Robert A. Kelly III bluethegrappler at gmail.com
Thu Mar 20 20:00:40 UTC 2014


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

On 03/05/2014 07:17 PM, Dan Lyke wrote:
> On Wed, 05 Mar 2014 18:46:07 -0500 Rod <rod-lists at epbfi.com>
> wrote:
>> I remember the perl script to decode dvd's. It was a popular end
>> tag on emails. damn perl is some black magic.
> 
> Not gonna deny that Perl is some black magic, but if you format it
> and unwrap the "-p":
> 
> 
> # Reads 4x the argument count as base 64 bytes, substitutes out
> any # non \w ([A-Za-z_0-9]) chars, returns the count bytes as
> random.
> 
> sub r { $l=shift;
> 
> # Open the filehandle "R" as the pipe of base64 encoding # reading
> from /dev/urandom
> 
> open(R,"base64 /dev/urandom|")||die$!; sysread(R,$R,$l*4); 
> close(R);
> 
> $R=~s/[^\w]//g; substr($R,0,$l)
> 
> # return is assumed. People doing this in my code will be
> thrashed. }
> 
> 
> # '-p' puts an assumed #     while (<>) { ... print $_; } # around
> your '-e' argument. 'while (<>)' is shorthand for # 'while we can
> read a line from the file into $_'
> 
> while (<>) { # Split the passwd line into an array based on ':' as
> a separator @P=split/:/;
> 
> # If the password field [1] is '$6' if($P[1]=~/\$6/) { # $s is 8
> random bytes, $p is 16 random bytes $s=&r(8); $p=&r(16);
> 
> # Replace the password with $p, salted with $r
> 
> $P[1]=crypt($p,"\$6\$$s");
> 
> # rebuild the new password line $_=join(":", at P); } print $_; }
> 
> 
> See? Nothin' to it.

Excellent! I was just thinking that someone should point out that an
obtuse one liner would generally be much more useful for didactic
purposes if it were broken down, formatted, and commented. The one
liner itself is brilliant, of course. But this certainly makes Perl
more approachable. Thanks for sharing!

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJTK0jnAAoJEFJIfKV7IxD6L9AP/RHsp67yUS9HOPIpWVVvcF2w
tS4ZwwpvFLK61ccjGBrmXf+9hp9W6TCpG46DKFI62opaIFj/tFruHwBwoxis/tyo
8UqGUTolH6lR4db8k0emDChkcx4UGlEVORYQBUf1fcl22EXRAUiSwbDMdzeRwv2H
uSeX/27Xc98+DkocrTRHWfEm44Pc8AWOtbWPHbl2+Ybg7XiCC7rRMWuOPxa0FQtF
e4kFE9WQrLoRfzRjXf/fwqfnIfKi5cke8Nb1jIIQT1Hrczh6APVy2m1c9PkuFVSd
4QrwjuG6ZiJYQDiklfzmq+w778ZPNHUTInOOe5NA/+G2o9AGPMNwkymflTL6x4L4
A0BeBStzeXRd3pkqIGpJsQAzEHdV72dDZV3sWDuMQtpo2FxgIta1Yt+KXwR5Aksa
ModfUaJhNxyi16FXtryYcVOBGTwgmlEm+aU7eFZM5yoUi1OznwuxxFNyQts+kfU8
0FjmQTD5MER/Q5DIarh1lT0cKp6/+kXAuS93gUY6/NdYV3mdPnscxaCbOOIjl7E8
pEE0PTfe4oNDZfG2u7J8qpNF5L6YaJnHuWfxxrOKHbGmeCebaYac8sv5UalMj4h9
U8YPg/RL75tyC/95JLcIBDKgC+lkfQcM1boIKvxMUaXi8DZQ8ZJ/5q/tus+j0c60
GM1muiWg5qaTrr+93p0L
=l1VP
-----END PGP SIGNATURE-----


More information about the Chugalug mailing list