[題目]

The purpose of this challenge is to demonstrate the MITRE Top 25 programming flaw: 'Reliance on Untrusted Inputs in a Security Decision'.

 

The developer of the vulnerable application uses a flawed authorization mechanism allowing the user to control administrative access.

You have the vulnerable code below. See if you can spot the programming error.

 

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<%@ page import="inc.insecure.*" %>

<%

 

if(session.getAttribute("ch2loggedin")==null || !(boolean)session.getAttribute("ch2loggedin")){

        response.sendRedirect("ch2.jsp?loggedin=false");

}

else{

        String isAdmin=request.getParameter("isAdmin");

        if(isAdmin!=null && isAdmin.toLowerCase().equals("true")){

        //administration page logic here

        //...

    }

}

 

 

[題目說明]

  這一題是要我們根據以上的JSP Java Code 找出漏洞可以讓我們登入網頁後可以藉著改變網址參數存取管理員才能使用的資源。

[弱點提示]

 

    The application uses a protection mechanism that relies on the existence or values of an input, but the input can be modified by an untrusted actor in a way that bypasses the protection mechanism.

From MITRE CWE 807

 

  該弱點是指雖然應用程式有保護機制,但該保護機制是建立在可輸入的值的基礎,然而該職有可能透過被修改成可繞過安全機制的值,而使重要資源被存取。

 

[解答]

 

  1. 進入網頁: https://abc.xxx.elasticbeanstalk.com/ch2.jsp
  2. 輸入網頁上的一班使用者帳密登入,登入後看到如下頁面。 此時停留在: : https://abc.xxx.elasticbeanstalk.com/ch2loggedin.jsp?isAdmin=false 頁面。
  3. 只要把 URL 的 isAdmin=false 改成 isAdmin = true,便可以破解網頁進入管理者頁面。 https://abc.xxx.elasticbeanstalk.com/ch2loggedin.jsp?isAdmin=true

[安全原理]

  該弱點被利用的關鍵在於程式碼中檢查Authentication 的code所用的input存在可被hacker以簡易的方式給予不會被攔阻的值域提供程式檢驗而通過的安全檢查的風險。

  例如程式會查驗參數 A=false 時則無權限,而該參數 A的值確可以透過在url中直接給予,因此只要hacker在url中將parameter A設為true即可以通過頁面檢查邏輯。

  從程式碼看亦是如此:

  code可以看到頁面會檢查url parameter “isAdmin”是否不為null( false)或true,若符合該條件則給予瀏覽頁面的權限,所以只要在url上把isAdmin指定為任何非null與false的值便可以通過檢查存取該頁面。

 

2019219日星期二

arrow
arrow

    jackterrylau 發表在 痞客邦 留言(0) 人氣()