3 ms·
Is there a setting I can change to turn off this "session -> code execution" feature?
by tedunangst 13y ago
Is there a setting I can change to turn off this "session -> code execution" feature?
- patio11 13y agoYou could, hypothetically, move from CookieStore to a different session store, but I am not positive that this will mitigate the vulnerability (by making it more difficult for the attacker to get write access to the session, not by making it more difficult to turn a session into code execution), and do not have a few hours to reacquaint myself with the code to give you a firmer answer there. I am weakly confident, on the basis of some spelunking in the Rails internals in February, that if you get attacker chosen data into the session you're uniformly hosed on (at least) Rails 2 and Rails 3.
- rmc 13y agoif you get attacker chosen data into the session you're uniformly hosed on (at least) Rails 2 and Rails 3. I wonder if you could expand on this? I'm not too knowledgeable about Rails or security, so I'd wonder how that works?
- patio11 13y agoLong story short: If a cookie is valid (HMAC signature matches what you'd expect given the cookie contents and your secret key), Rails (Rails 2) or Rack middleware (Rails 3) will attempt to use Marshal.load(txt) on the cookie contents to populate your session hash. You might naively assume that this creates a map of strings into other strings, but surprise, Marshal.load(txt) can create arbitrary object payloads and, through a code path which the margins of this comment are just slightly too thin to contain, allow you to do remote code execution. See: http://www.exploit-db.com/exploits/27527/ http://www.exploit-db.com/exploits/27527/ This can be done in an entirely automated fashion and requires no knowledge of the application other than the session's secret key.
- alinajaf 13y agoAnd Rails 4. The difference with Rails 4 is that the session is encrypted as well as HMAC'd, but it's still the case that as along as you have the token (or can otherwise craft a session) you're hosed.
- alinajaf 13y agoAs patio11 mentioned, moving off the CookieStore is a step in the right direction, with the understanding of course that you guard whatever you move to with your life. That means the db with the ActiveRecord store, or memcached if you're putting it in the cache store with the cache set to memcached. With memcached, be careful not to leave the port open to the internet if you're managing it on your own (it's designed to be used inside a trusted network, just like redis). In theory, an additional precaution one could take: change the default session serializer to `JSON`. By using `JSON` instead of `Marshal`, you're limited to storing strings, hashes and arrays in the session, but that's a good thing. The remote code execution vulnerability takes advantage of `Marshal` deserializing the session and loading objects deep within the Rails process in order to run arbitrary code. Take away that ability by using `JSON` instead of `Marshal` and you should no longer have to worry about this particular attack vector. After a brief spelunk of the Rails codebase (and not getting very far, my laptop bricked itself today) there doesn't seem to be an easy way to do this, apart from finding the instance of `ActiveSupport::MessageVerifier` in your rails process and then running something like `verifier.instance_variable_set(:@serializer, JSON)`.