本期主題為會(huì)話固定(CWE-384: Session Fixation)漏洞的相關(guān)介紹。
一、什么是會(huì)話固定?
對用戶進(jìn)行身份鑒別并建立一個(gè)新的會(huì)話時(shí)沒有讓原來的會(huì)話失敗。
二、會(huì)話固定漏洞的構(gòu)成條件有哪些?
當(dāng)用戶成功驗(yàn)證而應(yīng)用程序不更新cookie時(shí),這個(gè)時(shí)候就存在會(huì)話固定漏洞。
HTTP的無狀態(tài)性,導(dǎo)致Web應(yīng)用程序必須使用會(huì)話機(jī)制來識(shí)別用戶。如果用戶未登錄時(shí)的會(huì)話ID和登錄后的會(huì)話ID保持一致,那么攻擊者可以迫使受害者使用一個(gè)已知(有效)的會(huì)話ID,當(dāng)受害者通過身份驗(yàn)證,攻擊者就可以利用這個(gè)會(huì)話ID進(jìn)入驗(yàn)證后的會(huì)話(登錄狀態(tài))。
三、會(huì)話固定漏洞會(huì)造成哪些后果?
攻擊者可誘使用戶在攻擊者創(chuàng)建的會(huì)話基礎(chǔ)上進(jìn)行身份鑒別,從而竊取用戶通過身份鑒別的會(huì)話并冒充用戶進(jìn)行惡意操作。
四、會(huì)話固定漏洞的防范和修補(bǔ)方法有哪些?
對用戶進(jìn)行身份鑒別并建立一個(gè)新的會(huì)話時(shí)讓原來的會(huì)話失效。核心代碼如下。
// 會(huì)話失效
session.invalidate();
// 會(huì)話重建
session=request.getSession(true);
五、會(huì)話固定漏洞樣例:
protected WebSession updateSession_DELETEME(HttpServletRequest request,HttpServletResponse response, ServletContext context)
{
HttpSession hs;
hs = request.getSession(true);
//System.out.println( "Entering Session_id: " + hs.getId() );
// dumpSession( hs );
// Make a temporary session to avoid the concurreny issue
// in WebSession
WebSession session = new WebSession(this, context);
WebSession realSession = null;
Object o = hs.getAttribute(WebSession.SESSION);
if ((o != null) && o instanceof WebSession)
{
realSession = (WebSession) o;
}
session.setCurrentScreen(realSession.getCurrentScreen());
session.setCourse(realSession.getCourse());
session.setRequest(request);
// to authenticate
//System.out.println( "Leaving Session_id: " + hs.getId() );
//dumpSession( hs ); return (session);
}
……
使用Wukong靜態(tài)代碼安全檢測上述程序代碼,則可以發(fā)現(xiàn)代碼中存在著“會(huì)話固定”的安全漏洞。請見下圖:
“會(huì)話固定”在CWE中被編號(hào)為:CWE-384:Session Fixation