Perl - 我的解压缩系统调用zip文件破解的问题



我是一名大三学生,目前正在上一门脚本语言课,据说可以在一个学期内用中级水平的bash,perl和python来吐出我们。由于这门课是加速的,我们快速完成主题,如果我们有问题,我们的教授会支持使用论坛来补充我们的学习。

我目前正在做我们的第一项任务。要求是使用提供的单词列表"linux.words"和基本的暴力攻击来创建非常简单的字典攻击。蛮力需要补偿 4 个字母字符串的任意组合。

我使用打印语句来检查我的逻辑是否合理,看起来是合理的。如果你对如何提高我的逻辑有任何建议,我在这里学习,我全心全意。

这是在 Ubuntu v12.04 上,以防相关。

我尝试用像独角兽这样的直接词替换调用中的标量,它运行良好,显然是错误的密码,并且它正确返回。我已经在终端和脚本本身中都这样做了。我的教授看了整整15分钟,然后把我推荐给论坛,并说它看起来不错。他怀疑由于我使用Notepad++编写代码,因此可能存在隐藏字符。我使用 vim 直接在终端中重写了代码,它给出了与上述相同的错误。下面粘贴的代码来自 vim。

我的实际问题是我的系统调用给我带来了问题。它返回用于解压缩显示用法和其他帮助材料的帮助函数。

这是我的代码。

#!/usr/bin/perl 
use strict;
use warnings;
#Prototypes
sub brute();
sub dict();
sub AddSlashes($);
### ADD SLASHES ###
sub AddSlashes($)
{
    my $text = shift;
    $text =~ s/\/\\/g;
    $text =~ s/'/\'/g;
    $text =~ s/"/\"/g;
    $text =~ s/\0/\\0/g;
    return $text;
}
### BRUTEFORCE ATTACK ###
sub brute()
{
    print "Bruteforce Attack...n";
    print "Press any key to continue.n";
    if (<>)
    {
        #INCEPTION START
        my @larr1 = ('a'..'z'); #LEVEL 1 +
        foreach (@larr1)
        {
        my $layer1 = $_; #LEVEL 1 -
            my @larr2 = ('a'..'z'); #LEVEL 2 +
            foreach (@larr2)
            {
            my $layer2 = $_; # LEVEL 2 -
                my@larr3 = ('a'..'z'); #LEVEL 3 +
                foreach (@larr3)
                {
                my $layer3 = $_; #LEVEL 3 -
                    my@larr4 = ('a'..'z'); #LEVEL 4 +
                    foreach (@larr4)
                    {
                    my $layer4 = $_;
                    my $pass = ("$layer1$layer2$layer3$layer4"); 
                    print ($pass); #LEVEL 4 -
                    }
                }
            }
        }
    }
}
### DICTIONARY ATTACK ###
sub dict()
{
    print "Dictionary Attack...n"; #Prompt User
    print "Provide wordlist: ";
    my $uInput = "";
    chomp($uInput = <>); #User provides wordlist
    (open IN, $uInput) #Bring in wordlist
        or die "Cannot open $uInput, $!"; #If we cannot open file, alert
    my @dict = <IN>; #Throw the wordlist into an array
    foreach (@dict)
    {
        print $_; #Debug, shows what word we are on
        #next; #Debug
        my $pass = AddSlashes($_); #To store the $_ value for later use
        #Check pass call
        my $status = system("unzip -qq -o -P $pass secret_file_dict.zip > /dev/null 2>&1"); #Return unzip system call set to var
        #Catch the correct password
        if ($status == 0)
        {
            print ("Return of unzip is ", $status, " and pass is ", $pass, "n"); #Print out value of return as well as pass
            last;
        }
    }
}
### MAIN ###
dict();

exit (0);

这是我的错误

See "unzip -hh" or unzip.txt for more help.  Examples:
  unzip data1 -x joe   => extract all files except joe from zipfile data1.zip
  unzip -p foo | more  => send contents of foo.zip via pipe into program more
  unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer
aerify
UnZip 6.00 of 20 April 2009, by Debian. Original by Info-ZIP.
Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
  Default action is to extract files in list, except those in xlist, to exdir;
  file[.zip] may be a wildcard.  -Z => ZipInfo mode ("unzip -Z" for usage).
  -p  extract files to pipe, no messages     -l  list files (short format)
  -f  freshen existing files, create none    -t  test compressed archive data
  -u  update files, create if necessary      -z  display archive comment only
  -v  list verbosely/show version info       -T  timestamp archive to latest
  -x  exclude files that follow (in xlist)   -d  extract files into exdir
modifiers:
  -n  never overwrite existing files         -q  quiet mode (-qq => quieter)
  -o  overwrite files WITHOUT prompting      -a  auto-convert any text files
  -j  junk paths (do not make directories)   -aa treat ALL files as text
  -U  use escapes for all non-ASCII Unicode  -UU ignore any Unicode fields
  -C  match filenames case-insensitively     -L  make (some) names lowercase
  -X  restore UID/GID info                   -V  retain VMS version numbers
  -K  keep setuid/setgid/tacky permissions   -M  pipe through "more" pager
  -O CHARSET  specify a character encoding for DOS, Windows and OS/2 archives
  -I CHARSET  specify a character encoding for UNIX and other archives
See "unzip -hh" or unzip.txt for more help.  Examples:
  unzip data1 -x joe   => extract all files except joe from zipfile data1.zip
  unzip -p foo | more  => send contents of foo.zip via pipe into program more
  unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer
aerifying

它显然是不完整的。总的来说,我将切换蛮力();对于字典();根据需要进行测试。一旦我让系统调用工作,我会把它扔到暴力部分。

如果您需要我详细说明我的问题,请告诉我。我在这里专注于学习,所以请在您回复我的任何事情中添加白痴证明评论。

首先:不要使用 PERL 的原型。他们不会做你或你的教授可能希望他们做的事情。

第二:不要写自制的转义套路,比如AddSlashes。Perl 有 quotemeta。使用它。

您的问题不在于特定的编程语言。你的教授在你的问题上花了多少时间,你上了多少课与问题无关。专注于实际问题,而不是所有无关紧要的"东西"。

比如,sub brute的意义何在?您没有在此脚本中调用它,它与您的问题无关,因此不要发布它。将您的问题缩小到最小的相关部分。

不要提示输入dict正文中的单词列表文件。将功能分成一口大小的块,以便在每个上下文中您可以专注于手头的问题。dict_attack子例程应期望接收文件句柄或对单词数组的引用。为了保持较低的内存占用,我们假设它是一个文件句柄(因此您不必将整个单词列表保留在内存中)。

因此,您的main如下所示:

sub main {
    # obtain name of wordlist file
    # open wordlist file
    # if success, call dict_attack with filehandle
    # dict_attack returns password on success
}

现在,您可以专注于 dict_attack .

#!/usr/bin/perl
use strict;
use warnings;
main();
sub dict_attack {
    my $dict_fh = shift;
    while (my $word = <$dict_fh>) {
        $word =~ s/As+//;
        $word =~ s/s+z//;
        print "Trying $wordn";
        my $pass = quotemeta( $word );
        my $cmd = "unzip -qq -o -P $pass test.zip";
        my $status = system $cmd;
        if ($status == 0) {
            return $word;
        }
    }
    return;
}
sub main {
    my $words = join("n", qw(one two three four five));
    open my $fh, '<', $words or die $!;
    if (my $pass = dict_attack($fh)) {
        print "Password is '$pass'n";
    }
    else {
        print "Not foundn";
    }
    return;
}

输出:

C:\...> perl y.pl尝试一个尝试两个尝试三个尝试四个尝试五密码为"五"

最新更新