Acting under any different user via DB-stored credentials
Nextcloud stored the admin's SMB credentials in the database for every user when the admin visited the user list settings page, because the code did not check that the session user matched the user whose credentials were being saved. A normal user could then act as the admin and access SMB shares with higher privileges.
Originally disclosed on HackerOne
- Triaged in under an hour
- Fixed in 45 days
- Paid in 33 days
- Disclosed after 2 months
The issue is related to all Nextcloud versions. It is not patched yet. All versions (18-20) seems to be vulnerable. The issue came up in the following environment:
- nextcloud docker image (20.0.2 and 20.0.3)
- LDAP authentication
- external SMB shares via DB stored credentials
The problem came up after several users could not access their mounted SMB shares. When I checked, what was going on, it seems that DB credentials are getting stored from the session (table oc_storages_credentials) to the DB. The problem is, that there is no check if the current user in the session is the same as the user for whom the credentials get stored.
It seems that the credentials saved in the corresponding table (oc_storages_credentials) are wrong and therefore all SMB shares are showing errors.
When I initially add the external storage SMB mounts in the settings and then a user logs in the first time, the SMB shares work (with the correct login) which gets correctly saved in the DB.
Afterwards I can find one single entry on the oc_storages_credentials-table
However, when I (as an admin) navigate to: https://cloud.example.org/settings/users the table oc_storages_credentials gets (pre)populated with all the users (and some random credentials) - this also includes all users who weren´t logged-in yet. When the user logs in afterwards the credentials entry is already there and does not get updated.
Steps to reproduce
- Add external SMB mount with option "credentials saved in database"
- Manually check the MYSQL table
oc_storages_credentials- it should be empty - As an admin: navigate to (
/settings/users) - Recheck the MYSQL table
oc_storages_credentials- there is an entry for every user now - The stored credentials in the DB are now the admin credentials
- user can act as the admin user (their LDAP / AD password is stored in
oc_storages_credentialsfor every user
Expected behaviour
- Do not populate the table
oc_storages_credentialson "user list settings page" - If the current user credentials does not match the ones in the DB -> update it
Actual behaviour
password::logincredentials/credentialsentries are getting deployed initially from the admin user ...
Bugfix / Patch
There should be two files affected:
/apps/files_external/lib/Lib/Auth/Password/LoginCredentials.php/apps/files_external/lib/Listener/StorePasswordListener.php
It looks like there is a form of wrong impersonation going on here. -> The git-Diff for a security conform bugfix is attached.
Server configuration
I am using this docker image (no modifications): https://github.com/nextcloud/docker/tree/master/.examples/dockerfiles/full/fpm-alpine
Operating system: Docker on Ubuntu 20.04.1 LTS Web server: nginx with php-fpm Database: mariadb 10.5 as docker container PHP version: 7php .4 Nextcloud version: 20.0.2 Updated from an older Nextcloud/ownCloud or fresh install: updated from nextcloud 18.0.11 -> 19.0 -> 20.0.3 Where did you install Nextcloud from:
Impact
- Acting as a different user (as admin credentials are stored for every user in the DB)
- get a normal user account and accessing SMB shares on the network with higher privileges as himself
- getting access to internal ressources via external shared links
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the credential-storing code did not verify that the current session user was the same user for whom the credentials were being saved.
Impact
A normal user could act as the administrator and access SMB shares with higher privileges, and could reach internal resources through external shared links.
What the attacker needed
External SMB mount configured; credentials saved in database option enabled; admin visits user list settings page; LDAP authentication
The fix
The credential storage should not populate the table when the user list settings page is opened, and it should update stored credentials when the current user's credentials do not match; the text says it is not patched yet.
How it was found
- Add an external SMB mount with the option to save credentials in the database.
- Check the database table and confirm it is empty.
- As an administrator, open the user list settings page.
- Check the database table again and see an entry for every user.
- Observe that the stored credentials are the administrator's credentials.
- A user can then act as the administrator.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Nextcloud can save the username and password used to connect to external file shares in its database. When an administrator opened the user management page, the software saved the administrator's own login details for every user account instead of each person's own details. This meant a normal user could use the administrator's credentials to reach network shares with more access than they should have.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.