Commands / Detection and audit

Detection and audit

gcore

Also core dump, memory dump, process memory, gdb

Writes a running process's memory to a core file and leaves it running.

gcore comes with gdb. It attaches to a process through ptrace, writes its whole memory (stack, heap, the environment, loaded libraries) to core.PID, and detaches, so the program runs on. A program's memory holds what never reaches its disk: an address it decoded, a key, a session token; strings on the core file shows the readable parts. Attaching needs the right to trace the process: your own, or root's, and the machine may limit even that (/proc/sys/kernel/yama/ptrace_scope). It captures one process; a whole machine's memory needs a capture taken below the operating system.

gcore command usage

gcore [-o PREFIX] PID

Options

-o PREFIX
name the file PREFIX.PID instead of core.PID

gcore examples

sudo gcore -o agent 4242
Dumps process 4242's memory to agent.4242.
Saved corefile agent.4242
strings agent.4242 | grep TOKEN=
Finds a variable in the dump's readable text.

Pitfalls

  • ptrace: Operation not permitted means you may not trace that process: run it as root, and the container or machine must allow tracing.
  • The dump is as big as the process's memory, and it holds every secret the program had: treat it as evidence, and as sensitive.

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start learning