CTF-writeups

Some CTF writeups


Project maintained by Qyn-CTF

secret underground club 1 - Baby

Description:

Can you be part of the secret underground club?

First looks

We’re given the source code of the application (Some part left out):

from Crypto.PublicKey import RSA
import base64

from secret import FLAG

def main():
    key = RSA.generate(1024)

    p, q, d, e, n = key.p, key.q, key.d, key.e, key.n

    print(f"[DEBUG]: e={e:x}")
    print(f"[DEBUG]: n={n:x}")

    print(r""" Welcome to the secret underground club.
         To log in please provide a signature with the private key you received.""")

    try:
        message = int(input("Message:"), 16)
        signature = int(input("Signature:"), 16)

        if message == pow(signature, e, n) and message > 1 and signature > 1:
            print("Welcome")
            print(FLAG)
        else:
            print("Sorry mate")
    except:
        print("Computer is tired. Computer is going to sleep.")
        exit(1)


if __name__ == '__main__':
    main()

In here we can see that we get the value of exponent e and the modulus N and we give the server a message and signature such that the RSA encrypted signature is equal to the message.

Solving

For this, we can simply take a random integer for our signature and encrypt it and send that as our message:

#!/usr/bin/env python3

from pwn import *
p = remote("7b00000097080260c62a54e5-secretundergroundclub1.challenge.broker.cscg.live", 31337, ssl=True)

e = int(p.recvline().decode().split("e=")[1],16)
n = int(p.recvline().decode().split("n=")[1],16)

pt = 1337

ct = pow(pt, e, n)
p.sendline(f"{ct:x}")
p.sendline(f"{pt:x}")
p.interactive()

This will give us the flag:
CSCG{rsa_seems_easy_but_apparently_it_is_not}

Home