Perl 暴力破解

Perl brute force attack

我在尝试创建暴力破解脚本时遇到了很多麻烦。我需要破解的密码长度为1到4个字符,全部为小写字母。我想我已经想出了生成所有可能组合的代码,但我不确定如何在文件上测试它。任何指导或提示都会很棒。

$password = "aaaa";
while ( length $password < 5 ) {
print "$password\n";
$password++;

根据我找到的man页面,unzip returns无法解密时退出代码82。

sub try {
   my ($password) = @_;
   system("unzip -qq -o -P $password secret_file_brute.zip >/dev/null 2>&1");
   die("Can't launch unzip: $!\n") if $? == -1;
   die("unzip killed by signal ".($? & 0x7F)."\n") if $? & 0x7F;
   my $exit_code = $? >> 8;
   die("unzip exited with error $exit_code\n") if $exit_code && $exit_code != 82;
   return !$exit_code;
}

您的代码不会生成所有可能的密码(例如,它不会生成 aaa)。以下是:

sub brute_force {
   for (my $password = 'a'; length($password)<5; ++$password) {
      return $password if try($password);
   }

   return undef;
}

最后一点是显示结果。

{
   my $password = brute_force();
   defined($password)
      or die("Password not found\n");

   print("$password\n");
}

我遇到了类似的问题。要么你在我的 class 要么在全国各地的脚本 classes 同时做这个问题。我的教授鼓励使用论坛,但我们不能与我们大学的直接 class 同学分享答案。

如果您通过 class 通过我的用户名认识我,那么请不要使用我的代码。否则享受。我对代码进行了评论,因为从工作代码中学习是最好的学习方式。

只要你只使用字母,你就可以增加一个标量而不是嵌套循环。如果你确实需要使用其他字符,我敢打赌你可以只使用一个可能的字符数组并为每个位置递增该数组,但让我们忽略它,因为你似乎只需要那些字母 =)

sub brute2()
{
print "Bruteforce Attack...\n";
print "Enter password length: "; #Prompt user for maximum length for pass
chomp(my $plen = (<>)); #Receive input and remove newline character
print "Password Length is $plen\n";
$plen++;
print "Press any key to continue.\n"; #Execute once they hit any key
if (<>)
{

    my $pass = "a"; #This code assumes only letters a..z, so we just set here
    while ( length $pass < $plen ) #Run check loop until we exaust all possibilities within the maximum length
    {

        my $status = system("unzip -pp -o -P $pass secret_file_brute.zip > /dev/null 2>&1"); #System call to compare our password against a zip file, this will set status to the return value
        print ("Attempting: $pass Return: $status\n");
        if ($status == 0) #Return value of 0 means success
        {

        print ("Password is: $pass Return is: $status\n"); #Print correct password. I did return value also for debug
        last; #Break loop since we got correct password

        }
        $pass++; #Increment $pass var to next iteration IE "a" to "b", "aa" to "ab", "zzz" to "aaaa" etc...

    }

}
}