I only got to solve one of the three leet challenges. It was a cryptography challenge where I can brute force two parameters known to be between 0 and 1000 and then work backwards to figure out q based on a hint leaked in the output. From there, it’s simple RSA.



HackVent ball22 HV23.22 Secure Gift Wrapping Service
Categories: exploitationEXPLOITATION
Level: leet
Author: darkice

This year, a new service has been launched to support the elves in wrapping gifts. Due to a number of stolen gifts in recent days, increased security measures have been introduced and the gifts are being stored in a secret place. As Christmas is getting closer, the elves need to load the gifts onto the sleigh, but they can’t find them. The only hint to this secret place was probably also packed in one of these gifts. Can you take a look at the service and see if you can find the secret?

Please note that the libc file in the downloadable archive has been changed to match the one in the Docker.

Exploit the Docker and get the flag!

The sha256sum of the downloadable archive public.tar.xz is a0a416c96fb8daa6b2d50c245ab9b914b64431f4dbad381fbbad52b782f43297

Not Solved

I didn’t get to solve this challenge.



HackVent ball23 HV23.23 Roll your own RSA
Categories: cryptoCRYPTO
Level: leet
Author: cryze

Santa wrote his own script to encrypt his secrets with RSA. He got inspired from the windows login where you can specify a hint for your password, so he added a hint for his own software. This won’t break the encryption, will it?The download has (some parts of) the application.



The download contains a Python script and an output.txt.

The Python script encrypts a FLAG constant:

from Crypto.Util.number import *
from sage.all import *
from secret import FLAG, x, y
import random

# D = {x∈ℕ | 0 ≤ x ≤ 1000}
# D = {y∈ℕ | 0 ≤ y ≤ 1000}

def enc(flag, polynomial_function):
    p = getStrongPrime(512)
    q = getStrongPrime(512)
    N = p * q
    e = 65537
    hint = p**3 - q**8 + polynomial_function(x=x)
    encrypted = pow(bytes_to_long(flag), e, N)

def generate_polynomial_function(seed):
    x = SR.var("x")
    grade = random.choice([2,3])
    a = random.randint(9999, 999999)
    b = random.randint(8888, 888888)
    c = random.randint(7777, 777777)

    if grade == 2:
        y_x = a*x**2+b*x+c
    if grade == 3:
        d = random.randint(6666, 666666)
        y_x = a*x**3+b*x**2+c*x+d

    return y_x

y_x = generate_polynomial_function(y)
enc(FLAG.encode(), y_x)

It sends several things to STDOUT, all of which is found in output.txt:


The first number is the result of print(a+b+c). The others are labeled.


This is RSA encryption, so if I can get p and q, I can calculate everything else I need to decrypt. I know N = p*q, but I also get this hint output which is p**3 - q**8 + polynomial_function(x). I don’t know x, but I know it’s between 0 and 1000. If I can get the polynomial, I can brute force x.

To get the polynomial, I’ll need to know y, which is also unknown, but between 0 and 1000. Because I have the sum of a, b, and c, I can easily brute force y.

Get y

y is an unknown value between 0 and 1000 that is used to generate a polynomial. I’ll use code from generate_polynomial_function to check y inputs against the a+b+c outputs:

def crack_y():
    for y in range(1000):
        a = random.randint(9999, 999999)
        b = random.randint(8888, 888888)
        c = random.randint(7777, 777777)
        if a+b+c == 1709262:
            print(f"Found y: {y}")
            return y

Crack x, q

To get x, I just need to generate a polynomial with y, and then solve the hint equation for each x between 0 and 1000, breaking when I get exactly two answers. I’ll use SageMath to solve the equation:

def crack_x(y):
    y_x = generate_polynomial_function(y)
    for x in range(1000):
        q = var('q')
        equation = hint == (N/q)**3 - q**8 + y_x(x=x)
        print(f"\r{x}", end="")
            roots = equation.roots()
            print(f"\rFound x: {x}")
            print(f"Found q: {roots[0][0]}")
            return x, int(roots[0][0])
        except RuntimeError:


With q, I can now get p, then phi and d, which is used to decrypt:

y = crack_y()
x, q = crack_x(y)
p = N//q
print(f"Found p: {p}")
phi = (p-1)*(q-1)
d = pow(e, -1, phi)
pt = pow(ct, d, N)
print(f"Flag: {long_to_bytes(pt).decode()}")

Getting Sagemath installed in my VM was a pain, so I just opted for Docker:

oxdf@hacky$ docker run -it -u root -v .:/day23 sagemath/sagemath bash

After running pip install pycryptodome, running the current script in /day23 solves the challenge:

root@fbbf42ba5b86:/day23# time python3 dec.py 
Found y: 787
Found x: 692
Found q: 11766238441137316218698559717070508606046977055528210983326091441049009527090037271072944725167437804861554714103321826526867364254290450294447086896338759
Found p: 12179435756173513536974896795065942195337250662711676240184873598482470068786941630453314528951912732394640958491561461957261830568584848314092787092062267
Flag: HV23{1t_w4s_4b0ut_t1m3_f0r_s0me_RSA_4g41n!}

real    1m14.429s
user    2m33.437s
sys     0m2.805s

Flag: HV23{1t_w4s_4b0ut_t1m3_f0r_s0me_RSA_4g41n!}**



HackVent ball24 HV23.24 Santa's Shuffled Surprise
Categories: reverse_engineeringREVERSE_ENGINEERING
Level: leet
Author: JokerX

Santa found a dusty old floppy disk in his basement. He started the disk in his A500, but the QR code looks shuffled. Can you help him to read the QR code?


I didn’t get to solve this challenge.