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.2.zip (8.9 kB view details)

Uploaded Source

Built Distributions

hypno-0.1.2-cp38-cp38-manylinux2014_x86_64.whl (17.7 kB view details)

Uploaded CPython 3.8

hypno-0.1.2-cp38-cp38-manylinux1_x86_64.whl (17.7 kB view details)

Uploaded CPython 3.8

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

Uploaded CPython 3.7m

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

Uploaded CPython 3.7m

File details

Details for the file hypno-0.1.2.zip.

File metadata

  • Download URL: hypno-0.1.2.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.0 CPython/2.7.17

File hashes

Hashes for hypno-0.1.2.zip
Algorithm Hash digest
SHA256 fa44f4a9954962ffe942d8a5caa949710c278693b99ca556484e0a98df178e97
MD5 e4ebc469860f96e9e0f3542eaaecad6a
BLAKE2b-256 445e78f2a77aac52e0624743f29ecec12dd6b5a8e3272577ff99318bce036b58

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hypno-0.1.2-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 17.7 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.0 CPython/2.7.17

File hashes

Hashes for hypno-0.1.2-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6fc7fbd7bc6a7a1b3758ed0e58fb88d6c8ec42cebf13e38e4605cd564b8d272d
MD5 c3839a358d5d03f78ddfdc38b6304648
BLAKE2b-256 c52c1f52a0e6fbed442ff15dc768198155b3d26230e6f43bffedcb39a2547b3a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hypno-0.1.2-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 17.7 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.0 CPython/2.7.17

File hashes

Hashes for hypno-0.1.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d9362130532fc63e99418fd653f1eb8f5fd6aa9fe8e6fac136b076ff2b5871d0
MD5 b21fa6e40a8e719688644109b0f0c3fd
BLAKE2b-256 c9cab62251066a4f22c3c3895300909b23504a43427254e9d77866bac8395435

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hypno-0.1.2-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.0 CPython/2.7.17

File hashes

Hashes for hypno-0.1.2-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 939e385f90a89ef94576bcfc3f3324ec8632a61aa48453eb4a7de582cf1a8d14
MD5 b6b81206a1ba84db999342c049413a1c
BLAKE2b-256 06382f19b71d37720330124425bf322b2d2eec2ccc900d61eee1d1c0fd05d267

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hypno-0.1.2-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.0 CPython/2.7.17

File hashes

Hashes for hypno-0.1.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 95a7116ead3027b170895b1cc782680e5db4635bf9135c01d5d11d73df27134c
MD5 698dfa0c60ab6f692e47d0805e8db34e
BLAKE2b-256 60e1196d65150c4830b5704344e1ecae349109c07afeaf770c4813de107b7629

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