发个原创的防挂马的脚本
769
- greensnow2011-06-12金牌会员1053
用法:
- 生成网站内php,html,js,css等文件的hash列表
./check /var/www/html/www.site.com/ > filelist
- 检查该目录下文件是否有变动, 包括删除,修改和贴加文件等操作会打印出来
./check filelist- - # Copyright 2011 reve. All Rights Reserved.
- #!/usr/bin/perl -w
- use strict;
- use warnings;
- use YAML qw/Dump LoadFile/;
- use Digest::MD5 qw/md5_base64/;
- use File::Find;
- - my $result = {};
- my $former = {};
- sub calc {
- my $path = shift;
- local *FILE;
- open FILE, $path or die $!;
- local $/ = undef;
- local $_ = ;
- $result->{$path} = md5_base64 $_;
- }
- sub compare {
- while (my($k, $v) = each(%$former)) {
- if (exists $result->{$k}) {
- print "M: $k\n" unless $result->{$k} eq $v;
- delete $result->{$k};
- } else {
- print "D: $k\n";
- }
- }
- for (keys(%$result)) {
- print "A: $_\n";
- }
- }
- sub main {
- die "$0 dir or hashfile.\n" unless ($#ARGV == 0 and -e $ARGV[0]);
- sub cb {my $n = $File::Find::name; calc $n unless -d $n or $n !~ /\.(php|html|htm|css|js)$/i;}
- if (-d $ARGV[0]) {
- find({ follow => 1, wanted => \&cb}, $ARGV[0]);
- print Dump { ROOT => $ARGV[0], HASH => $result };
- } else {
- my $input = LoadFile $ARGV[0];
- $former = $input->{HASH};
- find({ follow => 1, wanted => \&cb}, $input->{ROOT});
- compare;
- }
- }
- main;
- 复制代码