Skip to main content

A static analyzer and interpreter for Python pickle data

Project description

Fickling

Fickling is a decompiler, static analyzer, and bytecode rewriter for Python pickle object serializations.

Pickled Python objects are in fact bytecode that is interpreted by a stack-based virtual machine built into Python called the "Pickle Machine". Fickling can take pickled data streams and decompile them into human-readable Python code that, when executed, will deserialize to the original serialized object.

The authors do not prescribe any meaning to the “F” in Fickling; it could stand for “fickle,” … or something else. Divining its meaning is a personal journey in discretion and is left as an exercise to the reader.

Learn more about it in our blog post and DEF CON 2021 talk.

Installation

Fickling has been tested on Python 3.8 through Python 3.11 and has very few dependencies. It can be installed through pip:

python -m pip install fickling

This installs both the library and the command line utility.

Usage

Fickling can be run programmatically:

>>> import ast
>>> import pickle
>>> from fickling.pickle import Pickled
>>> print(ast.dump(Pickled.load(pickle.dumps([1, 2, 3, 4])).ast, indent=4))
Module(
    body=[
        Assign(
            targets=[
                Name(id='result', ctx=Store())],
            value=List(
                elts=[
                    Constant(value=1),
                    Constant(value=2),
                    Constant(value=3),
                    Constant(value=4)],
                ctx=Load()))])

Fickling can also be run as a command line utility:

$ fickling pickled.data
result = [1, 2, 3, 4]

This is of course a simple example. However, Python pickle bytecode can run arbitrary Python commands (such as exec or os.system) so it is a security risk to unpickle untrusted data. You can test for common patterns of malicious pickle files with the --check-safety option:

$ fickling --check-safety pickled.data
Warning: Fickling failed to detect any overtly unsafe code, but the pickle file may still be unsafe.
Do not unpickle this file if it is from an untrusted source!

You can also safely trace the execution of the Pickle virtual machine without exercising any malicious code with the --trace option.

Finally, you can inject arbitrary Python code that will be run on unpickling into an existing pickle file with the --inject option.

License

This utility was developed by Trail of Bits. It is licensed under the GNU Lesser General Public License v3.0. Contact us if you're looking for an exception to the terms.

© 2021, Trail of Bits.

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

fickling-0.0.8.tar.gz (22.5 kB view details)

Uploaded Source

Built Distribution

fickling-0.0.8-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file fickling-0.0.8.tar.gz.

File metadata

  • Download URL: fickling-0.0.8.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for fickling-0.0.8.tar.gz
Algorithm Hash digest
SHA256 8fbcfc0da9a860d1928dde0c86f92ae8b961f5d49faf623f16cce0799fdf7825
MD5 ee8010d86c5aa7dca1684420032ea8de
BLAKE2b-256 7a0e21db182d65104c87feed9d17bd3479b1801c5d34593d8d84f7e11f503d00

See more details on using hashes here.

File details

Details for the file fickling-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: fickling-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 23.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for fickling-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 e08fcc2e88dbccde0c22b91df4a39d02728d50677f6a383783fd599ec502d485
MD5 f3e28690331ad8b73304b4c1be8177e4
BLAKE2b-256 0b379b9881686fff51631e3484bfbd2f90688339e13be24572949f2232fffb44

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