Stealing Downloads from Slack Users
A vulnerability in the Slack desktop app allowed an attacker to craft a slack:// link that, when clicked, changed the victim's download location to an attacker-controlled SMB share. This could cause future downloads to be sent to the attacker, who could then steal or manipulate the files.
Published on medium.com
David Wells
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
Slack ships a desktop client built on Electron, and like most Electron applications it registers custom protocol handlers. One of these is slack://, which the client uses for internal navigation and for opening settings. The feature is convenient: a link in a message, an email or a web page can hand control to the desktop app instead of the browser.
The report looks at what happens when a slack://settings link is allowed to carry a settings update. The client exposes a large set of application settings through the Settings-Reducer.ts module, and the protocol-link.ts module contains the code that processes incoming protocol links, including a function that can change Slack app settings when such a link is clicked. Nearly all of the settings in the reducer are modifiable through slack://settings links.
One of those settings is PrefSSBFileDownloadPath, the destination path used for files downloaded through the desktop client. If an attacker can set that value, every subsequent download by the victim is written to a location the attacker controls.
Setup
The researcher worked against the Slack desktop app on Windows and reverse engineered the Electron bundle, which the report describes as easy. The vulnerability was reported to Slack through HackerOne under a coordinated disclosure policy, and Slack patched it in version v3.4.0. The attacker side of the demonstration required a remote SMB share under the attacker's control. For the unauthenticated delivery path, a Slack channel subscribed to an RSS feed was used, with a private subreddit owned by the researcher standing in for a popular community.
No special privileges on the victim side are needed beyond using the desktop client and clicking a link.
Finding it
The starting point was the slack:// hyperlink support that Slack users already know from normal use. Grepping the application code for the protocol handling led to the protocol-link.ts module, where one function stood out: it can change Slack app settings when a link is clicked. Cross-referencing with Settings-Reducer.ts, which holds all Slack settings, showed that nearly all of them are reachable through slack://settings links.
Among those settings, PrefSSBFileDownloadPath was the most interesting. It controls where downloaded files are saved, so a link that rewrites it turns a click into a persistent redirection of the victim's downloads.
Exploitation
Step 1: craft a settings link that changes the download path
A link of the following shape changes the default download location when clicked, and the change persists until the victim manually changes it back:
slack://settings/?update={'PrefSSBFileDownloadPath':'<pathHere>'}
The link carries the setting name and the new path in its query string.
Step 2: work around the character filter with an SMB share
Slack filters certain characters out of these links. One of them is the colon, which means a normal Windows path with a drive root cannot be supplied. An SMB share sidesteps the sanitation entirely, because a UNC path needs no drive root. After setting up a remote SMB share, the attacker can send users or channels a link that redirects all downloads to it once clicked.
Step 3: confirm the setting changed and downloads follow it
After the link is clicked, the change is visible in the advanced settings of the client. Downloading a document afterwards does not save it locally: it is uploaded to the remote SMB share instead.
Step 4: obscure the link for authenticated channel members
The raw link looks sketchy on its own, and savvy users probably will not click it, so the link text should be hidden. Slack documentation initially suggested that hyperlinking words in a channel was not possible. Experimenting with the Slack API, and later finding the documentation for it, showed that text hyperlinking can be done through the attachments feature: an attachment field is added to the Slack POST request with the appropriate fields. When that message is submitted to a channel, the visible text http://google.com is hyperlinked to the malicious slack:// link, and clicking it instantly changes the victim's Slack download location.
Step 5: reach channels without membership through RSS
An attacker who is not a member of a channel can still get a link into it, because Slack channels can subscribe to RSS feeds to populate themselves with site updates, and those updates can contain links. In the demonstration, the researcher posted to a Reddit community (a private one he owned, standing in for a popular community that Slack users worldwide are subscribed to). The post contains an HTTP link, since Reddit does not allow slack:// links to be hyperlinked, and that HTTP link redirects to the malicious slack:// link. Once posted, the test Slack channel subscribed to the subreddit feed is populated with the new article entry and previews the text including the link.
This path has a drawback: when the victim clicks the link, the browser shows a prompt and the victim has to click "Yes", after which the Slack client's download location changes instantly.
Root cause
The slack://settings protocol handler accepts a settings update from a link and applies it when clicked. Because PrefSSBFileDownloadPath is among the settings exposed to that handler, a single click is enough to redirect all future downloads. The character filter on the link is not a security boundary: it blocks the colon needed for a drive-rooted path, but a UNC path to an SMB share needs no drive letter, so an SMB share sidesteps the sanitation entirely.
Impact
A remote attacker could submit a masqueraded link in a Slack channel that, if clicked by a victim, silently changes the download location of the Slack client to an attacker-owned SMB share. All future documents downloaded by the victim then end up on the attacker's file server until the setting is manually changed back. While the file sits on the attacker's server, the attacker could not only steal the document but also insert malicious code into it, so that opening it after download through Slack infects the victim's machine. The attacker controls the share the file is uploaded to, so the downloaded item can be manipulated and the Slack user who opens or executes it interacts with the modified document, script or other file instead. The report notes that the technique could be unmasked by savvy users, but that users click links, and that delivery through an untrusted RSS feed makes the impact more interesting. Slack investigated and found no indication that the vulnerability was ever used, nor reports that users were impacted.
Fix
Slack patched the issue in one of its latest updates, v3.4.0. The report does not describe the code change itself.
Variants to test
- Enumerate other settings reachable through the same protocol handler and check whether any of them change security-relevant behaviour, such as paths, proxies or auto-open handling. A positive result is a setting that changes persistently after a single click on a crafted link.
- Try other custom protocol handlers registered by the client and check whether they accept parameters that mutate state. A positive result is a handler that applies an update without confirmation.
- Test the character filter with encodings and alternative path forms, such as UNC paths, to see whether blocked characters can be avoided. A positive result is a path that survives filtering and is accepted by the client.
- Check whether link text can be disguised through message attachments or other formatting features in clients that render rich messages. A positive result is a message where the visible URL differs from the
slack://target. - Test RSS or feed integrations as an unauthenticated delivery channel into channels the attacker does not belong to. A positive result is attacker-controlled content appearing in a channel with a clickable link.
- Check whether the client prompts before applying protocol-driven changes. A positive result is a change applied with no prompt, or a prompt that can be dismissed by a single click.
What happened, in plain words
Slack is a chat application that many workplaces use to talk to each other. Besides the website, Slack offers a desktop program you install on your computer. That desktop program is built with a technology called Electron, which lets a company write a program using the same ingredients as a web page. One of the things an Electron program can do is register its own special kind of link, a bit like how mailto: opens your email program when you click an email address on a website. Slack's special link starts with slack://.
The researcher, David Wells, looked at what those slack:// links can do. He found that one particular kind of link, slack://settings, can change the settings inside the Slack desktop program. Nearly all of the settings in the program can be changed this way. One of those settings decides where downloaded files are saved on your computer. If an attacker can change that setting, then every file you download afterwards goes wherever the attacker wants, not to your own computer.
The attacker does not need to break into anything. They only need you to click a link. The link can be disguised so it looks like an ordinary web address. It can be sent to you in a channel you are in, or even slipped into a channel you are not in by using an RSS feed, which is a way for a channel to automatically pull in news from a website. When you click, your Slack program quietly starts sending your future downloads to a file server the attacker controls. The attacker can then read those files, and can even put harmful code inside them before you open them.
Slack fixed the problem in version v3.4.0 of the desktop app. Slack also checked and found no sign that anyone had actually used the trick, and no reports that users were harmed.
Background: the pieces you need to know
Before walking through the steps, here are the ideas the report relies on, explained from scratch.
- Electron: a toolkit for building desktop programs out of web technology. The same code that runs a website can run inside a window on your computer, with extra powers such as reading and writing files. Because the program is mostly readable text and script files, someone can open it up and read how it works. The report calls this reverse engineering, and says Electron makes it easy.
- Custom protocol handler: a special link prefix that your operating system hands to a particular program instead of to the browser.
http://andhttps://go to the browser.mailto:goes to your email program.slack://goes to the Slack desktop app. When you click such a link, the operating system launches the program and passes the rest of the link to it. - Settings: the preferences inside a program, such as where files are saved or which language is used. In Slack's code these live in a module called
Settings-Reducer.ts. A module is just a file of code that groups related things together. protocol-link.ts: the file of Slack code that handles incomingslack://links. The report found a function in it that can change app settings when such a link is clicked.PrefSSBFileDownloadPath: the name of the setting that stores where downloaded files are saved.Prefis short for preference. If an attacker controls this value, they control where your downloads go.- SMB share: a way for computers, mostly on Windows, to share a folder over a network. A folder shared this way has an address that starts with two backslashes, like
\\server\folder. This is called a UNC path. It does not need a drive letter such asC:, which matters later. - RSS feed: a web address that a program can subscribe to in order to receive a list of new articles or posts from a website. Slack channels can subscribe to one, and each new item appears in the channel as a message, including any links in it.
- API: a way for one program to talk to another over the internet by sending requests. Slack has an API that lets programs post messages into channels. The report uses it to build a message with a disguised link.
- HackerOne: a website where security researchers report bugs to companies. The researcher reported this issue to Slack through HackerOne, following a coordinated disclosure policy, which is an agreement about when and how the details may be made public.
Setting the scene
The researcher worked against the Slack desktop app on Windows. He reported the issue to Slack through HackerOne under a coordinated disclosure policy, and Slack patched it in version v3.4.0. To demonstrate the attack he needed a remote SMB share that he controlled, meaning a shared folder on a server he owned. For the delivery route that does not require being a member of a channel, he used a Slack channel subscribed to an RSS feed, with a private subreddit (a Reddit community) that he owned standing in for a popular community that many Slack users follow.
On the victim's side nothing special is needed. The victim uses the Slack desktop client and clicks a link.
Finding it
The starting point was the slack:// link support that Slack users already see in normal use. The researcher searched the application's code for the part that handles these links, a process the report calls grepping, which means searching through text files for a word or pattern. That led to the protocol-link.ts module, where one function stood out: it can change Slack app settings when a link is clicked. Cross-checking with Settings-Reducer.ts, the module that holds all Slack settings, showed that nearly all of them can be reached through slack://settings links.
Among all those settings, PrefSSBFileDownloadPath was the most interesting, because it controls where downloaded files are saved. A link that rewrites it turns a single click into a lasting redirection of the victim's downloads.
Exploitation
Step 1: craft a settings link that changes the download path
A link of the following shape changes the default download location when clicked, and the change stays in place until the victim manually changes it back:
slack://settings/?update={'PrefSSBFileDownloadPath':'<pathHere>'}
Reading it piece by piece:
slack://tells the operating system to hand this link to the Slack desktop app rather than to the browser.settings/points at the settings area of the app.?update=starts a parameter namedupdate. A parameter is a named value attached to a link, the same way a search address carries your search words after a question mark.{'PrefSSBFileDownloadPath':'<pathHere>'}is the value of that parameter. It is written in JSON, a simple text format for structured data. The part before the colon is the name of the setting, and the part after it is the new value.<pathHere>is a placeholder where the attacker puts the location they want downloads to go to.
The victim clicks, and the setting changes.
Step 2: work around the character filter with an SMB share
Slack filters certain characters out of these links. One of them is the colon. That matters because a normal Windows path such as C:\Users\... contains a colon after the drive letter, so a drive-rooted path cannot be supplied. An SMB share gets around the filter entirely, because a UNC path needs no drive root. After setting up a remote SMB share, the attacker can send users or channels a link that redirects all downloads to it once clicked.
Step 3: confirm the setting changed and downloads follow it
After the link is clicked, the change can be seen in the advanced settings of the client. Downloading a document afterwards does not save it locally: it is uploaded to the remote SMB share instead.
Step 4: obscure the link for authenticated channel members
The raw link looks sketchy on its own, and experienced users probably will not click it, so the link text should be hidden. Slack's documentation at first suggested that hyperlinking words in a channel was not possible. Experimenting with the Slack API, and later finding the documentation for it, showed that text hyperlinking can be done through the attachments feature. An attachment field is added to the Slack POST request with the appropriate fields. A POST request is one of the ways a program asks a server to do something, here to post a message. When that message is submitted to a channel, the visible text http://google.com is hyperlinked to the malicious slack:// link, and clicking it instantly changes the victim's Slack download location.
Step 5: reach channels without membership through RSS
An attacker who is not a member of a channel can still get a link into it, because Slack channels can subscribe to RSS feeds to fill themselves with updates from a website, and those updates can contain links. In the demonstration, the researcher posted to a Reddit community (a private one he owned, standing in for a popular community that Slack users worldwide follow). The post contains an HTTP link, since Reddit does not allow slack:// links to be hyperlinked, and that HTTP link redirects to the malicious slack:// link. A redirect is when one web address automatically sends the browser on to another address. Once posted, the test Slack channel subscribed to the subreddit feed is filled with the new article entry and previews the text including the link.
This route has a drawback: when the victim clicks the link, the browser shows a prompt and the victim has to click "Yes", after which the Slack client's download location changes instantly.
Root cause
The slack://settings handler accepts a settings update from a link and applies it when clicked. An origin check would be a test of where the link came from before acting on it. Because PrefSSBFileDownloadPath is among the settings exposed to that handler, a single click is enough to redirect all future downloads. The character filter on the link is not a security boundary: it blocks the colon needed for a drive-rooted path, but a UNC path to an SMB share needs no drive letter, so an SMB share sidesteps the sanitation entirely.
Impact
A remote attacker could submit a masqueraded link in a Slack channel that, if clicked by a victim, silently changes the download location of the Slack client to an attacker-owned SMB share. All future documents downloaded by the victim then end up on the attacker's file server until the setting is manually changed back. While the file sits on the attacker's server, the attacker could not only steal the document but also insert malicious code into it, so that opening it after download through Slack infects the victim's machine. The attacker controls the share the file is uploaded to, so the downloaded item can be manipulated, and the Slack user who opens or executes it interacts with the modified document, script or other file instead. The report notes that experienced users could spot the technique, but that users click links, and that delivery through an untrusted RSS feed makes the impact more interesting. Slack investigated and found no indication that the vulnerability was ever used, nor reports that users were impacted.
Fix
Slack patched the issue in one of its latest updates, v3.4.0. The report does not describe the code change itself.
Variants to test
- List the other settings reachable through the same protocol handler and check whether any of them change security-relevant behaviour, such as paths, proxies or auto-open handling. A positive result is a setting that changes persistently after a single click on a crafted link.
- Try other custom protocol handlers registered by the client and check whether they accept parameters that change state. A positive result is a handler that applies an update without confirmation.
- Test the character filter with encodings and alternative path forms, such as UNC paths, to see whether blocked characters can be avoided. A positive result is a path that survives filtering and is accepted by the client.
- Check whether link text can be disguised through message attachments or other formatting features in clients that render rich messages. A positive result is a message where the visible URL differs from the
slack://target. - Test RSS or feed integrations as a delivery channel into channels the attacker does not belong to, without needing an account in them. A positive result is attacker-controlled content appearing in a channel with a clickable link.
- Check whether the client prompts before applying protocol-driven changes. A positive result is a change applied with no prompt, or a prompt that can be dismissed by a single click.
Glossary
- API: a way for one program to talk to another over the internet by sending requests and receiving responses.
- Attachment (Slack): a structured part of a Slack message that can carry extra fields, including text that is turned into a clickable link.
- Character filter: code that removes or blocks certain characters from input before it is used.
- Coordinated disclosure: an agreement between a researcher and a company about when and how a reported vulnerability may be made public.
- Custom protocol handler: a link prefix such as
slack://that the operating system passes to a specific program instead of the browser. - Electron: a toolkit for building desktop programs from web technology, which makes their code relatively easy to read.
- Function: a named block of code that performs a task when it is called.
- Grepping: searching through text or code files for a word or pattern.
- HackerOne: a platform where security researchers report vulnerabilities to companies.
- HTTP link: an ordinary web address starting with
http://that opens in a browser. - JSON: a simple text format for structured data, built from names and values.
- Module: a file of code that groups related functions and data together.
- Origin check: a test of where a request or link came from before acting on it.
- Parameter: a named value attached to a link or request, usually after a question mark.
- POST request: a way for a program to ask a server to do something, such as post a message.
PrefSSBFileDownloadPath: the Slack setting that stores where downloaded files are saved.- Prompt: a dialog box that asks the user to confirm or choose something.
- Redirect: when one web address automatically sends the browser on to another address.
- Reverse engineering: taking a program apart to understand how it works.
- RSS feed: a web address a program can subscribe to in order to receive a list of new articles or posts from a website.
- Settings: the preferences inside a program, such as where files are saved.
- SMB share: a folder shared over a network, mostly between Windows computers.
- Subreddit: a community on Reddit.
- UNC path: a network address for a shared folder that starts with two backslashes and needs no drive letter.
- Vulnerability: a weakness in a program that lets someone make it behave in a way its makers did not intend.