Writeups
Search…
Gambler
So the encryption calculates x^3 + ax + b mod p. Initially, we don't know a, b, or p, but we can encrypt arbitrary messages and get the encryption of the flag.
So, how do we leak values with this? First of all, we encrypt 0 - the equation will equate to b.
Next, we encrypt 1 - the equation will be 1 + a + b, so subtract b and subtract 1 to get a, or some value that equates to a mod p.
Finally, we must leak p. This is simple, continue encrypting small messages and also encrypting them ourselves with the calculated a and b values. Eventually, we'll find that our calculated value is different to the value returned - from there, we work out the modulus that would require both of the values to be equal. In my case, my calculated value was negative and the value returned by the server was positive so adding the absolute values returned the modulus.
This gives us the equation x^3 + ax + b mod p = c where we know a,b, and c. From there I got maf slave rak to solve the equation using sage :P

Flag: CCTF{GerolamoCardano_4N_itaLi4N_p0lYma7H}

No script because I did it all manually in a python prompt but here have my PoW solver
1
from Crypto.Util.number import *
2
3
import os,hashlib,itertools
4
os.environ['PWNLIB_NOTERM'] = '1'
5
6
from pwn import *
7
from string import printable
8
printable = list(printable)
9
printable.remove('\n')
10
printable.remove('\x0b')
11
printable.remove('\x0c')
12
printable.remove('\t')
13
printable.remove(' ')
14
def powbuster(method,target,length):
15
hash = eval(f"hashlib.{method}")
16
for possible in itertools.combinations(printable,length):
17
possible = ''.join(possible).encode()
18
val = hash(possible).hexdigest()[-6:]
19
if val == target:
20
return possible
21
p = remote('05.cr.yp.toc.tf', 33371)
22
p.recvuntil(b"Please submit a printable string X, such that ")
23
method = p.recvuntil("(")[:-1].decode()
24
p.recvuntil("= ")
25
target = p.recvuntil(" ")[:-1].decode()
26
p.recvuntil("len(X) =")
27
length = int(p.recvline())
28
print(method,target,length)
29
ans = powbuster(method,target,length)
30
print(ans)
31
p.sendline(ans)
32
p.interactive()
Copied!
Last modified 1yr ago