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) chat

A tool/library allowing to inject python code into a running python process. Based on kmaork/pyinjector

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.4.zip (9.2 kB view details)

Uploaded Source

Built Distributions

hypno-0.1.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.9 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

hypno-0.1.4-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.9 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

hypno-0.1.4-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.9 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

hypno-0.1.4-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.9 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

File details

Details for the file hypno-0.1.4.zip.

File metadata

  • Download URL: hypno-0.1.4.zip
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for hypno-0.1.4.zip
Algorithm Hash digest
SHA256 2024d38a00a0d8b19fe8970dc44e7dcee67b26f5bcc0ed05d50490176660039c
MD5 414d6271f22e136e09a00b5de990c709
BLAKE2b-256 8c00262c608aa2b444b3cec4d988fb07c69173f9749cfadc085ee54616606446

See more details on using hashes here.

File details

Details for the file hypno-0.1.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hypno-0.1.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 11b846c69d8d9aaffcd6997aaa66420c562061df6de7f30c478d25f9eee1a2c0
MD5 81b0dd49c87e70fee5758d6e1a0f82bc
BLAKE2b-256 80a0346a13a3ff5fe8112c8e2206f1e5f4c88024380caca071c4443e93441dc8

See more details on using hashes here.

File details

Details for the file hypno-0.1.4-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hypno-0.1.4-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6e6f3b9250ca6099b9fad68361afe4d7e19dd8baf06786ebb698471e50ea0308
MD5 a7f6a2eb4bf9f0faa3991b5c3f9db7e2
BLAKE2b-256 fc255a9f4f849821ebf28cee94b8c636f68b84b22f65637bbbf25387a1ce6fd2

See more details on using hashes here.

File details

Details for the file hypno-0.1.4-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hypno-0.1.4-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eafdb5845b38e3e94722e6141410a1633f1bc7992f8feb589ae16e21a4ddbb1b
MD5 785e6ad941d438125bd6b429a3f148cd
BLAKE2b-256 7cdf52c7bc6b3ae5c113cae81087747517e29104382887e588824d7eeb6c8abc

See more details on using hashes here.

File details

Details for the file hypno-0.1.4-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hypno-0.1.4-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d6411056f6345c9c2ff88146eadefabcac553ed4c5acc10963d5d7e729565afd
MD5 f5175a6bad4a8905a8c7ee88b44860b3
BLAKE2b-256 7aa767dac1092cabb9a75fc97da39944ee619740377d7230029bb644b9868e20

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