Showing posts with label FTP. Show all posts
Showing posts with label FTP. Show all posts

June 16, 2015

10 Advance VsFTP Interview Questions and Answers – Part II

We were overwhelmed with the response we’ve received on our last article. Where we’ve presented10 wonderful question on Very Secure File Transfer Protocol. Continuing VSFTP interview article we are here presenting you yet another 10 Advance Interview Questions which surely will help you.
  1. 10 Basic Vsftp Interview Question/Answers – Part I
VsFTP Intervew Questions
VsFTP Intervew Questions – Part II
Please note vsftpd.conf file is used to control various aspects of configuration as specified in this article. By default, the vsftpd searches for the configuration file under /etc/vsftpd/vsftpd.conf. However, the format of file is very simple and it contains comment or directive. Comment lines begins with a ‘#‘ are ignored and a directive line has the following format.
option=value
Before we start the Question and their well explained Answer we would like to answer a question “Who is going to attend FTP Interview?”. Well no one. Perhaps no one would be attending FTP interview. But we are presenting subject wise questions to maintain a systematic approach so that in any Interview, you wont get a new question which you wont be knowing on any of the topics/subjects we covered here.
11. How would you block an IP which is acting malicious on your internal private VSFTP network?
Answer : We can Block IP either by adding the suspicious IP to ‘/etc/hosts.deny’ file or alternatively adding a DROP rule for the suspicious IP to iptables INPUT chain.
Block IP using host.deny file
Open ‘/etc/hosts.deny’ file.
# vi /etc/hosts.deny
Append the following line at the bottom of the file with the IP address that you want to block access to FTP.
#
# hosts.deny    This file contains access rules which are used to
#               deny connections to network services that either use
#               the tcp_wrappers library or that have been
#               started through a tcp_wrappers-enabled xinetd.
#
#               The rules in this file can also be set up in
#               /etc/hosts.allow with a 'deny' option instead.
#
#               See 'man 5 hosts_options' and 'man 5 hosts_access'
#               for information on rule syntax.
#               See 'man tcpd' for information on tcp_wrappers
#
vsftpd:172.16.16.1
Block IP using iptables rule
To block FTP access to particular IP address, add the following drop rule to iptables INPUT chain.
iptables -A RH-Firewall-1-INPUT -p tcp -s 172.16.16.1 -m state --state NEW -m tcp --dport 21 -j DROP
12. How to allow secured SSL connections to Anonymous users? How would you do?
Answer : Yes! It is possible to allow anonymous users to use secured SSL connections. The value of parameter ‘allow_anon_ssl’ should be ‘YES’ in the vsftpd.conf file. If it, set to NO it wont allow anonymous users to use SSL connections. The default value is NO.
# Add this line to enable secured SSL connection to anonymous users.
allow_anon_ssl=YES
13. How to allow Anonymous users to create new directory and write to that directory?
Answer : We need to edit the parameter ‘anon_mkdir_write_enable’ and set it’s value to ‘YES’. But in order to make the parameter working, ‘write_enable’ must be activated. The default is NO.
# Uncomment this to enable any form of FTP write command.
write_enable=YES
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
anon_mkdir_write_enable=YES
14. How to enable Anonymous downloads, but disable permission to write?
Answer : In the above said scenario, we need to edit the parameter ‘anon_world_readable_only’. The parameter should be enabled and set to ‘YES’. The default value is YES.
# Add this line to enable read only permission to anonymous users.
allow_anon_ssl=YES
15. How to CHMOD all Anonymous uploads automatically. How would you do?
Answer : To chmod all anonymous uploads automatically, we need to edit the parameter ‘chmod_enable’ and set it to ‘YES’. Anonymous users never get to use SITE CHMOD. The default value is YES.
# Add this line to chmod all anonymous uploads automatically.
chmod_enable=YES
16. How to disable directory listing in a FTP server?
Answer : The parameter ‘dirlist_enable’ comes to rescue at this point. The value of ‘dirlist_enable’ should be set to NO. The default value is YES.
# Add this line to disable directory listing.
dirlist_enable=NO
17. How to maintain sessions for logins of VSFTP. How will you do?
Answer : The parameter ‘session_support’ needs to be modified. This parameter controls and manages vsftp attempts to maintain session for logins. The default value is NO.
# Add this line to maintain session logins.
session_support=YES
18. How to display time in local time zone, when listing the contents of directory?
Answer : The parameter ‘usr_localtime’ needs to be modified. If enabled, vsftpd will list directory files in local time zone format. The default is to display GMT. The default value is NO.
# Add this line to display directory listing in local time zone.
usr_localtime=YES
19. How will you limit the maximum transfer rate from VSFTP server?
Answer : To limit the maximum transfer rate of VSFTP server we need the parameter ‘anon_max_rate’ in bytes per second, for anonymous client. The default value is 0 which means unlimited.
# Add this line to limit the ftp transfer rate.
anon_max_rate=0 # 0 means unlimited
20. How will you timeout the idle session of VSFTP?
Answer : The parameter ‘idle_session_timeout’ needs to be modified here. The timeout in second, which is the maximum time an anonymous user can spend in a session between his client machine and VSFTP server. As soon as the the timeout triggers, the client is logged out. The default time is 300.
# Add this line to set the ftp timeout session.
idle_session_timeout=300
That’s all for now. We will be coming up with next article very soon, till then stay tuned and connected and don’t forget to provide us with your valuable feedback in our comment section.

10 VsFTP (Very Secure File Transfer Protocol) Interview Questions and Answers

FTP stands for ‘File Transfer Protocol‘ is one of the most widely used and standard protocol available over Internet. FTP works in a ServerClient architecture and is used to transfer file. Initially FTP client were command-­line based. Now most of the platform comes bundled with FTP client and server program and a lot of FTP Client/Server Program is available. Here we are presenting 10 Interview Questions based on Vsftp (Very Secure File Transfer Protocol) on a Linux Server.
VsFTP Interview Questions
10 VsFTP Interview Questions
1. What is the Difference between TFTP and FTP Server?
Answer : TFTP is File Transfer Protocol which usages User Datagram Protocol (UDP) whereas FTP usages Transmission Control Protocol (TCP). TCP usages port number 20 for Data and 21 for control by default whereas TFTP usages port 69 by default.
Note: Briefly you can say FTP usages port 21 by default when clarification between Data and Control is not required.
2. How to Restrict Users and Disallow browsing beyond their Home Directories? How?
Answer : Yes! It is possible to restrict users to their home directories and browsing beyond home directories. This can be done by enabling chroot option in ftp configuration file (i.e. vsftpd.conf).
chroot_local_user=YES
3. How would you manage number of FTP clients that connect to your FTP server?
Answer : We need to set ‘max_client parameter’. This parameter controls the number of clients connecting, if max_client is set to 0, it will allow unlimited clients to connect FTP server.The maximum client parameter needs to be changed in vsftpd.conf and the default value is 0.
4. How to limit the FTP login attempts to fight against botnet/illegal login attempts?
Answer : We need to edit ‘max_login_fails parameter’. This parameter manages the maximum number of login attempts before the session is killed. The default value is ‘3’ which means a maximum of ‘3’ login attempts are possible failing which the session will be killed.
5. How to enable file upload from anonymous users to FTP Server?
Answer : Anonymous users can be allowed to upload files to FTP server by modifying parameter ‘anon_upload_enable’. If Value of anon_upload_enable is set to Yes, Anonymous users are permitted to upload files. In order to have a working anonymous upload, we must have parameter ‘write_enable’ activated. The Default Value is NO, which means anonymous upload is disabled.
6. How would you disabled downloads from FTP server?
Answer : Disabling Downloads from FTP Server can be implemented by modifying the parameter ‘download_enable’. If set to NO, all download request will be denied. The Default value is YES which Means, Downloading is Enabled.
7. How to enable and permit FTP login to local users?
Answer : The parameter ‘Local_enable’ is responsible for managing local users login. In order to activate local users login, we must set ‘local_enable=yes’ in file vsftpd.conf. The default value is NO, which means Local User Login is not permitted.
8. Is it Possible to maintain log of FTP requests and responses?
Answer : Yes! We can log FTP requests and responses. What we need to do is to modify the binary value of parameter ‘log_ftp_protocol’. If set to Yes, it will log all the requests, responses. The log may be very useful in Debugging. The default value of above parameter is NO which means no logs are maintained by default.
Note: In order to create and maintains logs successfully, the parameter ‘xferlog_std_format’ must be enabled.
9. How to disable the login for few seconds, in case of failed login. How will you achieve this?
Answer : The number of seconds we need to pause in case of failed login attempt can be achieved by modifying the value of parameter ‘delay_failed_login’. The default value is 1.
10. How to display certain text message before a client connects to FTP server. How would you get this done?
Answer : We can achieve this by setting ‘banner_file’. We need to set ftpd_banner=/path/to/banner-file in vsftpd.conf file.
FTP is a very Useful tool and is vast yet very interesting. Moreover it is useful from Interview Point of View. We have taken the pain to bring these questions to you and will cover more of these questions in our future article. Till then stay tuned and connected to Tecmint.

June 8, 2015

Cấu hình ftp server với vsftpd

FTP là 1 dịch vụ dùng để chia sẻ tài nguyên  bài viết này sẻ hướng dẫn các bạn cài đặt cấu hình ftp server với vsftpd

1. Giới thiệu

- Là 1 dịch vụ dùng để chia sẻ tài nguyên.

- FTP là FTP server chạy trên môi trường Linux.

- VSFTP sẽ phân quyền dựa trên cấu hình và File Permisson.


2. Yêu cầu

Xây dựng DNS cho domain hoclinux.net sao cho phân giải được record ftp.hoclinux.net


a. Cài đặt FTP Server

- Kiểm tra gói phần mềm, nếu chưa cài thì cài vào (xem mục cài đặt)

#rpm -qa vsftpd


- Tắt Firewall, SELinux

Open FTP port

Open /etc/sysconfig/iptables file, enter:
# vi /etc/sysconfig/iptables
Append following line to open ftp port 21 before REJECT line:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
Save and close the file. Restart the firewall:
# service iptables start

# vi /etc/vsftpd/user_list /cấu hình danh sách tài khoản ĐƯỢC PHÉP TRUY CẬP FTP
# vi /etc/vsftpd/ftpusers / cấu hình danh sách tài khoản KHÔNG ĐƯỢC PHÉP TRUY CẬP FTP


TẠO TÀI KHOẢN
Hãy bắt đầu bằng việc tạo một nhóm dùng để truy cập FTP:
#/usr/sbin/groupadd ftpaccounts /TopHostVN đặt tên nhóm là ftpaccounts
Thêm tài khoản mới và set vào nhóm ftpaccounts:
#/usr/sbin/adduser -g ftpaccounts -d /var/www/html/user1 user1 /Tạo tài khoản user tại thư mục /var/www/html/user1
Đừng quên set mật khẩu cho tài khoản user1 này luôn nhé:
# passwd user1 /nhập mật khẩu cho tài khoản này 2 lần là được.
Xét quyền quản lý thư mục cho user1
# chown user1:ftpaccounts /var/www/html/user1
Và đừng quên CHMOD thư mục:
# chmod 775 /var/www/html/user1
Cuối cùng, bạn cần khởi động lại vsftp:
# service vsftpd restart
Như vậy, bạn đã có thể set quyền truy cập thư mục http:///user1/ tới tài khoản user1.
QUẢN LÝ CÁC USER
Với vsftp, bạn có thể quản lý các user được cấp phép truy cập thông qua việc chỉnh sửa 2 file:
# vi /etc/vsftpd/user_list
# vi /etc/vsftpd/ftpusers

b. Cấu hình FTP Server - vsftpd

File cấu hình chính của vsftpd nằm trong thư mục /etc/vsftpd/vsftpd.conf. Ngoài ra còn có những file khác:

- /etc/vsftpd.ftpusers: liệt kê những người dùng không được phép login vào vsftpd.

- /etc/vsftpd.user_list: tập tin này được cấu hình để cấm hay cho phép những người dùng được liệt kê truy cập FTP Server. Điều này phụ thuộc vào tuỳ chọn userlist_deny được xét YES hay NO trong tập tin cấu hình.

ta mở file cấu hình chính lên

vi /etc/vsftpd/vsftpd.conf

ta sẽ cần chú ý những tuỳ chọn sau:

listen=YES/NO : VSFTPD chạy ở chế độ standalone.

session_support=YES/NO : VSFTPD quản lý giao dịch login của người dùng.

anonymous_enable=YES/NO : người dùng anonymous được phép login vào FTP Server.

cmds_allowed : Chỉ ra danh sách các lệnh ftp (cách nhau bởi dấu phẩy) được cho phép bởi FTP Server.

ftpd_banner : dòng thông báo sẽ hiển thị khi người dùng kết nối đến FTP Server.

local_enable==YES/NO : cho phép người dùng cục bộ login vào FTP Server.

userlist_deny=YES và userlist_enable=NO : thì tất cả những người dùng cục bộ bị cấm truy cập trừ những người dùng được chỉ ra trong userlist_file.

userlist_deny=NO và userlist_enable=YES : thì tất cả những người dùng được chỉ ra trong userlist_file bị cấm truy cập.

userlist_file=/etc/vsftpd.user_list : chỉ ra tập tin lưu danh sách người dùng.

anon_mkdir_write_enable=YES/NO : kết hợp với write_enable=YES thì người dùng anonymous được phép tạo thư mục mới trong thư mục cha có quyền ghi.

anon_root : chỉ ra thư mục gốc của user anonymous, mặc định là /var/ftp.

anon_upload_enable=YES/NO : kết hợp với write_enable=YES thì người dùng anonymous được phép upload tập tin trong thư mục cha có quyền ghi.

anon_world_readable_only=YES : user anonymous chỉ được phép download những tập tin có quyền đọc.

no_anon_password=YES/NO : yêu cầu user anonymous nhập vào password lúc đăng nhập.

local_enable=YES/NO : cho phép người dùng cục bộ truy cập đến Server.

chmod_enable=YES/NO : cho phép người dùng thay đổi quyền hạn trên tập tin.

chroot_local_user=YES/NO : người dùng di chuyển đến home directory của mình sau khi login vào.

guest_enable=YES/NO : cho phép người dùng anonymous login vào như user guest, mà được chỉ ra trong guest_username.

guest_username : chỉ ra username của người dùng guest (user mặc định ftp).

local_root: chỉ ra thư mục khi người dùng cục bộ login vào.

dirlist_enable=YES/NO : người dùng được phép xem nội dung của thư mục.

dirmessage_enable=YES/NO : hiển thi ra 1 thông điệp khi người dùng di chuyển vào thư mục. Thông điệp này được lưu trong tập tin có tên .message và được chỉ ra trong tuỳ chọn message_file.

message_file : chỉ ra tên của tập tin lưu thông điệp.

download_enable=YES/NO : cho phép download.

chown_uploads=YES/NO : tất cả những tập tin được upload bởi user anonymous được sở hữu bởi user được chỉ ra trong chown_username.

chown_username : chỉ ra user sở hữu những tập tin được upload bởi user anonymous (mặc định là user root).

write_enable=YES/NO : cho phép xoá, thay đổi và lưu trữ tập tin.

accept_timeout : chỉ ra thời gian một client sử dụng chế độ passive để thiết lập kết nối đến Server. Tính bằng giây.

anon_max_rate : chỉ ra tốc độ truyền dữ liệu tối đa cho người dùng anonymous. Tính bằng byte/second.

connect_timeout : chỉ ra thời gian một client sử dụng chế độ active để trả lời kết nối đến Server. Tính bằng giây.

data_connect_timeout : chỉ ra thời gian truyền dữ liệu tối đa. Khi kết thúc thời gian cho phép kết nối từ client sẽ bị đóng.

max_clients : chỉ ra số client tối đa đồng thời truy cập đến Server.

Khởi động vsftp:

service vsftpd start

Cho phép vsftp khởi động cùng hệ điều hành

chkconfig vsftpd on


3. Các bài Lab

3.1 Lab 1Cấu hình cho phép anonymous được phép truy cập FTP Server

- Sủa dòng 12 trong file cấu hình với nội dung như sau:

anonymous_enable=YES


- Start dịch vụ vsftpd

#service vsftpd start


- Kiểm tra:

+ dùng trình duyệt explorer trên Windows

+ dòng lệnh: mở CMD, rồi gõ lệnh sau:

ftp ftp.hoclinux.net

+ lưu ý: thư mục root của ftp là /var/ftp


3.2 Lab 2

Thay đổi thư mục gốc của FTP Server là /data/ftp

- Tạo thư mục

#mkdir /data

#mkdir /data/ftp


- Thêm vào cuối file cấu hình nội dung sau:

anon_root=/data/ftp


- restart lại dịch vụ

#service vsftpd restart


- Kiểm tra bằng trình duyệt explorer hoặc dòng lệnh.


3.3 Lab 3

Cấu hình để anonymous được upload file lên thư mục /upload trên Ftp Server

- Tạo thư mục

#mkdir /data/ftp/upload


- Chỉnh sửa nội dung sau trong tập tin cấu hình:

+ dòng 18

write_enable=YES

+ dòng 27

anon_upload_enable=YES


- restart dịch vụ

#service vsftpd restart


- Cấp quyền cho thư mục /data/ftp/upload

#chmod 757 /data/ftp/upload


- Kiểm tra.


3.4 Lab 4

Cấu hình để anonymous được upload thư mục lên thư mục /upload trên Ftp Server

- Chỉnh sửa nội dung sau trong tập tin cấu hình:

+ dòng 18

write_enable=YES

+ dòng 31

anon_mkdir_write=YES


3.5 Lab 5

Cấu hình để có thể xóa, đổi tên file

- Thêm vào cuối file tập tin cấu hình nội dung sau:

anon_other_write_enable=YES

3.6 Lab 6

Cấu hình sao cho anonymous upload file lên và download được file đó về

- Thêm nội dung sau vào cuối file cấu hình /etc/vsftpd/vsftpd.conf

anon_usmask=022


- Restart dịch vụ

#service vsftpd restart


- Kiểm tra


- Chú ý:

Nếu download về không được thì vào tools -> internet options -> sercurity ->trusted sited ->sites -> add


3.7 Lab 7

Cho phép các user local login vào Ftp Server

- Chỉnh file cấu hình nội dung dòng 15 như sau:

local_enable=YES


- restart dịch vụ

#service vsftpd restart


- Kiểm tra

Tạo user hoclinux1 và hv2 và login vào để kiểm tra.


3.8 Lab 8

Cấm user hoclinux1 login vào Ftp Server

- Chỉnh file cấu hình dòng 115

userlist_enable=YES


- thêm user hoclinux1 vào cuối file

/etc/vsftpd/user_list


- restart dịch vụ

#service vsftpd restart


- kiểm tra

login vào Ftp Server bằng user hoclinux1 để kiểm tra.


3.9 Lab 9

Cấm máy bên cạnh truy xuất FTP Server

- Chỉnh sửa file cấu hình, dòng 116

tcp_wrappers=YES


- thêm nội dung sau vào cuối file /etc/hosts.deny

vsftpd: 192.168.9.107


- restart dịch vụ

#service vsftpd rertart


- Kiểm tra

Truy cập FTP Server từ máy 192.168.9.107 vào máy xem có bị cấm không?