#!/usr/bin/perl -wT # # $Id: doskey.pl,v 1.9 2003/01/13 05:28:43 jmates Exp $ # # Copyright (c) 2000-2002, Jeremy Mates. This script is free # software; you can redistribute it and/or modify it under the same # terms as Perl itself. # # Run perldoc(1) on this file for additional documentation. # ###################################################################### # # REQUIREMENTS require 5; use strict; ###################################################################### # # MODULES use Carp; # better error reporting use Getopt::Std; # command line option processing ###################################################################### # # VARIABLES my $VERSION; ($VERSION = '$Revision: 1.9 $ ') =~ s/[^0-9.]//g; my (%opts, $number, $mac, $skeyinit, $skey, $skeyinfo, $info, $status); $number = 7; # default number of s/key passwords to generate # which hash algorithm to use; no need to obfuscate which one as new # OpenSSH 2.5.1 displays the hash used in S/Key challenge... $mac = '-rmd160'; # where to find certain binaries $skeyinit = '/usr/bin/skeyinit'; $skey = '/usr/bin/skey'; $skeyinfo = '/usr/bin/skeyinfo'; ###################################################################### # # MAIN # parse command-line options getopts('h?n', \%opts); help() if exists $opts{'h'} || exists $opts{'?'}; $number = $opts{'n'} if exists $opts{'n'}; # init skey with their chosen number of OTP's warn "$0: creating new s/key list...\n"; $status = system($skeyinit, '-n', $number, $mac); die "$skeyinit exited funny: $?\n" unless $status == 0; # get the info string (note that open() uses shell so ain't safe!) warn "$0: gathering s/key info...\n"; open(INFO, "$skeyinfo |") or die "Problem with $skeyinfo: $!\n"; while () { chomp; if (s/[^A-Za-z0-9. -]//g) { die "unknown character(s) striped from $skeyinfo output"; } # "untaint" the input... m/^(.*)/; $info = $1; } # show them their OTP's warn "$0: displaying upcoming passwords...\n"; $status = system("$skey -n $number $mac $info"); die "$skey exited funny: $?\n" unless $status == 0; exit; ###################################################################### # # SUBROUTINES # clean up enviro settings for Taint mode sub BEGIN { delete @ENV{qw:IFS CDPATH PATH ENV BASH_ENV:}; } # a generic help blarb sub help { print <<"HELP"; Usage: $0 [options] $0 is a script to automate the creation of one-time passwords. Options for version $VERSION: -h/-? Display this message -n N Generate N many passwords instead of $number. Run perldoc(1) on this script for additional documentation. HELP exit; } __END__ ###################################################################### # # DOCUMENTATION =head1 NAME doskey.pl - script to automate s/key password generation. =head1 SYNOPSIS To generate an arbitrary number of passwords: $ doskey.pl [-n number] =head1 DESCRIPTION doskey.pl ties together a bunch of s/key utilities to ease the pains of creating password lists, and should work fine on any OpenBSD system. By default, a random hash is used and a low number of passwords are generated; this was a design choice to suit my needs. Setup of s/key is beyond the scope of this document; consult the appropriate man pages to get s/key up and running. =head1 USAGE $ doskey.pl [-n number] A constant controls what the default number of passwords generated is, set really low to suit my (illusions of) nefarious designs. Either use the command line option to override the default, or hack this script. =head1 OPTIONS Not very many, just -h for help and -n that takes a numeric argument. =head1 ENVIRONMENT Requires an OpenBSD box, which should have s/key installed, or a system where s/key has been installed just like on OpenBSD. =head1 BUGS =head2 Reporting Bugs Newer versions of this script may be available from: http://sial.org/code/perl/ If the bug is in the latest version, send a report to the author. Patches that fix problems or add new features are welcome. =head2 Known Issues No known bugs. =head1 SEE ALSO perl(1), skey(1), skeyinfo(1), skeyinit(1) =head1 AUTHOR Jeremy Mates, http://sial.org/contact/ =head1 COPYRIGHT Copyright (c) 2000-2002, Jeremy Mates. This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 VERSION $Id: doskey.pl,v 1.9 2003/01/13 05:28:43 jmates Exp $ =cut