Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leaked Session Key Leads to Remote Code Execution #2937

Closed
Miserlou opened this issue Jan 30, 2017 · 3 comments
Closed

Leaked Session Key Leads to Remote Code Execution #2937

Miserlou opened this issue Jan 30, 2017 · 3 comments

Comments

@Miserlou
Copy link

[[Can somebody please sanity check this for me? I found this while reading the "session" code trying to debug something else. ]]

If a Pyramid session key gets leaked somehow (maybe a server is running in Debug mode) - because of how session handling uses the pickle serializer, this can lead to remote code execution (rather than just man in the middle attacks on users).

The problem code is here:

            cookieval = request.cookies.get(self._cookie_name)
            if cookieval is not None:
                try:
value = serializer.loads(bytes_(cookieval))

If I am an attacker with the key, I can simply sign my attack code, pickle it up, and the server will execute it, leading to complete and total pwn.

The solution is simple: replace pickle with a safe serializer. Django made this change in version 1.6 for this exact reason:

"If you’re using the signed cookie session backend and SECRET_KEY is known by an attacker (there isn’t an inherent vulnerability in Django that would cause it to leak), the attacker could insert a string into his session which, when unpickled, executes arbitrary code on the server. The technique for doing so is simple and easily available on the internet. Although the cookie session storage signs the cookie-stored data to prevent tampering, a SECRET_KEY leak immediately escalates to a remote code execution vulnerability."

Maybe I'm wrong here, but it seems like the safe thing to do would be to move away from pickle to JSON (or something faster but still safe) regardless.

@Miserlou
Copy link
Author

Miserlou commented Jan 30, 2017

A brief Googledork also reveals that the internets are full of leaky servers that are vulnerable to this.

@digitalresistor
Copy link
Member

This is a known issue.

#2709
#827

Also, what does the application running in debug mode have to do with it? If you mean with the debugtoolbar... then you already have remote code execution through the debugtoolbar itself (we don't recommend having the debugtoolbar enabled on production sites).

Yes, if your session cookie key is leaked somehow, you are vulnerable to remote code execution.

@mmerickel
Copy link
Member

Yes, losing any secret key will allow very terrible things to happen to whatever was relying on that secret key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants