# non heavy ftp

We are given read-only access to a LightFTP instance configured to only allow access to /server/data/. The flag, however, is at /flag.<some unknown uuid>. We, therefore, need to find a way to escape /server/data/ when listing and retrieving files.

LightFTP implements file operations such as LIST and RETR as follows

2. Normalize the file name (i.e. remove any ..) and prefix it with the FTP root.
3. Write the filename to the control connection’s context->FileName.
4. Check that the file exists and is of the right type.
5. Launch a thread for the data connection that
1. Establishes the connection. For passive mode, this means waiting for the client to connect.
2. Reads the filename from the control connection’s context->FileName.
3. Performs the file operation.
4. Sends the response to the client.

Since LightFTP only validates login credentials once we provide the password, it needs to store the username provided by the USER command somewhere until we send the PASS command. It does so in the control connection’s context->FileName. We can, therefore, set the FileName to a nearly arbitrary value between it being set to a known safe value and it actually being read in the data connection’s thread.

from pwn import *

def run(fake, file):
host = "47.89.253.219"
r = connect(host, 2121)