cscg20-rsa

CSCG 2020 Challenge 'RSA Service'
git clone https://git.sinitax.com/sinitax/cscg20-rsa
Log | Files | Refs | sfeed.txt

server.py (1205B)


      1#!/usr/bin/env python3.8
      2# Note: The server is running a version of pyopenssl patched with this:
      3# https://github.com/pyca/pyopenssl/pull/897
      4# Attacking the pyopenssl wrapper code is not the intended solution.
      5import OpenSSL.crypto as crypto
      6
      7welcome = '''=============== WELCOME TO THE RSA TEST SERVICE ===============
      8You can send me a message and a key to decrypt it!
      9If your setup works correctly, you will receive a flag as a reward!
     10But wait, it is quite noisy here!
     11'''
     12question_to_ask = b"Hello! Can you give me the flag, please? I would really appreciate it!"
     13
     14
     15print(welcome)
     16print("Please give me your private key in PEM format:")
     17key = ""
     18while x := input():
     19    key += x + "\n"
     20
     21message = input("Now give me your message: ")
     22message = b"Quack! Quack!"
     23print("Did you say '" + message.decode() + "'? I can't really understand you, the ducks are too loud!")
     24
     25
     26key = crypto.load_privatekey(crypto.FILETYPE_PEM, key)
     27assert key.check()
     28numbers = key.to_cryptography_key().private_numbers()
     29
     30d = numbers.d
     31N = numbers.p * numbers.q
     32
     33if pow(int.from_bytes(message, "big"), d, N) == int.from_bytes(question_to_ask, "big"):
     34    print("CSCG{DUMMY_FLAG}")
     35else:
     36    print("That was not kind enough!")