-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcat_farm.checker.py
executable file
·75 lines (56 loc) · 2.08 KB
/
cat_farm.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
#!/usr/bin/env python3.9
from gornilo import Checker, PutRequest, GetRequest, CheckRequest, Verdict
from random import randint
from api import Api
from uuid import uuid4
from gornilo.utils import generate_flag
from requests.exceptions import RetryError
checker = Checker()
def gen_cords():
return randint((2 ** 30) * -1, 2 ** 30), randint((2 ** 30) * -1, 2 ** 30)
@checker.define_check
def check(req: CheckRequest) -> Verdict:
try:
x, y = gen_cords()
x1, y1 = x-1, y+1
print(f"Generated cat at x:{x}, y:{y}!")
api = Api(req.hostname)
cat_id_1 = str(uuid4())
cat_id_2 = str(uuid4())
api.add_cat(cat_id_1, generate_flag(), x, y)
api.add_cat(cat_id_2, generate_flag(), x1, y1)
res = api.meow_meow(x - 2, y - 2)
if cat_id_1 not in res or cat_id_2 not in res:
return Verdict.MUMBLE("Can't do meow-meow")
try:
farm_id = str(uuid4())
api.create_farm(farm_id, generate_flag()[:randint(10, 16)], cat_id_1, cat_id_2)
res = api.get_farm(farm_id).split(",")
if cat_id_1 not in res or cat_id_2 not in res:
return Verdict.MUMBLE("U have lost ur cats on ur farm!")
except:
return Verdict.MUMBLE("bad proto")
return Verdict.OK()
except RetryError:
return Verdict.DOWN("could not retry you")
@checker.define_put(vuln_num=1, vuln_rate=1)
def put(put_req: PutRequest) -> Verdict:
try:
x, y = gen_cords()
api = Api(put_req.hostname)
cat_id_1 = str(uuid4())
api.add_cat(cat_id_1, put_req.flag, x, y)
except RetryError:
return Verdict.DOWN("could not retry you")
return Verdict.OK(cat_id_1)
@checker.define_get(vuln_num=1)
def get(get_req: GetRequest) -> Verdict:
try:
api = Api(get_req.hostname)
name = api.get_cat_name(get_req.flag_id)
except RetryError:
return Verdict.DOWN("could not retry you")
if name.strip() == get_req.flag.strip():
return Verdict.OK()
return Verdict.CORRUPT("Ur lost ur kitties!")
checker.run()