proftpdlog文件实时分析,动态封禁/解封

作者:凯旋网络来源:凯旋网络

proftpdlog文件实时分析,动态封禁/解封

作者:凯旋网络来源:凯旋网络
content
  • 广告推荐
    ;
    $line= proftpdlog文件实时分析,动态封禁/解封 - 凯旋网络

    proftpdlog文件实时分析,动态封禁/解封

    作者:凯旋网络来源:凯旋网络
    content
  • 广告推荐
    ;

    $badip=get_bad_ip($line);

    if(!$badip){
    next;
    }

    #printSTDERR"badip:$badip\n";

    #删除BADLIST中的过期IP
    refresh_bad_ip();

    #添加multilogin的ip到BADLIST
    add_bad_ip($badip);

    #把平均每秒连接次数>$DENY_RETRY_TIMES_PER_SEC的IP封掉
    check_bad_ip();

    #将封禁时间>$DENY_PERIOD的ip解封
    undeny_bad_ip();
    }

    exit(0);

    ##############################
    subget_bad_ip
    {
    local($line);
    $line= proftpdlog文件实时分析,动态封禁/解封 - 凯旋网络

    proftpdlog文件实时分析,动态封禁/解封

    作者:凯旋网络来源:凯旋网络
    content
  • 广告推荐
    [0];
    returnundefif(!$line);

    if($line=~/ftp\.zixia\.net\((\d \.\d \.\d \.\d )\[[^\]] \]\)-
    Connectionrefused\(maxclientsperhost\d \)\./){
    return$1;
    }else{
    returnundef;
    }
    }

    subadd_bad_ip
    {
    local($badip);
    $badip= proftpdlog文件实时分析,动态封禁/解封 - 凯旋网络

    proftpdlog文件实时分析,动态封禁/解封

    作者:凯旋网络来源:凯旋网络
    content
  • 广告推荐
    [0];
    die"add_bad_ip()takenoparamerr"unless$badip;

    ($seconds,$microseconds)=gettimeofday;

    $BADLIST{$badip}{$seconds.''.''.$microseconds}=1;
    #printSTDERR"add_bad_ip:$badip,$seconds\n";
    }

    subrefresh_bad_ip
    {
    foreach$ip(keys篋LIST){
    foreach$secmic(keys{$BADLIST{$ip}}){
    if($secmic=~/^(\d )\.(\d )$/){
    $seconds=$1;

    if(time-$seconds>$EVAL_PERIOD){
    delete$BADLIST{$ip}{$secmic};
    #printSTDERR"refresh_bad_ip:deletebadlist$ip$secmic\n";
    }
    }
    }
    $num=keys{$BADLIST{$ip}};
    if(0==$num){
    delete$BADLIST{$ip};
    }
    }
    }

    subcheck_bad_ip
    {
    foreach$ip(keys篋LIST){
    $login_num=keys({$BADLIST{$ip}});

    #printSTDERR"check_bad_ip:ip$iphas$login_numtimesloginattampts..\n";


    if($login_num>$DENY_TIMES){
    deny_bad_ip($ip);
    delete$BADLIST{$ip};
    }
    }
    }

    subdeny_bad_ip
    {
    local$ip;
    $ip= proftpdlog文件实时分析,动态封禁/解封 - 凯旋网络

    proftpdlog文件实时分析,动态封禁/解封

    作者:凯旋网络来源:凯旋网络
    content
  • 广告推荐
    [0];

    die"deny_bad_ipnoiperr"unless$ip;

    foreach(keys轓IED_IP){
    returnif(/^$ip$/)
    }

    $cmd="iptables-AftpDeny-ptcp-s$ip-jREJECT--reject-with
    tcp-reset";
    #printSTDERR"syscmd:$cmd\n";
    system($cmd);
    $DENIED_IP{$ip}=time;

    $date=`date`;#把当前日期赋值给$date
    chomp$date;#截去\n,这里也可以这样,chomp($date);
    system("printf\"s-16sdenied.\n\"\"$date\"$ip>>/var/log/proft
    pd.deny")
    }

    subundeny_bad_ip
    {
    foreach$ip(keys轓IED_IP){
    if(time-$DENIED_IP{$ip}>$DENY_PERIOD){
    $line_number=`iptables-nLftpDeny--line-number|
    grep$ip|awk{''print\$1''}`;
    chomp$line_number;
    $cmd="iptables-DftpDeny$line_number";

    system($cmd);
    delete$DENIED_IP{$ip};

    $date=`date`;#把当前日期赋值给$date
    chomp$date;#截去\n
    system("printf\"s-16sundenied.\n\"\"$date\"
    $ip>>/var/log/proftpd.deny")

    }
    }
    }

    subinit_iptables
    {
    $cmd1="iptables-FftpDeny>/dev/null2>&1";
    $cmd2="iptables-XftpDeny>/dev/null2>&1";
    $cmd3="iptables-NftpDeny>/dev/null2>&1";
    $cmd4="iptables-IINPUT-ptcp--dport59000:60000-jftpDeny";
    $cmd5="iptables-IINPUT-ptcp--dport20:21-jftpDeny";

    $exist=`iptables-nLINPUT|grepftpDeny|wc-l|awk{''print\$1''}`;


    system($cmd1);
    system($cmd2);
    system($cmd3);

    if(0==$exist){
    system($cmd4);
    system($cmd5);
    }
    }
    [关键词: 凯旋, 网络, 编程, PERL]
    上一篇:LINUX
    下一篇:用Perl饼来替换文件中的字符串
  • 广告推荐