> For the complete documentation index, see [llms.txt](https://easpyy.gitbook.io/portswigger/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://easpyy.gitbook.io/portswigger/exploiting-nosql-operator-injection-to-bypass-authentication.md).

# Exploiting NoSQL operator injection to bypass authentication

Link: https\://portswigger.net/web-security/nosql-injection/lab-nosql-injection-bypass-authentication

Description:

The login functionality for this lab is powered by a MongoDB NoSQL database. It is vulnerable to NoSQL injection using MongoDB operators.

To solve the lab, log into the application as the `administrator` user.

You can log in to your own account using the following credentials: `wiener:peter`.

Preparation:

* Install extension browser Cookie-Editor

Proof of concept:

1. Analisa pada web taget<br>

   <figure><img src="https://261650435-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdAiS2nxqUmGSg5rZoOOl%2Fuploads%2F0HJd6HQFtD2X67CHJxPx%2Fimage.png?alt=media&amp;token=bb236478-b2b8-489e-8d4a-243b10ea8152" alt=""><figcaption></figcaption></figure>
2. Ketika diinjeksikan paylaod basic NoSQL bypass authentication tampil pesan kesalahan yang memungkinkan bahwa form login tersebut rentan terhadap NoSQL Injection<br>

   <figure><img src="https://261650435-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdAiS2nxqUmGSg5rZoOOl%2Fuploads%2FBe2JUV3MknT1EVVZ7zmU%2Fimage.png?alt=media&amp;token=92322017-81d4-440a-91cc-3a4ec878f245" alt=""><figcaption></figcaption></figure>

   <figure><img src="https://261650435-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdAiS2nxqUmGSg5rZoOOl%2Fuploads%2FXKpVGO1QxzTdKBGzpGBa%2Fimage.png?alt=media&amp;token=ca1d921c-f5f6-4920-9719-d925e8b8c355" alt=""><figcaption></figcaption></figure>
3. Ketika menginjeksikan payload bypass authentication menggunakan `{”$ne”: null}` pada parameter `password` dan menggunakan `wiener` untuk data username nya, maka berhasil login ke user `wiener` tanpa menggunakan password asli<br>

   <figure><img src="https://261650435-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdAiS2nxqUmGSg5rZoOOl%2Fuploads%2FhmmakhUowUvUAXHeZYW6%2Fimage.png?alt=media&amp;token=ae05291f-681c-49db-9fdd-33eafeceaf0d" alt=""><figcaption></figcaption></figure>
4. Namun ketika menggunakan teknik yang sama dengan username `administrator`, hal tersebut tidak berhasil dengan error `Invalid username or password`. Dapat disimpulkan bahwa akun `administrator` tersebut tidak menggunakan username `administrator`<br>

   <figure><img src="https://261650435-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdAiS2nxqUmGSg5rZoOOl%2Fuploads%2FyfHYbNyHKl7rRh87MaYb%2Fimage.png?alt=media&amp;token=1e4a8ee3-df81-44f1-aff2-fc7a5e007f29" alt=""><figcaption></figcaption></figure>
5. Untuk tetap dapat melakukan bypass authentication ke akun administrator dengan keadaan tidak mengetahui username lengkap dari username `administrator` dapat menggunakan payload injection `{”$regex”:”admin.*”}` pada parameter `username` dengan payload pada parameter `password` sama dengan langkah sebelumnya<br>

   <figure><img src="https://261650435-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdAiS2nxqUmGSg5rZoOOl%2Fuploads%2FkBXGEoUmYVUn2ioOsVB5%2Fimage.png?alt=media&amp;token=00720e6b-d88f-4346-9f29-8dfc957f1d49" alt=""><figcaption></figcaption></figure>
6. Seperti yang dapat dilihat pada gambar diatas menunjukan bahwa berhasil login ditandai didapatinya `session akun administrator`. Copy session tersebut, buka browser dan paste cookie session tersebut ke Cookie-Editor agar browser tersebut menggunakan session admin sehingga tangtangan lab ini berhasil terselesaikan<br>

   <figure><img src="https://261650435-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdAiS2nxqUmGSg5rZoOOl%2Fuploads%2F6oMx2xCrSGWAkHdwg7z3%2Fimage.png?alt=media&amp;token=8a6f70a7-53d6-4cee-a337-503976ad2395" alt=""><figcaption></figcaption></figure>

   <figure><img src="https://261650435-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdAiS2nxqUmGSg5rZoOOl%2Fuploads%2FOhUpWBH4CmD7yidRyZMW%2Fimage.png?alt=media&amp;token=ce15fe49-f17b-413a-9ff5-a5c9843c54a0" alt=""><figcaption></figcaption></figure>

Thanks, Stay Ethical & Happy Hacking! 🍻
