LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2681|回复: 4

vsftpd-1.1.3配制实例之一:INTERNET_SITE

[复制链接]
发表于 2003-6-1 09:13:10 | 显示全部楼层 |阅读模式
README


This example shows how you might set up a (possibly large) internet facing
FTP site.

The emphasis will be on security and performance.

We will see how by integrating vsftpd with xinetd, we get a powerful
combination.

Step 1) Set up your xinetd configuration file.

An example xinetd configuration file "vsftpd.xinetd" is supplied.
To install it:

cp vsftpd.xinetd /etc/xinetd.d/vsftpd

Let's look at the important content in this file and see what it does:

disable                 = no
socket_type             = stream
wait                    = no

This says that the service is active, and it is using standard TCP sockets.

user                    = root
server                  = /usr/local/sbin/vsftpd

The server program /usr/local/sbin/vsftpd is used to handle incoming FTP
requests, and the program is started as root (vsftpd will of course quickly
drop as much privilege as possible). NOTE! Make sure that you have the vsftpd
binary installed in /usr/local/sbin (or change the file path in the xinetd
file).

per_source              = 5
instances               = 200

For security, the maximum allowed connections from a single IP address is 5.
The total maximum concurrent connections is 200.

no_access               = 192.168.1.3

As an example of how to ban certain sites from connecting, 192.168.1.3 will
be denied access.

banner_fail             = /etc/vsftpd.busy_banner

This is the file to display to users if the connection is refused for whatever
reason (too many users, IP banned).

Example of how to populate it:
echo "421 Server busy, please try later." > /etc/vsftpd.busy_banner

log_on_success          += PID HOST DURATION
log_on_failure          += HOST

This will log the IP address of all connection attempts - successful or not,
along with the time. If an FTP server is launched for the connection, it's
process ID and usage duration will be logged too. If you are using RedHat
like me, this log information will appear in /var/log/secure.


Step 2) Set up your vsftpd configuration file.

An example file is supplied. Install it like this:

cp vsftpd.conf /etc

Let's example the contents of the file:

# Access rights
anonymous_enable=YES
local_enable=NO
write_enable=NO
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO

This makes sure the FTP server is in anonymous-only mode and that all write
and upload permissions are disabled. Note that most of these settings are
the same as the default values anyway - but where security is concerned, it
is good to be clear.

# Security
anon_world_readable_only=YES
connect_from_port_20=YES
hide_ids=YES
pasv_min_port=50000
pasv_max_port=60000

These settings, in order
- Make sure only world-readable files and directories are served.
- Originates FTP port connections from a secure port - so users on the FTP
server cannot try and fake file content.
- Hide the FTP server user IDs and just display "ftp" in directory listings.
This is also a performance boost.
- Set a 50000-60000 port range for passive connections - may enable easier
firewall setup!

# Features
xferlog_enable=YES
ls_recurse_enable=NO
ascii_download_enable=NO
async_abor_enable=YES

In order,
- Enables recording of transfer stats to /var/log/vsftpd.log
- Disables "ls -R", to prevent it being used as a DoS attack. Note - sites
wanting to be copied via the "mirror" program might need to enable this.
- Disables downloading in ASCII mode, to prevent it being used as a DoS
attack (ASCII downloads are CPU heavy).
- Enables older FTP clients to cancel in-progress transfers.

# Performance
one_process_model=YES
idle_session_timeout=120
data_connection_timeout=300
accept_timeout=60
connect_timeout=60
anon_max_rate=50000

In order,
- Activates a faster "one process per connection" model. Note! To maintain
security, this feature is only available on systems with capabilities - e.g.
Linux kernel 2.4.
- Boots off idle users after 2 minutes.
- Boots off idle downloads after 5 minutes.
- Boots off hung passive connects after 1 minute.
- Boots off hung active connects after 1 minute.
- Limits a single client to ~50kbytes / sec download speed.


Step 3) Restart xinetd.

(on RedHat)
/etc/rc.d/init.d/xinetd restart

If you run into problems, check:
1) Your /etc/xinetd.d directory only has one FTP service.
 楼主| 发表于 2003-6-1 09:13:53 | 显示全部楼层

vsftpd.conf

# Access rights
anonymous_enable=YES
local_enable=NO
write_enable=NO
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO
# Security
anon_world_readable_only=YES
connect_from_port_20=YES
hide_ids=YES
pasv_min_port=50000
pasv_max_port=60000
# Features
xferlog_enable=YES
ls_recurse_enable=NO
ascii_download_enable=NO
async_abor_enable=YES
# Performance
one_process_model=YES
idle_session_timeout=120
data_connection_timeout=300
accept_timeout=60
connect_timeout=60
anon_max_rate=50000
 楼主| 发表于 2003-6-1 09:15:23 | 显示全部楼层
vsftpd.xinetd


# vsftpd is the secure FTP server.
service ftp
{
        disable                 = no
        socket_type             = stream
        wait                    = no
        user                    = root
        server                  = /usr/local/sbin/vsftpd
        per_source              = 5
        instances               = 200
        no_access               = 192.168.1.3
        banner_fail             = /etc/vsftpd.busy_banner
        log_on_success          += PID HOST DURATION
        log_on_failure          += HOST
}
发表于 2003-10-10 03:40:47 | 显示全部楼层

vsftpd-1.1.3配制实例之一:INTERNET_SITE (英特网站点)

本例将引导你如何建立一个(可能大型)的面向英特网的 FTP 站点。
重点要放在安全和性能方面。

我们将会看到 vsftpd 是如何与 xinetd 整合到一起, 这是一个非常强大的组合。

第一步)建立 xined 的配置文件。

vsftpd 已经给我们提供了一份 xinetd 配置文件样例 "vsftpd.xinetd"。
cp vsftpd.xinetd /etc/xinetd.d/vsftpd

让我们一起来看看文件中的重要内容以及它具体做了那些工作:
disable                 = no
socket_type             = stream
wait                    = no

以上说明服务被激活,正在使用标准的 TCP 连接接口。

user                    = root
server                  = /usr/local/sbin/vsftpd

服务端程序 /usr/local/sbin/vsftpd 用来处理收到的 FTP 请求,程序以 root 身份启动(当然 vsftpd 将马上减低尽可能多的权限)。注意!确信你已经把 vsftpd 二进制文件安装到 /usr/local/sbin (或者只需要改变文件路径即可)。

per_source              = 5
instances               = 200

为了安全原因,来自同一个 IP 地址最多允许 5 个连接。
同一时间最多允许的所有连接总数为 200。

no_access               = 192.168.1.3

作为演示如何禁止特定站点连接的样例,这里 192.168.1.3 被禁止访问。

banner_fail             = /etc/vsftpd.busy_banner

如果用户连接时由于某个原因被拒绝,这个文件将显示给给用户。
如何书写样例:
echo "421 Server busy, please try later." > /etc/vsftpd.busy_banner

log_on_success          += PID HOST DURATION
log_on_failure          += HOST

将会连同时间一起记录所有企图连接的 IP 地址 - 包括成功或失败。如果 FTP 服务器运行并允许连接,它的进程号以及持续使用的时间也会被记录。假如你像我一样正在使用 RedHat,记录信息将位于 /var/log/secure。

第二步)建立 vsftpd 配置文件。

已经提供样例。如下安装:
cp vsftpd.conf /etc

让我们来看看文件内容:
# Access rights (访问权限)
anonymous_enable=YES
local_enable=NO
write_enable=NO
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO

上面保证 FTP 服务器处于 anonymous-only 模式,所有的写权限和上传权限被禁止。注意,总之大多数设置保持默认值 - 但是考虑到安全问题,最好写清楚。

# Security (安全性)
anon_world_readable_only=YES
connect_from_port_20=YES
hide_ids=YES
pasv_min_port=50000
pasv_max_port=60000

这里的设置,目的
- 确信只提供泛读文件和目录。
- 限制发起 FTP 连接的端口,只允许来自安全端口 - 这样位于 FTP 服务器上的用户就不能尝试和伪造文件内容。
- 隐藏 FTP 服务器的用户 ID,在目录列表里只显示 "ftp"。
同时提高了性能。
- 为被动连接设置端口范围 50000-60000 - 可以允许打开简单的防火墙设置。

# Features (特性)
xferlog_enable=YES
ls_recurse_enable=NO
ascii_download_enable=NO
async_abor_enable=YES

目的,
- 打开传输状态统计记录 /var/log/vsftpd.log
- 禁用命令 "ls -R", 防止被用来制造 Dos 攻击。注意 - 如果站点间想通过 "mirror" 程序进行复制操作,可能需要打开它。
- 关闭 ASCII 下载模式,防止被用来制造 Dos 攻击(ASCII 模式下载很费 CPU 资源)。
- 取消进程间(in-progress) 传输,以支持老式的 FTP 客户端。

# Performance (性能)
one_process_model=YES
idle_session_timeout=120
data_connection_timeout=300
accept_timeout=60
connect_timeout=60
anon_max_rate=50000

目的,
- 激活更加快速的 "连接和进程一对一“ 模式。注意!为了保证安全,此功能仅限于支持特殊性能的系统 - 如:

Linux kernel 2.4.
- 引导后 2 分钟闲置用户。
- 引导后 5 分钟闲置下载连接。
- 引导后 1 分钟悬挂被动连接。
- 引导后 1 分钟悬挂活动连接。
- 限制单用户每秒的下载速度 ~50k 字节。

第三步) 重启 xinetd 服务
(对于 Redhat)
/etc/rc.d/init.d/xinetd restart

如果你碰到问题,检查:
1)你的 /etc/xinetd.d 目录只允许一个 FTP 服务。





不知道下面是否还有???
发表于 2003-10-10 09:04:37 | 显示全部楼层
太好了,终于有同志在这里说点深有体会的东东了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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