While performing some house cleaning this evening, I came across the following Perl nugget:
#!/usr/bin/perl
my @alphanumeric = ('a'..'z', 'A'..'Z', 0..9);
my $randpassword = join '', map $alphanumeric[rand @alphanumeric], 0..8;
print "$randpasswordn"
This awesome little 3-line script will produce random 8-character alphanumeric passwords:
$ randpasswd.pl
ahvtGRE6U
$ randpasswd.pl
lxVLA7xLv
I wish I knew where I grabbed this from so I could publicly thank the author.
One unnerving thing about UNIX Operating Systems is the number of setuid and setgid root binaries. These binaries run with root privileges, and are often the first binaries examined by individuals wishing to escalate privileges on a system. To keep tabs on setuid and setgid files, the following find(1) statement can be run periodically:
$ find / -type f \( -perm -2000 -o -perm -4000 \) | sort
This will find and sort all binaries with the setuid or setgid bit set. The output can be stored in a secure location, and periodically compared (with a trusted kernel and version of find) with the current set of binaries on a server. While not foolproof, it is definitely better that nothing. :)
While debugging a problem tonight, I had to read through the Solaris mutex.c source code file. If you are interested in learning the nitty gritty details behind mutual exclusion, I highly recommend reading over the section Big Theory Statement for mutual exclusion locking primitives. I am amazed at how well the Sun engineers commented the code!
While messing around with Perl, I created a Perl program that displays output similar to the Linux stat utility:
$ stat.pl /etc/services /etc/passwd /etc/shadow /etc/shadow-
File: /etc/services
Size: 15 Blocks: 2 Block Size: 8192
Device: 22282240 Inode: 7876 Links: 1
Perms: 777 Uid: ( 0 / root ) Gid: ( 0 / root )
Access Time (mtime) : Tue Sep 13 18:48:34 2005
Change Time (ctime) : Mon Aug 15 22:48:37 2005
Modification Time (mtime): Mon Aug 15 22:48:37 2005
File: /etc/passwd
Size: 725 Blocks: 2 Block Size: 8192
Device: 22282240 Inode: 9021 Links: 1
Perms: 644 Uid: ( 0 / root ) Gid: ( 0 / root )
Access Time (mtime) : Tue Sep 13 18:50:51 2005
Change Time (ctime) : Tue Aug 16 00:25:09 2005
Modification Time (mtime): Tue Aug 16 00:25:09 2005
File: /etc/shadow
Size: 376 Blocks: 2 Block Size: 8192
Device: 22282240 Inode: 10176 Links: 1
Perms: 400 Uid: ( 0 / root ) Gid: ( 0 / root )
Access Time (mtime) : Tue Sep 13 18:50:51 2005
Change Time (ctime) : Tue Aug 16 00:25:18 2005
Modification Time (mtime): Tue Aug 16 00:25:18 2005
This will be a useful little utility once I cleanup the Perms and Device lines. :)
I came across SQLZOO last week while searching Google for SQL programming tutorials. In addition to the numerous awesome tutorials, they show the vendor specific SQL required to perform numerous database specific functions (e.g., show all tables in my schema). Great site!