-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenlogs.py
131 lines (119 loc) · 3.13 KB
/
genlogs.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
"""
Générer des logs pour le challenge 3
"""
import os
import random
import datetime
import dotenv
dotenv.load_dotenv()
actions = [
'Failed login: {username} - {password}',
'Failed login: {username} - {password}',
'Failed login: {username} - {password}',
'Failed login: {username} - {password}',
'Failed login: {username} - {password}',
'Failed login: {username} - {password}',
'Failed login: {username} - {password}',
'Failed login: {username} - {password}',
'Successful login: {username}',
'Successful login: {username}',
'Successful login: {username}',
'404 {url} Not found',
'404 {url} Not found',
'404 {url} Not found',
'404 {url} Not found',
'404 {url} Not found',
'404 {url} Not found',
'User {username} logged out',
'User {username} logged out',
'User {username} logged out',
'Server backup completed',
'Server is up',
'Server is up',
'Server is up',
'Server is up',
'Server is up',
'Server is up',
'Server is up',
'Server is up',
]
usernames = [
"RooT",
"Alice",
"Alice",
"Alice",
"Jean",
"Jean",
"Jean",
"Joe",
"Pierre",
"Pierre",
"Pierre",
"Kevin",
"Kevin",
"Kevin",
"Kevin",
"Kevin",
"Kevin",
"amin",
"amin",
"amin",
"amin",
"Yvonne",
"Yvonne",
"Yvonne",
"Yvonne",
"admin",
"admin",
"admin",
"admin",
"admin",
"admin",
"admin",
"root",
"root",
"root",
"root",
"root",
]
passwords = ['12345"6', 'qwe| rty', 'a#})_|zerty', 'azq-erty+12~34', "@dm!n", "[Admin!]!", "ad|^|in123",
"admin@1234.fr",
"qefbiu45", "l#b5u^gds", "4*zq!?{zdz", "521zw", '#az&#qfq)fdwx']
urls = ['/flag',
'/post/10',
'/post/13',
'/connexion',
'/page/1158',
'/exit',
'/me',
'/about',
'/contact',
'/register',
'/admin'
]
def get_random_element(arr):
return random.choice(arr)
def generate_log(initdate, ct):
action_template = get_random_element(actions)
if ct == 3245:
secdate = initdate + datetime.timedelta(seconds=random.randint(41, 123))
return f"{initdate.isoformat()} - Failed login: rOOt - {os.getenv('PW3_SH')}\n{secdate.isoformat()} - Successful login: RooT"
elif ct == 0:
return f"{initdate.isoformat()} - Server started successfully !"
else:
action = action_template \
.replace('{username}', get_random_element(usernames)) \
.replace('{password}', get_random_element(passwords)) \
.replace('{url}', get_random_element(urls))
return f"{initdate.isoformat()} - {action}"
def generate_logs(count):
tmplogs = []
initdate = datetime.datetime(2019, 1, 2, 10, 43, 4)
for ct in range(count):
tmplogs.append(generate_log(initdate, ct))
initdate = initdate + datetime.timedelta(minutes=random.randint(10, 800), seconds=random.randint(7, 43))
return tmplogs
log_count = 7364 # Number of logs to generate
logs = generate_logs(log_count)
with open('www/chall3/logs.txt', 'w') as f:
f.write('\n'.join(logs))