Skip to main content

Kifurushi

Pypi version Coverage Status Documentation Status Ruff License Apache 2 Poetry

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

Metadata

Release files for kifurushi 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kifurushi 0.6.0
File Size Uploaded Provenance Actions
kifurushi-0.6.0.tar.gz 19.7 kB Without provenance Details for kifurushi-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kifurushi 0.6.0
File Interpreter ABI Platform Actions
kifurushi-0.6.0-py3-none-any.whl Python 3 none any Details for kifurushi-0.6.0-py3-none-any.whl

Total release size: 43.0 kB

Release files / kifurushi-0.6.0.tar.gz

Download URL kifurushi-0.6.0.tar.gz
Size 19.7 kB
Tags Source
SHA-256 checksum
How to use checksums
cc2b004210dc3901d3ae6d912bbd5672b986e50a5a38df95e6d4b255e67d9601
BLAKE2b-256 checksum
How to use checksums
a1bf755f646b598f453d0b57bdf8adc1af91547705b5c53114c0135803e40a57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.11.3 Windows/10

Release files / kifurushi-0.6.0-py3-none-any.whl

Download URL kifurushi-0.6.0-py3-none-any.whl
Size 23.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
007834f11913ff61937db4ea357e46575d13487ef7e2b9027684eff22aeba091
BLAKE2b-256 checksum
How to use checksums
73aff71d80190b92542c9d09895254880950683b35711930e92b75237fd719c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.11.3 Windows/10

Security for kifurushi 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page