Faking Session/Cookies?

前端 未结 3 527
余生分开走
余生分开走 2020-12-28 20:09

I\'m not exactly sure how the $_SESSION work in PHP. I assume it is a cookie on the browser matched up with an unique key on the server. Is it possible to fake

相关标签:
3条回答
  • 2020-12-28 20:19

    Sessions in PHP by default store the data in a file on the server (/tmp/) and store an identifier cookie usually PHPSESSID (it will be a hexadecimal number, e.g. f00f8c6e83cf2b9fe5a30878de8c3741).

    If you have someone else's identifier, then you could in theory use their session.

    However, most sites check to ensure the user agent is consistent and also regenerate the session identiifer every handful of requests, to mitigate this.

    As for guessing a session, it's possible, but extremely unlikely. It'd be easier to guess credit card numbers (smaller pool of characters (0-9 over 0-9a-f) and a checksum to validate it). Though of course you'd also need the expiry and security code.

    0 讨论(0)
  • 2020-12-28 20:21

    Properly implemented, session ids are very long and random enough to make guessing unfeasible (though if you were able to guess a particular user's session id then yes you would be acting as that user). However you can sniff and hijack sessions -- this is what firesheep does: http://en.wikipedia.org/wiki/Firesheep

    0 讨论(0)
  • 2020-12-28 20:24

    Yes.

    The only thing identifying a user is a pseudo-random value being sent along with each request. If an attacker can guess the right values to send, he can pose as somebody else.

    There are different ways to make this harder:

    • make session ids longer (more entropy, harder to guess)
    • check additional information like the user agent (essentially more entropy)
    • obviously: use a good random number generator
    • expire sessions sooner to give a smaller set of valid session ids at any one time
    • renew session ids often, even for valid ids
    • use SSL to encrypt all communication to avoid outright cookie hijacking
    0 讨论(0)
提交回复
热议问题