PlatyLocker private storage is still readable

blockchain
flag PP{pr1v4t3_15_n0t_s3cr3t::nc8axkA1O7Db}

PP{pr1v4t3_15_n0t_s3cr3t::nc8axkA1O7Db}

Summary

The ransomware contract Chal keeps the RSA private exponent on chain, declared bytes private privateExponent. Solidity's private keyword only suppresses the auto-generated getter — the value still lives in contract storage and is readable by anyone with an RPC endpoint via eth_getStorageAt. With (n, e, d, c) all public we decrypt the AES file key ourselves (key = c^d mod n, lowest 32 bytes), check keccak256(key) == keyHash, and call restoreFiles(key). No ransom is ever paid.

Win condition: Setup.isSolved() → TARGET.filesRestored() == true.

Solution / Exploit

Source: contracts/Chal.sol, contracts/Setup.sol, service/locker_operator.py, exploit platylocker_exploit.py.

Step 1 — the "secret" key

solidity
bytes public modulus;
bytes public publicExponent;
bytes private privateExponent; // private, so only the contract can use it
bytes public encryptedKey;     // your AES file key, encrypted with our public key
bytes32 public keyHash;
bool public filesRestored;

private is not a confidentiality mechanism: storage is public. service/locker_operator.py shows how an RSA-1024 key pair is generated per victim and pushed on chain:

python
1e = 65537
2p, q = getPrime(BITS // 2), getPrime(BITS // 2)   # BITS = 1024
3phi = (p - 1) * (q - 1)
4n = p * q
5d = inverse(e, phi)
6aes_key = os.urandom(32)
7c = pow(int.from_bytes(aes_key, "big"), e, n)
8chal.functions.initialize(to_bytes(n), e.to_bytes(3, "big"), to_bytes(d),
9                          to_bytes(c), Web3.keccak(aes_key))

The modexp precompile is only used by _decrypt() inside payRansom() (which demands 1000 ETH) — irrelevant, since we hold d directly.

Step 2 — leak d from storage

Chal's storage layout is fixed and known:

slot variable
0 modulus (bytes)
1 publicExponent (bytes)
2 privateExponent (bytes)
3 encryptedKey (bytes)
4 keyHash (bytes32)
5 filesRestored (bool)

A bytes value uses the long encoding when len >= 32: the slot holds 2*len + 1, and the payload lives at keccak256(slot) (spanning consecutive slots). The exploit's read_long_bytes() handles both encodings and pulls d out of slot 2:

python
1d_bytes = read_long_bytes(w3, target_addr, SLOT_PRIVATE_EXPONENT)   # SLOT_PRIVATE_EXPONENT = 2
2d = int.from_bytes(d_bytes, "big")

Step 3 — decrypt the AES key and restore

python
1n = int.from_bytes(chal.functions.modulus().call(), "big")
2c = int.from_bytes(chal.functions.encryptedKey().call(), "big")
3key_int = pow(c, d, n)
4key = (key_int % (1 << 256)).to_bytes(32, "big")
5assert Web3.keccak(key) == chal.functions.keyHash().call()   # sanity check
6send(w3, acct, chal.functions.restoreFiles(key))

keyHash (also public) is used purely as a self-check that the decryption is correct before sending the transaction.

Run

bash
1RPC_URL=http://127.0.0.1:8545/<uuid> \
2PRIVATE_KEY=<player key> \
3SETUP_ADDRESS=<setup addr> \
4FLAG='PP{pr1v4t3_15_n0t_s3cr3t::nc8axkA1O7Db}' \
5python3 platylocker_exploit.py

Expected output

No raw run log was retained; below is the literal format of the script's print statements (not a captured transcript).

output
[*] n = 1024 bits, e = 65537, c = 1024 bits
[+] leaked private exponent from slot 2 (128 bytes)
[+] AES file key recovered: <64 hex chars>
[+] restoreFiles() sent, filesRestored = True
[+] isSolved() = True
FLAG: PP{pr1v4t3_15_n0t_s3cr3t::nc8axkA1O7Db}

Flag(s)

output
PP{pr1v4t3_15_n0t_s3cr3t::nc8axkA1O7Db}

Notes / Pitfalls

  • private ≠ secret. The core lesson: Solidity visibility only affects the autogenerated ABI getter, never storage confidentiality. eth_getStorageAt on the right slot returns the value.
  • Long-bytes storage layout. The bytes values here are ≥ 32 bytes so they use the 2*len+1 / keccak256(slot) long encoding, not the short in-slot encoding. Getting this wrong silently returns garbage. read_long_bytes() handles both.
  • Slot order matters. The slot number depends on declaration order. Slot 2 is privateExponent because modulus is declared first, then publicExponent; any extra state variable inserted earlier shifts it.
  • key is the low 256 bits of the modexp result. The contract itself takes mload(add(result, mload(result))) (the trailing 32 bytes); the exploit mirrors this with key_int % (1 << 256).
  • initialize() is operator-gated and one-shot (require(modulus.length == 0)), so the values are fixed once the operator sets up the victim.