From c8845312fe105699495b7c076cfe1ef3d892cabd Mon Sep 17 00:00:00 2001 From: Maxime Vorwerk Date: Thu, 20 Jun 2024 14:22:19 +0200 Subject: [PATCH] Dachshund Attacks --- dachshund_attacks/sol.py | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 dachshund_attacks/sol.py diff --git a/dachshund_attacks/sol.py b/dachshund_attacks/sol.py new file mode 100755 index 0000000..8e35197 --- /dev/null +++ b/dachshund_attacks/sol.py @@ -0,0 +1,42 @@ +#!/home/maxime/.pyvenv/bin/python3 +from sympy import Rational, Symbol, solve +from sympy.ntheory.continued_fraction import continued_fraction, continued_fraction_convergents +from pwn import * + +conn = connect("mercury.picoctf.net", 30761) +conn.recvuntil(b':') +e = int(conn.recvline().strip()) +conn.recvuntil(b':') +n = int(conn.recvline().strip()) +conn.recvuntil(b':') +c = int(conn.recvline().strip()) +conn.close() + +print("n =", n, '\n') +print("e =", e, '\n') +print("c =", c, '\n') + + +cont_frac = continued_fraction(Rational(e, n)) +convergents = continued_fraction_convergents(cont_frac) + + +for convergent in convergents: + if convergent.p == 0: + continue + pk = convergent.p + pd = convergent.q + pphi = (e*pd - 1)//pk + + p = Symbol('p', integer=True) + roots = solve(p**2 + (pphi - n - 1)*p + n, p) + + if len(roots) == 2: + pp, pq = roots + if pp*pq == n: + print("factorized!") + P = pow(c, pd, n) + print(P.to_bytes((P.bit_length()+7)//8, byteorder='big')) + break + +