LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
12
返回列表 发新帖
楼主: bluespray

有没有人知道:在LINUX如何限制FTP重试次数?

[复制链接]
发表于 2003-11-20 12:00:40 | 显示全部楼层
将你的pure ftp使用的验证方式贴出来。
是用系统账号,还是PAM,还是采用mysql or LADP?
发表于 2003-11-20 12:31:17 | 显示全部楼层
能改变/etc/passwd的权限吗?每隔几分钟就才让远程用户有权读取/etc/passwd.而且只能读三次。
发表于 2003-11-20 14:33:04 | 显示全部楼层
最初由 home 发表
能改变/etc/passwd的权限吗?每隔几分钟就才让远程用户有权读取/etc/passwd.而且只能读三次。


不过这样不行,其他用户怎么办??
发表于 2003-11-20 16:44:20 | 显示全部楼层
proftpd就有吧...
 楼主| 发表于 2003-11-20 17:13:00 | 显示全部楼层
我用的是采用mysql 配置文件如下:

==========================================


##############################################
#                                            #
# Sample Pure-FTPd Mysql configuration file. #
# See README.MySQL for explanations.         #
#                                            #
##############################################


# Optional : MySQL server name or IP. Don't define this for unix sockets.

MYSQLServer    localhost


# Optional : MySQL port. Don't define this if a local unix socket is used.

MYSQLPort       3306


# Optional : define the location of mysql.sock if the server runs on this host.

MYSQLSocket     /tmp/mysql.sock


# Mandatory : user to bind the server as.

MYSQLUser       root


# Mandatory : user password. You must have a password.

MYSQLPassword  xxxxxx


# Mandatory : database to open.

MYSQLDatabase  test


# Mandatory : how passwords are stored
# Valid values are : "cleartext", "crypt", "md5" and "password"
# ("password" = MySQL password() function)
# You can also use "any" to try "crypt", "md5" *and* "password"

MYSQLCrypt cleartext any


# In the following directives, parts of the strings are replaced at
# run-time before performing queries :
#
# \L is replaced by the login of the user trying to authenticate.
# \I is replaced by the IP address the user connected to.
# \P is replaced by the port number the user connected to.
# \R is replaced by the IP address the user connected from.
# \D is replaced by the remote IP address, as a long decimal number.
#
# Very complex queries can be performed using these substitution strings,
# especially for virtual hosting.


# Query to execute in order to fetch the password

MYSQLGetPW      SELECT passwd FROM users WHERE userid="\L" AND checked=1


# Query to execute in order to fetch the system user name or uid

MYSQLGetUID     SELECT uid FROM users WHERE userid="\L" AND checked=1


# Query to execute in order to fetch the system user group or gid

MYSQLGetGID     SELECT gid FROM users WHERE userid="\L" AND checked=1


# Query to execute in order to fetch the home directory

MYSQLGetDir     SELECT homedir FROM users WHERE userid="\L" AND checked=1


# Optional : query to get the maximal number of files
# Pure-FTPd must have been compiled with virtual quotas support.

# MySQLGetQTAFS  SELECT QuotaFiles FROM users WHERE User="\L"
  MySQLGetQTAFS   UPDATE users SET upload=1 WHERE userid="\L" AND checked=1


# Optional : query to get the maximal disk usage (virtual quotas)
# The number should be in Megabytes.
# Pure-FTPd must have been compiled with virtual quotas support.

MySQLGetQTASZ  SELECT quota FROM users WHERE userid="\L" AND checked=1


# Optional : ratios. The server has to be compiled with ratio support.

# MySQLGetRatioUL SELECT ULRatio FROM users WHERE User="\L"
# MySQLGetRatioDL SELECT DLRatio FROM users WHERE User="\L"
MySQLGetRatioUL Update users set count=count+1 where  userid="\L"
MySQLGetRatioDL INSERT into  upload(userid,ip) values("\L","\R")

# Optional : bandwidth throttling.
# The server has to be compiled with throttling support.
# Values are in Kb/s .

MySQLGetBandwidthUL SELECT ULBandwidth FROM users WHERE userid="\L"
MySQLGetBandwidthDL SELECT DLBandwidth FROM users WHERE  userd="\L"


# If you upgraded your tables to transactionnal tables (Gemini,
# BerkeleyDB, Innobase...), you can enable SQL transactions to
# avoid races. Leave this commented if you are using the
# traditionnal MyIsam databases or old (< 3.23.x) MySQL versions.

# MySQLTransactions On

================================================

启动命令如下:
========================

/usr/sbin/pure-ftpd-mysql -c 100 -k 98 -L 1000:5 -y 4:3 -j -I 5 -R -l mysql:/etc/pure-ftpd/db/pureftpd-mysql.conf  -O clf:/var/log/pure-ftpd/transfer.log &

============================

因为我发现有部分用户的密码被人知道了,可能是因为被FTP密码软件破解软件破解的,因为可以一直重试,不像Serv-U可以做到1分钟重试10次就禁止连接30分钟!
 楼主| 发表于 2003-11-25 09:33:25 | 显示全部楼层
等了几天,都没有人知道!
失望!!!!!!!!!!!!!!!
发表于 2003-11-25 11:53:38 | 显示全部楼层
你可以到清华的BBS上找到一个用PEAL写的脚本,通过分析LOG文件,然后利用IPTABLE来阻止单位时间内重试次数太多问题!!
当FTP人数很多的时候,不知道会不会对性能有影响!!
我没试过!
不过这个脚本是对PROFTP的!!我想这个方法应该可以改造一下,适用于PUREFTP
发表于 2003-11-25 13:27:17 | 显示全部楼层
最初由 shadowlimin 发表
你可以到清华的BBS上找到一个用PEAL写的脚本,通过分析LOG文件,然后利用IPTABLE来阻止单位时间内重试次数太多问题!!
当FTP人数很多的时候,不知道会不会对性能有影响!!
我没试过!
不过这个脚本是对PROFTP的!!我想这个方法应该可以改造一下,适用于PUREFTP

兄弟这个脚本你有吗 我在清华上没找到 有的话发一个给我 xwang@linuxsir.cn:cool:
发表于 2003-11-25 15:19:04 | 显示全部楼层
兄弟可以给我发一份吗?谢谢了
dlzwj@ce.net.cn
发表于 2003-11-25 16:13:01 | 显示全部楼层

转自清华BBS

by zixia@zixia.net

-- 注意 copy 后 有些应该在 1 行的编辑一下

#!/usr/bin/perl -w
#
# proftpd log 文件实时分析,动态封禁/解封
# 用法:  
#       tail -f /var/log/proftpd | /usr/bin/proftpdeny.pl
#
# Zhuohuan Li <zixia@zixia.net>
# Beijing 2003-02-23
#  

use Time::HiRes qw(gettimeofday);


# 封禁时间,以秒为单位
$DENY_PERIOD=600;

# 对最近多久的日志进行统计
$EVAL_PERIOD=60;

# 在 EVAL_PERIOD 中的最多连接次数
$DENY_TIMES=5;



# 数组,记录 IP/最后登陆时间/重试次数
%BADLIST = ();
%DENIED_IP = ();

init_iptables();

while (<STDIN>){
        chomp $_;
        $line = $_;

        $badip = get_bad_ip($line) ;

        if (! $badip ) {
                next;
        }

#print STDERR "badip: $badip\n";

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

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

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

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

exit(0);

##############################
sub get_bad_ip
{
        local( $line );
        $line = $_[0];
        return undef if ( ! $line );

        if ( $line =~ /ftp\.zixia\.net \((\d+\.\d+\.\d+\.\d+)\[[^\]]+\]\) -  
Connection refused \(max clients per host \d+\)\./ ) {
                return $1;
        } else {
                return undef;
        }
}

sub add_bad_ip
{
        local ( $badip );
        $badip = $_[0];
        die "add_bad_ip() take no param err" unless $badip;

        ($seconds, $microseconds) = gettimeofday;

        $BADLIST{$badip}{$seconds . '.' . $microseconds} = 1;

#print STDERR "add_bad_ip: $badip, $seconds\n";
}

sub refresh_bad_ip
{
        foreach $ip ( keys %BADLIST ){
                foreach $secmic ( keys %{$BADLIST{$ip}} ){
                        if ( $secmic =~ /^(\d+)\.(\d+)$/ ){
                                $seconds = $1;

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

sub check_bad_ip
{
        foreach $ip ( keys %BADLIST ){
                $login_num = keys ( %{$BADLIST{$ip}} );

#print STDERR "check_bad_ip: ip $ip has $login_num times login attampts..\n";


                if ( $login_num > $DENY_TIMES ) {
                        deny_bad_ip ( $ip ) ;
                        delete $BADLIST{$ip};
                }
        }
}        
         
sub deny_bad_ip
{        
        local $ip;
        $ip = $_[0];
                 
        die "deny_bad_ip no ip err" unless $ip;
  
        foreach ( keys %DENIED_IP ){
                return if ( /^$ip$/ )
        }
         
        $cmd = "iptables -A ftpDeny -p tcp -s $ip -j REJECT --reject-with  
tcp-reset";
#print STDERR "sys cmd: $cmd\n";
        system ( $cmd );
        $DENIED_IP{$ip} = time;

        $date = `date`;
        chomp $date;
        system ( "printf \"%s %-16s denied.\n\" \"$date\" $ip >>/var/log/proft
pd.deny" )
}

sub undeny_bad_ip
{
        foreach $ip ( keys %DENIED_IP ){
                if ( time - $DENIED_IP{$ip} > $DENY_PERIOD ) {
                        $line_number = `iptables -nL ftpDeny --line-number |  
grep $ip | awk {'print \$1'}`;
                        chomp $line_number;
                        $cmd = "iptables -D ftpDeny $line_number";
                                 
                        system ( $cmd );
                        delete $DENIED_IP{$ip};

                        $date = `date`;
                        chomp $date;
                        system ( "printf \"%s %-16s undenied.\n\" \"$date\"  
$ip >>/var/log/proftpd.deny" )
                 
                }        
        }        
}        

sub init_iptables
{
        $cmd1 = "iptables -F ftpDeny > /dev/null 2>&1";
        $cmd2 = "iptables -X ftpDeny > /dev/null 2>&1";
        $cmd3 = "iptables -N ftpDeny > /dev/null 2>&1";

        $cmd4 = "iptables -I INPUT -p tcp --dport 59000:60000 -j ftpDeny";
        $cmd5 = "iptables -I INPUT -p tcp --dport 20:21 -j ftpDeny";
                 
        $exist = `iptables -nL INPUT | grep ftpDeny | wc -l | awk {'print  
\$1'}`;
                        

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

        if ( 0==$exist ) {
                system( $cmd4 ) ;
                system( $cmd5 ) ;
        }
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表