Init. Commit
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
import urllib.request
|
||||
|
||||
|
||||
def get_bytes(url: str) -> bytes:
|
||||
with urllib.request.urlopen(url, timeout=5) as response:
|
||||
return response.read()
|
||||
|
||||
|
||||
def post_bytes(url: str, body: bytes) -> dict:
|
||||
req = urllib.request.Request(
|
||||
url,
|
||||
data=body,
|
||||
method="POST",
|
||||
headers={"Content-Type": "application/octet-stream"},
|
||||
)
|
||||
with urllib.request.urlopen(req, timeout=5) as response:
|
||||
return json.loads(response.read().decode())
|
||||
|
||||
|
||||
def solve(base_url: str) -> str:
|
||||
base = base_url.rstrip("/")
|
||||
record = bytearray(get_bytes(base + "/sealed-note"))
|
||||
record[-1] ^= 1
|
||||
result = post_bytes(base + "/inspect", bytes(record))
|
||||
preview = result.get("preview", "")
|
||||
match = re.search(r"caplag\{[^}]+\}", preview)
|
||||
if not match:
|
||||
raise RuntimeError(f"flag not found in preview: {result}")
|
||||
return match.group(0)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
if len(sys.argv) != 2:
|
||||
raise SystemExit(f"usage: {sys.argv[0]} http://host:port")
|
||||
print(solve(sys.argv[1]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user