mirror of
https://github.com/carlospolop/hacktricks
synced 2025-02-16 22:18:27 +00:00
197 lines
10 KiB
Markdown
197 lines
10 KiB
Markdown
# 27017,27018 - Pentesting MongoDB
|
|
|
|
<details>
|
|
|
|
<summary><strong>Impara l'hacking di AWS da zero a eroe con</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
|
|
|
|
Altri modi per supportare HackTricks:
|
|
|
|
* Se vuoi vedere la tua **azienda pubblicizzata in HackTricks** o **scaricare HackTricks in PDF** Controlla i [**PIANI DI ABBONAMENTO**](https://github.com/sponsors/carlospolop)!
|
|
* Ottieni il [**merchandising ufficiale di PEASS & HackTricks**](https://peass.creator-spring.com)
|
|
* Scopri [**The PEASS Family**](https://opensea.io/collection/the-peass-family), la nostra collezione di esclusive [**NFT**](https://opensea.io/collection/the-peass-family)
|
|
* **Unisciti al** 💬 [**gruppo Discord**](https://discord.gg/hRep4RUj7f) o al [**gruppo Telegram**](https://t.me/peass) o **seguici** su **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
|
|
* **Condividi i tuoi trucchi di hacking inviando PR a** [**HackTricks**](https://github.com/carlospolop/hacktricks) e [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
|
|
|
|
</details>
|
|
|
|
<figure><img src="../../.gitbook/assets/image (1) (3) (1).png" alt=""><figcaption></figcaption></figure>
|
|
|
|
Unisciti al server [**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) per comunicare con hacker esperti e cacciatori di bug bounty!
|
|
|
|
**Insight sull'hacking**\
|
|
Interagisci con contenuti che approfondiscono l'emozione e le sfide dell'hacking
|
|
|
|
**Notizie sull'hacking in tempo reale**\
|
|
Resta aggiornato sul mondo dell'hacking frenetico attraverso notizie e approfondimenti in tempo reale
|
|
|
|
**Ultime notizie**\
|
|
Rimani informato sul lancio delle nuove bug bounty e sugli aggiornamenti cruciali della piattaforma
|
|
|
|
**Unisciti a noi su** [**Discord**](https://discord.com/invite/N3FrSbmwdy) e inizia a collaborare con i migliori hacker oggi stesso!
|
|
|
|
## Informazioni di base
|
|
|
|
**MongoDB** è un **sistema di gestione di database open source** che utilizza un **modello di database orientato ai documenti** per gestire diverse forme di dati. Offre flessibilità e scalabilità per la gestione di dati non strutturati o semi-strutturati in applicazioni come l'analisi dei big data e la gestione dei contenuti.
|
|
**Porta predefinita:** 27017, 27018
|
|
```
|
|
PORT STATE SERVICE VERSION
|
|
27017/tcp open mongodb MongoDB 2.6.9 2.6.9
|
|
```
|
|
## Enumerazione
|
|
|
|
### Manuale
|
|
```python
|
|
from pymongo import MongoClient
|
|
client = MongoClient(host, port, username=username, password=password)
|
|
client.server_info() #Basic info
|
|
#If you have admin access you can obtain more info
|
|
admin = client.admin
|
|
admin_info = admin.command("serverStatus")
|
|
cursor = client.list_databases()
|
|
for db in cursor:
|
|
print(db)
|
|
print(client[db["name"]].list_collection_names())
|
|
#If admin access, you could dump the database also
|
|
```
|
|
**Alcuni comandi MongoDB:**
|
|
|
|
```plaintext
|
|
- `show dbs`: Mostra tutti i database presenti nel server MongoDB.
|
|
- `use <database>`: Seleziona il database specificato per eseguire le operazioni successive.
|
|
- `show collections`: Mostra tutte le collezioni presenti nel database selezionato.
|
|
- `db.<collection>.find()`: Restituisce tutti i documenti presenti nella collezione specificata.
|
|
- `db.<collection>.findOne()`: Restituisce il primo documento trovato nella collezione specificata.
|
|
- `db.<collection>.insertOne(<document>)`: Inserisce un nuovo documento nella collezione specificata.
|
|
- `db.<collection>.updateOne(<filter>, <update>)`: Aggiorna il primo documento che soddisfa il filtro specificato nella collezione specificata.
|
|
- `db.<collection>.deleteOne(<filter>)`: Elimina il primo documento che soddisfa il filtro specificato nella collezione specificata.
|
|
```
|
|
|
|
Per ulteriori informazioni sui comandi MongoDB, consulta la documentazione ufficiale.
|
|
```bash
|
|
show dbs
|
|
use <db>
|
|
show collections
|
|
db.<collection>.find() #Dump the collection
|
|
db.<collection>.count() #Number of records of the collection
|
|
db.current.find({"username":"admin"}) #Find in current db the username admin
|
|
```
|
|
### Automatico
|
|
|
|
MongoDB is a NoSQL database that is commonly used in web applications. It runs on port 27017 by default. When performing a network service pentest, it is important to check if MongoDB is running on this port.
|
|
|
|
#### Checking for MongoDB
|
|
|
|
To check if MongoDB is running on port 27017, you can use the following command:
|
|
|
|
```
|
|
nmap -p 27017 <target_ip>
|
|
```
|
|
|
|
If MongoDB is running, you will see an open port result.
|
|
|
|
#### Exploiting MongoDB
|
|
|
|
Once you have confirmed that MongoDB is running, you can proceed to exploit it. There are several techniques that can be used to exploit MongoDB, including:
|
|
|
|
1. Default Credentials: MongoDB often has default credentials set, such as username: `admin` and password: `admin`. You can try these credentials to gain unauthorized access.
|
|
|
|
2. Injection Attacks: MongoDB is vulnerable to injection attacks, similar to SQL injection. You can try injecting malicious code to manipulate the database.
|
|
|
|
3. Unauthorized Access: MongoDB may have misconfigured access controls, allowing unauthorized users to access the database. You can try accessing the database without proper authentication.
|
|
|
|
4. File System Access: MongoDB allows users to store files in the database. If file system access is enabled, you can try accessing sensitive files stored in the database.
|
|
|
|
#### Prevention and Mitigation
|
|
|
|
To prevent MongoDB exploitation, it is important to follow security best practices, such as:
|
|
|
|
- Change default credentials and use strong, unique passwords.
|
|
- Implement proper access controls and authentication mechanisms.
|
|
- Regularly update and patch MongoDB to fix any known vulnerabilities.
|
|
- Monitor and log MongoDB activity for any suspicious behavior.
|
|
- Encrypt sensitive data stored in MongoDB to protect it from unauthorized access.
|
|
|
|
By following these practices, you can reduce the risk of MongoDB exploitation and protect your data from unauthorized access.
|
|
```bash
|
|
nmap -sV --script "mongo* and default" -p 27017 <IP> #By default all the nmap mongo enumerate scripts are used
|
|
```
|
|
### Shodan
|
|
|
|
* Tutti i mongodb: `"informazioni sul server mongodb"`
|
|
* Cerca i server mongodb completamente aperti: `"informazioni sul server mongodb" -"parzialmente abilitato"`
|
|
* Solo abilita parzialmente l'autenticazione: `"informazioni sul server mongodb" "parzialmente abilitato"`
|
|
|
|
## Accesso
|
|
|
|
Di default, mongo non richiede una password.\
|
|
**Admin** è un database mongo comune.
|
|
```bash
|
|
mongo <HOST>
|
|
mongo <HOST>:<PORT>
|
|
mongo <HOST>:<PORT>/<DB>
|
|
mongo <database> -u <username> -p '<password>'
|
|
```
|
|
Lo script nmap: _**mongodb-brute**_ verificherà se sono necessarie le credenziali.
|
|
```bash
|
|
nmap -n -sV --script mongodb-brute -p 27017 <ip>
|
|
```
|
|
### [**Forza bruta**](../generic-methodologies-and-resources/brute-force.md#mongo)
|
|
|
|
Guarda dentro _/opt/bitnami/mongodb/mongodb.conf_ per sapere se sono necessarie delle credenziali:
|
|
```bash
|
|
grep "noauth.*true" /opt/bitnami/mongodb/mongodb.conf | grep -v "^#" #Not needed
|
|
grep "auth.*true" /opt/bitnami/mongodb/mongodb.conf | grep -v "^#\|noauth" #Not needed
|
|
```
|
|
## Previsione degli Object ID di Mongo
|
|
|
|
Esempio [da qui](https://techkranti.com/idor-through-mongodb-object-ids-prediction/).
|
|
|
|
Gli Object ID di Mongo sono stringhe esadecimali di **12 byte**:
|
|
|
|
![http://techidiocy.com/_id-objectid-in-mongodb/](../.gitbook/assets/id-and-objectids-in-mongodb.png)
|
|
|
|
Ad esempio, ecco come possiamo analizzare un vero Object ID restituito da un'applicazione: 5f2459ac9fa6dc2500314019
|
|
|
|
1. 5f2459ac: 1596217772 in decimale = venerdì 31 luglio 2020 17:49:32
|
|
2. 9fa6dc: Identificatore della macchina
|
|
3. 2500: ID del processo
|
|
4. 314019: Un contatore incrementale
|
|
|
|
Degli elementi sopra, l'identificatore della macchina rimarrà lo stesso finché il database eseguirà la stessa macchina fisica/virtuale. L'ID del processo cambierà solo se il processo di MongoDB viene riavviato. Il timestamp verrà aggiornato ogni secondo. L'unico problema nel tentativo di indovinare gli Object ID semplicemente incrementando il contatore e i valori del timestamp, è il fatto che Mongo DB genera gli Object ID e assegna gli Object ID a livello di sistema.
|
|
|
|
Lo strumento [https://github.com/andresriancho/mongo-objectid-predict](https://github.com/andresriancho/mongo-objectid-predict), dato un Object ID di partenza (puoi creare un account e ottenere un ID di partenza), restituisce circa 1000 Object ID probabili che potrebbero essere stati assegnati agli oggetti successivi, quindi devi solo forzarli.
|
|
|
|
## Post
|
|
|
|
Se sei root puoi **modificare** il file **mongodb.conf** in modo che non siano necessarie le credenziali (_noauth = true_) e **effettuare il login senza credenziali**.
|
|
|
|
***
|
|
|
|
<figure><img src="../../.gitbook/assets/image (1) (3) (1).png" alt=""><figcaption></figcaption></figure>
|
|
|
|
Unisciti al server [**HackenProof Discord**](https://discord.com/invite/N3FrSbmwdy) per comunicare con hacker esperti e cacciatori di bug!
|
|
|
|
**Hacking Insights**\
|
|
Interagisci con contenuti che approfondiscono l'emozione e le sfide dell'hacking
|
|
|
|
**Notizie sull'hacking in tempo reale**\
|
|
Resta aggiornato sul mondo dell'hacking frenetico attraverso notizie e approfondimenti in tempo reale
|
|
|
|
**Ultime notizie**\
|
|
Rimani informato sui nuovi bug bounty in lancio e sugli aggiornamenti cruciali della piattaforma
|
|
|
|
**Unisciti a noi su** [**Discord**](https://discord.com/invite/N3FrSbmwdy) e inizia a collaborare con i migliori hacker oggi stesso!
|
|
|
|
<details>
|
|
|
|
<summary><strong>Impara l'hacking di AWS da zero a eroe con</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
|
|
|
|
Altri modi per supportare HackTricks:
|
|
|
|
* Se vuoi vedere la tua **azienda pubblicizzata in HackTricks** o **scaricare HackTricks in PDF** Controlla i [**PACCHETTI DI ABBONAMENTO**](https://github.com/sponsors/carlospolop)!
|
|
* Ottieni il [**merchandising ufficiale di PEASS & HackTricks**](https://peass.creator-spring.com)
|
|
* Scopri [**The PEASS Family**](https://opensea.io/collection/the-peass-family), la nostra collezione di esclusive [**NFT**](https://opensea.io/collection/the-peass-family)
|
|
* **Unisciti al** 💬 [**gruppo Discord**](https://discord.gg/hRep4RUj7f) o al [**gruppo Telegram**](https://t.me/peass) o **seguici** su **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
|
|
* **Condividi i tuoi trucchi di hacking inviando PR ai** [**HackTricks**](https://github.com/carlospolop/hacktricks) e [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
|
|
|
|
</details>
|