Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save socketz/a73416e51e10e3efeaa044af4380f3bb to your computer and use it in GitHub Desktop.

Select an option

Save socketz/a73416e51e10e3efeaa044af4380f3bb to your computer and use it in GitHub Desktop.
Find in-memory modification of kernel.yama.ptrace_scope with bpftrace - PoC
#!/usr/bin/env bpftrace
BEGIN
{
printf("ptrace_scope address: %p\n", kaddr("ptrace_scope"));
$data_addr = kaddr("ptrace_scope");
@last_val = *(int32*)$data_addr; // Initial value
printf("Monitoring kernel.yama.ptrace_scope at address 0x%x (initial value: %d)\n",
$data_addr, @last_val);
}
interval:s:1
{
$data_addr = kaddr("ptrace_scope");
$current = *(int32*)$data_addr;
if (@last_val != $current) {
time("%H:%M:%S ");
printf("ALERT: kernel.yama.ptrace_scope changed from %d to %d!\n",
@last_val, $current);
@last_val = $current;
}
}
END
{
clear(@last_val);
printf("Monitoring stopped\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment