GithubHelp home page GithubHelp logo

cbpfexamples's Introduction

cbpfexamples

PACKET FILTERING

Two C programs to show how to attach a cBPF filter program to a raw socket or to an udp socket.

cbpfprogs.txt file contains different filters with different level of complexity that can be used in raw.c.

USAGE

raw

gcc raw.c -o raw

sudo setcap cap_net_raw+ep ./raw

./raw [-i ifname]

The default interface name is eth0.

To change filter copy the cbpf assembly from the cbpfprogs.txt file and paste it in the initialization block of struct sock_prog bpfcode[].

Based on the filter you choose to use you should accordingly uncomment/comment the functions to print the correct headers.

udp

gcc udp.c -o udp

./udp

To test the filter execute on another terminal

nc -p 1030 -u localhost 55555

and then

nc -p 1031 -u localhost 55555

EXAMPLE

raw

example example

udp

example example

FILTERS EXPLANATION

[To do]

SECCOMP

C programs to show seccomp mode 1 (strict), seccomp mode 2 (filter) and libseccomp usage.

PREREQUISITES

libseccomp

Download the tarball from https://github.com/seccomp/libseccomp/releases

# ./configure
# make [V=0|1]
# make install

USAGE

strictexlib.c

gcc -o strictexlib strictexlib.c -lseccomp
./strictexlib

strict.c strictdup.c strictdupmacro.c

gcc -o strict strict.c
./strict
gcc -o strictdup strictdup.c
./strictdup
gcc -o strictdupmacro strictdupmacro.c
./strictdupmacro

EXAMPLE

strictexlib

With seccomp_syscall_priority and seccomp_export_pfc uncommented. example

strictdup

Executed using strace with SECCOMP_RET_TRAP and with dup(STDERR_FILENO) uncommented. example

cbpfexamples's People

Contributors

midist0xf avatar

Stargazers

matteoclz avatar giovifz avatar

Watchers

James Cloos 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.