Silent Primary a balance tamper that never touched the binlog

forensics
flag RxR{401137_24850.75_221}

Two MySQL 8.0.36 data directories, a primary and its read replica, one account balance that disagrees, and no replication errors anywhere. The change never entered the binary log at all - finding it means comparing the clustered index pages of both servers directly, then bracketing the tamper in the primary's redo log with the commit markers MySQL writes on every GTID.

Step 1: diff the accounts pages without a server

Both my.cnfs point at a fintech schema; the interesting table, fintech.accounts, is a 16 KiB-page .ibd whose page 4 holds the whole clustered index - 250 accounts, 401001 to 401250.

Pitfall

I tried to cheat first: boot a throwaway mysqld on a copy of each datadir and just SELECT. Both copies died on startup, so this went back to reading pages by hand.

The record body is predictable: [0x80|account_id 4B][DB_TRX_ID 6B][DB_ROLL_PTR 7B] [holder_name][balance 6B][tier][opened 3B]. DECIMAL(12,2) stores with the sign folded into the top bit of the first byte - 24,850.75 is 80 00 00 61 12 4b.

249 of 250 rows are byte-identical outside the transaction fields. One isn't - account 401137, Tariq Al-Mansour, tier premier:

output
primary: 84,850.75 (80 00 01 4b 72 4b)
replica: 24,850.75 (80 00 00 61 12 4b)

A delta of exactly 60,000.00 - the kind of round number that shows up when somebody edits a row by hand.

Pitfall

My first page walk reported only 249 records and made it look like account 401250 was missing entirely. This page parks its supremum record at offset 107 and the chain wraps back to it, so a naive forward walk stops early. Anchoring on the 0x80 | account_id prefix instead finds all 250. The balance answer didn't change, but I didn't want to keep comparing rows with one silently absent.

Step 2: which side is legitimate, and did the tamper ever get logged

No local MySQL to run mysqlbinlog, so I used the one from mysql-server-core 8.0.36 against the primary binlog, the replica binlog, and the replica relay log (mysqlbinlog --base64-output=DECODE-ROWS -v). The primary's own stream says: account 401137 inserted at 24,200.75, then GTID 104 (ledger_events #27, +650.00 wire_in), then GTID 105 (accounts UPDATE 401137, 24,200.75 -> 24,850.75). 24,200.75 + 650.00 = 24,850.75 - the replica's value. 84,850.75 appears zero times in either server's binlog, the relay log, or any ledger row. The replica holds the legitimate balance; the primary carries the tamper.

Note

A second, unrelated divergence exists in this bundle: the replica's own binlog goes hollow for marketing_cache from GTID 24 onward (BEGIN/COMMIT stubs, no table file on disk), while its relay log matches the primary's binlog across all 400 transactions - meaning the replica applied everything it was given. That's a different problem and never touches a balance; I chased it for a while before ruling it out.

The redo log has the smoking gun: primary/data/#innodb_redo/#ib_redo10 at offset 327358 holds a single update record carrying both images 49 bytes apart (before 24,850.75 / after 84,850.75), trx id 2288. No event for it in mysql-bin.000003, no GTID interval - the session ran with binary logging off. That's also why "replication health: zero errors" is true and useless: the replica never got the chance to disagree.

Step 3: ordering the tamper against logged commits

MySQL writes mysql.gtid_executed through the normal commit path, so those row images inside the redo stream act as per-transaction commit markers. Around the tamper:

output
marker 220  @325929
trx 2286    @326107    GTID 221, ledger_events #73, acct 401089
marker 221  @326514    <- GTID 221 committed
tamper      @327358    trx 2288, unlogged
trx 2290    @327632    GTID 222, ledger_events #74, acct 401204
marker 222  @328044    <- GTID 222 committed

Insight

Trx ids walk 2280 (GTID 218) -> 2286 (GTID 221) -> 2288 (tamper) -> 2290 (GTID 222) -> 2295 (GTID 224), and the redo stream places the tamper record between GTID 221's commit and GTID 222's. I double-checked the rule against a known-good case: GTID 105's own update sits at 191970, bracketed cleanly by marker 104 (@191092) and marker 105 (@192297) - a transaction's own change record always lands between the previous commit and its own. Same rule, applied to an unlogged change, says it happened right after GTID 221 committed.

Show the full solve script
solve.py python
1#!/usr/bin/env python3
2"""Silent Primary - solve from the shipped data dirs to the flag."""
3import glob, os, re, sys
4from decimal import Decimal
5
6PAGE, LEAF = 16384, 4 * 16384
7ID_LO, ID_HI = 401001, 401250
8MARKS = re.compile(rb'[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}:(\d+)')
9
10def enc(d):
11    d = Decimal(d)
12    i, f = divmod(abs(int((d * 100).to_integral_value())), 100)
13    out = bytearray([i // 10**9] + list((i % 10**9).to_bytes(4, 'big')) + [f])
14    if d < 0:
15        out = bytearray(b ^ 0xFF for b in out)
16    out[0] ^= 0x80
17    return bytes(out)
18
19def dec(bs):
20    b = bytearray(bs)
21    neg = not b[0] & 0x80
22    b[0] ^= 0x80
23    if neg:
24        b = bytearray(x ^ 0xFF for x in b)
25    v = Decimal(b[0]) * 10**9 + int.from_bytes(bytes(b[1:5]), 'big') + Decimal(b[5]) / 100
26    return -v if neg else v
27
28def accounts(path):
29    with open(path, 'rb') as fh:
30        fh.seek(LEAF); pg = fh.read(PAGE)
31    starts = {}
32    for i in range(len(pg) - 4):
33        if pg[i] == 0x80:
34            aid = int.from_bytes(pg[i:i+4], 'big') & 0x7FFFFFFF
35            if ID_LO <= aid <= ID_HI:
36                starts.setdefault(aid, i)
37    rows = {}
38    for aid, a in starts.items():
39        j = a + 17
40        while 32 <= pg[j] < 127:
41            j += 1
42        rows[aid] = dec(pg[j:j+6])
43    return rows
44
45def bracket(marks, off):
46    return (max(m for m in marks if m[0] < off)[1], min(m for m in marks if m[0] > off)[1])
47
48def main(root):
49    p = accounts(os.path.join(root, 'primary/data/fintech/accounts.ibd'))
50    r = accounts(os.path.join(root, 'replica/data/fintech/accounts.ibd'))
51    diff = [a for a in sorted(p) if p[a] != r[a]]
52    aid = diff[0]
53    tampered, legit = p[aid], r[aid]
54
55    hit = None
56    for f in sorted(glob.glob(os.path.join(root, 'primary/data/#innodb_redo/#ib_redo*'))):
57        blob = open(f, 'rb').read()
58        a = blob.find(enc(tampered))
59        if a < 0: continue
60        b = blob.rfind(enc(legit), max(0, a - 200), a)
61        if b > 0:
62            hit = blob, a; break
63    blob, a = hit
64    marks = [(m.start(), int(m.group(1))) for m in MARKS.finditer(blob)]
65    prev, _ = bracket(marks, a)
66    print(f'RxR{{{aid}_{legit}_{prev}}}')
67
68if __name__ == '__main__':
69    main(sys.argv[1] if len(sys.argv) > 1 else 'Silent Primary')
session
[+] 250/250 account rows decoded from both .ibd files
[+] only account 401137 differs: primary 84850.75 vs replica 24850.75
[+] #ib_redo10 @327358/327407: one update record holds both images, 49 bytes apart (no binlog event)
[+] commit markers straddling that record: 221 then 222
 
RxR{401137_24850.75_221}

Flag

output
RxR{401137_24850.75_221}