Professor Franklin
Accessibility settings

Preferences are saved in this browser when storage is available.

Getting Started

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

Figure 1. MySQL evidence sources
SourceRecordsDefault
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 logEvery statement received, including SELECTs, with connection IDsOff; heavy, so rarely enabled in production
Slow query logStatements that exceed a time thresholdOff
Error logStartup, shutdown, crashes, some authentication failuresOn
Audit plugin logConnections and statements by user, as configuredOnly 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.

Figure 2. The change, decoded from Northgate’s binary log
#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/*!*/;
  1. Column 1 is the customer ID, from the table schema.
  2. The before image: the original email.
  3. The after image: the attacker’s address.
  4. 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

Figure 3. Northgate’s trace, with the last verified step
  1. WAF 03:11:58.904 id 7f3a91c2
  2. Load balancer 03:11:58.911 id 7f3a91c2
  3. Application 03:11:59.020 id 7f3a91c2
  4. 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.

Row-based binlog event

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.