Ninja Banana
Ninja Banana

Reputation: 21

Perl code, defining arguments

I have a perl code, but whenever I run it, I can't seem to figure out how to define the first and second argument. Here is the code, help much appreciated.

#!/usr/bin/env perl
use Crypt::PBKDF2;

if (@ARGV < 2) {   
print "[!] Error: please specify hash (first argument) and salt (second argument)\n";
exit (1); 
} 
my $match = pack ("H*", $ARGV[0]); # TODO: check if it is of length 40 
my $salt  = pack ("H*", $ARGV[1]); # of length 8? 
my $iter  = 1000; 
my $pbkdf2 = Crypt::PBKDF2->new (hash_class => 'HMACSHA1', iterations => $iter);
my $num;
for ($num = 0; $num < 10000; $num++) {
   my $pass = sprintf ("%04d", $num);
   my $hash = $pbkdf2->PBKDF2 ($salt, $pass);
   if ($match eq $hash) {
      printf ("%s:%s:%s:%s\n", unpack ("H*", $hash), unpack ("H*", $salt), $iter, $pass);
      exit (0);
   }
}
exit (1);

Upvotes: 2

Views: 122

Answers (2)

Dave Cross
Dave Cross

Reputation: 69244

All of Perl's special variables are defined in perldoc perlvar, which says the following..

@ARGV

The array @ARGV contains the command-line arguments intended for the script.

If you have suggestions on how that can be made clearer, I'd love to hear them :-)

Upvotes: 0

lightbringer
lightbringer

Reputation: 835

if you're refering to these 2 arguments

my $match = pack ("H*", $ARGV[0]); # TODO: check if it is of length 40 
my $salt  = pack ("H*", $ARGV[1]); # of length 8?

They are defined in the command line.

Assuming your script file is script.pl In the command line, you need to run

perl script.pl <match> <salt>

@ARGV is the array containing the command line arguments in Perl

Upvotes: 2

Related Questions