360杯資訊安全技術大賽Web第一題分析

來源:互聯網
上載者:User

原題如下,提示是 程式員的壞習慣

根據提示,在當前URL後加.bak,獲得源碼

<?phperror_reporting(0); function auth($password, $hidden_password){    $res=0;    if (isset($password) && $password!=""){                if ( $password == $hidden_password ){                        $res=1;                }    }    $_SESSION["logged"]=$res;    return $res;} function display($res){    $aff= "          <html>          <head>          </head>          <body>            <form action='' method='POST'>              Password               <input type='password' name='password' />                             <input type='submit' value='Login' />            </form>            <h3>".htmlentities($res)."</h3>          </body>          </html>";    return $aff;}session_start();if ( ! isset($_SESSION["logged"]) )    $_SESSION["logged"]=0; $aff="";include("config.inc.php"); $password=$_POST["password"];echo "<pre>";if (!ini_get("register_globals")) {    $superglobals = array($_SERVER, $_ENV,$_FILES, $_COOKIE, $_POST, $_GET);    if (isset($_SESSION)) {        array_unshift($superglobals, $_SESSION);    }    foreach ($superglobals as $superglobal) {        extract($superglobal, 0 );    }}echo "</pre>";if (( isset ($password) && $password!="" && auth($password,$hidden_password[360])==1) || (is_array($_SESSION) && $_SESSION["logged"]==1 ) ){    $aff=display("$hidden_password[360]");} else {    $aff=display("Try again");}echo $aff; ?>

經研究發現有變數覆蓋漏洞:
auth函數用來判斷使用者提交的password是否與程式中的hidden_password[360]相同,如果相同,則設定$_SESSION["logged"]=1,見由於hidden_password[360]可被覆蓋,因此構造如下連結:

http://localhost:8080/1.php?hidden_password[360]=1

在頁面開啟後,提交密碼為1

if (( isset ($password) && $password!="" && auth($password,$hidden_password[360])==1) || (is_array($_SESSION) && $_SESSION["logged"]==1 ) )

此句成立的條件是“使用者提交密碼不為空白並且與hidden_password[360]相同”或者“$_SESSION["logged"]==1”
在訪問上述連結後,hidden_password[360]被覆蓋為1,提交的密碼也為1,在函數auth中,$_SESSION["logged"]就會被設定,根據if成立的條件,此時再重新訪問http://localhost:8080/1.php,即可得到$hidden_password[360]的原值

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.