I'm on a CTF. It's using TornadoServer 4.5.1, and the application is written in Python 2.7.

Every time I login, I receive a cookie. I'm pasting below several cookies so you can see similarities:




Even if I create a new user, or if I login again, the schema of the cookie is ALWAYS the same:

session_id="2|1:0|10:[TIMESTAMP???]|10:session_id|88:SHA-256 -> BASE64???|ASCII HEX???"

So those numbers "2|1", "0|10", "session_id|88" are not used to stablish the user.

I don't know if any of them can be used to establish if you are a simple user or admin, as I don't have any admin account.

Looking for more information about this cookie I've found that it must be created by Tornado, as I see other people using other applications with similar cookies: https://github.com/jupyter/help/issues/541




I can deduct that the name of the cookie is later repeated inside the cookie (for example session_id, username-localhost-8889, oauthenticator-state).

Why am I focusing on the session cookie? Because I've seen that it is pickled:

        def serialize(self):
        dump = {'session_id': self.session_id,
                'data': self.data,
                'duration': self.duration,
                'expires': self.expires,
                'ip_address': self.ip_address,
                'user_agent': self.user_agent,
                'security_model': self.security_model,
                'regeneration_interval': self.regeneration_interval,
                'next_regeneration': self.next_regeneration}
        return base64.encodestring(pickle.dumps(dump))

        def deserialize(datastring):
            return pickle.loads(base64.decodestring(datastring))

        def save(self):
            Write the session to Memcached. Session ID is used as
            key, value is constructed as colon separated values of
            serialized session, session expiry timestamp, ip address
            and User-Agent.
            The value is not stored indefinitely. It's expiration time
            in seconds is calculated as the difference between the saving
            time and session expiry.
            if not self.dirty:
            value = ':'.join((self.serialize(),
            # count how long should it last and then add or rewrite
            if self.expires is None:
                # set expiry 30 days, max for memcache
                # http://code.google.com/p/memcached/wiki/FAQ#What_are_the_limi
                # ts_on_setting_expire_time?_%28why_is_there_a_30_d
                    self.session_id, value, time=timedelta.max.seconds * 30)
                live_sec = self.expires - datetime.datetime.utcnow()
                    self.session_id, value, time=live_sec.seconds)
            self.dirty = False

        def load(session_id, connection):
            '''Load the session from storage.'''
                value = connection.get(session_id)
                if value:
                    data = value.split(':', 1)[0]
                    kwargs = MemcachedSession.deserialize(data)
                    return MemcachedSession(connection, **kwargs)
                return None
            return None

Based on "data = value.split(':', 1)[0]" I suppose that from that cookie it only takes "2|1" which is useless to deserialize... Maybe there is something that when the cookie is read its order is changed and then it tries to deserialize the end of the cookie (which is longer and could make sense)? I don't know, I've tried to decode and deserialize and I don't read anything useful.

I'm trying to inject a pickle code, which could be later executed and provide me with a reverse shell, but I haven't been successful.

Looking at the source code that I've been provided (which is not all the source code) I can read:

Session ID is used as key, value is constructed as colon separated values of serialized session, session expiry timestamp, ip address and User-Agent.

I thought that maybe I could provide a pickled reverse shell in my User-Agent data when I login (and the session cookie is created), but it doesn't work.

And if I modify anything on the session cookie, then it is not accepted by the application, so I suppose that it's signed somehow, but I don't realize how.

Any ideas on how to exploit this pickle, or to understand what the session cookie contains and how can I edit it?

I've tried tons of combinations, read about pickle reverse shells that work beautifully, and applied all my ideas but I can't exploit it.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.