Attacking FTP
Last updated
Last updated
Related Pages & Tools
The (FTP
) is a standard network protocol used to transfer files between computers. It also performs directory and files operations, such as changing the working directory, listing files, and renaming and deleting directories or files. By default, FTP listens on port TCP/21
.
To attack an FTP Server, we can abuse misconfiguration or excessive privileges, exploit known vulnerabilities or discover new vulnerabilities. Therefore, after gaining access to the FTP Service, we need to be aware of the content in the directory so we can search for sensitive or critical information, as we previously discussed. The protocol is designed to trigger downloads and uploads with commands. Thus, files can be transferred between servers and clients. A file management system is available to the user, known by the operating system. Files can be stored in folders, which may be located in other folders. This results in a hierarchical directory structure. Most companies use this service for software or website development processes.
Nmap
default scripts -sC
includes the Nmap script which checks if a FTP server allows anonymous logins. The version enumeration flag -sV
provides interesting information about FTP services, such as the FTP banner, which often includes the version name. We can use the ftp
client or nc
to interact with the FTP service. By default, FTP runs on TCP port 21.
As we discussed, anonymous authentication can be configured for different services such as FTP. To access with anonymous login, we can use the anonymous
username and no password. This will be dangerous for the company if read and write permissions have not been set up correctly for the FTP service. Because with the anonymous login, the company could have stored sensitive information in a folder that the anonymous user of the FTP service could have access to.
This would enable us to download this sensitive information or even upload dangerous scripts. Using other vulnerabilities, such as path traversal in a web application, we would be able to find out where this file is located and execute it as PHP code, for example.
Supply the username and password anonymous:anonymous
Once we get access to an FTP server with anonymous credentials, we can start searching for interesting information. We can use the commands ls
and cd
to move around directories like in Linux. To download a single file, we use get
, and to download multiple files, we can use mget
. For upload operations, we can use put
for a simple file or mput
for multiple files. We can use help
in the FTP client session for more information.
Many different attacks and methods are protocol-based. However, it is essential to note that we are not attacking the individual protocols themselves but the services that use them. Since there are dozens of services for a single protocol and they process the corresponding information differently, we will look at some.
Note: Although we may find services vulnerable to brute force, most applications today prevent these types of attacks. A more effective method is Password Spraying.
An FTP bounce attack is a network attack that uses FTP servers to deliver outbound traffic to another device on the network. The attacker uses a PORT
command to trick the FTP connection into running commands and getting information from a device other than the intended server.
Consider we are targeting an FTP Server FTP_DMZ
exposed to the internet. Another device within the same network, Internal_DMZ
, is not exposed to the internet. We can use the connection to the FTP_DMZ
server to scan Internal_DMZ
using the FTP Bounce attack and obtain information about the server's open ports. Then, we can use that information as part of our attack against the infrastructure.
The Nmap
-b flag can be used to perform an FTP bounce attack:
Modern FTP servers include protections that, by default, prevent this type of attack, but if these features are misconfigured in modern-day FTP servers, the server can become vulnerable to an FTP Bounce attack.
In discussing the latest vulnerabilities, we will focus this section and the following ones on one of the previously shown attacks and present it as simply as possible without going into too much technical detail. This should help us facilitate the concept of the attack through an example related to a specific service to gain a better understanding.
We create a raw HTTP PUT
request (-X PUT
) with basic auth (--basic -u <username>:<password>
), the path for the file (--path-as-is https://<IP>/../../../../../whoops
), and its content (--data-binary "PoC."
) with this command. Additionally, we specify the host header (-H "Host: <IP>"
) with the IP address of our target system.
In short, the actual process misinterprets the user's input of the path. This leads to access to the restricted folder being bypassed. As a result, the write permissions on the HTTP PUT
request are not adequately controlled, which leads to us being able to create the files we want outside of the authorized folders. However, we will skip the explanation of the Basic Auth
process and jump directly to the first part of the exploit.
1.
The user specifies the type of HTTP request with the file's content, including escaping characters to break out of the restricted area.
Source
2.
The changed type of HTTP request, file contents, and path entered by the user are taken over and processed by the process.
Process
3.
The application checks whether the user is authorized to be in the specified path. Since the restrictions only apply to a specific folder, all permissions granted to it are bypassed as it breaks out of that folder using the directory traversal.
Privileges
4.
The destination is another process that has the task of writing the specified contents of the user on the local system.
Destination
Up to this point, we have bypassed the constraints imposed by the application using the escape characters (../../../../
) and come to the second part, where the process writes the contents we specify to a file of our choice. This is when the cycle starts all over again, but this time to write contents to the target system.
5.
The same information that the user entered is used as the source. In this case, the filename (whoops
) and the contents (--data-binary "PoC."
).
Source
6.
The process takes the specified information and proceeds to write the desired content to the specified file.
Process
7.
Since all restrictions were bypassed during the directory traversal vulnerability, the service approves writing the contents to the specified file.
Privileges
8.
The filename specified by the user (whoops
) with the desired content ("PoC."
) now serves as the destination on the local system.
Destination
After the task has been completed, we will be able to find this file with the corresponding contents on the target system.
In the module, we cover detailed information about possible misconfigurations of such services. For example, many different settings can be applied to an FTP server, and some of them lead to different options that could cause possible attacks against that service. However, this module will focus on specific attacks rather than finding individual misconfigurations.
If there is no anonymous authentication available, we can also brute-force the login for the FTP services using a list of the pre-generated usernames and passwords. There are many different tools to perform a brute-forcing attack. Let us explore one of them, . With Medusa
, we can use the option -u
to specify a single user to target, or you can use the option -U
to provide a file with a list of usernames. The option -P
is for a file containing a list of passwords. We can use the option -M
and the protocol we are targeting (FTP) and the option -h
for the target hostname or IP address.
Source:
In this case, we will discuss the CoreFTP before build 727
vulnerability assigned . This vulnerability is for an FTP service that does not correctly process the HTTP PUT
request and leads to an authenticated directory
/path traversal,
and arbitrary file write
vulnerability. This vulnerability allows us to write files outside the directory to which the service has access.
This FTP service uses an HTTP POST
request to upload files. However, the CoreFTP service allows an HTTP PUT
request, which we can use to write content to files. Let's have a look at the attack based on our concept. The for this attack is relatively straightforward, based on a single cURL
command.