-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivity_sim.py
More file actions
61 lines (41 loc) · 1.8 KB
/
Copy pathactivity_sim.py
File metadata and controls
61 lines (41 loc) · 1.8 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
from math import ceil
import time
import random
from encryption import populate_file
def write_net_data(n_filename, url_list):
n_outfile = open(n_filename, 'a+')
url = random.choice(url_list)
n_outfile.write(url)
n_outfile.close()
if __name__ == '__main__':
switch_time = 0
run_default = (input('Run default? (y/n) ') == 'y')
if run_default:
d_filename = 'encryption/mem_data.txt'
n_filename = 'network/net_data.txt'
n_good_filepath = 'network/good_urls.txt'
n_bad_filepath = 'network/bad_urls.txt'
else:
d_filename = input("Data Filename: ").strip()
n_filename = input("Network output filename: ").strip()
n_good_filepath = input("Good network file path: ").strip()
n_bad_filepath = input("Bad network file path: ").strip()
time_to_run = float(input("time to run: ").strip())*60
attack_switch = (input('Attack switch? (y/n) ').strip() == 'y')
if(attack_switch):
switch_time = float(input("switch time: ").strip())*60
url_list = open(n_good_filepath, 'r+').readlines()
bad_file = open(n_bad_filepath, 'r+')
attack = False
start = time.time()
while(time.time()-start < time_to_run):
print(f"\rrunning: {ceil(((time.time()-start)/time_to_run)*100)}%" , end=' ')
if(not attack and attack_switch and time.time() - start > switch_time):
print(f"\rSwitching to attack at", time.strftime("%H:%M:%S",time.localtime()), "\t\t\t")
attack = True
bad_urls = bad_file.readlines()
write_net_data(n_filename, bad_urls)
url_list.extend(bad_urls)
populate_file.write_file(attack=attack, filename=d_filename)
write_net_data(n_filename,url_list)
print("Complete!")