-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbookster.checker.py
executable file
·264 lines (246 loc) · 11.5 KB
/
bookster.checker.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
#!/usr/bin/env python3.11
import asyncio
import os.path
import uuid
import requests
from gornilo import CheckRequest, Verdict, PutRequest, GetRequest, NewChecker, VulnChecker
import random
from api import Api, AuthError, ParseError
from utils import generate_email, generate_name, generate_password, get_video_by_id, get_some_text, \
generate_video_filename, get_hash, generate_playlist
checker = NewChecker()
PORT = 8900
TOTAL_SAMPLES = 600
GENERATE_TIMEOUT = 6
DEFAULT_PHOTO_HASH = 'ce236d351d660927919aeead1450177f402812b8f4365ce7a54f4a895f71b834'
DEFAULT_PHOTO_SIZE = 98165
@checker.define_check
async def check_service(request: CheckRequest) -> Verdict:
api = Api(request.hostname, PORT)
email = generate_email()
username = generate_name()
password = generate_password()
try:
# index check
status, data = api.get_index()
if status != 200:
return Verdict.MUMBLE(f"Index failed with status {status}")
# register check
status, data = api.signup(email, username, password)
if status != 201:
print(email, username, password)
print(data)
return Verdict.MUMBLE(f"Signup failed with status {status}")
if "username" not in data or data["username"] != username:
return Verdict.MUMBLE("Signup wrong username")
if "email" not in data or data["email"] != email:
return Verdict.MUMBLE("Signup wrong email")
if "id" not in data:
return Verdict.MUMBLE("Signup no id")
# login check
status, data = api.login(username, password)
if status != 200:
return Verdict.MUMBLE(f"Login failed with status {status}")
# check create book without photo
book_id = random.randint(1, TOTAL_SAMPLES)
book_sample = get_video_by_id(book_id)
text = get_some_text()
send_filename = generate_video_filename()
title_without_photo = str(uuid.uuid4())
status, data = api.create_book(title_without_photo, text + 'nopreview', book_sample['video'], send_filename)
if status != 201:
return Verdict.MUMBLE(f"Create book failed with status {status}")
if "uid" not in data:
return Verdict.MUMBLE("Create book no uid")
if "text" not in data or data["text"] != text + 'nopreview':
return Verdict.MUMBLE("Create book wrong text")
if "title" not in data or data["title"] != title_without_photo:
return Verdict.MUMBLE("Create book wrong title")
if "video" not in data:
return Verdict.MUMBLE("Create book no video")
uid_no_wait_photo = data["uid"]
# check create book with photo
title_with_photo = str(uuid.uuid4())
status, data = api.create_book(title_with_photo, text, book_sample['video'], send_filename)
if status != 201:
return Verdict.MUMBLE(f"Create book failed with status {status}")
if "uid" not in data:
return Verdict.MUMBLE("Create book no uid")
if "text" not in data or data["text"] != text:
return Verdict.MUMBLE("Create book wrong text")
if "title" not in data or data["title"] != title_with_photo:
return Verdict.MUMBLE("Create book wrong title")
if "video" not in data:
return Verdict.MUMBLE("Create book no video")
uid_wait_photo = data["uid"]
# create book with playlist
title_playlist = str(uuid.uuid4())
playlist = generate_playlist()
status, data = api.create_book(title_playlist, text, playlist, send_filename, False)
if status != 201:
return Verdict.MUMBLE(f"Create book failed with status {status}")
if "uid" not in data:
return Verdict.MUMBLE("Create book no uid")
if "text" not in data or data["text"] != text:
return Verdict.MUMBLE("Create book wrong text")
if "title" not in data or data["title"] != title_playlist:
return Verdict.MUMBLE("Create book wrong title")
if "video" not in data:
return Verdict.MUMBLE("Create book no video")
uid_playlist = data["uid"]
await asyncio.sleep(GENERATE_TIMEOUT)
# check get book with photo
status, data = api.get_book(uid_wait_photo)
if status != 200:
return Verdict.MUMBLE(f"Get book failed with status {status}")
if "uid" not in data or data["uid"] != uid_wait_photo:
return Verdict.MUMBLE("Get book wrong uid")
if "text" not in data or data["text"] != text:
return Verdict.MUMBLE("Get book wrong text")
if "title" not in data or data["title"] != title_with_photo:
return Verdict.MUMBLE("Get book wrong title")
if "video" not in data:
return Verdict.MUMBLE("Get book no video")
if "video_preview" not in data:
return Verdict.MUMBLE("Get book no video_preview")
if data["video_preview"] is None:
print(book_sample['video'])
with open(book_sample['video'], 'rb') as f:
print(f.read()[:600])
return Verdict.MUMBLE("Video preview not generated")
video_preview = data["video_preview"]
status, data = api.get_file(data["video"], os.path.getsize(book_sample['video']))
if status != 200:
return Verdict.MUMBLE(f"Get video file failed with status {status}")
video_hash = get_hash(book_sample['video'])
if data != video_hash:
return Verdict.MUMBLE("Get video file wrong hash")
status, data = api.get_file(video_preview, os.path.getsize(book_sample['photo']))
if status != 200:
return Verdict.MUMBLE(f"Get preview file failed with status {status}")
preview_hash = get_hash(book_sample['photo'])
# generated hash compare
if data != preview_hash:
return Verdict.MUMBLE("Get preview file wrong hash")
# check get book without photo
status, data = api.get_book(uid_no_wait_photo)
if status != 200:
return Verdict.MUMBLE(f"Get book failed with status {status}")
if "uid" not in data or data["uid"] != uid_no_wait_photo:
return Verdict.MUMBLE("Get book wrong uid")
if "text" not in data or data["text"] != text + 'nopreview':
return Verdict.MUMBLE("Get book wrong text")
if "title" not in data or data["title"] != title_without_photo:
return Verdict.MUMBLE("Get book wrong title")
if "video" not in data:
return Verdict.MUMBLE("Get book no video")
if "video_preview" not in data:
return Verdict.MUMBLE("Get book no video_preview")
if data["video_preview"] is None:
return Verdict.MUMBLE("Video preview not generated")
video_preview = data["video_preview"]
status, data = api.get_file(data["video"], os.path.getsize(book_sample['video']))
if status != 200:
return Verdict.MUMBLE(f"Get video file failed with status {status}")
video_hash = get_hash(book_sample['video'])
if data != video_hash:
return Verdict.MUMBLE("Get video file wrong hash")
status, data = api.get_file(video_preview, DEFAULT_PHOTO_SIZE)
if status != 200:
return Verdict.MUMBLE(f"Get preview file failed with status {status}")
# generated hash compare
if data != DEFAULT_PHOTO_HASH:
return Verdict.MUMBLE("Get preview file wrong hash")
# check get book for playlist
status, data = api.get_book(uid_playlist)
if status != 200:
return Verdict.MUMBLE(f"Get book failed with status {status}")
if "uid" not in data or data["uid"] != uid_playlist:
return Verdict.MUMBLE("Get book wrong uid")
if "text" not in data or data["text"] != text:
return Verdict.MUMBLE("Get book wrong text")
if "title" not in data or data["title"] != title_playlist:
return Verdict.MUMBLE("Get book wrong title")
if "video" not in data or data['video'] is None:
return Verdict.MUMBLE("Get book no video")
if "video_preview" not in data:
return Verdict.MUMBLE("Get book no video_preview")
if data["video_preview"] is not None:
return Verdict.MUMBLE("Video preview generated for bad playlist")
except AuthError:
return Verdict.MUMBLE("Login error")
except ParseError:
return Verdict.MUMBLE("Wrong url to download file")
except requests.ConnectionError:
return Verdict.DOWN('connection error')
except requests.Timeout:
return Verdict.DOWN('timeout error')
except requests.RequestException:
return Verdict.MUMBLE('http error')
return Verdict.OK()
@checker.define_vuln("flag_id is uid")
class XSSChecker(VulnChecker):
@staticmethod
def put(request: PutRequest) -> Verdict:
api = Api(request.hostname, PORT)
username = generate_name()
password = generate_password()
email = generate_email()
try:
status, data = api.signup(email, username, password)
if status != 201:
print(data)
return Verdict.MUMBLE(f"Signup failed with status {status}")
status, data = api.login(username, password)
if status != 200:
return Verdict.MUMBLE(f"Login failed with status {status}")
if "auth_token" not in data:
return Verdict.MUMBLE("Login no auth_token")
token = data["auth_token"]
video_id = random.randint(1, 100)
book_sample = get_video_by_id(video_id)
title = generate_name()
status, data = api.create_book(title, request.flag, book_sample['video'], 'video.avi')
if status != 201:
return Verdict.MUMBLE(f"Create book failed with status {status}")
if "uid" not in data:
return Verdict.MUMBLE("Create book no uid")
uid = data["uid"]
status, data = api.get_book(uid)
if status != 200:
return Verdict.MUMBLE(f"Get book failed with status {status}")
return Verdict.OK_WITH_FLAG_ID(uid, token)
except AuthError:
return Verdict.MUMBLE("Login error")
except ParseError:
return Verdict.MUMBLE("Wrong url to download file")
except requests.ConnectionError:
return Verdict.DOWN('connection error')
except requests.Timeout:
return Verdict.DOWN('timeout error')
except requests.RequestException:
return Verdict.MUMBLE('http error')
@staticmethod
def get(request: GetRequest) -> Verdict:
token = request.flag_id
api = Api(request.hostname, PORT, token)
try:
status, data = api.get_book(request.public_flag_id)
if status != 200:
return Verdict.CORRUPT(f"Get book failed with status {status}")
if "text" not in data or data["text"] != request.flag:
return Verdict.CORRUPT("Get book wrong text")
except AuthError:
return Verdict.MUMBLE("Login error")
except requests.ConnectionError:
return Verdict.DOWN('connection error')
except requests.Timeout:
return Verdict.DOWN('timeout error')
except requests.RequestException:
return Verdict.MUMBLE('http error')
except ValueError:
print('Bad token - flag id: ', token)
return Verdict.MUMBLE('Value error or bad token')
return Verdict.OK()
if __name__ == '__main__':
checker.run()