Search for a command to run...
Mom! My Wii won't let me run custom games! It's 2008 already and this console is still locked down โ time to hack it.
Connection informations:
type: ssh
ssh username: wii-user
ssh password: wii-user
challenge directory: /app
The Wii launcher uses strncmp() instead of memcmp() to verify signatures. Since strncmp() stops at null bytes, we can forge signatures by finding a game whose hash starts with 0x00 and using a signature that decrypts to all zeros.
So, the launcher verifies game signatures by:
m = sig^e mod nIt uses strncmp() for the comparison instead of .
memcmp()strncmp() stops comparing at the first null byte (\x00). So if both strings have a null byte early, it only compares up to that point.
Looking at the code:
strncmp(decrypted_sig + (sig_len - 32), computed_hash, 32)
If either string has a null byte, the comparison stops there. If they match up to that null byte, strncmp() returns 0 (equal) even though the full hashes don't match.
We need the public key from the launcher binary. It's in a custom .wii_key section:
objdump -s -j .wii_key launcher
Extract the PEM encoded public key and save it as public_key.pem.
We need a game whose SHA256 hash starts with 0x00. This way, strncmp() will stop immediately and only compare 0 bytes, which always match.
base_game = b'''#!/bin/bash
cat /app/flag.txt
'''
for i in range(1000000):
test_game = base_game + struct.pack('<I', i)
test_hash = SHA256.new(test_game).digest()
if test_hash[0] == 0x00: # Hash starts with null byte
# Found it
break
After some brute forcing, we find a game whose hash is:
0004bad414043f20ce02b6850c8bf535793613e3a82f9f6d74a755aff21b4fe3
It starts with 00.
Now we need a signature that when decrypted has 0x00 at byte 224 (the start of the hash region in the 256-byte decrypted block).
Since our game's hash starts with 00, and we want the decrypted signature's hash region to also start with 00, we can use signature value 1:
sig = 1
decrypted = pow(1, e, n) # 1^65537 mod n = 1
# When converted to bytes, this gives us zeros in the hash region
# Create the signed game
signed_game = game_data + signature_bytes
Execute:
./launcher exploit_game_signed
The launcher will:
00 04 BA D4... (starts with 00)00 00 00 00... (starts with 00)strncmp(): compares 0 bytes, returns 0 (match!)/app/flag.txtWe get the flag: RM{Wii_W4s_S3cUr3_but_N0t_for_Fail0verflow!}