Skip to main content

ku

ku is fast, async, modern, little tcp man-in-the-middle proxy library, written in pure Python 3.

Features

  • Dump data between clients and server
  • Spoof data in both directions
  • Drop data selectively
  • IPv6 Ready (pass upstream_6 for upstreaming ipv6 or enclose ipv6 addr in brackets like [::1] for listening addrs

Is this proxy fast?

Proxy speed comparison results

TODO

  • Tcp mitm proxy library
  • Proxy executable script (kun (alpha))

Installation

pip install -U ku-proxy

Author

seeklay

License

MIT

Simple proxy usage:

Try to run this script and open http://localhost:80 in you browser

from ku import ku, tcpsession
from time import sleep

proxy = ku(("localhost", 80, "[::1]", 80), ("g.co", 80))

while 7:
    try:
        sleep(0.07)
    except KeyboardInterrupt:
        proxy.shutdown() #proxy creates a thread to async poll for socket events
        break            #we need to call shutdown() to break the thread loop

Advanced proxy usage:

from ku import ku, tcpsession, Pass, Reject
from time import sleep

class conn(tcpsession):

    def __init__(self, client, server, proxy):
        self.client = client
        self.server = server
        self.proxy = proxy
        self.id = id(self)        
        print(F"#{self.id} new conn {client.getpeername()}->{client.getsockname()}::{server.getsockname()}->{server.getpeername()}")

    def clientbound(self, data):        
        print(F"#{self.id} server->client  {len(data)}")
        print(data)
        return Pass

    def serverbound(self, data):        
        print(F"#{self.id} client->server  {len(data)}")
        print(data)
        #return None
        #in python None is returned by default, None == Pass

    def connection_made(self):
        print(F"#{self.id} connection_made")

    def connection_lost(self, side, err):
        side = 'client' if side is self.client else 'server' if side is not None else 'proxy'
        print(F"#{self.id} connection_lost by {side} due to {err}")

print("Starting...")
proxy = ku(("localhost", 80), ("api.ipify.org", 80), conn)
print("Started")

while 1:
    try:
        sleep(0.07)
    except KeyboardInterrupt:
        print("Shutting down...")
        proxy.shutdown()
        print("Exiting...")
        break

See examples/ for more

Release files for ku-proxy 0.2.1

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

Built distribution (wheel)

Table of built distributions (wheels) for ku-proxy 0.2.1
File Interpreter ABI Platform
ku_proxy-0.2.1-py3-none-any.whl Python 3 none any Details

Release files / ku_proxy-0.2.1-py3-none-any.whl

Download URL ku_proxy-0.2.1-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9408683a53e4767b5aa0d4f8e11778f53135c2b9474128db2b4bbd6cd9876079
BLAKE2b-256 checksum
How to use checksums
8cd5c74f308ac5e18b33c23a42e55ba316b7b98406681259d2f7a501ab99ad84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.9

Release history Release notifications | RSS feed

This release

0.2.1 This release

1 release file

0.2.0

1 release file

0.1.1

1 release file

0.1.0

1 release file

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