Building a Timeline in pandas
Every piece of evidence so far carries time: the browser history says when the file was downloaded, the file system when it was written, Sysmon when it ran, the proxy when it phoned home, memory which process still had the connection open. Separately they are facts; merged and sorted they become a story, and stories answer the questions management and lawyers ask: when did it start, what happened in which order, what did the attacker touch, and what happened before the first alert? Building that timeline is the central analytical step of most forensic investigations.
The classic tool is plaso (log2timeline), which extracts events from hundreds of artefact types into one "super timeline", viewed in Timesketch or a spreadsheet. The core of the method fits in a pandas notebook, and that is what this lesson builds from synthetic artefacts. pandas for log analysis is introduced in Python and pandas for Logs.
Definitions
- Super timeline: all events from all sources in one table: time (UTC), source, host, user, event type, description, and a reference back to the evidence item.
- Time normalisation: converting every source's time format and zone to UTC. Formats seen in practice: Unix seconds, NTFS FILETIME (100 ns since 1601), WebKit/Chrome time (microseconds since 1601), ISO 8601 strings with or without an offset, and local times with no zone at all.
- Pivot: an event you trust (the alert, the first beacon) from which you search backwards and forwards.
- Dwell time: from the first evidence of compromise to detection.
Merging four sources
The synthetic case: the lab user downloads labagent.exe and runs it; it drops a file, sets a Run value, and beacons. Four artefacts, each in its own native time format: browser history (Chrome stores microseconds since 1601), MFT entries (UTC strings, from an MFT parser), the Windows event log as exported on a laptop set to UTC+7 (local time strings), and proxy log lines (Unix seconds).
import pandas as pd
browser = pd.DataFrame({"visit_time": [13412944993000000, 13412945041000000], # Chrome: µs since 1601
"url": ["https://files.lab.test/tools/", "https://files.lab.test/tools/labagent.exe"]})
mft = pd.DataFrame({"si_created": ["2026-01-15 10:04:02", "2026-01-15 10:04:12", "2026-01-15 08:30:00"],
"path": [r"C:\Users\lab\Downloads\labagent.exe", r"C:\Users\Public\Libraries\labagent.dat",
r"C:\Users\lab\Documents\notes.txt"]})
evtx = pd.DataFrame({"local_time": ["2026-01-15 17:04:12", "2026-01-15 17:04:12", "2026-01-15 17:04:12"],
"event": ["Sysmon 1: labagent.exe started by explorer.exe", "Sysmon 13: Run\\LabAgentUpdater set",
"Sysmon 1: cmd.exe /c whoami /all"]})
proxy = pd.DataFrame({"epoch": [1768471573, 1768471633, 1768471694, 1768469000],
"line": ["GET update.beacon.lab.test/api/v1/ping 200 LabAgent/1.0"] * 3
+ ["GET www.lab.test/ 200 Mozilla/5.0"]})
frames = [
pd.DataFrame({"time": pd.to_datetime(browser.visit_time - 11644473600 * 10**6, unit="us", utc=True),
"source": "browser", "event": "visit " + browser.url}),
pd.DataFrame({"time": pd.to_datetime(mft.si_created, utc=True), "source": "mft",
"event": "created " + mft.path}),
pd.DataFrame({"time": pd.to_datetime(evtx.local_time).dt.tz_localize("Asia/Ho_Chi_Minh").dt.tz_convert("UTC"),
"source": "evtx", "event": evtx.event}),
pd.DataFrame({"time": pd.to_datetime(proxy.epoch, unit="s", utc=True), "source": "proxy",
"event": proxy.line}),
]
tl = pd.concat(frames).sort_values(["time", "source"], kind="stable").reset_index(drop=True)
pd.set_option("display.width", 140, "display.max_colwidth", 70)
print(tl.assign(time=tl.time.dt.strftime("%H:%M:%S")).to_string(index=False))
pivot = tl[tl.event.str.contains("labagent", case=False)].time.min()
first_beacon = tl[tl.event.str.contains("beacon.lab.test")].time.min()
print("\nfirst event involving labagent:", pivot.strftime("%Y-%m-%d %H:%M:%S %Z"))
print("download to first beacon:", first_beacon - pivot) time source event
08:30:00 mft created C:\Users\lab\Documents\notes.txt
09:23:20 proxy GET www.lab.test/ 200 Mozilla/5.0
10:03:13 browser visit https://files.lab.test/tools/
10:04:01 browser visit https://files.lab.test/tools/labagent.exe
10:04:02 mft created C:\Users\lab\Downloads\labagent.exe
10:04:12 evtx Sysmon 1: labagent.exe started by explorer.exe
10:04:12 evtx Sysmon 13: Run\LabAgentUpdater set
10:04:12 evtx Sysmon 1: cmd.exe /c whoami /all
10:04:12 mft created C:\Users\Public\Libraries\labagent.dat
10:06:13 proxy GET update.beacon.lab.test/api/v1/ping 200 LabAgent/1.0
10:07:13 proxy GET update.beacon.lab.test/api/v1/ping 200 LabAgent/1.0
10:08:14 proxy GET update.beacon.lab.test/api/v1/ping 200 LabAgent/1.0
first event involving labagent: 2026-01-15 10:04:01 UTC
download to first beacon: 0 days 00:02:12
Merged, the story reads top to bottom: unrelated activity (a note from 08:30, a normal web visit), then the user browses the file server, downloads labagent.exe (browser at 10:04:01, the MFT shows the file created a second later), runs it (10:04:12), and within the same second the sample drops its file, sets its Run value and starts cmd.exe; the first beacon follows two minutes later. Without the conversion, the event log's 17:04:12 would have put execution seven hours after the beacons.
How timelines drive the investigation
- Backwards from the pivot: what happened just before the download? (Here: a visit to the tools page, so: where did the link come from? Mail logs are the next source.)
- Forwards: everything after first execution is potentially attacker activity: logons, new services, files written, data sent.
- Across hosts: the same timeline over all affected machines shows lateral movement; the earliest event anywhere is the real start (and the dwell time).
- Gaps are findings too: a log that stops is often a cleared log (Security event 1102 records clearing the Security log).
How to make timelines reliable
- Write UTC everywhere and keep the original value and its source zone in a column, so a conversion error can be checked.
- Sync clocks with NTP and record each host's clock offset at collection time (compare with a reference) and correct for it.
- Keep a reference to the evidence item and record number for every row, so each claim in the report can be traced.
Pitfalls
- Unknown zones: a timestamp without an offset is ambiguous; find out from the source (system settings, the registry's
TimeZoneInformation, the log format's documentation). - Daylight saving time: local times repeat or skip an hour at the switch; convert with a real time zone database, not a fixed offset.
- Different meanings: browser "visit" time vs download "end" time, file "created" vs "copied here" (MACB). Label events precisely.
- Too much data: a full plaso run gives millions of rows; filter by time window around pivots and by relevant sources first.
Practice
1. Convert the Chrome value 13412945041000000 to UTC by hand.
Subtract the 1601 to 1970 offset in microseconds (11,644,473,600 s = 11644473600000000 µs): 1768471441000000 µs = 1768471441 s Unix time = 2026-01-15 10:04:01 UTC.
2. The event log export came from a laptop in Hanoi (UTC+7, no daylight saving). What would the timeline show if you treated its times as UTC?
Execution at 17:04:12, seven hours after the beacons at 10:06 to 10:08, an impossible order (the beacons before the program ran) that should make you check zones immediately.
3. Add a fifth source: a DNS log with ISO 8601 times like 2026-01-15T10:06:52+00:00.
pd.DataFrame({"time": pd.to_datetime(dns.ts, utc=True), "source": "dns", "event": "query " + dns.name}) appended to frames; to_datetime reads the offset in ISO 8601 strings and converts to UTC.
Test yourself
What is a super timeline?
- A long backup
- All events from all evidence sources normalised to one time zone and sorted
- A Gantt chart of the response
- A timeline of one log file
What is the epoch and unit of Chrome's history timestamps?
- 1970, seconds
- 1601, microseconds
- 1601, 100 ns
- 2001, seconds
In the example, how long after the download did the first beacon occur?
- About 11 seconds
- About 2 minutes 12 seconds
- 7 hours
- 1 second
Why keep the original timestamp and its zone in the timeline?
- For decoration
- So conversions can be checked and every row traced back to the evidence
- pandas requires it
- To make the file larger