Skip to main content

A tool/library allowing to inject python code into a running python process.

Project description

Hypno

PyPI version PyPI Supported Python Versions GitHub license Tests (GitHub Actions)

A tool/library allowing to inject python code into a running python process.

Installation

pip install hypno

Both source distributions and manylinux1 wheels are upoloaded to pypi for every release.

Usage

CLI

hypno <pid> <python_code>

API

from hypno import inject_py

inject_py(pid, python_code)

Example

This example runs a python program that prints its pid, and then attaches to the newly created process and injects it with another print statement using hypno.

python -c "import os, time; print('Hello from', os.getpid()); time.sleep(0.5)" &\
hypno $! "import os; print('Hello again from', os.getpid())"

How it works

We use the pyinjector library as a primitive allowing us to inject arbitrary code into processes, because it is simple to use and can be installed easily and on most linux machines.

pyinjector needs an .so to inject, so we compile a minimal library as a C-extension. That library calls PyRun_SimpleString upon initialization.

In order to allow injecting a process multiple times, the injected library must have a unique path for each injection. We do that by copying the library for every call.

As we don't want to recompile the library for every injection to replace the executed string, and we already control the path from which our library is injected, we encode the injected python code into the the injected libraries' paths. When the injected library is loaded, it finds its own name using dladdr and parses the python code from it.

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

hypno-0.1.3.zip (8.9 kB view details)

Uploaded Source

Built Distributions

hypno-0.1.3-cp38-cp38-manylinux2014_x86_64.whl (17.8 kB view details)

Uploaded CPython 3.8

hypno-0.1.3-cp38-cp38-manylinux1_x86_64.whl (17.8 kB view details)

Uploaded CPython 3.8

hypno-0.1.3-cp37-cp37m-manylinux2014_x86_64.whl (18.8 kB view details)

Uploaded CPython 3.7m

hypno-0.1.3-cp37-cp37m-manylinux1_x86_64.whl (18.8 kB view details)

Uploaded CPython 3.7m

File details

Details for the file hypno-0.1.3.zip.

File metadata

  • Download URL: hypno-0.1.3.zip
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/2.7.17

File hashes

Hashes for hypno-0.1.3.zip
Algorithm Hash digest
SHA256 d6dc210febbf93daf2eab28a43d84523c742328298acddba48e47189d02b71d8
MD5 cfc5d3fca958d9ad7bddeb593e48e545
BLAKE2b-256 aa24eecf9268c537dc0c7259495bedf4ea3360c1b7353a351ae6810cf2b379eb

See more details on using hashes here.

File details

Details for the file hypno-0.1.3-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

  • Download URL: hypno-0.1.3-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/2.7.17

File hashes

Hashes for hypno-0.1.3-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 21e1286ed164a8357646f24b9ea547e28840bc0aa6a121832060e05ce76714aa
MD5 d76b56092f7d49bc1393badc29f4706d
BLAKE2b-256 1fd088473a3b87addef0450bb453b1c25ff55adc4d42156d30ee006ab6f5c15f

See more details on using hashes here.

File details

Details for the file hypno-0.1.3-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: hypno-0.1.3-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/2.7.17

File hashes

Hashes for hypno-0.1.3-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b7d223faed53fa81c19d1e78583bddceebc3d20a91459a0445fe64e12ae1fe46
MD5 0562b4f80657e99ca5e5a1266f9d7c9b
BLAKE2b-256 c1dcf631f0b27f9aeac94f0bd54264bcf469ade595d7189f9a695f0302de5e9e

See more details on using hashes here.

File details

Details for the file hypno-0.1.3-cp37-cp37m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: hypno-0.1.3-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/2.7.17

File hashes

Hashes for hypno-0.1.3-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b4027f4338df12e9f72fb2c5ef878e385e7fd0169da16e88248dee67720cb839
MD5 17118fc2ea7b777d2ee5b93b75f19d80
BLAKE2b-256 6f8b521346a6de25cd897cb5f7bae03d2841d978d2fad8d2aa096cd39e3abbba

See more details on using hashes here.

File details

Details for the file hypno-0.1.3-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: hypno-0.1.3-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/2.7.17

File hashes

Hashes for hypno-0.1.3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 fc0dd84bb68ca76ceea064aef4b9b19bfdd21469e1b10c20a84138270f15fd07
MD5 2f094902a0c9aef1278f62886459fad2
BLAKE2b-256 1604cf1a01b824e5f2be8680998339cbbc13dbd2382c0b5bbf1d0dfd6f2207ca

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