Skip to main content

A simple library to forge network packets

Project description

Kifurushi

Pypi version Coverage Status Documentation Status License Apache 2

A simple library to forge network packets.

Why?

I was playing with the DNS protocol using the excellent scapy library. It is very simple to forge network data with this library. I have always wondered why protocol libraries like h2 or aioquic don't use it to forge packets instead of doing it all by hands and then I thought maybe it is because it will be overkill to import the whole library containing many protocol implementations just for one thing you want to use (or maybe library authors don't know the scapy library...). It would be glad to just use the scapy ability to forge packets without importing the huge protocol library. This is where the idea of kifurushi comes from.

It is a simple library that will help you forge network data quickly. It is less capable than scapy because its specific goal is to implement a concrete protocol as opposed to scapy which makes it possible to give free rein to its imagination. So if you find that your needs cannot be simply express with kifurushi, you probably need to use scapy.

Installation

with pip:

pip install kifurushi

With poetry an alternative package manager:

poetry add kifurushi

kifurushi starts working from python3.6 and also supports pypy3. It has one dependency:

  • attrs: A library helping to write classes without pain.

Documentation

The documentation is available at https://kifurushi.readthedocs.io

Usage

import socket
import enum
from kifurushi import Packet, ShortField, ByteField, IntEnumField

HOST = 'disney-stuff.com'
PORT = 14006


class Mood(enum.Enum):
  happy = 1
  cool = 2
  angry = 4


class Disney(Packet):
  __fields__ = [
    ShortField('mickey', 2),
    ByteField('minnie', 3, hex=True),
    IntEnumField('donald', 1, Mood)
  ]


with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
  disney = Disney()
  s.connect((HOST, PORT))
  disney.donald = Mood.cool.value
  # we send the packet data
  s.sendall(disney.raw)
  # we create another packet object from raw bytes
  received_packet = Disney.from_bytes(s.recv(1024))
  print(received_packet)

To see more protocol implementations check the folder examples of the project.

Warnings

  • If you use the excellent Pycharm editor, you may notice weird warnings when instantiating kifurushi fields. At the moment I'm writing this documentation, I'm using Pycharm 2020.3 and there is an issue when subclassing attrs classes. So just ignore the warning saying to fill the format parameter if you don't need it.
  • kifurushi is a young project, so it is expected to have breaking changes in the api without respecting the semver principle. It is recommended to pin the version you are using for now.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kifurushi-0.3.1.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

kifurushi-0.3.1-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file kifurushi-0.3.1.tar.gz.

File metadata

  • Download URL: kifurushi-0.3.1.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.6.15 Linux/5.11.0-1020-azure

File hashes

Hashes for kifurushi-0.3.1.tar.gz
Algorithm Hash digest
SHA256 03b0c83902b5cb1c5fb238fd200341f4ecaad990e3de5bb21e43572f84982afb
MD5 db72c2cf6bc20c7819fe3aeb90c21bee
BLAKE2b-256 bdf74465fc2a5ac3d9d63f8c5774f9431f0fff345e2261064edd07ecf87e86e5

See more details on using hashes here.

File details

Details for the file kifurushi-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: kifurushi-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.6.15 Linux/5.11.0-1020-azure

File hashes

Hashes for kifurushi-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ca1d52a4ac909909a17de796c7c6b0104b1f1c0b2584f95de41525b8b5ac0f2a
MD5 f1da7fa5d55c36172a69ea87729d33d0
BLAKE2b-256 9e7eedda89fa635a9e082e9c01f146b4ff723ba9f10ce9b4fbb9dd145dce1cbd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page