Monday, October 25, 2010

FTP Server with anonymous upload

DELIVERABLE
Secure FTP server with upload directory for anonymous users.

INSTALLATION
[root@server ~]# yum -y install vsftpd
[root@server ~]# chkconfig vsftpd on

IPTABLES 
[root@server ~]# iptables -I MYCHAIN -s 192.168.1.0/24 -p tcp --dport 21 -j ACCEPT
[root@server ~]# service iptables save
Saving firewall rules to /etc/sysconfig/iptables:          [  OK  ]

Add ip_conntrack_ftp into IPTABLES_MODULES in /etc/sysconfig/iptables-config:
[root@server ~]# grep IPTABLES_MODULES= /etc/sysconfig/iptables-config
IPTABLES_MODULES="ip_conntrack_netbios_ns ip_conntrack_ftp"

CONFIGURATION
[root@server ~]# grep -v ^# /etc/vsftpd/vsftpd.conf
anonymous_enable=YES
local_enable=YES
write_enable=YES
local_umask=022
anon_upload_enable=YES #
anon_umask=077#
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
chown_uploads=YES#
chown_username=daemon#
xferlog_std_format=YES
listen=YES

pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES

Flip the SELINUX boolean:
[root@server ~]# setsebool allow_ftpd_anon_write on

Create a directory for upload:
[root@server ~]# mkdir /var/ftp/incoming
[root@server ~]# chgrp ftp /var/ftp/incoming/
[root@server ~]# chmod 730 /var/ftp/incoming/

Ensure it has a right context:
[root@server ~]# chcon -t public_content_rw_t /var/ftp/incoming/

TCP wrappers:
[root@server ~]# echo "vsftpd:  192.168.1." >> /etc/hosts.allow
[root@server ~]# grep -v ^# /etc/hosts.allow
mountd,portmap: 192.168.1.
vsftpd:  192.168.1.

Restart the service:
[root@server ~]# service vsftpd restart
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]

VERIFICATION
Let's connect from the client station and upload the file:
[root@piotr ~]# lftp server.example.com -u anonymous
Password:
lftp anonymous@server.example.com:~> ls   
drwx-wx---    2 0        50           4096 Oct 24 21:16 incoming
drwxr-xr-x    2 0        0            4096 May 13  2009 pub
lftp anonymous@server.example.com:/> cd incoming/
lftp anonymous@server.example.com:/incoming> put anaconda-ks.cfg
930 bytes transferred
lftp anonymous@server.example.com:/incoming> bye

Now on the server, uploaded file indeed is owned by user daemon:
[root@server ~]# ll /var/ftp/incoming/
total 8
-rw------- 1 daemon ftp 930 Oct 25 00:18 anaconda-ks.cfg

No comments:

Post a Comment