crypto/no_padding_no_problem

This commit is contained in:
Oystein Kristoffer Tveit 2024-09-06 19:18:11 +02:00
parent ed63e69062
commit 44cc389da9
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
1 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,35 @@
#!/usr/bin/env nix-shell
#!nix-shell -i python3 -p python3 python3Packages.pwntools python3Packages.pycryptodome
from pwn import *
from Crypto.Util.number import long_to_bytes
def decipher(r: tube, ciphertext: bytes) -> str:
r.recvuntil(b'Give me ciphertext to decrypt: ')
r.sendline(ciphertext)
r.recvuntil(b'Here you go: ')
return r.recvline().strip()
def main():
addr, port, *_ = "mercury.picoctf.net 33780".split(" ")
r = remote(addr, int(port))
r.recvuntil(b'Good Luck!\n\n\n')
n = int(r.recvline().split(b' ')[1].strip())
e = int(r.recvline().split(b' ')[1].strip())
enc = int(r.recvline().split(b' ')[1].strip())
print(f"{n=}")
print(f"{e=}")
print(f"{enc=}")
padding = 2
encrypted_padding = pow(padding, e, n)
payload = (enc * encrypted_padding)
output = decipher(r, str(payload).encode())
flag = long_to_bytes(int(output) // padding).decode()
print(flag)
if __name__ == "__main__":
main()