---
title: "8. Enumeration - FTP"
date: 2024-07-14
draft: false
---

1. One of the oldest protocols. 
2. Application layer of tcp/ip stack. (Same layer as HTTP/POP)
3. In an FTP connection, two channels are opened. First, the client and server establish a control channel through `TCP port 21`.
4.  The client sends commands to the server, and the server returns status codes. Then both communication participants can establish the data channel via `TCP port 20`.
5. This channel is used exclusively for data transmission, and the protocol watches for errors during this process.
6. A distinction is made between `active` and `passive` FTP.
	1. Active - client establish. connect. as described above, informs server via which client-side port the server can xmit responses. If there's a firewall around the client the server cannot reply because all external connections are blocked. Because of this we have:
	2. Passive - Server announces port thru which client can establish data channel - Since client initiates connection, firewall does not block xfer
7. The FTP knows different [commands](https://www.smartfile.com/blog/the-ultimate-ftp-commands-list/) and status codes. Not all of these commands are consistently implemented on the server. https://en.wikipedia.org/wiki/List_of_FTP_server_return_codes

**TFTP 
1. Trivial FTP
2. Simpler than ftp , performed file xfer btwn client/serv
3. No user auth
4. Uses UDP - unreliable and causes it to use udp-assisted application layer recovery 
5. TFTP unlike FTP, no user auth - does not support protected login w/ passwords and sets limit on access 
6. Unlike the FTP client, `TFTP` does not have directory listing functionality.
7. Practically, this leads to TFTP operating exclusively in directories and with files that have been shared with all users and can be read and written globally.

### vsftpd - 
/etc/ftpusers -> users unallowed to use server
config file location
```shell-session
stejwes@htb[/htb]$ cat /etc/vsftpd.conf | grep -v "#"
```

dangerous settings:
anonymous_enable
anon_upload_enable
anon_mkdir_write_enable
no_anon_password
anon_root
write_enable

possible to use `debug` and `trace` to give us more information about the files we are looking at 

**`Downloading` files from such an FTP server is one of the main features, as well as `uploading` files created by us. This allows us, for example, to use LFI vulnerabilities to make the host execute system commands. Apart from the files, we can view, download and inspect. Attacks are also possible with the FTP logs, leading to `Remote Command Execution` (`RCE`). This applies to the FTP services and all those we can detect during our enumeration phase.

##### FTP cheatsheet

|**Command**|**Description**|
|---|---|
|`ftp <FQDN/IP>`|Interact with the FTP service on the target.|
|`nc -nv <FQDN/IP> 21`|Interact with the FTP service on the target.|
|`telnet <FQDN/IP> 21`|Interact with the FTP service on the target.|
|`openssl s_client -connect <FQDN/IP>:21 -starttls ftp`|Interact with the FTP service on the target using encrypted connection.|
|`wget -m --no-passive ftp://anonymous:anonymous@<target>`|Download all available files on the target FTP server.|


#### NSE scripts
```bash
┌──(root㉿kali)-[~]
└─# find / -type f -name ftp* 2>/dev/null | grep scripts        
/usr/share/nmap/scripts/ftp-anon.nse
/usr/share/nmap/scripts/ftp-proftpd-backdoor.nse
/usr/share/nmap/scripts/ftp-vuln-cve2010-4221.nse
/usr/share/nmap/scripts/ftp-syst.nse
/usr/share/nmap/scripts/ftp-libopie.nse
/usr/share/nmap/scripts/ftp-vsftpd-backdoor.nse
/usr/share/nmap/scripts/ftp-bounce.nse
/usr/share/nmap/scripts/ftp-brute.nse
```

nc and telnet work as normal but for ssl/tls we use openssl 
```shell-session
openssl s_client -connect 10.129.14.136:21 -starttls ftp
```
this can be useful because we can grab the SSL certificate
