Blocking Visual Studio Code embedded reverse shell before it's too late
ipfyx.fr
ipfyx.fr
If the attacker can run commands and upload binaries, it really doesn't matter what VS Code does. There are lots of commands and binaries that can open network connections.
Edit: The attacker apparently needs to control the URL and exfiltrate the activation code [0], so if they can already execute commands and open network connections, then this enables them to execute commands and open network connections. So, as mentioned by other commenters, this does sound a lot like Raymond Chen's airtight hatchway [1].
[0] https://badoption.eu/blog/2023/01/31/code_c2.html
[1] https://devblogs.microsoft.com/oldnewthing/20060508-22/?p=31...
Personally I'm not particularly moved by the lolbin and footgun case it does make. I am just mildly put off by how text editors and IDEs are inextricably bundled with so many double-edged remote capabilities.
E.g., it used to be an effective security measure to have a daemon listen on loopback only. But then browsers relaxed the same-origin policy and today every sleazy banner ad can get the browser to open a TCP connection on loopback and at least send a TLS handshake - and, if the daemon accepts that, an OPTIONS request with an attacker-controlled URL. So a daemon has to perform at least some basic validation on incoming connections to be secure.
If your threat model involves people trying to exfiltrate data from a developer machine with an internet connection in an innocent-looking way, this VSC feature is a problem. Most companies either don't make an attempt at preventing that, or would use an airgapped setup so it's not something worth caring about.
And even if you're not in the innermost area, an attack might exist entirely in the space between two hatchways and not breach any.
There is some likelihood that VS Code may already be installed (depending on who the attacker wants to target), so the victim "just" has to be tricked to run a single shell command - and the attacker immediately gets live shell access, without having to worry about firewalls, connectivity, finding the victim's address, etc.
So I think the danger of this is less that it's technically an RCE exploit (as indeed you already need an existing way to run code to trigger it) - but rather that it lets an attacker turn a relatively simple capability (planting a single shell command with no back channel that the victim might run at some point in the future) into a sophisticated one (having access to a full remote shell with all bells and whistles, including firewall traversal, automatic reconnect and file transfer).
Edit: ok, looks like the attacker already needs a back channel to get hold of the access code for the tunnel.
What we have here is a way for an attacker using shady means (email-delivered 0day, parking lot thumbdrive, browser drive-by compromise) to take over a computer and then drop a signed package that will allow for remote control over time that looks completely legitimate. To a network IDS, that access will look like an authorized cloud tunnel, completely normal. To a file scanner, it will look like an vendor-signed binary, the gold standard. To the complete defense-in-depth stack, the entire c2 chain is cloaked in legitimacy. If you get a single detection at all for the initial compromise (not possible with 0day), the entire rest of the kill chain looks like legitimate access and vanishes.
It's a nightmare for defense in depth and hunt teams.
On a default Unix-like desktop shell you can’t really do much permanent harm without elevating your permissions.
alias sudo='./.my-evil-sudo-binary'
And wait till the next time the user authenticates, they wont see anything amiss and you just silently delete the alias after you’ve got the sudo password.Also even without root dumping .ssh and the browser’s cookie jar is probably plenty to achieve lateral movement and you don’t need root for that.
There’s lots of ways to tunnel, but a methodology that looks and may be legit is a great one. This a great way to have a long term, persistent exfiltration mechanism. Compromise some desktops, move laterally through the network and you have a river of data flowing out.
* The fact that it's in a popular signed binary means it bypasses app allow-lists.
* The fact that it flows through Microsoft's servers bypasses firewall allow-lists.
* The fact that no stage2 is required bypasses antivirus scanning.
I say "unfortunately" because I personally think attempting to differentiate good behavior from malicious behavior is losing battle. Design-based or resilience-based security controls are the way to go IMO: https://kellyshortridge.com/blog/posts/control-vs-resilience...
https://devblogs.microsoft.com/oldnewthing/20060508-22/?p=31...
Phishing does involve an insider being confused and letting someone in, though. The question is what a vscode user could be tricked into doing. That part of the explanation could be fleshed out more?
I'm also reminded of how browsers do defense in depth. The "airtight hatch" argument implies that second-level security is worthless because the first level is secure. Having a useful binary already there on the system might be useful for chaining with another exploit?
But that assumes a developer environment can be made into a low-privilege container, sort of like a browser's render process. I don't think many people work that way?
Perhaps someday we will work in containers and code editors will be locked down like browsers. The most straightforward path to that would probably be for the code editor to run in the browser.
That's something VS Code can do, so a policy that says you must use a browser-based version of VS Code might actually work for some organizations?
So for us, this function should have an enable flag which is off by default. The slim minority who do want it and would use it can suffer the inordinate burden of having to go into the preferences panel and clicking enable.
You can argue whether it is a hole (it is) or whether it is a piece of a hole (it is). But it should be off by default and on by permission.
Yo Microsoft, add a preference for this thing which defaults off.
If you don’t know the feature set of the software you use, maybe don’t use the software instead of blaming the vendor.
Yo Microsoft, add a preference for this thing which defaults off.
2. It’s about an attacker exploiting the feature, the attacker is enabling it and doing the login. Whether you need to enable it yourself is largely irrelevant, in fact you’re probably more likely to notice an ongoing attack if you use the feature yourself.
Anyway, default is pointless, a gadget is a gadget as long as the bits are there and easily executable.
Saying this in reference to modern Microsoft, with their default-opt-in-to-drive-market-share strategy, is a pretty high bar.
Effectively it means "Don't use Windows."
An ideal development environment would: (1) allow for executing unsigned/self-signed code without jumping through hoops or relying on a 3rd party or App Store, (2) allow for escalation and automatic descalation of fine-grained privileges with native UX for grants (LittleSnitch on macOS has a good design for this specifically for networking IMO —- one could imagine extending this to the file system).
There are plenty of systems that have some aspects of these, but I have not seen both, at least not in a form accessible enough to be ubiquitous in 2023.
This feels like Raymond Chen’s other side of the airtight hatch.
Yes, if you can get a binary you control onto the user’s system and get them to run it, you can use that to have remote code execution. But then, the whole exploit described is remote code execution.
I'm not saying that's a huge concern, but something one has to consider when protecting their organisation.
But that's already assuming you get compromised anyway, and that your compromised workstations have things worth reaching on their internal network/VPN. All things that are true on real corporate networks, but "fixing" this vulnerability is still pretty low impact in the grand scheme of things one could do to to improve the situation. But in my experience, most CISOs aren't that great at setting priorities and threat modeling anyway: One just recently told me they doesn't want XSS vulnerabilities reported, because the scanner would find them anyway - but sends out daily all-caps emails about specific emails being phishing.
Your developer uses VSCode and sends a lot of data to vscode.dev or another Microsoft domain? Sounds totally normal, nothing suspicious here, move on!
If you exposed it willingly.
Yet I managed to find a fully remote RCE and exploit it in 30 minutes after they did all this.
The industry is a fucking scam.
Perhaps you shouldn't treat your users like stupid cattle, or you're not going to get anything better but only worse.
I'd like you to give me all your kitchen knives. If you need to cook a steak or something, you can just give me a call and I will supervise you while you use the knife.
I wouldn't want you to make a mistake and make it too easy to injure yourself.
This is easier said then done and if you go the direction of complicated procedures employees will usually just try to bypass procedures entirely.
However I think there is a middle ground or a sweet spot here. The tech has come a long way in the past decade or so. Its pretty easy to have a set up where almost no employee can deploy to production from their local machine.
Its also the easiest its ever been to have a sandboxed production environment and a near parallel staging environment.
That's not a rhetorical question, I 'm actually curious to find out. The reason I ask is that of all the big security breaches that end up in the news, I cannot recall a single case where these sorts of issues (for instance, not locking down deployment to production) was the root cause.
it seems this opens up a easy way to exfilarate corporate data (without detection?)
correct me if I am wrong please
attacker (or a cooperating employee) can browse and download any files from target machine inside corporate network by opening the generated vscode.dev/tunnel URL from a browser on any device anywhere in the world ?
Random thought: Since there are N editors and M languages, that's N x M plugins. Surely there's a better way to reduce the effort involved.
Yeah, it’s called LSP. The core of most plugins is just an lsp that’s shared between vim, neovim, emacs, vscode, sublime, etc. all the editor needs is to support generic lsp, or have a generic lsp plugin like vim/emacs.
For example if you look at neovim, you just load the actual lsp and wire it up to the editor in lua. That’s more or less the majority of the “extension code” for something like sublime or vscode (plus some other niceties)
Companies using that are probably the reason for, or at least a big motivator for, the feature in question. Lots of developer creativity is spent on working around corporate "security" practices that otherwise prevent work from being done.
No one in corporate uses WD because it's unmanaged. OTOH, MDE P1+VM is a steaming pile of shit that arbitrarily deletes things on untold millions of end-user devices because of the way Microsoft doesn't do properly risk management (canary) for new definitions.
I cannot think of a single argument for this being default functionality.