Skip to content

Commit 83dac3e

Browse files
authored
Merge pull request #2162 from HackTricks-wiki/update_Say_hi_to_Pike__20260423_132927
Say hi to Pike!
2 parents 043c0a5 + 6ecec6f commit 83dac3e

1 file changed

Lines changed: 101 additions & 1 deletion

File tree

src/generic-methodologies-and-resources/basic-forensic-methodology/linux-forensics.md

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,104 @@ head -1 maps #Get address of the file. It was 08048000-08049000
195195
dd if=mem bs=1 skip=08048000 count=1000 of=/tmp/exec2 #Recorver it
196196
```
197197

198+
## Syscall Trace Triage with SQLite and FTS5
199+
200+
When a process is still running or can be re-executed in a lab, **`strace`** can provide a fast behavioral trace without needing kernel modules or full EDR telemetry. For large traces, avoid reading the raw log directly or pasting it into an LLM: store it in a **SQLite** database and query only the minimal subset you need.
201+
202+
> [!WARNING]
203+
> Attaching `strace` changes process timing and may affect race conditions or other fragile bugs. Prefer reproducing on a copy/lab system when possible.
204+
205+
### Capture
206+
207+
For a new process:
208+
209+
```bash
210+
strace -ff -ttt -yy -s 4096 -o /tmp/trace.log <command>
211+
```
212+
213+
For a live process:
214+
215+
```bash
216+
strace -ff -ttt -yy -s 4096 -o /tmp/trace.log -p <PID>
217+
```
218+
219+
Useful options:
220+
221+
- `-ff`: follow forks/threads and keep per-process outputs
222+
- `-ttt`: epoch timestamps for easy timeline correlation
223+
- `-yy`: resolve file descriptors to backing paths/sockets when possible
224+
- `-s 4096`: keep long path and buffer arguments from being truncated
225+
226+
### Normalize
227+
228+
A practical schema is one row per syscall and one row per argument:
229+
230+
```sql
231+
CREATE TABLE syscalls (
232+
id INTEGER PRIMARY KEY,
233+
pid INTEGER NOT NULL,
234+
timestamp REAL NOT NULL,
235+
name TEXT NOT NULL,
236+
ret_val INTEGER,
237+
errno TEXT
238+
);
239+
240+
CREATE TABLE syscall_args (
241+
id INTEGER PRIMARY KEY,
242+
syscall_id INTEGER NOT NULL REFERENCES syscalls(id),
243+
position INTEGER NOT NULL,
244+
raw TEXT NOT NULL,
245+
type INTEGER NOT NULL
246+
);
247+
```
248+
249+
This avoids trying to flatten heterogeneous syscall lines into a single wide table and keeps joins predictable during triage.
250+
251+
### Index text-heavy arguments with FTS5
252+
253+
Naive path hunting with `LIKE "%...%"` becomes very slow on large traces. Create an FTS5 index for argument text and search that instead:
254+
255+
```sql
256+
CREATE VIRTUAL TABLE syscall_args_fts
257+
USING fts5(raw, content='syscall_args', content_rowid='id');
258+
259+
INSERT INTO syscall_args_fts(rowid, raw)
260+
SELECT id, raw FROM syscall_args;
261+
```
262+
263+
Example: recover file activity under `/tmp` without scanning every row:
264+
265+
```sql
266+
SELECT s.timestamp, s.pid, s.name, a.position, a.raw
267+
FROM syscall_args_fts f
268+
JOIN syscall_args a ON a.id = f.rowid
269+
JOIN syscalls s ON s.id = a.syscall_id
270+
WHERE syscall_args_fts MATCH 'tmp'
271+
AND s.name IN ('openat', 'stat', 'lstat', 'rename', 'unlink', 'execve')
272+
ORDER BY s.timestamp;
273+
```
274+
275+
### High-signal investigations
276+
277+
- **PATH hijacking / fake sudo**: search for writes and `chmod`/`rename` activity under `~/.local/bin/`, then correlate with later `execve` of privileged-looking names such as `sudo`.
278+
- **TOCTOU on temporary files**: pivot on the same `/tmp/...` path across `stat`, `access`, `openat`, `rename`, `unlink`, `link`, `symlink`, and `execve` to identify check/use gaps.
279+
- **Crash root cause**: correlate `mmap` of a file with writes or truncation of the same inode/path by another process, then inspect the signal/exit sequence for `SIGBUS`.
280+
- **Network destination recovery**: filter `connect`, `sendto`, `sendmsg`, `recvfrom`, and socket-related arguments to extract peer IPs and ports.
281+
282+
### LLM-assisted trace analysis
283+
284+
If you want an LLM to assist, expose a **read-only** SQLite handle and give it the full schema. Let it issue raw SQL instead of wrapping the database behind narrow helper functions. This usually works better for joins, temporal correlation, and FTS lookups.
285+
286+
Practical rules:
287+
288+
- Keep the database read-only, for example with `sqlite3 'file:trace.db?mode=ro'`.
289+
- Give the model examples of valid `JOIN` and `FTS5 MATCH` queries.
290+
- Do **not** paste raw multi-GB `strace` logs into the prompt.
291+
- Ask focused questions such as:
292+
- "List persistent files written by this program."
293+
- "Did it create or replace executables in user-controlled PATH directories?"
294+
- "Explain why this trace ends in SIGBUS."
295+
198296
## Inspect Autostart locations
199297

200298
### Scheduled Tasks
@@ -556,6 +654,8 @@ git diff --no-index --diff-filter=D path/to/old_version/ path/to/new_version/
556654
- [Red Canary – Patching for persistence: How DripDropper Linux malware moves through the cloud](https://redcanary.com/blog/threat-intelligence/dripdropper-linux-malware/)
557655
- [Forensic Analysis of Linux Journals](https://stuxnet999.github.io/dfir/linux-journal-forensics/)
558656
- [Red Hat Enterprise Linux 9 - Auditing the system](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/security_hardening/auditing-the-system_security-hardening)
657+
- [Say hi to Pike!](https://www.synacktiv.com/en/publications/say-hi-to-pike.html)
658+
- [strace](https://strace.io/)
659+
- [SQLite FTS5 Extension](https://www.sqlite.org/fts5.html)
559660

560661
{{#include ../../banners/hacktricks-training.md}}
561-

0 commit comments

Comments
 (0)