-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtester.py
106 lines (85 loc) · 3.02 KB
/
tester.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
from pwn import *
import time
import threading
import os
from os.path import exists
import random
NUM_CLIENTS = 20
IMG_FILE = "jv_bokassa.png"
MSG_SPEED = 5
NUM_ITERATIONS = 5
USER_PREFIX = "user"
NUM_SERVERS = 2
class Client:
# password = "pwd"
users = []
def __init__(self, username):
self.ps = None
self.username = username
self.ps = process(argv=['./client.py', '--cmd'])
self.ps.sendline(b'1')
self.ps.sendline(self.username.encode())
self.ps.sendline(self.username.encode())
self.ps.recvuntil(b'word: ')
Client.users.append(username)
self.log_file = open("log/" + username+"_log.txt", "wb")
def create_process(self)->None:
self.repetitive_msg(0, 1)
time.sleep(5)
self.repetitive_msg(1, 1)
time.sleep(5)
for i in range(NUM_ITERATIONS):
self.repetitive_msg(i+2, 20.0/MSG_SPEED)
# for i in range(5):
# self.img_msg(i+2, 10)
def repetitive_msg(self, i, t):
for user in Client.users:
self.ps.sendline(f'dm, {user}, helloworld{i}'.encode())
time.sleep(random.randint(0,10)/100.0*t)
def img_msg(self, i, t):
for user in Client.users:
x = random.randint(1, 10)
if x == 1:
self.ps.sendline(f"dm file, {user}, {i}_{IMG_FILE}".encode())
else:
self.ps.sendline(f'dm, {user}, helloworld{i}'.encode())
time.sleep(random.randint(0,10)/100.0*t)
def close(self):
# time.sleep(2)
for i in range(NUM_CLIENTS*2* (NUM_ITERATIONS+2) ):
try:
self.log_file.write(self.ps.recvuntil(b"d", timeout=10) + b"d")
# self.log_file.flush()
except:
pass
self.ps.sendline(b'exit')
if self.ps.poll(block = True):
self.ps.close()
if not exists("log"): os.makedirs("log")
os.system("bash cleaner.sh >/dev/null")
auth_ps = process(argv=["./auth_server.py", ])
time.sleep(2)
servers_ps = [process(argv=["./server.py", str(1+i), str(9001+i)]) for i in range(NUM_SERVERS)]
time.sleep(2)
clients1 = [Client(f"{USER_PREFIX}{i}") for i in range(0, int(NUM_CLIENTS/2))]
print("LMAO")
threads1 = [threading.Thread(target=Client.create_process, args=(client,)) for client in clients1]
for thread in threads1:
thread.start()
print("LMAO1")
time.sleep(5)
print("LMAO2")
clients2 = [Client(f"{USER_PREFIX}{i}") for i in range(int(NUM_CLIENTS/2), NUM_CLIENTS)]
threads2 = [threading.Thread(target=Client.create_process, args=(client,)) for client in clients2]
for thread in threads2:
thread.start()
# for thread in threads[int(len(threads)/2):]:
# thread.start()
closing_threads = [threading.Thread(target=Client.close, args=(client,)) for client in clients1+clients2]
for thread in closing_threads:
thread.start()
for thread in threads1+threads2:
thread.join()
for thread in closing_threads:
thread.join()
os.system(f"python3.8 analysis.py {NUM_CLIENTS} {USER_PREFIX}")