MongoDB database quick reference.
Nmap scripts
ls -la /usr/share/nmap/scripts/mongodb*
IP=x.x.x.x
WL=/usr/share/wordlists/rockyou.txt
USERS=/usr/share/seclists/Usernames/top-usernames-shortlist.txt
nmap -p 27017 --script mongodb-databases $IP
nmap -p 27017 --script mongodb-brute --script-args passdb=${WL},userdb=${USERS} $IP
MongoDB Server
Start the database
mongod
When MongoDB is in a Docker container
Connect to MongoDB when the container is running
#docker-compose <cmd> <service-name> <cmd>
docker-compose exec mongodb mongo
MongoDB Client
Add MongoDB JDBC driver to client tool like SQuirreL.
Show version
mongo --version
Connect to database (default is test)
mongo <server:port>
/usr/bin/mongo localhost:27017/admin -u sa -p pwd
Show current database
db
List all databases
show dbs
List of all available databases
show databases
Connect to a different database
use <database_name>
List of users for current database
show users
List of all roles, both user-defined and built-in, for the current database
show roles
List profile
show profile
List all collections in current db
show collections
List all items in a collection
db.<collectionName>.find()
List items matching the condition
db.<collectionName>.find({ name: 'Jon Snow' })
Insert one item in a collection
db.<collectionName>.insertOne()
db.characters.insertOne({ name: 'Jon Snow' })
db.characters.insertOne({ name: 'Arya Stark' })
Update items matching the condition
#db.<collectionName>.find( { name: 'Jon Snow' } )
db.<collectionName>.update(
{ name: 'Jon Snow' },
{
$set: {
password: "ABC123"
}
}
)
Delete all items from a collection
db.<collectionName>.remove( { } )
Delete items matching the condition
#db.<collectionName>.find( { name: 'Jon Snow' } )
db.<collectionName>.remove( { name: 'Jon Snow' } )