【问题标题】:Perl brute force attackPerl 暴力破解
【发布时间】:2015-03-09 00:11:55
【问题描述】:

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

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

【问题讨论】:

  • 什么样的文件?该文件中的密码是如何使用的?
  • 没有标准的密码保护“文件”机制,因此我们无法告诉您如何以编程方式将密码插入用于保护它的未指定系统。
  • 这是我被告知要做的,但我不知道如何实现它。 $returnVal = system("解压 -qq -o -P $password secret_file_brute.zip > /dev/null 2>&1");
  • 什么意思?这就是实现。
  • 是的,但这不是一次测试 $password 中的所有单词吗?我希望它一个一个地测试每个单词,直到找到匹配项

标签: perl while-loop passwords brute-force


【解决方案1】:

我遇到了类似的问题。无论您是在我的班上还是在全国各地的脚本班上都同时做这个问题。我的教授鼓励使用论坛,但我们无法与我们大学的直接同学分享答案。

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

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

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...

    }

}
}

【讨论】:

    【解决方案2】:

    根据我找到的man页面,unzip在无法解密时返回退出码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");
    }
    

    【讨论】:

    • 谢谢,但我如何在特定文件上进行测试?
    • 根据您的其他 cmets 更新。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-04
    • 2011-03-28
    • 1970-01-01
    • 2023-03-12
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多