From 71574f16495c0e43ee915d00a086b426dfed8002 Mon Sep 17 00:00:00 2001 From: Maxime Vorwerk Date: Sun, 4 Aug 2024 00:01:29 +0200 Subject: [PATCH] b00tl3grsa3 --- b00tl3grsa3/sol.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 b00tl3grsa3/sol.py diff --git a/b00tl3grsa3/sol.py b/b00tl3grsa3/sol.py new file mode 100755 index 0000000..10d1169 --- /dev/null +++ b/b00tl3grsa3/sol.py @@ -0,0 +1,35 @@ +#!python3 +from sage.all import * +import pwn + +conn = pwn.remote("jupiter.challenges.picoctf.org", 4557) + +conn.recvuntil(b"c: ") +c = Integer(conn.recvline().strip()) +pwn.log.info("c: 0x{:x}".format(c)) + +conn.recvuntil(b"n: ") +n = Integer(conn.recvline().strip()) +pwn.log.info("n: 0x{:x}".format(n)) + +conn.recvuntil(b"e: ") +e = Integer(conn.recvline().strip()) +pwn.log.info("e: 0x{:x}".format(e)) + +conn.close() + +pwn.log.info("factoring n") +factors = factor(n) +pwn.success("factorization: {}".format(factors)) + +totient = prod([x[0]-1 for x in factors]) +pwn.log.info("totient: {:x}".format(totient)) + +pwn.log.info("calculating d") +d = pow(e, -1, totient).lift() +pwn.log.success("d: {:x}".format(d)) + +m = pow(c, d, n).lift() +flag = pwn.pack(int(m), 'all', 'big', False) +pwn.log.info("flag: {}".format(flag)) +