mongod how to discover visible database

47 Views Asked by At

grant readWrite privilege to user app_admin like below:

db.createUser({"user":"app_admin", "pwd":"itnihao", "roles": [{"role": "readWrite", "db":"app1"},{"role": "readWrite", "db":"app2"},{"role": "readWrite", "db":"app3"}]})

The question is user app_admin how to discover the visible database app1, app2, app3 without the listDatabases privilege?

I find the mongod GUI tool studio 3TMongodb Compass can do this.

1

There are 1 best solutions below

0
On BEST ANSWER

After tcpdump the studio 3T, find the usersInfo can do this.

> db.runCommand({"usersInfo": {"user": "app_admin", "db": "admin"}})
{
    "users" : [
        {
            "_id" : "admin.app_admin",
            "user" : "app_admin",
            "db" : "admin",
            "roles" : [
                {
                    "role" : "readWrite",
                    "db" : "app4"
                },
                {
                    "role" : "readWrite",
                    "db" : "app1"
                },
                {
                    "role" : "readWrite",
                    "db" : "app2"
                },
                {
                    "role" : "readWrite",
                    "db" : "app3"
                }
            ]
        }
    ],
    "ok" : 1
}