mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
259 lines
12 KiB
Markdown
259 lines
12 KiB
Markdown
# 21 - Pentesting FTP
|
||
|
||
{{#include ../../banners/hacktricks-training.md}}
|
||
|
||
## 기본 정보
|
||
|
||
**파일 전송 프로토콜 (FTP)**는 서버와 클라이언트 간의 컴퓨터 네트워크에서 파일 전송을 위한 표준 프로토콜입니다.\
|
||
이것은 **일반 텍스트** 프로토콜로, **새 줄 문자 `0x0d 0x0a`**를 사용하므로 때때로 **`telnet`** 또는 **`nc -C`**를 사용하여 **연결해야** 합니다.
|
||
|
||
**기본 포트:** 21
|
||
```
|
||
PORT STATE SERVICE
|
||
21/tcp open ftp
|
||
```
|
||
### Connections Active & Passive
|
||
|
||
In **Active FTP** the FTP **client** first **initiates** the control **connection** from its port N to FTP Servers command port – port 21. The **client** then **listens** to port **N+1** and sends the port N+1 to FTP Server. FTP **Server** then **initiates** the data **connection**, from **its port M to the port N+1** of the FTP Client.
|
||
|
||
But, if the FTP Client has a firewall setup that controls the incoming data connections from outside, then active FTP may be a problem. And, a feasible solution for that is Passive FTP.
|
||
|
||
In **Passive FTP**, the client initiates the control connection from its port N to the port 21 of FTP Server. After this, the client issues a **passv comand**. The server then sends the client one of its port number M. And the **client** **initiates** the data **connection** from **its port P to port M** of the FTP Server.
|
||
|
||
Source: [https://www.thesecuritybuddy.com/vulnerabilities/what-is-ftp-bounce-attack/](https://www.thesecuritybuddy.com/vulnerabilities/what-is-ftp-bounce-attack/)
|
||
|
||
### Connection debugging
|
||
|
||
The **FTP** commands **`debug`** and **`trace`** can be used to see **how is the communication occurring**.
|
||
|
||
## Enumeration
|
||
|
||
### Banner Grabbing
|
||
```bash
|
||
nc -vn <IP> 21
|
||
openssl s_client -connect crossfit.htb:21 -starttls ftp #Get certificate if any
|
||
```
|
||
### STARTTLS를 사용하여 FTP에 연결하기
|
||
```
|
||
lftp
|
||
lftp :~> set ftp:ssl-force true
|
||
lftp :~> set ssl:verify-certificate no
|
||
lftp :~> connect 10.10.10.208
|
||
lftp 10.10.10.208:~> login
|
||
Usage: login <user|URL> [<pass>]
|
||
lftp 10.10.10.208:~> login username Password
|
||
```
|
||
### Unauth enum
|
||
|
||
With **nmap**
|
||
```bash
|
||
sudo nmap -sV -p21 -sC -A 10.10.10.10
|
||
```
|
||
`HELP` 및 `FEAT` 명령어를 사용하여 FTP 서버에 대한 정보를 얻을 수 있습니다:
|
||
```
|
||
HELP
|
||
214-The following commands are recognized (* =>'s unimplemented):
|
||
214-CWD XCWD CDUP XCUP SMNT* QUIT PORT PASV
|
||
214-EPRT EPSV ALLO* RNFR RNTO DELE MDTM RMD
|
||
214-XRMD MKD XMKD PWD XPWD SIZE SYST HELP
|
||
214-NOOP FEAT OPTS AUTH CCC* CONF* ENC* MIC*
|
||
214-PBSZ PROT TYPE STRU MODE RETR STOR STOU
|
||
214-APPE REST ABOR USER PASS ACCT* REIN* LIST
|
||
214-NLST STAT SITE MLSD MLST
|
||
214 Direct comments to root@drei.work
|
||
|
||
FEAT
|
||
211-Features:
|
||
PROT
|
||
CCC
|
||
PBSZ
|
||
AUTH TLS
|
||
MFF modify;UNIX.group;UNIX.mode;
|
||
REST STREAM
|
||
MLST modify*;perm*;size*;type*;unique*;UNIX.group*;UNIX.mode*;UNIX.owner*;
|
||
UTF8
|
||
EPRT
|
||
EPSV
|
||
LANG en-US
|
||
MDTM
|
||
SSCN
|
||
TVFS
|
||
MFMT
|
||
SIZE
|
||
211 End
|
||
|
||
STAT
|
||
#Info about the FTP server (version, configs, status...)
|
||
```
|
||
### 익명 로그인
|
||
|
||
_anonymous : anonymous_\
|
||
\_anonymous :_\
|
||
\_ftp : ftp_
|
||
```bash
|
||
ftp <IP>
|
||
>anonymous
|
||
>anonymous
|
||
>ls -a # List all files (even hidden) (yes, they could be hidden)
|
||
>binary #Set transmission to binary instead of ascii
|
||
>ascii #Set transmission to ascii instead of binary
|
||
>bye #exit
|
||
```
|
||
### [Brute force](../../generic-hacking/brute-force.md#ftp)
|
||
|
||
여기 기본 ftp 자격 증명의 멋진 목록을 찾을 수 있습니다: [https://github.com/danielmiessler/SecLists/blob/master/Passwords/Default-Credentials/ftp-betterdefaultpasslist.txt](https://github.com/danielmiessler/SecLists/blob/master/Passwords/Default-Credentials/ftp-betterdefaultpasslist.txt)
|
||
|
||
### Automated
|
||
|
||
Anon 로그인 및 바운스 FTP 검사는 기본적으로 nmap의 **-sC** 옵션으로 수행됩니다:
|
||
```bash
|
||
nmap --script ftp-* -p 21 <ip>
|
||
```
|
||
## 브라우저 연결
|
||
|
||
You can connect to a FTP server using a browser (like Firefox) using a URL like:
|
||
```bash
|
||
ftp://anonymous:anonymous@10.10.10.98
|
||
```
|
||
사용자에 의해 제어되는 데이터를 **FTP 서버**에 **직접 전송하는 웹 애플리케이션**이 있는 경우, 이중 URL 인코딩된 `%0d%0a` (이중 URL 인코딩에서는 `%250d%250a`) 바이트를 전송하여 **FTP 서버가 임의의 작업을 수행**하게 할 수 있습니다. 이러한 임의의 작업 중 하나는 사용자가 제어하는 서버에서 콘텐츠를 다운로드하거나 포트 스캐닝을 수행하거나 다른 평문 기반 서비스(예: http)와 통신을 시도하는 것입니다.
|
||
|
||
## FTP에서 모든 파일 다운로드
|
||
```bash
|
||
wget -m ftp://anonymous:anonymous@10.10.10.98 #Donwload all
|
||
wget -m --no-passive ftp://anonymous:anonymous@10.10.10.98 #Download all
|
||
```
|
||
사용자/비밀번호에 특수 문자가 포함된 경우, [다음 명령어](https://stackoverflow.com/a/113900/13647948)를 사용할 수 있습니다:
|
||
```bash
|
||
wget -r --user="USERNAME" --password="PASSWORD" ftp://server.com/
|
||
```
|
||
## Some FTP commands
|
||
|
||
- **`USER username`**
|
||
- **`PASS password`**
|
||
- **`HELP`** 서버가 지원하는 명령어를 표시합니다.
|
||
- **`PORT 127,0,0,1,0,80`** 이는 FTP 서버에 IP 127.0.0.1의 포트 80과 연결을 설정하도록 지시합니다 (_5번째 문자는 "0"으로, 6번째는 10진수로 포트를 입력해야 하거나 5번째와 6번째를 사용하여 포트를 16진수로 표현해야 합니다_).
|
||
- **`EPRT |2|127.0.0.1|80|`** 이는 FTP 서버에 IP 127.0.0.1의 포트 80과 TCP 연결을 설정하도록 지시합니다 (_"2"로 표시됨_). 이 명령은 **IPv6을 지원합니다**.
|
||
- **`LIST`** 현재 폴더의 파일 목록을 전송합니다.
|
||
- **`LIST -R`** 재귀적으로 목록을 나열합니다 (서버에서 허용하는 경우).
|
||
- **`APPE /path/something.txt`** 이는 FTP에 **수동** 연결 또는 **PORT/EPRT** 연결에서 수신한 데이터를 파일에 저장하도록 지시합니다. 파일 이름이 존재하면 데이터를 추가합니다.
|
||
- **`STOR /path/something.txt`** `APPE`와 같지만 파일을 덮어씁니다.
|
||
- **`STOU /path/something.txt`** `APPE`와 같지만 존재할 경우 아무 작업도 하지 않습니다.
|
||
- **`RETR /path/to/file`** 수동 또는 포트 연결이 설정되어야 합니다. 그런 다음 FTP 서버는 해당 연결을 통해 지정된 파일을 전송합니다.
|
||
- **`REST 6`** 이는 서버에 다음 번에 `RETR`를 사용하여 무언가를 전송할 때 6번째 바이트에서 시작해야 함을 지시합니다.
|
||
- **`TYPE i`** 전송을 이진으로 설정합니다.
|
||
- **`PASV`** 이는 수동 연결을 열고 사용자가 연결할 수 있는 위치를 표시합니다.
|
||
- **`PUT /tmp/file.txt`** 지정된 파일을 FTP에 업로드합니다.
|
||
|
||
.png>)
|
||
|
||
## FTPBounce attack
|
||
|
||
일부 FTP 서버는 PORT 명령을 허용합니다. 이 명령은 서버에 다른 FTP 서버의 특정 포트에 연결하고 싶음을 나타내는 데 사용할 수 있습니다. 그런 다음 이를 사용하여 FTP 서버를 통해 호스트의 어떤 포트가 열려 있는지 스캔할 수 있습니다.
|
||
|
||
[**여기에서 FTP 서버를 악용하여 포트를 스캔하는 방법을 배우세요.**](ftp-bounce-attack.md)
|
||
|
||
이 동작을 악용하여 FTP 서버가 다른 프로토콜과 상호작용하도록 만들 수도 있습니다. **HTTP 요청을 포함하는 파일을 업로드**하고 취약한 FTP 서버가 **임의의 HTTP 서버로 전송하도록** 하거나, 심지어 FTP 요청을 업로드하고 취약한 FTP 서버가 다른 FTP 서버에서 파일을 다운로드하도록 만들 수 있습니다.\
|
||
이론은 간단합니다:
|
||
|
||
1. **취약한 서버에 요청(텍스트 파일 내)을 업로드합니다.** 다른 HTTP 또는 FTP 서버와 통신하려면 `0x0d 0x0a`로 줄을 변경해야 합니다.
|
||
2. **원하지 않는 문자를 전송하지 않도록 `REST X`를 사용합니다** (아마도 요청을 파일 내에 업로드하기 위해 파일의 시작 부분에 이미지 헤더를 넣어야 했을 것입니다).
|
||
3. **임의의 서버 및 서비스에 연결하기 위해 `PORT`를 사용합니다.**
|
||
4. **저장된 요청을 서버에 전송하기 위해 `RETR`를 사용합니다.**
|
||
|
||
이것이 **_**소켓이 쓰기 불가능하다는**_ **오류를 발생시킬 가능성이 높습니다** **왜냐하면 연결이 `RETR`로 데이터를 전송하기에 충분히 오래 지속되지 않기 때문입니다**. 이를 피하기 위한 제안은 다음과 같습니다:
|
||
|
||
- HTTP 요청을 전송하는 경우, **같은 요청을 연속으로 넣습니다** **\~0.5MB** 이상까지. 이렇게:
|
||
|
||
{{#file}}
|
||
posts.txt
|
||
{{#endfile}}
|
||
|
||
- **프로토콜과 관련된 "정크" 데이터로 요청을 채우려고 시도합니다** (FTP와 대화할 때는 아마도 정크 명령이나 `RETR` 명령을 반복하여 파일을 가져오는 것).
|
||
- **많은 널 문자 또는 다른 문자로 요청을 채우려고 시도합니다** (줄로 나누거나 나누지 않고).
|
||
|
||
어쨌든, 여기 [다른 FTP 서버에서 파일을 다운로드하도록 FTP 서버를 악용하는 방법에 대한 오래된 예제가 있습니다.](ftp-bounce-download-2oftp-file.md)
|
||
|
||
## Filezilla Server Vulnerability
|
||
|
||
**FileZilla**는 일반적으로 **로컬**에 **FileZilla-Server**(포트 14147)를 위한 **관리 서비스**를 **바인딩**합니다. 이 포트에 접근하기 위해 **당신의 머신**에서 **터널**을 생성할 수 있다면, **빈 비밀번호**를 사용하여 **연결**하고 FTP 서비스에 대한 **새 사용자**를 **생성**할 수 있습니다.
|
||
|
||
## Config files
|
||
```
|
||
ftpusers
|
||
ftp.conf
|
||
proftpd.conf
|
||
vsftpd.conf
|
||
```
|
||
### Post-Exploitation
|
||
|
||
vsFTPd의 기본 구성은 `/etc/vsftpd.conf`에서 찾을 수 있습니다. 여기에서 몇 가지 위험한 설정을 찾을 수 있습니다:
|
||
|
||
- `anonymous_enable=YES`
|
||
- `anon_upload_enable=YES`
|
||
- `anon_mkdir_write_enable=YES`
|
||
- `anon_root=/home/username/ftp` - 익명 사용자를 위한 디렉토리.
|
||
- `chown_uploads=YES` - 익명으로 업로드된 파일의 소유권 변경
|
||
- `chown_username=username` - 익명으로 업로드된 파일의 소유권을 부여받는 사용자
|
||
- `local_enable=YES` - 로컬 사용자가 로그인할 수 있도록 활성화
|
||
- `no_anon_password=YES` - 익명 사용자에게 비밀번호를 묻지 않음
|
||
- `write_enable=YES` - 명령 허용: STOR, DELE, RNFR, RNTO, MKD, RMD, APPE, 및 SITE
|
||
|
||
### Shodan
|
||
|
||
- `ftp`
|
||
- `port:21`
|
||
|
||
## HackTricks Automatic Commands
|
||
```
|
||
Protocol_Name: FTP #Protocol Abbreviation if there is one.
|
||
Port_Number: 21 #Comma separated if there is more than one.
|
||
Protocol_Description: File Transfer Protocol #Protocol Abbreviation Spelled out
|
||
|
||
Entry_1:
|
||
Name: Notes
|
||
Description: Notes for FTP
|
||
Note: |
|
||
Anonymous Login
|
||
-bi <<< so that your put is done via binary
|
||
|
||
wget --mirror 'ftp://ftp_user:UTDRSCH53c"$6hys@10.10.10.59'
|
||
^^to download all dirs and files
|
||
|
||
wget --no-passive-ftp --mirror 'ftp://anonymous:anonymous@10.10.10.98'
|
||
if PASV transfer is disabled
|
||
|
||
https://book.hacktricks.wiki/en/network-services-pentesting/pentesting-ftp/index.html
|
||
|
||
Entry_2:
|
||
Name: Banner Grab
|
||
Description: Grab FTP Banner via telnet
|
||
Command: telnet -n {IP} 21
|
||
|
||
Entry_3:
|
||
Name: Cert Grab
|
||
Description: Grab FTP Certificate if existing
|
||
Command: openssl s_client -connect {IP}:21 -starttls ftp
|
||
|
||
Entry_4:
|
||
Name: nmap ftp
|
||
Description: Anon login and bounce FTP checks are performed
|
||
Command: nmap --script ftp-* -p 21 {IP}
|
||
|
||
Entry_5:
|
||
Name: Browser Connection
|
||
Description: Connect with Browser
|
||
Note: ftp://anonymous:anonymous@{IP}
|
||
|
||
Entry_6:
|
||
Name: Hydra Brute Force
|
||
Description: Need Username
|
||
Command: hydra -t 1 -l {Username} -P {Big_Passwordlist} -vV {IP} ftp
|
||
|
||
Entry_7:
|
||
Name: consolesless mfs enumeration ftp
|
||
Description: FTP enumeration without the need to run msfconsole
|
||
Note: sourced from https://github.com/carlospolop/legion
|
||
Command: 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' && msfconsole -q -x 'use auxiliary/scanner/ftp/colorado_ftp_traversal; set RHOSTS {IP}; set RPORT 21; run; exit' && msfconsole -q -x 'use auxiliary/scanner/ftp/titanftp_xcrc_traversal; set RHOSTS {IP}; set RPORT 21; run; exit'
|
||
```
|
||
{{#include ../../banners/hacktricks-training.md}}
|