chroot ftp server


Posted in:

สวัสดีครับเพื่อนๆ หลังจากห่างหายจากการเขียนบทความไปนานเนื่องด้วยความขี้เกียจ วันนี้ก็เลยคิดว่าได้ฤกษ์สักทีที่จะมาเขียนบทความให้ชาวคลับได้อ่านกัน บทความวันนี้เป็นการสอนทำ ftp server แบบที่เรียกกันว่า chroot ftp server ครับ ( เอ้าๆ งงๆ ไม่รู้จัก chroot กันอ่ะดี้ )

คือ งี้ครับการทำ chroot คือ การจำลอง environment ของระบบ linux ไปไว้ในที่ใดที่หนึ่งใน harddisk เช่น สมมติว่าปกติเราทำงานเป็น webmaster ดูแล website + webserver ให้บริษัทแห่งหนึ่ง โดยที่ webserver ที่เราดูแลอยู่ดั๊นเป็นที่ต้องตาต้องใจของเหล่า hacker จอมเซี้ยว เว่ากันซื่อๆเลยก็คือโดน hack เข้า server อยู่นั่นแหละ ไม่รู้มันจะ hack อะไรกันนักหนา hack เข้ามาได้ก็เล่น server เราซะเดี้ยงไปเลย เผลอๆแอบเอา script ไปวางซ่อนไว้ที่ path ไหนในเครื่องก็ไม่รู้ ไอ้เจ้าเครื่อง love เราก็เลยเป็นอันปั่นป่วนถึงขั้นต้อง format เครื่อง ( แงๆๆๆ rooney จา ฟ้องหม่ามี๊ ...... T T )

แต่เหมือนสวรรค์ทรงโปรดดันนึกขึ้นได้ว่า "เฮ้ linux มันทำ chroot environment ได้นี่หว่า" ก็เลยจัดการสร้างไดเรคทอรีเปล่าๆขึ้นมาไดเรคทอรีนึงสมมติว่าชื่อไดเรคทอรีว่า new_environment แล้วก็จัดการยัดระบบ linux ลงไปในไดเรคทอรีนี้ ซึ่งหลังจากทำเสร็จพอ double click เข้าไปในไดเรคทอรีนี้ก็จะเจอไดเรคทอรีต่างๆ เช่น bin , sbin , etc , home , ... เหมือนกับว่าไดเรคทอรีเปล่าที่สร้างขึ้นมาใหม่นี้เป็นระบบ linux อีกระบบนึงไปเลย

ทีนี้เวลาทำ web ก็เปลี่ยนจากที่เอาไฟล์ไปวางใน /var/www ก็หันมาวางไว้ใน /new_environment/var/www ที่เราจำลองเอาไว้ ประกอบกับ configure ค่าอะไรเพิ่มสักหน่อยทีนี้ webserver เราก็จะเปลี่ยนจากที่รันไฟล์จากไดเรคทอรีของระบบ (/var/www) ก็จะไปรันจากไดเรคทอรีที่สร้างขึ้นมาเองต่างหาก ถ้าโดน hack ขึ้นมาจริงๆก็ คือ โดน hack ระบบจำลองไม่ใช่ระบบ linux ของเครื่องเราจริงๆ (hacker มันจะติดอยู่ในไดเรคทอรี new_environment ออกไปเกินนี้ไม่ได้ครับ)

ส่วน chroot ftp server ก็หลักการคือๆกันครับคงไม่ต้องอธิบายเพิ่ม แต่ว่าก่อนจะไปที่วิธีทำขออธิบายเกี่ยวกับ ftp server สักนิดครับ คือ ftp ถ้าแยกตามประเภทการ login จะมีอยู่ 3 ประเภท (จัดประเภทโดย rooney ครับ จริงๆอาจจะมากกว่านี้)

1. real ftp = ต้องมีการ login ก่อนถึงเข้าใช้งาน ftp server ได้ โดย user ในการ login จะเป็น user ในระบบ linux ซึ่งข้อเสีย คือ เมื่อ user ทำการ login เข้ามาแล้วจะมีสิทธิ์เหมือน user ที่ใช้ login เข้ามา จะว่าไปคุณ user ท่านนี้อาจจะซนเปลี่ยนไดเรคทอรีไปนู่นมานี่เพ่นพ่านไปเรื่อยตามสิทธิ์ที่มี หรืออาจจะเผลอไปทำอะไรเสี่ยวๆกับระบบก็อาจจะเป็นได้ ใครจะไปรู้

2. anonymous ftp = อันนี้น่าจะคุ้นเคยกันเป็นอย่างดี เพราะมันก็ คือ ftp server ตาม net ที่เราเข้าไป download ไฟล์ต่างๆโดยไม่ต้องพิมพ์ username และ password เพื่อ login เช่น ftp server ของ ftp://mirror.in.th สรุปก็คือ ftp server แบบนี้ไม่ต้อง login (จริงๆแล้วมัน login นะครับ แต่ว่า browser จัดการ login ให้เราโดยอัตโนมัติให้เป็น user ชื่อ anonymous ซึ่งไม่ใช่ user ในระบบ linux โดยที่เราไม่รู้ตัว เราเลยนึกว่าไม่ได้ login)

3. guest ftp = คล้ายอันแรกนะครับแต่ต่างกันหน่อย คือ เมื่อ login เข้าเครื่องไปแล้ว(ใช้ user ของระบบในการ login) จะถูกจำกัดสิทธิ์หลายๆอย่าง เช่น ออกไปเพ่นพ่านนอกไดเรคทอรีที่กำหนดไว้ไม่ได้ ใช้คำสั่งต่างๆได้จำกัด

 


ว่าแล้วก็เริ่มกันเลยดีกว่าครับ

1. ไป download โปรแกรมที่ช่วยสร้าง chroot environment มาก่อนครับ

http://olivier.sessink.nl/jailkit/jailkit-2.0.tar.gz

2. $sudo cp jailkit-2.0.tar.gz /opt ---> ทำการ copy โปรแกรมไปไว้ใน /opt

3. $sudo tar -zxvf jailkit-2.0.tar.gz ---> ทำการแตกไฟล์ที่ได้มา

4. $sudo aptitude install build-essential ---> ทำการติดตั้งชุดโปรแกรมที่ช่วยในการ compile โปรแกรม

5. $cd jailkit-2.0 ---> เข้าไปในไดเรคทอรีที่ได้จากการแตกไฟล์

6. $./configure ---> check ส่วนประกอบที่จะใช้ในการ compile โปรแกรม

7. $make --> ทำการ compile โปรแกรม

8. $sudo make install --> ทำการติดตั้งโปรแกรมครับ

9. $sudo mkdir /jail ---> สร้างไดเรคทอรีที่จะเป็น chroot environment

*ขั้นถัดมาจะเป็นการติดตั้งโปรแกรมต่างๆลงใน chroot environment

10. $sudo jk_init -v /jail basicshell

11. $sudo jk_init -v /jail editors

12. $sudo jk_init -v /jail extendedshell

13. $sudo jk_init -v /jail netutils

14. $sudo jk_init -v /jail ssh

15. $sudo jk_init -v /jail sftp

16. $sudo adduser apollo ---> เพิ่ม user เข้าระบบโดย user คนนี้จะถูกใช้ในการ login เพื่อ ftp

17. $sudo jk_jailuser -m -j /jail apollo ---> นำ user ที่เพิ่งเพิ่มเข้าระบบในขั้นตอนที่แล้วเข้าไปเป็น
user ของระบบ chroot environment

18. $less /etc/passwd ---> ลอง check สถานะ user ที่เพิ่งเพิ่มเข้าไปจะเห็นประมาณนี้ครับ

apollo:x:1002:1002:,,,:/jail/./home/apollo:/usr/sbin/jk_chrootsh

*จะเห็นว่า home directory ของ user ท่านนี้ถูกชี้ไปยัง chroot environment ครับ (/jail/./home/apollo)

19. $sudo gedit /jail/etc/passwd ---> เข้าไปแก้ไฟล์จะเห็นไฟล์ดังนี้

apollo:x:1002:1002:,,,:/home/apollo:/usr/sbin/jk_lsh

*ให้ทำการแก้ /usr/sbin/jk_lsh ไปเป็น /bin/bash

20. $sudo aptitude install vsftpd openssh-server ---> ทำการติดตั้งโปรแกรม ftp server กับ ssh server

21. $sudo gedit /etc/vsftpd.conf ---> แก้ไขไฟล์ configure ของโปรแกรม ftp server โดยเอาเครื่องหมาย #หน้าสองบรรทัดนี้ออกครับ

local_enable=YES

write_enable=YES

22. $sudo /etc/init.d/vsftpd restart ---> ทำการ restart โปรแกรม ftp server หลังจากแก้ค่า configure ครับ

*ปล. หลังจากที่ได้ลอง ftp ดู โดยใช้โปรแกรม file zilla ปรากฎว่าพอ login สำเร็จก็จะเข้ามาอยู่ใน /jail/home/apollo โดยไม่สามารถย้ายไดเรคทอรีขึ้นไปไดเรคทอรีข้างบนได้ครับ แต่ถ้า login ด้วย sftp จะสามารถย้ายไดเรคทอรีขึ้นไปข้างบนได้ เช่น จาก /jail/home/apollo ไป /jail/home ได้ และจาก /jail/home ขึ้นไปอีก level ได้แต่ก็ยังไม่สามารถออกไปนอก /jail ได้ครับ


###จบแล้วครับ###

แนะนำนิดนึงครับ

ถ้าใช้ vsFTPd อยู่แล้วไม่ต้องลงโปรแกรมอะไรเพิ่มลงไปก็ได้ครับแก้ไขไฟล์ config มันนิดเดียวโดยเพิ่ม

chroot_local_user = YES

#เข้าไปต่อท้ายไฟล์ config ของมันก็ทำให้ user ที่ ftp เ้ข้าไปออกนอก /home ของตัวเองไม่ได้แล้วครับ
** ย้ำว่าไม่ใช่แก้ local_user ไปเป็น chroot_local_user น่ะครับ พิมพ์เิ่พิ่มเข้าไปใหม่

ไม่ work ครับ

คุณ mrgill ครับ อย่าว่างั้นงี้เลยนะครับ ได้ลองเทสจริงรึยังครับ ผมลองหลายรอบแล้ว

ถ้าตั้งค่า chroot_local_user=YES

มันไม่ work ด้วยประการทั้งปวงครับ ผมยังสามารถเข้าไปได้ทุกไดเรคทอรที่มีสิทธิ์เลยครับ ถ้าไม่ทำ chroot ให้มัน ผมเดาว่ามันต้องทำอะไรเพิ่มนอกจากตั้งค่า chroot_local_user=YES สักอย่าง ตัว option นี้ถึงจะใช้ได้ซึ่งผมก็ยังไม่ทราบว่าทำไงก็เลยต้องทำวิธีนี้ครับ เซ็งเลย - -?

เอ...

เอ... วันนี้ลองทำตามวิธีที่เขียนไว้เองข้างบนบนเครื่อง feisty มันดัน login ไม่ผ่านแฮะ(จากตัวอย่างผมทำบน dapper) ไม่แน่ใจว่าเป็นที่ไอ้ jailkit มันไม่ work บน feisty หรือ ผมเขียนวิธีตกไปบางบรรทัด เพราะตอนทำขั้นตอนมันเยอะ เอาเป็นว่าเดี๋ยวแก้ปัญหาได้จะเข้ามาปรับปรุงเนื้อหาให้ใหม่ครับ ^_^

รับรองว่าได้พันล้านเปอร์เซ็น

ผมลองแล้วครับ vsftpd ไม่ว่าจะ config บน os อะไรก็เหมือนกันผมลองมาหมดแล้วทั้ง RHEL, CentOS, FC, Ubuntu, FreeBSD, OpenBSD

ดู vsftpd.conf ของผมน่ะครับ

# Example config file /etc/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
#
# Run standalone? vsftpd can run either from an inetd or as a standalone
# daemon started from an initscript.
listen=YES
#
# Run standalone with IPv6?
# Like the listen parameter, except vsftpd will listen on an IPv6 socket
# instead of an IPv4 one. This parameter and the listen parameter are mutually
# exclusive.
#listen_ipv6=YES
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format
#xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd.banned_emails
#
# You may restrict local users to their home directories. See the FAQ for
# the possible risks in this before using chroot_local_user or
# chroot_list_enable below.
#chroot_local_user=YES
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd.chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
#
# Debian customization
#
# Some of vsftpd's settings don't fit the Debian filesystem layout by
# default. These settings are more Debian-friendly.
#
# This option should be the name of a directory which is empty. Also, the
# directory should not be writable by the ftp user. This directory is used
# as a secure chroot() jail at times vsftpd does not require filesystem
# access.
secure_chroot_dir=/var/run/vsftpd
#
# This string is the name of the PAM service vsftpd will use.
pam_service_name=vsftpd
#
# This option specifies the location of the RSA certificate to use for SSL
# encrypted connections.
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
# This option specifies the location of the RSA key to use for SSL
# encrypted connections.
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
chroot_local_user=YES

ผมเพิ่มเข้าไปแค่บรรทัดเดียวจริงๆ

chroot_local_user=YES

แค่บรรทัดสุดท้าย

configure file

# Example config file /etc/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
#
# Run standalone? vsftpd can run either from an inetd or as a standalone
# daemon started from an initscript.
listen=YES
#
# Run standalone with IPv6?
# Like the listen parameter, except vsftpd will listen on an IPv6 socket
# instead of an IPv4 one. This parameter and the listen parameter are mutually
# exclusive.
#listen_ipv6=YES
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
#local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format
#xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd.banned_emails
#
# You may restrict local users to their home directories. See the FAQ for
# the possible risks in this before using chroot_local_user or
# chroot_list_enable below.
#chroot_local_user=YES
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd.chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
#
# Debian customization
#
# Some of vsftpd's settings don't fit the Debian filesystem layout by
# default. These settings are more Debian-friendly.
#
# This option should be the name of a directory which is empty. Also, the
# directory should not be writable by the ftp user. This directory is used
# as a secure chroot() jail at times vsftpd does not require filesystem
# access.
secure_chroot_dir=/var/run/vsftpd
#
# This string is the name of the PAM service vsftpd will use.
pam_service_name=vsftpd
#
# This option specifies the location of the RSA certificate to use for SSL
# encrypted connections.
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
# This option specifies the location of the RSA key to use for SSL
# encrypted connections.
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
chroot_local_user=YES

*ปล. configure แบบนี้บน debian etch , dapper , feisty ยังออกนอก home ได้ครับ ต่างกันจุดเดียว คือ ไม่ได้ uncomment ตรง #local_umask=022 ซึ่งไม่เกี่ยวกับการทำ chroot ครับ

*ปล.2 ขออนุญาตเอาไป post ไว้ใน board นะ ให้คนอื่นมาช่วยออกความเห็น

centrino14's picture

ของผมออกนอก home ไม่ได้ครับ

listen=YES
anonymous_enable=YES
local_enable=YES
write_enable=YES
local_umask=077
#anon_upload_enable=YES
anon_mkdir_write_enable=YES
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
#chown_uploads=YES
#chown_username=whoever
#xferlog_file=/var/log/vsftpd.log
#xferlog_std_format=YES
#idle_session_timeout=600
#data_connection_timeout=120
#nopriv_user=ftpsecure
#async_abor_enable=YES
ascii_upload_enable=YES
ascii_download_enable=YES
#deny_email_enable=YES
#banned_email_file=/etc/vsftpd.banned_emails
chroot_local_user=YES
secure_chroot_dir=/var/run/vsftpd
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key

เอาแบบย่อๆ ของผมออกนอก home ไม่ได้นะครับ เกี่ยวกับที่ต่อบรรทัดท้ายสุดหรือเปล่าครับ เพราะผมไม่ได้เพิ่มนะ เอาแค่ # ออกครับ อยู่ตรงตำแหน่งเดิมที่มันอยู่ครับ

เพิ่มเติมครับ ใช้ gFTP connect ไปที่ 127.0.0.1 ครับ ไม่ได้ลองจากเครื่องลูกไปยัง Sever จริงๆ
ปล.ไอพีนี้แหละ ไอพีผมที่ Hack web กระทรวง ICT ^_*V

ลองแล้วทั้ง 2 แบบ

ผมลองแล้วทั้ง 2 แบบครับ ทั้งเติม chroot_local_user=YES ไว้ท้ายไฟล์และแบบ uncomment ตรงหน้าบรรทัด chroot_local_user ก็ยังสามารถออกนอก home ได้ครับ เลยต้องทำ chroot environment ถึงออกไม่ได้ - -? (จะยังไงดีเนี่ย ผมชักสับสนชีวิต)

*ปล. ขอถามไรอย่าง ตอนแบ่ง partition นี่ คุณ centrino14 กับ mrgill ได้แยก home ไว้คนละ partition กับ / หรือเปล่าครับ รบกวนเข้ามาตอบด้วยครับ เพราะเครื่องผมทุกเครื่องผมจะแยก home ออกจาก / (จะเกี่ยวกันมั๊ยฟะเนี่ยชักเลอะเทอะ)

เอ่อ...

ไม่เกี่ยวอยู่ดีแฮะ การแบ่ง home ออกจาก / นี่ก็ไม่เกี่ยวกันครับ จะแบ่งหรือไม่แบ่งก็เหมือนกัน
เอาเป็นว่าหาคำตอบต่อไป(ทำไมไม่เหมือนกันฟะ เซ็งตัวเอง)

ปัญหากระจ่างแล้วครับ

สรุป

1. ถูกทั้งสองฝ่ายครับไม่ต้องเถียงกัน

2. chroot_local_user=YES ใช้ได้ผลครับ แต่ใช้ได้เฉพาะกรณี connect เข้าไป server แบบ unsecure
คือ connect ผ่าน port 21 (ใช้ ethereal จับ username , password และ data ได้นะครับ)

3. ถ้า connect ไปยัง FTP server แบบเข้ารหัส (ftp over ssh) โดยใช้ port 22 จะใช้option นี้ไม่
ได้ครับ ต้องทำ chroot environment แบบที่ผมทำ ซึ่งยาวจนเซ็ง

4. ขอบคุณทุก comment ครับ

###จบซะที###

ก็แน่นอนครับ

20 กะ 21 ใช้ vsftpd ส่วน 22 มันใช้ sftp ซึ่งเรียกใช้ ssh มันคนละโปรแกรมกัน config บน vsftpd แล้วจะให้ ssh ทำงานแบบเดียวกันไม่ได้หรอกครับ

เฮ้อ....

เรื่องที่อยากชี้แจง

1. post ในลักษณะนี้ มันหงุดหงิดคนอ่าน(เนื้อหาใช้ได้ แต่คำพูดมันอ้อนไปหน่อย)

"20 กะ 21 ใช้ vsftpd ส่วน 22 มันใช้ sftp ซึ่งเรียกใช้ ssh มันคนละโปรแกรมกัน config บน vsftpd แล้วจะให้ ssh ทำงานแบบเดียวกันไม่ได้หรอกครับ"

เพิ่มเติม

2. port 21 เป็น control port ใช้รับ-ส่ง username , password กับ client

3. port 20 เป็น data port ใช้รับ-ส่ง data กับเครื่อง client

4. ใช้ port 21 กับ 20 ก็ต่อเมื่อ server เราเป็น ftp server แบบ active ftp ซึ่ง ftp server แบบนี้ในโลกเหลืออยู่ไม่มาก ทีไม่มีแมวที่ไหนใช้เพราะ ftp แบบนี้มีข้อเสียเพราะขั้นตอน establish data port จะเริ่มต้นจากทาง server จึงต้อง configre firewall 2 ฝั่ง คือ firewall ฝั่ง server ต้องทำการเปิด port 21 ส่วน firewall ฝั่ง client ต้องทำการเปิด high port ให้server connect เข้ามาได้ซึ่งเป็นการกระทำที่งี่เง่าเกินจะรับได้(แต่มหาวิทยาลัยก็ยังนิยมสอนว่าใช้ 2 port นี้)

5. ในปัจจุบัน ftp server ส่วนมากเป็น ftp server แบบ passive ftp คือ ใช้ port 21 เป็น control port และ port > 1024 ที่สุ่มขึ้นมาทำเป็น data port โดยการ establish connection ทั้ง control port และ data port จะเริ่มที่ client จึงสะดวกกว่าเดิมมากเพราะการ configure firewall จะทำที่ฝั่ง server อย่างเดียว คือ เปิด port 21 ที่firewall ฝั่ง server อย่างเดียว(ส่วน high port ที่ฝั่ง server ไม่ต้องเปิด เพราะมันจะเห็น data port ที่client เรียกเข้ามาเป็น related port ซึ่งเป็น port ที่ต่อเนื่องจาก connection แรกจึง allow ให้ผ่านได้ ที่ทำงี้ได้เนื่องจาก firewall ในปัจจุบันเป็น statefull firewall)

*ปล. ถ้า ใช้เป็น sftp จะใช้แต่ port 22 เป็นทั้ง control port และ data port

6. ตั้งแต่ทำงานมายังไม่เคยเห็นคนในที่ทำงานหรือพวกที่มีความรู้เรื่อง network ท่านใดเป็นปลื้มกับการใช้ftp เพียวๆเลยนะครับ ถ้าไม่จำเป็นต้องใช้จริงๆจะไม่ค่อยใช้กัน เพราะว่ามันสามารถใช้โปรแกรมดักเอา username , password , data ได้ ผมจึงไม่เคยใช้ ftp แบบธรรมดาครับ จึงเรียนมาเพื่อทราบ

*ปล. ขอเชิญชวนให้ใช้ ftp over ssh นะครับ เชื่อเถอะครับ ไม่โดน hack อาจจะยังไม่เห็นประโยชน์

อยากจะขอถามเพิ่มเติมหน่อยครับ

คือจากที่อ่านมา ผมเห็นด้วยนะครับ ไม่อยากใช้ port21 กับ ftp ธรรมดา

แต่ผมมีปีญหานิดหน่อย พอดีที่ บ. ให้ออกแค่ port 80,21 ผมก็เลยทำตามเพื่อน
คือ เซ็ต server ตัวเองให้ SSH ผ่าน port 21 แทน ที่นี้ อยากจะใช้ sftp ผ่านเน็ตเว็ค จาก บ.
ที่ผมออกได้แค่ port 21,80 โดย port 21 ถ้า connect มาที่ server ผมแล้ว มันจะเป็น SSH
จะทำยังไงเพื่อให้ connect มาเป็น sftp ได้อ่ะครับ

เข้าใจตรงกันซ่ะที

เอาเป็นว่าผมว่าทางที่ดีที่สุดอย่าให้ user เข้า shell ได้จะดีทีุ่สุด user ที่ชอบซุกซนก็มีเยอะน่ะครับ

ดีครับ

อันนี้เป็นคำแนะนำที่ดี เห็นด้วยครับ

อ่า..

อ่า.. แต๊งกิ้ว กำลังเล่นกับ vsftpd.conf อยู่พอดี ได้เทคนิคใหม่อีกแย้ว ^^



ลืมสร้างไฟล์นี้หรือปล่าวครับ

chroot_local_user=YES
#chroot_list_file=/etc/vsftpd.chroot_list <== เอา comment ออกซะ
touch /etc/vsftpd.chroot_list
nano /etc/vsftpd.chroot_list แก้ไขเอา user ที่ต้องการขังเข้าไปไว้ในนี้
จบ...

อยากถามว่

อยากถามว่าถ้าเป็น web serverน่ะครับ apache2.2.8 จะทำไม่เหมือนกันตรงไหนครับ และsetยังไงครับ

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <i> <center> <span> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <br> <dt> <dd> <object> <embed> <hr> <img> <blockquote> <b> <u> <del> <div> <p> <table> <tr> <td> <font>

More information about formatting options