-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.py
58 lines (45 loc) · 1.41 KB
/
example.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
import secrets
from typing import Optional
from httpx import AsyncClient
from enochecker3 import (
ChainDB,
Enochecker,
FlagSearcher,
GetflagCheckerTaskMessage,
MumbleException,
PutflagCheckerTaskMessage,
)
from enochecker3.utils import assert_equals, assert_in
checker = Enochecker("ExampleService", 1337)
app = lambda: checker.app
@checker.putflag(0)
async def putflag_test(
task: PutflagCheckerTaskMessage,
client: AsyncClient,
db: ChainDB,
) -> None:
token = secrets.token_hex(32)
r = await client.post("/note", json={"token": token, "flag": task.flag})
assert_equals(r.status_code, 200, "storing note with flag failed")
await db.set("token", token)
@checker.getflag(0)
async def getflag_test(
task: GetflagCheckerTaskMessage, client: AsyncClient, db: ChainDB
) -> None:
try:
token = await db.get("token")
except KeyError:
raise MumbleException("Missing database entry from putflag")
r = await client.get(f"/note/{token}")
assert_equals(r.status_code, 200, "getting note with flag failed")
assert_in(task.flag, r.text, "flag missing from note")
@checker.exploit(0)
async def exploit_test(searcher: FlagSearcher, client: AsyncClient) -> Optional[str]:
r = await client.get(
"/note/*",
)
assert not r.is_error
if flag := searcher.search_flag(r.text):
return flag
if __name__ == "__main__":
checker.run()