forked from kimocoder/wifite2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.py
executable file
·187 lines (154 loc) · 6.87 KB
/
Server.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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import os
import socket
import sys
import threading
from pyhashcat import Hashcat
from datetime import datetime
from time import sleep
import argparse
from wifite.util.color import Color
parser = argparse.ArgumentParser()
parser.add_argument('--ip', type=str, help='IP address of the server', required=True)
parser.add_argument('--port', type=int, help='Listening port of the server', required=True)
parser.add_argument('--password', type=str, help='Set the password for the server', required=True)
parser.add_argument('--wordlist', type=str, help='Wordlist to used for cracking', required=True)
args = parser.parse_args()
IP = args.ip
PORT = args.port
ADDR = (IP, PORT)
SIZE = 1024
FORMAT = "utf-8"
HANDSHAKE_DATA_PATH = "hs"
PASSWORD = args.password
def print_banner():
Color.pl('')
Color.pl(r' {G} :=++****++-: {W}')
Color.pl(r' {G} -*%@@@@%%##%%@@@@%*- {W}')
Color.pl(r' {G} :*@@@#=:. .:=#@@@*: {W}')
Color.pl(r' {G} .#@@%- -%@@#. {W}')
Color.pl(r' {G} =@@%- -*#= =**. -@@@= {W}')
Color.pl(r' {G} =@@# :*@@#: .*@@#. +@@@= {W}')
Color.pl(r' {G} :@@# -%@@#: .*@@%- :%@@@@@: {W}')
Color.pl(r' {G} #@@: -%@@%- +@@@= *@@@=:@@# {W}')
Color.pl(r' {G} @@@ :%@@@+ -%@@%. -@@@@: @@@ {W}')
Color.pl(r' {G} @@% +@@@@- -#@@@% :#@@@#. %@@ {W}')
Color.pl(r' {G} #@@#@@@@#::+%@@@@@- .=%@@@@- .@@# {W}')
Color.pl(r' {G} :@@@@@@@@@@@%@@@@@@@@@@@@+ #@@: {W}')
Color.pl(r' {G} +@@@@@@@%= .@@@@@@@@@@+ *@@+ {W}')
Color.pl(r' {G} +@@@%=: :%@@@@%+: :%@@+ {W}')
Color.pl(r' {G} :%@@#- . -#@@%: {W}{C}Wifte & Hascat over TCP{W}')
Color.pl(r' {G} -#@@@*=. .=*@@@#- {W}{D}a Hashcat backend server for Wifite{W}')
Color.pl(r' {G} .=#@@@@@%#**#%@@@@@#=. {W}{D}created by {O}wvthoog{W}')
Color.pl(r' {G} :-+**####**+-: {C}{D}https://wvthoog.nl{W}')
Color.pl('')
def cracking(conn, handshake, dictionary):
hc = Hashcat()
hc.reset()
hc.hash = handshake.name
hc.dict1 = dictionary
hc.quiet = True
hc.potfile_disable = True
hc.hwmon_disable = True
recent_file_name = datetime.now().strftime('out/%d-%m-%Y-%H-%M-%S') + '.out'
open(recent_file_name, 'x')
hc.outfile = recent_file_name
hc.outfile_format = 2 # plain text
Color.pl('{!} {C}Writing hash to {R}%s{W}' % hc.outfile)
hc.attack_mode = 0
hc.hash_mode = 22000
hc.workload_profile = 2
Color.pl('{+} {C}Running hashcat')
if hc.hashcat_session_execute() >= 0:
for devs in range(hc.status_get_device_info_cnt()):
if hc.status_get_skipped_dev(devs) == False:
active_devs = devs
# print('Active device:', active_devs)
else:
inactive_devs = devs
# print('Skipped devices:', inactive_devs)
while True:
# send info about cracking process back to client
sleep(1)
# print('Cracking WPA Hanshake:', str(round(hc.status_get_progress_finished_percent(), 2)) + '%'
# , 'ETA:', str(hc.status_get_time_estimated_relative())
# , '@', str(hc.status_get_speed_sec_all()), '(current keys:',
# str(hc.status_get_guess_candidates_dev(active_dev)) + ')')
msg_percentage = str(round(hc.status_get_progress_finished_percent(), 2))
msg_time_left = str(hc.status_get_time_estimated_relative())
msg_kbps = str(hc.status_get_speed_sec_all())
msg_keys = str(hc.status_get_guess_candidates_dev(active_devs))
status = '\r{!} {C}Hascat running {W}%s' % msg_percentage + '% {C}done'
Color.clear_entire_line()
Color.p(status)
# print('[+] Cracking WPA Handshake:', msg_percentage + '%', 'ETA:', msg_time_left
# , '@', msg_kbps, '(current keys:', msg_keys + ')')
conn.send(f'CRACKING[CMD]{msg_percentage}[MSG]{msg_time_left}[MSG]{msg_kbps}[MSG]{msg_keys}'.encode(FORMAT))
if hc.status_get_status_string() == "Cracked":
break
if hc.status_get_status_string() == "Aborted":
break
if hc.status_get_status_string() == "Exhausted":
break
sleep(2)
with open(hc.outfile, 'r') as f:
cracked = [i.strip() for i in f.readlines()]
if len(cracked) > 0:
for c in cracked:
# salt, ahash, bhash, ssid, plain = c.split(hc.separator.decode('utf-8'))
plain = c.split(hc.separator.decode('utf-8'))
Color.pl('\n{!} {C}Hash {G}cracked: {W}%s' % plain[0])
return plain[0]
else:
Color.pl('\n{!} {C}Hash {R}NOT cracked{W}')
return None
else:
print("STATUS: ", hc.status_get_status_string())
def handle_client(conn, addr):
Color.pl('{!} {C}Client {R}%s{O}' % addr[0] + ' connected')
conn.send("Welcome to the hash cracking server".encode(FORMAT))
if conn.recv(SIZE).decode(FORMAT) == PASSWORD:
Color.pl('{+} {C}Login {G}success')
conn.send('Password success'.encode(FORMAT))
else:
Color.pl('{!} {C}Login {R}failed')
conn.send('Password failed'.encode(FORMAT))
conn.close()
return
while True:
data = conn.recv(SIZE).decode(FORMAT)
data = data.split("[CMD]")
cmd = data[0]
if cmd == "UPLOAD":
Color.pl('{!} {C}Hash received')
handshake = data[1]
filepath = os.path.join(HANDSHAKE_DATA_PATH, 'handshake.hccapx')
with open(filepath, "w") as handshake_file:
handshake_file.write(handshake)
send_data = "OK[CMD]File uploaded successfully"
conn.send(send_data.encode(FORMAT))
cracked = cracking(conn, handshake_file, args.wordlist)
if cracked != None:
conn.send(f'CRACKED[CMD]{cracked}'.encode(FORMAT))
else:
conn.send('CRACKED[CMD]None'.encode(FORMAT))
elif cmd == "LOGOUT":
break
Color.pl('{!} {C}Client {R}%s{O}' % addr[0] + ' disconnected')
conn.close()
def main():
print_banner()
Color.pl('{+} {C}Server is starting{W}')
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(ADDR)
server.listen()
Color.pl('{+} {C}Server is listening on IP: {R}%s{O}' % IP + ' and port: {R}%s{W}' % PORT)
while True:
conn, addr = server.accept()
thread = threading.Thread(target=handle_client, args=(conn, addr))
thread.start()
Color.pl('{+} {C}Total connections: {R}%s{O}' % str(threading.activeCount() - 1))
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
sys.exit(0)