Git Product home page Git Product logo

ebpf-1's Introduction

eBPF

Collection of BPF programs for Linux.

Host Isolation

Programs

  • KprobeConnectHook hooks into tcp_v4_connect and adds destination IP to allowlist if PID is allowed
  • TcFilter attaches to network interface and filters packets based on allowed IPs

Demo

  • UpdateIPsDemo Userspace tool for updating IP and subnet allowlist
  • UpdatePidsDemo Userspace tool for updating PID allowlist
  • KprobeConnectHookDemo Loader for KprobeConnectHook eBPF program
  • TcLoaderDemo Loader for TcFilter eBPF program, attaches to ens33 interface by default
Run the demos
  1. Follow the build section to build the project so that you have the build/ folder
  2. Run cd build/target/ebpf
  3. Run sudo ../../non-GPL/TcLoader/TcLoaderDemo - packet filter is now attached to ens33
  4. Run sudo ../../non-GPL/HostIsolation/KprobeConnectHook/KprobeConnectHookDemo - connect hook is attached
  5. Run firefox in another tab - verify that all internet access is blocked
  6. Run pgrep firefox to get the PID of the browser
  7. Run sudo ../../non-GPL/HostIsolationMapsUtil/UpdatePidsDemo <firefox PID>
  8. Verify that firefox connects to any page
  9. Quit KprobeConnectHook with Ctrl+C and run sudo ../../non-GPL/TcLoader/TcLoaderDemo unload to detach both eBPF programs

Tests (BPF_PROG_TEST_RUN)

BPFTcFilterTests

BPFTcFilterTests test suite for the TcFilter.bpf.o program

Usage

cd build/target/ebpf
sudo ../test/BPFTcFilterTests

Or if you want to use a custom path for the eBPF object file.

sudo ELASTIC_EBPF_TC_FILTER_OBJ_PATH=build/target/ebpf/TcFilter.bpf.o  build/target/test/BPFTcFilterTests

Build dependencies

Some distros might not have bmake or an older CMake, compiling them from source is usually a good alternative.

bmake is the NetBSD make tool and it's used to build elftoolchain's libelf, the BSD Licensed ELF library we use as alternative to the GNU/Linux licensed elfutils's libelf.

Ubuntu/Debian

apt install clang llvm cmake bmake zlib1g-dev m4 gcc g++ libc6-dev-i386

CentOS/Fedora/AL2

yum install gcc g++ clang llvm zlib-devel m4 bmake

Build

The build is a pretty standard CMake project.

mkdir build
cd build
cmake ..
make

Besides the usual CMake variables, you can set the following variables which are specific to this project.

Variable Description
-DTARGET_DIR Directory to use to store the compiled targets
-DLIBBPF_CONTRIB Alternative directory to use for libbpf sources instead of the bundled one
target
├── ebpf
│   ├── KprobeConnectHook.bpf.o
│   └── TcFilter.bpf.o
├── include
│   ├── Common.h
│   ├── KprobeLoader.h
│   ├── TcLoader.h
│   └── UpdateMaps.h
├── libeBPF.a
└── test
    └── BPFTcFilterTests

Directory layout:

ebpf-1's People

Contributors

dwhyrock avatar ferullo avatar fntlnz avatar leodido avatar mjwolf avatar mmat11 avatar nicholasberlin avatar rhysre avatar stanek-michal avatar tabell avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.