{"id":130,"date":"2008-09-19T13:46:00","date_gmt":"2008-09-19T13:46:00","guid":{"rendered":""},"modified":"2011-04-25T08:39:38","modified_gmt":"2011-04-25T08:39:38","slug":"session-fixation-%e6%94%bb%e9%98%b2%e5%ae%9e%e6%88%98","status":"publish","type":"post","link":"https:\/\/www.inbreak.net\/archives\/130.html","title":{"rendered":"Session Fixation \u653b\u9632\u5b9e\u6218"},"content":{"rendered":"
\n
\n

\u3000\u3000\u3010IT168 \u4e13\u7a3f\u3011<\/strong>\u6700\u8fd1\u7b14\u8005\u5728\u7f51\u4e0a\u770b\u5230\u4e00\u4e2a\u65b0\u6587\u7ae0\u300aJSESSIONID Regeneration in Struts 2<\/a>\u300b\uff0c\u8bb2\u7684\u662f\u4e00\u6bb5\u4ee3\u7801\uff0c\u5728STRUTS 2\u6846\u67b6\u4e2d\uff0c\u9632\u5fa1Session Fixation\u653b\u51fb\u3002\u7b14\u8005\u6bd4\u8f83\u8001\u571f\uff0c\u770b\u4e0d\u61c2\u82f1\u6587\uff0c\u8fd8\u597d\u80fd\u770b\u61c2\u4ee3\u7801\uff0c\u53d1\u73b0\u8fd9\u662f\u4e00\u79cd\u5e73\u65f6\u5f00\u53d1\u4e2d(\u81f3\u5c11\u81ea\u5df1\u662f\u8fd9\u6837)\uff0c\u4ece\u6765\u6ca1\u6ce8\u610f\u8fc7\u7684\u653b\u51fb\u3002\u5173\u4e8e\u8fd9\u79cd\u653b\u51fb\uff0c\u523a\u5728\u81ea\u5df1\u535a\u5ba2\u4e0a\u5199\u4e86\u7bc7\u6587\u7ae0\u300a\u5173\u4e8eSession Fixation<\/a>\u300b\u3002\u6211\u5728\u90ae\u4ef6\u5217\u8868\uff0c\u548c\u6587\u7ae0\u540e\u9762\u8ddf\u5e16\u8ba8\u8bba\u4e86\u4e0b\uff0c\u4f46\u662f\u4ecd\u7136\u611f\u89c9\u81ea\u5df1\u8bf4\u7684\u4e0d\u662f\u5f88\u6e05\u6670\uff0c\u6bd5\u7adf\u6ca1\u6709\u5b9e\u6218\uff0c\u6240\u4ee5\u5b9e\u8df5\u4e86\u4e00\u4e0b\u81ea\u5df1\u7684\u60f3\u6cd5\uff0c\u91cd\u65b0\u5199\u7bc7\u6587\u7ae0\u8865\u5145\u4e0b\u3002\u6ce8\uff1a\u4e3a\u4e86\u4fdd\u8bc1\u8d28\u91cf\uff0c\u672c\u6587\u5047\u8bbe\u8bfb\u8005\u5bf9cookie\u548csession\u57fa\u672c\u6982\u5ff5\u548c\u7279\u6027\u5df2\u7ecf\u638c\u63e1\u3002<\/p>\n

\u3000\u3000\u4f5c\u8005\u662f\u4ece\u9632\u5fa1\u4ee3\u7801\u4e2d\uff0c\u53d1\u73b0\u8fd9\u79cd\u653b\u51fb\u7684\u5b58\u5728\uff0c\u6240\u4ee5\uff0c\u6211\u4eec\u5148\u770b\u9632\u5fa1\u7684\u4ee3\u7801\uff1a<\/p>\n

 <\/p>\n

\n
Java\u4ee3\u7801<\/div>\n
    \n
  1. public<\/span> <\/span>void<\/span> doGet(HttpServletRequest request, HttpServletResponse response)   <\/span><\/span><\/li>\n
  2.      <\/span>throws<\/span> ServletException, IOException {   <\/span><\/li>\n
  3.      <\/span>if<\/span>(userid.equals(<\/span>"admin"<\/span>) && password.equals(<\/span>"admin"<\/span>)) {   <\/span><\/li>\n
  4.         request.getSession().invalidate();   <\/span><\/li>\n
  5.         HttpSession session = request.getSession(<\/span>true<\/span>);   <\/span><\/li>\n
  6.         session.setAttribute(<\/span>"AUTHENTICATED"<\/span>, <\/span>new<\/span> Boolean(<\/span>true<\/span>));   <\/span><\/li>\n
  7.         response.sendRedirect(<\/span>"PageRequiringAuthentication.jsp"<\/span>);   <\/span><\/li>\n
  8. \/\/Additional Code Would Normally Follow<\/span>  <\/span><\/li>\n<\/ol>\n<\/div>\n

    \u3000\u3000\u8fd9\u662f\u4e00\u4e2a\u5f88\u5e38\u89c1\u7684\u767b\u5f55\u8fc7\u7a0b\uff0c\u9996\u5148\u9a8c\u8bc1\u7528\u6237\u540d\u5bc6\u7801\u662f\u5426\u6b63\u786e\uff0c\u6b63\u786e\u540e\uff0c\u5e72\u6389\u5f53\u524dsession\u3002\u7136\u540e\u91cd\u65b0\u83b7\u53d6\u4e00\u4e2a\u65b0session\uff0c\u7ee7\u7eed\u6267\u884c\u8d4b\u4e88\u7528\u6237\u7ba1\u7406\u6743\u9650\u3002\u5173\u952e\u5c31\u662f\uff0c\u8fd9\u6bb5\u4ee3\u7801\u5e72\u6389\u4e86\u5f53\u524d\u7684session\u3002\u5f53\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u4e4b\u95f4\u7684session\u9500\u6bc1\u65f6\uff0c\u56e0\u4e3a\u5ba2\u6237\u7aef\u4ecd\u7136\u5411\u670d\u52a1\u5668\u53d1\u9001\u6570\u636e\uff0c\u6240\u4ee5\u670d\u52a1\u5668\u4f1a\u81ea\u52a8\u7684\u65b0\u751f\u6210\u4e00\u4e2asession\u3002\u4e3a\u4ec0\u4e48\u4ee5\u524d\u7684session\u4e0d\u80fd\u7528\u5462\uff1f<\/p>\n

    \u3000\u3000\u5728\u4f5c\u8005\u521a\u770b\u5230\u90ae\u4ef6\u7684\u65f6\u5019\uff0c\u4e00\u76f4\u770b\u4e0d\u660e\u767d\uff0c\u56e0\u4e3a\u7ad9\u5728\u7a0b\u5e8f\u5458\u7684\u89d2\u5ea6\uff0c\u4f5c\u8005\u4e0d\u77e5\u9053\u4e3a\u5565\u975e\u8981\u8ba9session\u9500\u6bc1\u4e86\u3002\u5982\u679c\u4e0d\u6d88\u6bc1session\uff0c\u7a0b\u5e8f\u4e00\u6837\u6b63\u786e\u6267\u884c\uff0c\u653b\u51fb\u8005\u4e0d\u77e5\u9053\u7ba1\u7406\u5458\u5bc6\u7801\uff0c\u4e00\u6837\u8fdb\u4e0d\u6765\u3002\u5982\u679c\u8fd9\u4e2a\u4eba\u77e5\u9053\u7ba1\u7406\u5458\u5bc6\u7801\uff0c\u90a3\u4e48\u5bf9\u4e8e\u7a0b\u5e8f\u672c\u8eab\u6765\u8bf4\uff0c\u8fd9\u4e2a\u4eba\u5c31\u5df2\u7ecf\u662f\u4e00\u4e2a\u7a0b\u5e8f\u6240\u671f\u671b\u7684\u7ba1\u7406\u5458\u4e86\u3002\u4f46\u662f\u6362\u4e2a\u89d2\u5ea6\u60f3\u4e00\u4e0b\uff0c\u7ba1\u7406\u5458\u5728\u7ba1\u7406\u7f51\u7ad9\u7684\u65f6\u5019\uff0c\u901a\u5e38\u90fd\u505a\u4e9b\u4ec0\u4e48\uff1f\u5728\u7ba1\u7406\u5458\u767b\u9646\u524d\uff0c\u4ed6\u8fd8\u53ea\u662f\u4e00\u4e2a\u666e\u901a\u7684\u6d4f\u89c8\u8005\uff0c\u4f1a\u53bb\u6d4f\u89c8\u4e00\u4e9b\u516c\u5f00\u9875\u9762\uff0c\u4ed6\u53ef\u80fd\u5728\u54ea\u91cc\u53d1\u73b0\u4e86\u95ee\u9898\uff0c\u9700\u8981\u8fdb\u540e\u53f0\u5904\u7406\u4e00\u4e0b\uff0c\u4e8e\u662f\u4ed6\u5c31\u767b\u5f55\u4e86\u3002\u5c31\u5728\u8fd9\u4e2a\u5f88\u666e\u901a\u7684\u8fc7\u7a0b\u4e2d\uff0c\u5982\u679c\u7a0b\u5e8f\u6ca1\u6709\u5728\u8ba4\u8bc1\u6210\u529f\u540e\uff0c\u9500\u6bc1session\uff0c\u5219\u7ba1\u7406\u5458\u5728\u767b\u5f55\u524d\u548c\u767b\u5f55\u540e\uff0csession\u662f\u540c\u4e00\u4e2a\u3002\u5047\u8bbe\u6211\u4eec\u80fd\u591f\u5728\u524d\u53f0\uff0c\u4f7f\u7528\u4e86XSS\u4e00\u7c7b\u624b\u6bb5\uff0c\u83b7\u5f97\u4e86\u8fd9\u4e2a session\uff0c\u7b49\u4ed6\u4e00\u65e6\u767b\u5f55\uff0c\u5c31“\u91ce\u9e21\u53d8\u51e4\u51f0”\u4e86\u3002<\/p>\n

    \u3000\u3000\u5728\u4ee5\u5f80\u7684XSS\u653b\u51fb\u3001CSRF\u653b\u51fb\u4e2d\uff0c\u6211\u4eec\u603b\u662f\u628a\u76ee\u5149\u653e\u5728\u7ba1\u7406\u5458\u767b\u9646\u540e\uff0cXSS \u4ed6\u3001CSRF\u4ed6\u3002\u90fd\u6ca1\u6709\u60f3\u8fc7\uff0c\u5982\u679c\u7ba1\u7406\u5458\u767b\u9646\u540e\uff0c\u4e0d\u6d4f\u89c8XSS\u9875\u9762\uff0c\u600e\u4e48\u653b\u51fb\uff1f\u770b\u5230\u8fd9\u6bb5\u9632\u5fa1\u4ee3\u7801\uff0c\u4f5c\u8005\u7a81\u7136\u60f3\u5230\u4e86\u4e00\u79cd\u653b\u51fb\u624b\u6bb5\uff0c\u53ea\u8981\u7ba1\u7406\u5458\u66fe\u7ecf\u6d4f\u89c8\u8fc7 XSS\u9875\u9762\uff08\u8fd9\u65f6\u5019\u53ea\u662f\u666e\u901a\u7528\u6237\uff09\uff0c\u5c31\u80fd\u5728\u4ed6\u767b\u5f55\u540e\uff0c\u5373\u4f7f\u4e0d\u518d\u6d4f\u89c8XSS\u9875\u9762\uff0c\u4e5f\u80fd\u653b\u51fb\u5230\u3002<\/p>\n

    \u3000\u3000\u4e3a\u4e86\u8be6\u7ec6\u7684\u63cf\u8ff0\u548c\u91cd\u73b0\u8fd9\u79cd\u653b\u51fb\u65b9\u5f0f\uff0c\u4f5c\u8005\u7279\u610f\u4e0b\u8f7d\u4e86\u52a8\u7f51BBS 8\u6700\u65b0\u7248\u672c\u3002\u9996\u5148\u505a\u4e24\u4e2a\u5b9e\u9a8c\uff0c\u6765\u9a8c\u8bc1\u52a8\u7f51\u662f\u5426\u5b58\u5728\u8fd9\u4e2a\u6f0f\u6d1e\uff1a<\/p>\n

    \u3000\u30001\u3001\u5728\u767b\u5f55\u524d\uff0c\u67e5\u770b\u81ea\u5df1\u7684SESSIONID\uff0c\u7ba1\u7406\u5458\u524d\u53f0\u767b\u5f55\u540e\uff0c\u518d\u67e5\u770bSESSIONID\uff0c\u767b\u5f55\u540e\u53f0\uff0c\u518d\u67e5\u770b\u3002\u53d1\u73b0\u8fd9\u4e2a\u503c\u6ca1\u6709\u53d8\u52a8\u3002\u5c31\u662f\u8bf4\u52a8\u7f51\u5b58\u5728\u8fd9\u4e2a\u6f0f\u6d1e\uff0c\u767b\u5f55\u524d\u540e\uff0cSESSIONID\u6ca1\u6709\u53d8\u3002<\/p>\n

    \u3000\u30002\u3001\u4e3a\u4e86\u4fdd\u8bc1\u5b9e\u9a8c\u6210\u529f\uff0c\u9700\u8981\u77e5\u9053\u52a8\u7f51\u7684\u540e\u53f0\u662f\u5426\u4ec5\u4ec5\u901a\u8fc7SESSION\u6765\u9a8c\u8bc1\u8eab\u4efd\u3002\u767b\u5f55\u540e\uff0c\u6293\u5305\u3002\u4fee\u6539\u5305\u4e2d\u7684\u4fe1\u606f\uff0c\u4fee\u6539username\uff0c\u63d0\u4ea4\uff0c\u8fd4\u56de\u6570\u636e\u8868\u660e\u53ef\u4ee5\u540c\u8fc7\u3002\u518d\u4fee\u6539SESSIONID\uff0c\u5374\u51fa\u73b0“\u672c\u9875\u9762\u4e3a\u7ba1\u7406\u5458\u4e13\u3002\u3002\u3002”\u5b57\u6837\uff0c\u6ca1\u6709\u901a\u8fc7\u8ba4\u8bc1\u3002\u8fd9\u8bf4\u660e\u52a8\u7f51\u540e\u53f0\u662f\u4ec5\u4ec5\u901a\u8fc7session\u9a8c\u8bc1\u7684\uff0c\u800c\u4e0d\u662fcookie\u3002<\/p>\n

    \u3000\u3000\u8bc1\u660e\u4e86\u8fd9\u4e2a\u6f0f\u6d1e\u7684\u5b58\u5728\uff0c\u4e0b\u9762\u5c31\u5229\u7528\u8fd9\u4e2a\u6f0f\u6d1e\uff0c\u653b\u51fb\u767b\u5f55\u524d\u7684\u7ba1\u7406\u5458\u3002\u52a8\u7f51\u8bba\u575b\u7684\u7528\u6237\u8eab\u4efd\u6a21\u5f0f\uff0c\u53ef\u4ee5\u5f88\u597d\u7684\u8be0\u91ca\u8fd9\u79cd\u653b\u51fb\uff0c\u7528\u8fc7\u52a8\u7f51\u7684\u8bfb\u8005\u90fd\u77e5\u9053\uff0c\u6d4f\u89c8\u52a8\u7f51\u7684\u7528\u6237\u5206\u4e3a\u4ee5\u4e0b\u51e0\u79cd\u7ea7\u522b\uff1a“\u672a\u6ce8\u518c\u7528\u6237”\u3001“\u6ce8\u518c\u7528\u6237”\u3001“\u524d\u53f0\u7ba1\u7406\u5458”\u3001“\u540e\u53f0\u7ba1\u7406\u5458”\u3002\u6211\u4eec\u5148\u67b6\u8bbe\u597d\u653b\u51fb\u73af\u5883\uff0c\u4e4b\u540e\u8ba9\u4e00\u4e2a\u672a\u767b\u9646\u7684\u7ba1\u7406\u5458\uff0c\u6d4f\u89c8\u8bba\u575b\u7684XSS\u9875\u9762\uff0c\u4e4b\u540e\u767b\u5f55\u5230\u540e\u53f0\u3002<\/p>\n

    \n

    \u3000\u3000\u603b\u4f53\u6765\u770b\uff0c\u5229\u7528\u8fd9\u6837\u7684\u6f0f\u6d1e\uff0c\u9700\u8981\u4ee5\u4e0b\u4e00\u4e9b\u4e1c\u897f\uff1a<\/p>\n

    \u3000\u30001\u3001a.php\uff0c\u4e00\u4e2a\u811a\u672c\uff0c\u7528\u6765\u63a5\u6536XSS\u9875\u9762\u4f20\u6765\u7684SESSIONID\uff0c\u7136\u540e\u4fdd\u5b58\u5728haha.txt\uff0c\u53ef\u4ee5\u653e\u5728\u4efb\u4f55\u4e00\u4e2a\u652f\u6301php\u7684\u7a7a\u95f4\u91cc\u3002<\/p>\n

    \u3000\u30002\u3001go.py\uff0c\u6ca1\u96945\u79d2\uff0c\u8bf7\u6c42\u4e00\u6b21haha.txt\uff0c\u83b7\u5f97SESSIONID\u503c\u3002\u4e4b\u540e\u628a\u83b7\u5f97\u7684SESSIONID\u503c\u653e\u5165\u8bf7\u6c42\u7684COOKIE\u4e2d\uff0c\u8bf7\u6c42\u540e\u53f0\u9875\u9762\u7684“\u6dfb\u52a0\u7ba1\u7406\u5458\u529f\u80fd”\u3002<\/p>\n

    \u3000\u30003\u3001\u4e00\u4e2a\u524d\u53f0\u7684XSS\u6f0f\u6d1e\uff0c\u8fd9\u4e2a\u6f0f\u6d1e\u6211\u4eec\u81ea\u5df1\u53ef\u4ee5\u6784\u9020\u51fa\u6765\u3002<\/p>\n

    \u3000\u3000\u4f5c\u8005\u4e3a\u4e86\u4ec5\u4ec5\u8bf4\u660e\u8fd9\u4e2a\u95ee\u9898\uff0c\u800c\u4e0d\u662f\u5927\u91cf\u7684\u5236\u9020\u653b\u51fb\uff0c\u6240\u4ee5\u5355\u72ec\u4e3a\u52a8\u7f51\u5199\u4e86\u4e2a\u5bf9\u5e94\u7684\u811a\u672c\uff0cgo.py\u8fd9\u4e2a\u811a\u672c\uff0c\u8bf7\u6c42\u4e86\u52a8\u7f51\u540e\u53f0\u7684“\u6dfb\u52a0\u7ba1\u7406\u5458\u529f\u80fd”\u3002\u4ed6\u4f1a\u4e00\u76f4\u53bb\u8bf7\u6c42\uff0c\u4e0d\u7ba1\u7ba1\u7406\u5458\u6709\u6ca1\u6709\u767b\u5f55\uff0c\u5728\u767b\u5f55\u524d\uff0c\u4f1a\u6536\u5230“\u672c\u9875\u9762\u4e3a\u7ba1\u7406\u5458\u4e13\u3002\u3002\u3002”\u5b57\u6837\u3002\u4f46\u662f\u7ba1\u7406\u5458\u4e00\u65e6\u767b\u5f55\uff0c\u5c31\u4f1a\u8bf7\u6c42\u6210\u529f\u8fd9\u4e2a\u529f\u80fd\u3002<\/p>\n

    \u3000\u3000\u4e0b\u56fe\u53ef\u4ee5\u8bf4\u660e\u8fd9\u6b21\u6a21\u62df\u5b9e\u9a8c\uff1a<\/p>\n

    \"1.jpg\"<\/a><\/p>\n

    \u3000\u3000\u7b2c\u4e00\u6b65\u3002\u9996\u5148\u67b6\u8bbe\u597d\u8f85\u52a9\u653b\u51fb\u7684\u670d\u52a1\u5668\uff0c\u670d\u52a1\u5668\u4e2d\u6709\u4e24\u4e2a\u6587\u4ef6\uff0c\u4e00\u4e2a\u662fa.php\u3002\u8fd9\u4e2a\u6587\u4ef6\u7528\u6765\u63a5\u6536XSS\u53d1\u6765\u7684SESSIONID\u4fe1\u606f\uff0c\u7136\u540e\u4fdd\u5b58\u4e3ahaha.txt\u3002<\/p>\n

    \u3000\u3000\u7b2c\u4e8c\u6b65\u3002\u6267\u884cgo.py\u3002\u8fd9\u4e2a\u6587\u4ef6\u4f1a\u6bcf\u96945\u79d2\uff0c\u8bf7\u6c42\u4e00\u6b21haha.txt\uff0c\u8bfb\u53d6\u5176\u4e2d\u7684\u6570\u636e\uff0c\u89e3\u6790\u4e3a\u5bf9\u5e94\u7684SESSIONID\uff0c\u628aSESSIONID\u653e\u5728\u53d1\u52a8\u5305\u7684COOKIE\u4e2d\uff0c\u4e4b\u540e\u8bf7\u6c42\u4e00\u6b21“\u6dfb\u52a0\u7ba1\u7406\u5458”\u8fd9\u4e2a\u529f\u80fd\u3002<\/p>\n

    \u3000\u3000\u7ba1\u7406\u5458\u767b\u5f55\u540e\u53f0\u4e4b\u540e\uff0cSESSIONID\u5c31\u4f1a\u6210\u4e3a\u4e86\u4e00\u4e2a\u53ef\u4ee5\u901a\u8fc7\u8bba\u575b\u9a8c\u8bc1\u7684SESSIONID\uff0c\u8fd9\u65f6\u5019\u7684\u8bf7\u6c42\u4f1a\u6210\u4e3a\u5408\u6cd5\u8bf7\u6c42\uff0c\u767b\u5f55\u4e4b\u524d\u7684\u8bf7\u6c42\uff0c\u5168\u90fd\u662f\u5783\u573e\u6570\u636e\u3002\u5728\u6574\u4e2a\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u8981\u6c42\u7ba1\u7406\u5458\u5728\u767b\u5f55\u524d\u6d4f\u89c8\u4e00\u6b21XSS\u9875\u9762\uff0c\u7136\u540e\u767b\u9646\u3002\u767b\u5f55\u540e\uff0c\u5927\u698215\u79d2\u7684\u65f6\u5019\uff0c\u5c31\u53ef\u4ee5\u9000\u51fa\u4e86\u3002\u8fd9\u70b9\u65f6\u95f4\uff0c\u6211\u4eec\u7684\u653b\u51fb\uff0c\u5df2\u7ecf\u6210\u529f\u3002<\/p>\n

    \u3000\u3000\u8bf7\u6ce8\u610f\uff0c\u8fd9\u6b21\u653b\u51fb\u7684\u6f14\u793a\u4e2d\uff0c\u91cd\u70b9\u4e0d\u662f\u52a8\u7f51\u51fa\u73b0\u4e86XSS\u6f0f\u6d1e\uff0c\u800c\u662fSession Fixation\uff0c\u6240\u4ee5\u6211\u4eec\u5728\u524d\u53f0\u5047\u8bbe\u4ed6\u51fa\u73b0\u4e86XSS\u6f0f\u6d1e\u3002\u5236\u9020\u8fd9\u4e2a\u6f0f\u6d1e\u5f88\u7b80\u5355\uff0c\u8bba\u575b\u540e\u53f0\u6709\u4e2a\u7ed9\u7248\u9762\u52a0“\u672c\u7248\u7248\u89c4”\u7684\u529f\u80fd\uff0c\u652f\u6301HTML\u3002\u628aXSS\u7684\u5185\u5bb9\u653e\u8fd9\u91cc\uff1a<\/p>\n