Back to articles
Write-Ups

InterIUT 2025 | Write-ups of my challenges

Write-ups of my challenges for InterIUT 2025: bzhash reverse engineering, inverted RSA, hashcat and exploitation of a biased RNG.

InterIUT CTF 2025
Table of contents

This article contains the write-ups of my challenges for InterIUT 2025, namely:

  • [Reverse] “bzhash”, difficulty: Easy;
  • [Crypto] “Revenu de Solidarité Active (RSA)”, difficulty: Very easy;
  • [Crypto] “lowtropy”, difficulty: Easy;
  • [Crypto] “C’est toi l’OTP !”, difficulty: Hard.

[Reverse] “bzhash”, difficulty: Easy

After reverse engineering the “bzhash” binary, we understand that we need to find a second preimage of the value “J’adore la crypto” for the hash function implemented in the binary.

More precisely, we understand that the function works as follows:

  1. A byte string II is given as input.
  2. A “padding” function (roughly PKCS#7) transforms it into I′I' such that len(I') % 4 == 0.
  3. The string I′I' is split into blocks of 44 characters.
  4. The XOR sum of these blocks is computed to create HH; in Python one could write: H = xor(*[I_prime[i:i+4] for i in range(0, len(I_prime), 4)]).

Once the hash function’s behavior is understood, it is quite easy to find a second preimage because this function is really bad; here are three methods (there are surely others!):

  1. Append a block of 4 null bytes to the end of pad("J'adore la crypto").
  2. Append two identical blocks to the end of pad("J'adore la crypto") so that their XOR sum cancels out.
  3. The shameful solution: append random data until it works; since the block size is very small, it can be brute-forced.

The implementation of solution (1.) and (2.):

echo "4a2761646f7265206c612063727970746f03030300000000" | xxd -r -p | ./bzhash
echo "4a2761646f7265206c612063727970746f0303030101010101010101" | xxd -r -p | ./bzhash

[Crypto] “Revenu de Solidarité Active (RSA)”, difficulty: Very easy

TL;DR the chal.py file encrypts the flag (mm) by computing: c=m−1(modn)c = m^{-1} \pmod{n}. It is enough to invert cc again and remove the padding to recover the flag.

Indeed, when we give a negative exponent to Python’s pow() function (−1-1 in our case), it does not perform modular exponentiation for the value −1(modn)-1 \pmod{n} but performs a modular inverse; which is trivial to invert.

Here is the implementation of the solution in Python:

from sys import argv

if len(argv) != 2:
    print("Usage : python solve.py out-path.txt")
    exit()

out = open(argv[1])
nc = []
while ( (l := out.readline()) != ""):
    nc.append(int(l.split("= ")[1]))

n, c = nc
e = -1

m = pow(c, e, n)
m = m.to_bytes((m.bit_length() + 7) // 8)
m = m[:m.find(b"}")+1].decode()

print(m)

[Crypto] “lowtropy”, difficulty: Easy

TL;DR Despite the use of PBKDF2, the entropy of a PIN code is much lower than that of a password, so they should not be stored in the same way.

A brute-force attack is therefore possible; here is the hashcat command (see the hashcat documentation) to use to crack this hash:

echo "sha256:10000:fe+WzU0xXSviLbSZVTGd3WR42SdADxTeXy0i8JR5k7g=:QEViJ8jx0kF3ARzk1Ya4UmQD4HpclbmXsGJ6ZABMnzI=" > /tmp/hash.txt
hashcat -m 10900 -a 3 /tmp/hash.txt ?d?d?d?d?d?d

[Crypto] “C’est toi l’OTP !”, difficulty: Hard

The chal.py file implements a biased RNG; indeed, a byte (oo) is given by the formula: o=i+j+k+l(mod256)o = i + j + k + l \pmod{256}. With i,j,k,li, j, k, l numbers drawn randomly from the set: {48,49,50,51,52,53,54,55,56,57,97,98,99,100,101,102}\lbrace48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102\rbrace. We are therefore far from a uniform distribution.

Here is an image illustrating the proportion of occurrence of the bytes generated by this RNG:

Byte occurrence frequency

Once we know the bytes that appear most often, we just need to request the encrypted flag a large number of times to see which byte stands out the most. We then know that this byte was encrypted with a byte most frequently produced by the RNG.

An analysis of the RNG bias is available in the analysis.py file. The implementation of the solution that exploits the bias is available below:

from pwn import process, remote
from hashlib import sha1
from tqdm import tqdm
from sys import argv

while True:
    if len(argv) == 3:
        conn = remote(argv[1], int(argv[2]))
    elif len(argv) == 2:
        conn = process(["python", argv[1]])
    else:
        print("Usage:")
        print("python solve.py host port")
        print("or")
        print("python solve.py path-to-chal.py")
        exit()

    # skip header
    conn.recvline()

    def get_enc_flag() -> bytes:
        conn.recvuntil(b"> ")
        conn.sendline(b"again")

        l = conn.recvline().strip()
        l = bytes.fromhex(l.decode())

        return l

    def get_hint() -> bytes:
        conn.recvuntil(b"> ")
        conn.sendline(b"hint")

        l = conn.recvline().strip()
        l = bytes.fromhex(l.decode())

        return l

    sha1_flag = get_hint()
    # on les connait grâce à analysis.py
    possible_bytes = [47, 49, 0, 2, 1, 48]
    all_enc_flag = []
    flag_len = 70

    print("Récupération de 50_000 chiffrés du flag...")
    for _ in tqdm(range(50_000)):
        all_enc_flag.append(get_enc_flag())

    stats = [{k:0 for k in range(256)} for _ in range(flag_len)]
    for aef in all_enc_flag:
        for idx,val in enumerate(aef):
            stats[idx][val] += 1

    stats = [dict(sorted(s.items(), key=lambda item: item[1])) for s in stats]

    build_flag = []
    for st in stats:
        stt = list(st.keys())[-1]
        for pb in possible_bytes:
            if pb ^ stt in [0, 255]:
                build_flag.append(pb^stt)

    bf = bytes(build_flag)
    if len(bf) == flag_len and sha1_flag.hex() == sha1(bf).hexdigest():
        print("interiut{" + bf.hex() + "}")
        break

    conn.close()
Press Esc to close