Skip to content

Commit 77a0902

Browse files
authored
Merge pull request #2159 from HackTricks-wiki/research_update_src_generic-methodologies-and-resources_basic-forensic-methodology_linux-forensics_20260422_143108
Research Update Enhanced src/generic-methodologies-and-resou...
2 parents c437e28 + e9f3d9f commit 77a0902

1 file changed

Lines changed: 100 additions & 1 deletion

File tree

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

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,30 @@ Paths where a malware could be installed as a service:
259259
- **\~/.config/autostart/**: For user-specific automatic startup applications, which can be a hiding spot for user-targeted malware.
260260
- **/lib/systemd/system/**: System-wide default unit files provided by installed packages.
261261

262+
#### Hunt: systemd timers and transient units
263+
264+
Systemd persistence is not limited to `.service` files. Investigate `.timer` units, user-level units, and **transient units** created at runtime.
265+
266+
```bash
267+
# Enumerate timers and inspect referenced services
268+
systemctl list-timers --all
269+
systemctl cat <name>.timer
270+
systemctl cat <name>.service
271+
272+
# Search common system and user paths
273+
find /etc/systemd/system /run/systemd/system /usr/lib/systemd/system -maxdepth 3 \( -name '*.service' -o -name '*.timer' \) -ls
274+
find /home -path '*/.config/systemd/user/*' -type f \( -name '*.service' -o -name '*.timer' \) -ls
275+
276+
# Transient units created via systemd-run often land here
277+
find /run/systemd/transient -maxdepth 2 -type f -ls 2>/dev/null
278+
279+
# Pull execution history for a suspicious unit
280+
journalctl -u <name>.service
281+
journalctl _SYSTEMD_UNIT=<name>.service
282+
```
283+
284+
Transient units are easy to miss because `/run/systemd/transient/` is **non-persistent**. If you are collecting a live image, grab it before shutdown.
285+
262286
### Kernel Modules
263287

264288
Linux kernel modules, often utilized by malware as rootkit components, are loaded at system boot. The directories and files critical for these modules include:
@@ -298,6 +322,58 @@ Linux systems track user activities and system events through various log files.
298322
> [!TIP]
299323
> Linux system logs and audit subsystems may be disabled or deleted in an intrusion or malware incident. Because logs on Linux systems generally contain some of the most useful information about malicious activities, intruders routinely delete them. Therefore, when examining available log files, it is important to look for gaps or out of order entries that might be an indication of deletion or tampering.
300324
325+
### Journald triage (`journalctl`)
326+
327+
On modern Linux hosts, the **systemd journal** is usually the highest-value source for **service execution**, **auth events**, **package operations**, and **kernel/user-space messages**. During live response, try to preserve both the **persistent** journal (`/var/log/journal/`) and the **runtime** journal (`/run/log/journal/`) because short-lived attacker activity may only exist in the latter.
328+
329+
```bash
330+
# List available boots and pivot around the suspicious one
331+
journalctl --list-boots
332+
journalctl -b -1
333+
334+
# Review a mounted image or copied journal directory offline
335+
journalctl --directory /mnt/image/var/log/journal --list-boots
336+
journalctl --directory /mnt/image/var/log/journal -b -1
337+
338+
# Inspect a single journal file and check integrity/corruption
339+
journalctl --file system.journal --header
340+
journalctl --file system.journal --verify
341+
342+
# High-signal filters
343+
journalctl -u ssh.service
344+
journalctl _SYSTEMD_UNIT=cron.service
345+
journalctl _UID=0
346+
journalctl _EXE=/usr/sbin/useradd
347+
```
348+
349+
Useful journal fields for triage include `_SYSTEMD_UNIT`, `_EXE`, `_COMM`, `_CMDLINE`, `_UID`, `_GID`, `_PID`, `_BOOT_ID`, and `MESSAGE`. If journald was configured without persistent storage, expect only recent data under `/run/log/journal/`.
350+
351+
### Audit framework triage (`auditd`)
352+
353+
If `auditd` is enabled, prefer it whenever you need **process attribution** for file changes, command execution, login activity, or package installation.
354+
355+
```bash
356+
# Fast summaries
357+
aureport --start today --summary -i
358+
aureport --start today --login --failed -i
359+
aureport --start today --executable -i
360+
361+
# Search raw events
362+
ausearch --start today -m EXECVE -i
363+
ausearch --start today -ua 1000 -m USER_CMD,EXECVE -i
364+
ausearch --start today -m SERVICE_START,SERVICE_STOP -i
365+
366+
# Software installation/update events (especially useful on RHEL-like systems)
367+
ausearch -m SOFTWARE_UPDATE -i
368+
```
369+
370+
When rules were deployed with keys, pivot from them instead of grepping raw logs:
371+
372+
```bash
373+
ausearch --start this-week -k <rule_key> --raw | aureport --file --summary -i
374+
ausearch --start this-week -k <rule_key> --raw | aureport --user --summary -i
375+
```
376+
301377
**Linux maintains a command history for each user**, stored in:
302378

303379
- \~/.bash_history
@@ -413,6 +489,28 @@ Useful fields:
413489
- **dtime**: deletion timestamp set when the inode was unlinked.
414490
- **ctime/mtime**: helps correlate metadata/content changes with incident timeline.
415491

492+
### Capabilities, xattrs, and preload-based userland rootkits
493+
494+
Modern Linux persistence often avoids obvious `setuid` binaries and instead abuses **file capabilities**, **extended attributes**, and the dynamic loader.
495+
496+
```bash
497+
# Enumerate file capabilities (think cap_setuid, cap_sys_admin, cap_dac_override)
498+
getcap -r / 2>/dev/null
499+
500+
# Inspect extended attributes on suspicious binaries and libraries
501+
getfattr -d -m - /path/to/suspicious/file 2>/dev/null
502+
503+
# Global preload hook affecting every dynamically linked binary
504+
cat /etc/ld.so.preload 2>/dev/null
505+
stat /etc/ld.so.preload 2>/dev/null
506+
507+
# If a suspicious library is referenced, inspect its metadata and links
508+
ls -lah /lib /lib64 /usr/lib /usr/lib64 /usr/local/lib 2>/dev/null | grep -E '\\.so(\\.|$)'
509+
ldd /bin/ls
510+
```
511+
512+
Pay special attention to libraries referenced from **writable** paths such as `/tmp`, `/dev/shm`, `/var/tmp`, or odd locations under `/usr/local/lib`. Also check for capability-bearing binaries outside normal package ownership and correlate them with package verification results (`rpm -Va`, `dpkg --verify`, `debsums`).
513+
416514
## Compare files of different filesystem versions
417515

418516
### Filesystem Version Comparison Summary
@@ -456,7 +554,8 @@ git diff --no-index --diff-filter=D path/to/old_version/ path/to/new_version/
456554
- **Book: Malware Forensics Field Guide for Linux Systems: Digital Forensics Field Guides**
457555

458556
- [Red Canary – Patching for persistence: How DripDropper Linux malware moves through the cloud](https://redcanary.com/blog/threat-intelligence/dripdropper-linux-malware/)
557+
- [Forensic Analysis of Linux Journals](https://stuxnet999.github.io/dfir/linux-journal-forensics/)
558+
- [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)
459559

460560
{{#include ../../banners/hacktricks-training.md}}
461561

462-

0 commit comments

Comments
 (0)