代碼閱讀總結之ASP.NET StartKit TimeTracker(角色許可權之捉蟲筆記)

來源:互聯網
上載者:User

相關文章導航
  1. Sql Server2005 Transact-SQL 新兵器學習總結之-總結
  2. Flex,Fms3相關文章索引
  3. FlexAir開源版-全球免費群組視訊聊天室,免費網路遠程群組視訊會議系統((Flex,Fms3聯合開發))<視訊交談,會議開發執行個體8>

 

在ASP.NET StartKit TimeTracker中由於程式設計上的小失誤,我們可以利用這個BUG來達到越權訪問aspx頁面的能力.

我們都知道該系統定義了三種角色,分別為
Administrator(管理員)
Project Manager(專案管理者)
Consultant(顧問)

只有Administrator角色的使用者才可以訪問管理資訊頁面(ProjectList.aspx)

現在我來描述一下錯誤現象:

現在我有一個管理員的帳戶ai_ai@126.com.
我們先用這個帳戶登陸,去建立一個Consultant角色的帳戶:ai_c@126.com
然後馬上關閉瀏覽器.(注意我這裡說的關閉是用MOUSE點擊瀏覽器關閉按鈕而不是用程式提供的登出按鈕)
再開啟瀏覽器進入登陸頁,用帳戶:ai_c@126.com登陸系統.
這時我們就可以利用顧問角色的帳戶訪問管理資訊頁面
http://localhost/TTWebCSVS_cn/ProjectList.aspx?index=2

這個BUG豈不是和系統角色存取權限相背.

現在讓我們來找蟲
我們可以看到該系統的登陸使用者角色資訊是存放在一個COOKIE中的.
資料存放前進行了加密,利用了類FormsAuthentication.Encrypt的靜態方法.
該COOKIE的名稱在Global中定義為一個常量:
public const string UserRoles = "userroles"
這就是BUG之一

現在我們再看Global中Application_AuthenticateRequest事件中另一段代碼:
Response.Cookies[UserRoles].Value = cookieStr;
Response.Cookies[UserRoles].Path = "/";
Response.Cookies[UserRoles].Expires = DateTime.Now.AddMinutes(1);
從以上我們可以得知,該COOKIE的有效時間是一分鐘.
這樣我們在前一登陸帳戶關閉後,一分鐘內馬上利用另一帳戶登陸,這樣後面的帳戶可以取到前一帳戶的角色資訊.
因為2個登陸帳戶用的是同一個叫userroles的COOKIE
這又是BUG之一

為瞭解決這個BUG,我們可以對程式越微修改
就是把COOKIE名稱唯一化.

在protected void Application_AuthenticateRequest(Object sender, EventArgs e)

在代碼
if (Request.IsAuthenticated == true) 
{
後面添加
string UserRoles=Global.UserRoles+Context.User.Identity.Name;
這樣可以保證每個登陸帳戶的角色資訊COOKIE名稱不一樣.

同時注意還要修改,退出按鈕事件 (Banner.ascx.cs中)

private void LogOff_Click(object sender, System.EventArgs e)
{
function onclick()
{
function onclick()
{
this.style.display='none'; Codehighlighter1_63_482_Open_Text.style.display='none'; Codehighlighter1_63_482_Closed_Image.style.display='inline'; Codehighlighter1_63_482_Closed_Text.style.display='inline';
}
}
}" id="Codehighlighter1_63_482_Open_Image">{
function onclick()
{
function onclick()
{
this.style.display='none'; Codehighlighter1_63_482_Closed_Text.style.display='none'; Codehighlighter1_63_482_Open_Image.style.display='inline'; Codehighlighter1_63_482_Open_Text.style.display='inline';
}
}
}" id="Codehighlighter1_63_482_Closed_Image" style="DISPLAY: none">        {
            FormsAuthentication.SignOut();

            string UserRoles=Global.UserRoles+Context.User.Identity.Name;
            // Invalidate roles token
            Response.Cookies[UserRoles].Value = "";
            Response.Cookies[UserRoles].Path = "/";
            Response.Cookies[UserRoles].Expires = new System.DateTime(1999, 10, 12);

            Context.User = null;
            Response.Redirect("Default.aspx", false);
        }

 

當然還可以有其他解決辦法
例如把登陸使用者角色資訊資料放到系統的身分識別驗證cookie的身份驗票的UserData(Cookie中儲存的使用者定義字串)中

具體實現可以參考我的另一文章:
代碼閱讀總結之ASP.NET StartKit TimeTracker(角色許可權)
http://www.cnblogs.com/aierong/archive/2004/12/21/79966.html

謝謝!

收藏與分享

收藏到QQ書籤  添加到百度搜藏 {
function onclick()
{
window.open('http://myweb.cn.yahoo.com/popadd.html?url='+encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(document.title), 'Yahoo','scrollbars=yes,width=440,height=440,left=80,top=80,status=yes,resizable=yes');
}
}">添加到雅虎收藏

RSS訂閱我 什麼是RSS?

     
        
     
     

東莞.net俱樂部

歡迎您的加入

相關關鍵詞:
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.