Giter VIP home page Giter VIP logo

kneecap's Introduction

Kneecap

Kneecap enables you to generate network packets from a high-level logical spec such as this example:

eth.constrain <@ ethernet.source_address = ethernet.mac_address "[1-5,10]:34:56:78:90:*" &&
                     ethernet.ethertype = ethernet.ethertype_ipv4 @>
    <== ip.constrain <@@ ipv4.version = 4 &&
                         ipv4.source_address = ipv4.ipv4_address "10.10.10.[55-60]" &&
                         ipv4.source_address = ipv4.destination_address &&
                         ipv4.internet_header_length = 5 &&
                         ipv4.total_length = 170 &&
                         ipv4.TTL = 5 &&
                         ipv4.protocol = ipv4.protocol_ip_in_ip
                         (*ipv4.source_address < ipv4.destination_address*)
                      @@>

This example describes an IPv4 packet encapsulated inside an Ethernet frame, and specifies constraints on both layers. This spec is translated into bitvector constraints that are given to an SMT solver. Solutions returned by the solver correspond to network packets. You can find out more by reading the paper.

Example output

Kneecap provides an API for generating packets. It comes with a sample program that generates packets using Kneecap and then saves them in the pcap file format. You can view these files' contents using tools like Wireshark or various others. This section contains example output files from this sample program.

64-byte Ethernet packets, in batches of 1000

584-byte Ethernet packets, in batches of 1000

1000 packets containing six stacked protocols, described in the paper

Dependencies

Building

I ran this on Ubuntu 14 (using Mono 3.2.8) and OSX 10.10.5 (using Mono 3.8.0), but the process should be similar on other systems.

Let $KNEECAP_DIR be the path of your Kneecap repo clone.

  1. Get a Z3 release from https://github.com/Z3Prover/z3/releases and build it.
# go to directory where you've untarred Z3.
export Z3_DIR=`pwd`
./configure
cd build; make

Note: On OSX I gave the --x86 command-line flag to ./configure, since for some reason the version of Mono I'm using expected Z3's DLL to be compiled for 32.bit

  1. Build the managed wrapper to Z3.
cd ../src/api/dotnet
msbuild Microsoft.Z3.csproj
  1. We will use Z3 to build Kneecap. Copy files over.
cp ${Z3_DIR}/src/api/dotnet/obj/Debug/Microsoft.Z3.dll ${KNEECAP_DIR}
  1. Build Kneecap
cd ${KNEECAP_DIR}
msbuild kneecap.sln

Running

$ MONO_PATH=${MONO_PATH}:${KNEECAP_DIR}/kneecap/ mono ${KNEECAP_DIR}/kneet/bin/Debug/kneet.exe

You should see a list of numbers counting up to a thousand, at the end of which the program will terminate. Each of the numbers corresponded to a packet being generated, which was recorded in a .pcap file in your directory.

Problems?

Mono might complain that it cannot find certain files. Sometimes such error messages can be misleading: Mono can find the files, but they don't contain what it expected to find. Set MONO_LOG_LEVEL=debug in your environment to have Mono tell you more.

kneecap's People

Contributors

niksu 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.