-3

次のperlスクリプトを実行しようとしていますが、エラーが表示されます。必要なファイルは、スクリプトファイルの同じディレクトリに配置します。

#! /usr/bin/perl

@attackFileList=("_perParamDefaut_URLs.txt", "_perParam_URLs.txt", "_Cartesian_URLs.txt", "_Random_URLs.txt");
@legitFileList=("_Legit_URLs.txt");

$app=$ARGV[0];

print "Testing $app\n";
$startTime=time();
$attackCaught=$notCaught=$syntaxError=$other=$total=$error=$redirect=$success=0;
for $fileEnding (@attackFileList) {
    $fileName="$app$fileEnding";
    open(inputFile, "D:\\$app/$fileName") || die "Could not open $fileName\n";
    while ($line=<inputFile>) {
        chomp $line;
        @wget = split / /, $line;

        if ($wget[1] ne "--post-data") {
                        $wget[1] =~ s/"/\\"/g;
                $wget[1] =~ s/`/\\`/g;
                $wget[1] =~ s/_nosessions/_current/;
                $wget[1] =~ s/endeavor.cc.gt.atl.ga.us/localhost:8080/;
                $wget[1] =~ s/^\\"(.*)\\"$/"\1"/;
                $command=$wget[0]." -O - "."\"".$wget[1]."\"";
        } else {
                $wget[2] =~ s/"/\\"/g;
                $wget[2] =~ s/`/\\`/g;
                $wget[3] =~ s/_nosessions/_current/;
                $wget[3] =~ s/endeavor.cc.gt.atl.ga.us/localhost:8080/;
            $wget[2] =~ s/^\\"(.*)\\"$/"\1"/;
            $command=$wget[0]." -O - ".join(" ", $wget[1], $wget[2], $wget[3]);
        }

        $output=`$command 2>&1`;
        $retValue=$?>>8;
        if (($retValue == 0)||($output=~/302 Moved Temporarily/)) {
            if ($output=~/amnesia\.SQLIAException/) {
                    $attackCaught++;
                #print errorLog "PolicyViolationException:\n \t$wget[3]\n\t$wget[2]\n\t$command\n\n";
                } elsif ($output=~/amnesia\.UndetectedSQLIA/) {
                    $notCaught++;
                print errorLog "UndetectedSQLIA:\n \t$wget[3]\n\t$wget[2]\n\t$command\n\n";
                } elsif ($output=~/lexer\.SQLLexerException/) {
                    $syntaxError++;
                #print errorLog "SyntaxError:\n \t$wget[3]\n\t$wget[2]\n\t$command\n\n";
                } else {
                if ($output=~/302 Moved Temporarily/) {
                    $redirect++;
                }
                    $other++;
            }
            $success++;
        } else {
            $error++;
        }
        $total++;
        if (($total % 100) == 0) {print "$total, ";}
    }
    close(inputFile);
}
print "\n";
$endTime=time();

$elapsedTime=$endTime-$startTime;

print "**Testing Results: Attack**\n";
print "Total: $total\n";
print "\tValid URL requests: $success\n";
print "\t\tSQLIA detected: $attackCaught\n";
print "\t\tUndetected: $notCaught\n";
print "\t\tSyntax Errors: $syntaxError\n";
print "\t\tOther: $other\n";
print "\t\t\tRedirects: $redirect\n";
print "\tError URL requests: $error\n";
$omitted=$total-$error-$success;
print "\tOmitted: $omitted\n";
print "\nTime: $elapsedTime seconds\n";

open (outFile, ">>Effective.results") || die "Could not open Effective.results\n";
print outFile "$app-attk\t$total\t$success\t$attackCaught\t$notCaught\t$syntaxError\t$other\t$error\t$omitted\n";
close(outFile);

$startTime=time();
$attackCaught=$notCaught=$syntaxError=$other=$total=$error=$redirect=$success=0;
foreach $fileEnding (@legitFileList) {
    $fileName="$app$fileEnding";
    open(inputFile, "$app/$fileName") || die "Could not open $fileName\n";
    while ($line=<inputFile>) {
        chomp $line;
        @wget = split / /, $line;

        if ($wget[1] ne "--post-data") {
            $wget[1] =~ s/"/\\"/g;
                $wget[1] =~ s/`/\\`/g;
            $wget[1] =~ s/_nosessions/_current/;
            $wget[1] =~ s/endeavor.cc.gt.atl.ga.us/localhost:8080/;
            $wget[1] =~ s/^\\"(.*)\\"$/"\1"/;
                    $command=$wget[0]." -O - "."\"".$wget[1]."\"";
        } else {
            $wget[2] =~ s/"/\\"/g;
                        $wget[2] =~ s/`/\\`/g;
            $wget[3] =~ s/_nosessions/_current/;
            $wget[3] =~ s/endeavor.cc.gt.atl.ga.us/localhost:8080/;
            $wget[2] =~ s/^\\"(.*)\\"$/"\1"/;
            $command=$wget[0]." -O - ".join(" ", $wget[1], $wget[2], $wget[3]);
        }

        $output=`$command 2>&1`;
        $retValue=$?>>8;
        if (($retValue == 0)||($output=~/302 Moved Temporarily/)) {
            if ($output=~/amnesia\.SQLIAException/) {
                    $attackCaught++;
                print errorLog "SQLIAException:\n\t$wget[3]\n\t$wget[2]\n\t$command\n\n";
                } elsif ($output=~/amnesia\.UndetectedSQLIA/) {
                    $notCaught++;
                print errorLog "UndetectedSQLIA:\n \t$wget[3]\n\t$wget[2]\n\t$command\n\n";
                } elsif ($output=~/lexer\.SQLLexerException/) {
                    $syntaxError++;
                print errorLog "SyntaxError:\n \t$wget[3]\n\t$wget[2]\n\t$command\n\n";
                } else {
                if ($output=~/302 Moved Temporarily/) {
                    $redirect++;
                }
                    $other++;
            }
            $success++;
        } else {
            $error++;
        }

        $total++;
        if (($total % 100) == 0) {print "$total, ";}
    }
    close(inputFile);

}
print "\n";
$endTime=time();
close(errorLog);
$elapsedTime=$endTime-$startTime;

print "**Testing Results: Legit**\n";
print "Total: $total\n";
print "\tValid URL requests: $success\n";
print "\t\tSQLIA detected: $attackCaught\n";
print "\t\tUndetected: $notCaught\n";
print "\t\tSyntax Errors: $syntaxError\n";
print "\t\tOther: $other\n";
print "\t\t\tRedirects: $redirect\n";
print "\tError URL requests: $error\n";
$omitted=$total-$error-$success;
print "\tOmitted: $omitted\n";
print "\nTime: $elapsedTime seconds\n";

open (outFile, ">>Effective.results") || die "Could not open Effective.results\n";
print outFile "$app-legit\t$total\t$success\t$attackCaught\t$notCaught\t$syntaxError\t$other\t$error\t$omitted\n";
close(outFile);

呼び出し:perlscript.batポータル

結果:ファイルportal_perParamDefault_URLs.txtを開くことができませんでした

4

2 に答える 2

3

あなたのコーディングはひどいですが、あなたの質問への答えは、_perParamDefault_URLsあなたがどこにいるの_perParamDefaut_URLsかということかもしれません。

他の人に時間を割いて助けを求める前に、コードを適切にフォーマットして読みやすくし、プログラムの先頭にuse strictanduse warningsを追加し、すべての変数をmy最初の使用ポイントの近くで宣言してください。

また、レキシカル ファイルハンドル ( の 3 つのパラメーター形式) を使用し、ダイ文字列の内容に変数をopen追加する必要があります。$!へのボイラープレート呼び出しは次のopenようになります

open my $fh, '<', $filename or die "Unable to open '$filename': $!";
于 2012-08-13T10:59:46.977 に答える
1

Windows パスは、バックスラッシュの代わりにスラッシュでFile::Spec処理するか、次のように処理することをお勧めします。

my $full_path = File::Spec->catpath( "D", $app, $fileName )
open( inputFile, $full_path) or die $!;
于 2012-08-13T09:39:02.493 に答える