Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

php - Faking Session/Cookies?

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 that and by pass logins that only uses sessions to identify the user.

If $_SESSION doesn't work like that, can someone potentially fake cookies and bypass logins?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...