amir9339 / ebpf_maps_hooking

POC developed while writing the paper "A weakness in eBPF-based runtime security applications"

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ™ˆ Hiding from Tracee

This repository contains the POC developed while writing the paper: β€œA weakness in eBPF-based runtime security applications”.

The paper presents a weak point in the architecture of eBPF-based security applications that are heavily based on eBPF maps. In the paper, I discussed Tracee, a runtime security application built by Aqua Security as an example of a security product based only on eBPF. The POC was developed to bypass one detection method of Tracee.

πŸ“ The repository includes four directories:

β”œβ”€β”€ docs                           includes the paper in Markdown format
β”œβ”€β”€ extended_diamorphin            The full POC
β”œβ”€β”€  ftrace__htab_map_lookup_elem  The code for the hook
└── setup_env                      environment setup scripts

⚠️ It is necessary to note that

The code here relies on static kernel code (extended_diamrphine/src/bpf/ *) and was tested only on Ubuntu 18.04 / 20.04 with Kernel version 5.4.0 It will probably not run on other kernel versions!

If you want to run on a different kernel, there is a script called get_bpf_dir.sh that update the static code

πŸƒβ€β™€οΈ Run and test

Few step are required before running the POC.

First, setup the development environment:

# Setup dev environment
cd setup_env/
./setup_env.sh

# Compile Diamorphine and load to the kernel
cd Diamorphine/
make
sudo insmod diamorphine.ko

# Compile Tracee from source
cd tracee
make

## Compile the program
cd ../../extended_diamorphine
make

Run:

sudo insmod diamorphine.ko

Unload:

# Uninstall Diamorphine
kill -63 0 && sudo rmmod diamorphine
sudo rmmod htab

πŸ§ͺ Example output

$ cd setup_env/tracee/
$ sudo ./dist/tracee-ebpf -t e=hooked_syscalls
TIME             UID    COMM             PID     TID     RET              EVENT                ARGS
$ sudo dmesg | tail

# Fake table allocated successfully
[4.874517] Fake table addr: 00000000198b1f93 
# The hook succeeded!
[5.172042] The original syscall_table_addr from map: 000000000a0fb5da But 00000000827549d2 returned 

About

POC developed while writing the paper "A weakness in eBPF-based runtime security applications"


Languages

Language:C 93.1%Language:Shell 5.9%Language:Makefile 1.0%