Chapter 14 · Reading 3 of 3
Did it reach the database?
CHFI domains 1, 3, 4, 5, 6
The application says it updated customer 552190 at 03:11:59. Applications can log an intention and then fail: a transaction might roll back, a constraint might reject the value, or the log line might be written before the database replies. Northgate’s rail customer database runs on MySQL, and its finance system on Microsoft SQL Server. The examiner needs the database’s own record of what committed.
MySQL: which log records what
| Source | Records | Default |
|---|---|---|
| Binary log (binlog) | Committed changes, for replication and recovery. Row-based format holds before and after values. | Enabled by default in MySQL 8.0; expires after 30 days by default |
| General query log | Every statement received, including SELECTs, with connection IDs | Off; heavy, so rarely enabled in production |
| Slow query log | Statements that exceed a time threshold | Off |
| Error log | Startup, shutdown, crashes, some authentication failures | On |
| Audit plugin log | Connections and statements by user, as configured | Only if an audit plugin is installed |
The mysqlbinlog utility reads binary logs. With row-based logging, mysqlbinlog --base64-output=DECODE-ROWS -v prints each changed row as pseudo-SQL, with the before image (WHERE) and after image (SET) and columns numbered @1, @2 and so on in table order. Each transaction ends with a COMMIT and an Xid.
#261120 3:12:00 server id 11 end_log_pos 48211903 Update_rows: table id 214 ### UPDATE `rail`.`customers` ### WHERE ### @1=552190 ### @4='p.okoye@mail.example' ### SET ### @1=552190 ### @4='p.okoye@inbox-relay.example' #261120 3:12:00 server id 11 Xid = 9184412 COMMIT/*!*/;
- Column 1 is the customer ID, from the table schema.
- The before image: the original email.
- The after image: the attacker’s address.
- The transaction committed.
The binlog header times are the server’s clock, which the examiner verifies as for any system (Chapter 8). The schema, from SHOW CREATE TABLE or the data dictionary, is needed to name the numbered columns, and it can itself be evidence if an attacker added a column, a trigger or a stored procedure.
SQL Server: transaction log, audit and traces
SQL Server writes every change to the database’s transaction log (.ldf file) before applying it. Under the simple recovery model, log space is reused quickly after checkpoints. Under the full recovery model, the log is kept until backed up, and transaction-log backups preserve the history. Undocumented functions such as fn_dblog (active log) and fn_dump_dblog (log backups) expose log records, and commercial tools such as ApexSQL Log turn them into readable change histories with before and after values. SQL Server Management Studio is used to query the database, and SQL Server Audit, if configured, records logins and statements at the server or database level. The default trace, enabled by default though deprecated, records schema changes, permission changes and some errors in rolling files of limited size.
Retention decides what you can see
Every source has a horizon. MySQL 8.0 purges binary logs after 30 days by default (binlog_expire_logs_seconds = 2,592,000). Replicas may keep their own copies. SQL Server’s simple recovery model may keep only minutes of log. Audit files roll over at a configured size. Before the logs are lost, the examiner copies them, hashes the copies and records the retention settings, which also explain any gaps later.
The request-to-transaction trace
- WAF 03:11:58.904 id 7f3a91c2
- Load balancer 03:11:58.911 id 7f3a91c2
- Application 03:11:59.020 id 7f3a91c2
- MySQL commit 03:12:00, Xid 9184412 customer 552190
The database link is joined by customer ID and time, not by request ID. No other update to customer 552190 occurred between 03:00 and 03:30, which makes the join unambiguous.
The trace is complete. A request from 203.0.113.140, using customer 498877’s session, changed customer 552190’s email through a tampered parameter, and the database committed the change. The before image lets Northgate restore the original value, and the same search across the binary logs, looking for updates where the session’s customer and the updated customer differ, finds eleven more accounts changed the same way that week.
On the exam, the binary log shows committed changes but not reads, the general log shows every statement but is usually off, and the SQL Server transaction log’s reach depends on the recovery model. The next chapter, Memory and malware forensics, examines a process whose executable is not on the disk at all.
Inspect the three records, then use the evidence to answer the question.
1. Before
@4='p.okoye@mail.example'
2. After
@4='p.okoye@inbox-relay.example'
3. Commit
Xid = 9184412 COMMIT, 03:12:00 UTC
Apply the reading
The MySQL general query log was off, but binary logging was on. What can the binary log show, and what can it not?
Compare your reasoning
The binary log records committed changes, with times and, in row-based format, the before and after values. It does not record SELECT statements or failed attempts, so it cannot show what data an attacker read.