【问题标题】:Brute force attack test on password for file文件密码蛮力攻击测试
【发布时间】:2015-03-06 08:12:33
【问题描述】:

我正在尝试创建一个可以处理特定文件密码的蛮力。

我不确定如何让这段代码工作。这就是我到目前为止所拥有的。此代码为密码生成正确的可能组合,但我不确定如何将其实现为暴力攻击。

my @alpha = qw(a b c d e f g h i j k l m n o p q r s t u v w x y z);
my $password = @alpha[1];
my @combo = ();

for my $one(@alpha){
for my $two(@alpha){
for my $three(@alpha){
for my $four(@alpha){ push @combo, "$one$two$three$four\n"} }}

我假设我需要在某处使用此命令,secret_file_brute.zip 是我用来测试的文件。

我不知道如何声明$password 变量以及如何从上面一一输入我生成的组合,其中$password 命令是直到密码匹配为止。

$returnVal = system("unzip -qq -o -P $password
secret_file_brute.zip > /dev/null 2>&1");

【问题讨论】:

  • 旁白:您可能不希望在 @combo 元素中使用 \n - 看起来您将其放在那里以查看打印输出(而 join 本来是更好的方法实现)
  • 您是否尝试生成由 26 个拉丁字母组成的所有可能的密码组合(例如 8 个字符长)?

标签: perl passwords combinations system-calls brute-force


【解决方案1】:

我认为您正在尝试使用 26 个拉丁字符生成所有可能的密码组合。正确的?为什么不使用 increment 运算符?

$password = "a";
for (;;) {
    say "$password";
    $password++;
}

$password 将从a 变为z,然后从aa 变为zz,然后从aaa 变为zzz,等等。因此从26 个拉丁字母字符。

如果您只对四个字符组合感兴趣:

$password = "aaaa";
while ( length $password < 5 ) {
    say "$password";
    $password++;
}

【讨论】:

    【解决方案2】:

    暴力破解密码效率非常低,因此除了作为概念证明之外没有真正的用处。 你有一个 4 个字符的字母密码,这是一个相当简单的情况。

    首先 - 你可以写:

    my @alpha =( "a".."z" );
    

    在你做的时候生成单词会起作用,但你会插入一个换行符,这意味着你正在运行的任何system 命令都不起作用。

    您还可能会发现,在进行中进行尝试会提高您的速度,尤其是因为您可以轻松地使用多处理来进行此类操作。

    另外 - 您可以捕获 system 的返回码,以查看何时成功。捕获系统的 text 输出无济于事 - 您需要检查 $? - 请参阅:http://perldoc.perl.org/functions/system.html

    可能是这样的?

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use Parallel::ForkManager;
    
    my $parallel = 8;
    
    my @alpha = ( "a" .. "z" );
    
    my $manager = Parallel::ForkManager->new($parallel);
    
    my $parent_pid = $$; 
    
    for my $one (@alpha) {
        for my $two (@alpha) {
            for my $three (@alpha) {
                for my $four (@alpha) {
                    $manager->start and next;
                    system(
                        "unzip -qq -o -P $one$two$three$four secret_file_brute.zip > /dev/null 2>&1"
                    );
                    if ( not $? ) {
                          print "Password was $one$two$three$four\n";
                          kill $parent_pid;
                    }
    
                    $manager->finish;
                }
            }
        }
    }
    

    【讨论】:

    • 这很好用,但有没有办法在没有 Parallel::Forkmanger 或任何其他模块的情况下做到这一点?
    • 是的。注释掉这些行。或者只是阅读内置的 fork()。但我要指出 Perl 的一大优势是代码重用。
    猜你喜欢
    • 2021-01-10
    • 1970-01-01
    • 1970-01-01
    • 2011-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-01
    相关资源
    最近更新 更多