Uwusignatures CTF Challenge Solution

Challenge Overview

Challenge Name: Uwusignatures Category: Crypto Points: 261 Author: elijah5399

Description:

As an uwu girl, I decided to make this digital signature scheme to share my signatures with everyone!

I'll only show you half of my signature though, because I'm shy...

Surely, no one would steal from a cutie like myself... right?

Connection: nc challs.nusgreyhats.org 33301

Initial Analysis

The challenge provides a Python file uwusignatures.py implementing a custom digital signature scheme. Let's examine the key components:

Code Analysis

class Uwu:
    def __init__(self, keylen):
        self.p = getPrime(keylen)
        self.g = getRandomRange(1, self.p)
        self.x = getRandomRange(2, self.p)  # private key
        self.y = pow(self.g, self.x, self.p)  # public key
        self.k = getRandomRange(1, self.p)
        while GCD(self.k, self.p - 1) != 1:
            self.k = getRandomRange(1, self.p)
        print(f"{self.p :} {self.g :} {self.y :}")
        print(f"k: {self.k}")  # 🚨 CRITICAL VULNERABILITY!

Key Observations:

  1. This is a variant of ElGamal digital signatures

  2. CRITICAL FLAW: The server prints the nonce k value!

  3. The same k is reused for all signatures (not regenerated per signature)

  4. To get the flag, we need to forge a signature for "gib flag pls uwu"

Signature Scheme Details

Signing: s = ((h - x * r) * k^(-1)) mod (p-1) Verification: g^h ≡ y^r * r^s (mod p) Where:

  • h = SHA256(message)

  • r = g^k mod p

  • x = private key

  • k = nonce (leaked!)

The Vulnerability: K-Reuse Attack

When the same nonce k is reused across multiple signatures, it creates a catastrophic vulnerability:

  1. Same r value: Since r = g^k mod p, reusing k means r is identical for all signatures

  2. Private key recovery: With two signatures using the same k, we can algebraically recover the private key x

Exploitation Strategy

Step 1: Gather Information

Connect to the server and collect:

  • Public parameters: p, g, y

  • The leaked nonce: k

  • Two signatures for different messages

Server Response:

Step 2: Obtain Known Signatures

Request signatures for two different messages:

Step 3: Recover Private Key

With the leaked k and known signatures, we can recover the private key x:

Step 4: Forge Target Signature

Now we can forge a signature for the target message:

Step 5: Submit and Get Flag

Submit the forged signature:

Server Response:

Flag

grey{h_h_H_h0wd_y0u_Do_tH4T_OMO}

Key Takeaways

  1. Never reuse nonces in cryptographic schemes - it's catastrophic for security

  2. Never leak private values like nonces, even "accidentally"

  3. K-reuse attacks are a classic vulnerability in signature schemes (DSA, ECDSA, etc.)

  4. Proper implementation should generate a fresh, random nonce for each signature

  5. Defense in depth - even if nonces were properly generated, leaking them would still be fatal

This challenge demonstrates why cryptographic implementations must be extremely careful about nonce generation and keeping secrets truly secret!

Last updated