Perl - WPA の 256bit キー を求める

SSID と passphrase (8文字から63文字のASCII印字可能文字) から WPA の 256bit キー を求める Perl スクリプト。前提として Crypt::PBKDF2 が必要。

#!/usr/bin/env perl
use strict;
use warnings;
use Crypt::PBKDF2;
use Getopt::Long qw{:config auto_help};

GetOptions(\my %options, qw{ssid=s pass=s}) or exit 1;

if (!exists $options{ssid} || !exists $options{pass}) {
    die "Specify ssid and passphrase.\n";
}
elsif (length($options{pass}) < 8 || length($options{pass}) > 63) {
    die "Passphrase must be 8..63 characters.\n";
}

my $ssid = $options{ssid};
my $pass = $options{pass};
my $len  = length($ssid);

my $pbkdf2 = Crypt::PBKDF2->new(
    hash_class => 'HMACSHA1',
    iterations => 4096,
    output_len => 256 / 8,
    salt_len   => $len,
);

my $hex  = $pbkdf2->PBKDF2_hex($ssid, $pass);
print $hex, "\n";

=head1 SYNOPSIS

    wpa-key -s SSID -p PASS

=cut

使用例

f:id:ks0608:20120606020811p:plain