mod_security日志信息提取工具 - modgrep

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#!/usr/bin/perl

use Getopt::Std;
use vars qw/ %opt /;
my $opt_string = 'hf:s:v:';
getopts( "$opt_string", \%opt ) or usage();
usage() if $opt{h};

if ($opt{f}) {
    open(FH,"<$opt{f}") || die "cant find $opt{f} file $!\n";
}

if ($opt{s}) {
    $sstr = $opt{s};
}

$/ = "-Z--\n";

while(my $line = <FH>) {
    chomp $line;
    if ($line =~ m/$sstr/g) {
        print "========================================\nMatched Transaction for Search String ($sstr)\n========================================\n";
        print $line,"-Z--\n";
        print "\n";

    }
}
close(FH);

exit;

sub usage()

{
    print STDERR << "EOF";

This program does...

usage: $0 [-hf:s:v:]
    if a file is compressed then it will be uncompressed on the fly

    default   : display usage
    -f file   : file to search through
    -s string : string to match on - enclosed in quotes if it
                contains spaces

    -v level  : verbose output
    -h        : this (help) message

example:

         $0
         $0 -f
         $0 -s
         $0 -v level               Verbose/Debug messages, where level = 0..9
EOF
    exit;
}