• Stars
    star
    139
  • Rank 262,954 (Top 6 %)
  • Language
    C
  • License
    BSD 3-Clause "New...
  • Created over 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Dectect syscall hooking using eBPF

BPF-HookDetect

Detect Kernel Rootkits hooking syscalls

Overview

Kernel Rootkits such as Diamorphine hook various syscall functions so they can either:

  • Hide files and processes from usermode applications, by altering the data returned from the Kernel
  • Facilitate a covert channel from usermode-kernel to trigger actions such as priliege escallation

This project attempts to detect this syscall hooking using eBPF, and it's ability to get kernel stack traces. HookDetect monitors the following syscalls:

  • kill
    • Used to send signals to other processes
  • getdents and getdents64
    • Used to list files and folders

HookDetect will check every use of these syscalls to check two things:

  • How many stack frames are there between the initial kernel entrypoint and the actual syscall function
    • This detects when a hook interposes on the function to alter it's return data
  • After the kernel detected the processes making a syscall, was the read function actually called?
    • This detect for the covert-channel uses where the real syscall is not actually run

Details

For more details, see this blog: Detecting kernel hooking using eBPF

This code has been tested on:

  • Ubuntu 21.04, Kernel 5.11.0-17
  • RHEL 7.6, Kernel 3.10.0-957

Build

To use pre-build binaries, grab them from the Releases page.

To build from source, do the following:

Dependecies

As this code makes use of CO-RE, it requires a recent version of Linux that has BTF Type information. See these notes in the libbpf README for more information. For example Ubuntu requries Ubuntu 20.10+.

To build it requires these dependecies:

  • zlib
  • libelf
  • libbfd
  • clang 11
  • make

On Ubuntu these can be installed by

sudo apt install build-essential clang-11 libelf-dev zlib1g-dev libbfd-dev libcap-dev libfd-dev

Build

To Build from source, recusivly clone the respository the run make in the src directory to build:

git clone --recursive https://github.com/pathtofile/bpf-hookdetect.git
cd bpf-hookdetect/src
make

The binaries will built into bpf-hookdetect/src/bin.

Run

To run, run the hookdetect binary as root. If the program detects a function was hooked, it will print the syscall name, along with the process and PID:

$> sudo ./bpf-hookdetect/src/bin/hookdetect
sys_getdents64 is hooked for PID 2584743 (ls) - Real function called but data possibly altered
sys_kill is hooked for PID 2584087 (bash) - Real function not called

To print out the stack traces from each syscall logged, run hookdetect with --verbose:

$> sudo ./bpf-hookdetect/src/bin/hookdetect --verbose
sys_kill:
    0xffffffff886b88e1 -> __x64_sys_kill
    0xffffffff89234d38 -> do_syscall_64
    0xffffffff8940008c -> entry_SYSCALL_64_after_hwframe
sys_kill is hooked for PID 2584087 (bash) - Real function called but data possibly altered

Example Test

To test, download, make, and install the Diamorphine rootkit. Once rootkit is installed, start hookdetect and run:

# Sending signal 63 is intercepted by Diamorphine, and real syscall function is not called
kill -63 0

# But when sending other signals the real function is called
kill -s 23 $$

Resources

The project's skeleton is adapted from libbpf-bootstrap

The code to convert stack addresses to function names is taken from the BCC Project

More Repositories

1

bad-bpf

A collection of eBPF programs demonstrating bad behavior, presented at DEF CON 29
C
530
star
2

Sealighter

Sysmon-Like research tool for ETW
C++
328
star
3

SealighterTI

Combining Sealighter with unpatched exploits to run the Threat-Intelligence ETW Provider
C
159
star
4

PPLRunner

Run Processes as PPL with ELAM
C
141
star
5

siemcraft

Security Information and Event Management in Minecraft
Go
115
star
6

commandline_cloaking

A collection of projects demonstrating various commandline cloaking techniques on Linux
Go
53
star
7

bpf-pipesnoop

Example program using eBPF to log data being based in using shell pipes
C
40
star
8

toucli

Use TouchID and the Secure Enclave to encrypt data from the commandline.
Swift
15
star
9

SimpleAmsiProvider

A simple provider to analyse what gets passed into Microsoft's Anti-Malware Scan Interface
C++
13
star
10

tf_wireguard

Simple Terraform Scripts to setup a WireGuard server on various cloud providers.
HCL
11
star
11

https.server

Python SimpleHTTPServer wrapped in TLS
Python
8
star
12

bpf-uprobedbg

C
7
star
13

ctlwatcher

Monitor Certificate Transparency logs for domains matching regexes.
Rust
6
star
14

ld_preload_go

Simple example of creating an `LD_PRELOAD` library in Go that hooks LibC's main function.
Go
5
star
15

ebpf-pinned-fentry

Example how to run eBPF probes without a usermode process using fentry
C
3
star
16

Presentations

A Repo to hold slides from presentations, etc.
3
star
17

cookiecache

Simplify getting and using cookies from the browser to use in Python.
Python
3
star
18

dockenv

Dockenv - Run python in docker the easy way
Python
2
star
19

etwRunner

Basic KrabsETW runner template
C++
2
star
20

terraform-provider-bitlaunch

BitLaunch Terraform Provider
Go
2
star
21

pyauditlogger

Auto-Add Python 3.8 audit hooks to all python scripts
Python
1
star
22

hijack-watcher

Rust version of HijackWatcher
Rust
1
star
23

etw_watcher

Using GitHub Actions to create commit diffs
PowerShell
1
star
24

PowerInject

Inject Interactive PowerShell into an arbitrary process
C
1
star
25

sigstore-watcher

Watches SigStore Code Signing Logs
Rust
1
star
26

sgproxy

Basic HTTP/S proxy. Created to add HTTP Auth to a request from a client that doesn't support supplying auth in URL, for example VScode's Juypyter Notebook Server browser.
Go
1
star
27

Puppeteer-Stealth-Docker

This is a simple example of how do stealthy headless chrome webscraping from a Docker container.
Dockerfile
1
star