Live data from Hacker News

Using Rust Macros to exfiltrate secrets

github.com

31–40 of 76 posts

Re: Using Rust Macros to exfiltrate secrets

#31
post #16
post #4

Earlier quoted context omitted.

Also, it’s not a new problem; a Makefile or configure script can run arbitrary code as well.

Citation needed. Show me a Makefile + IDE combination that executed code by simply opening a file. I think you’re missing the language server part of this.

Does opening an android project in android studio implicitly run any of the code in the project? I'm guessing it does, because the ide seems to be very busy all the time, even when idle

Re: Using Rust Macros to exfiltrate secrets

#33
post #17
post #2

Proc macros can run arbitrary code, so this POC is not that interesting - apart from raising awareness for the problem. This can be done even easier without users having to use a macro: with `build.rs` build scripts, which are run by default. So all you'd need is to compromise some popular dependency with a custom build.rs Many other languages have the same (or at least similar) problem (Makefiles, npm hooks, ...) Th…

> Many other languages have the same problem (Makefiles, npm hooks, ...) This simply isn’t true. All of these require an action by a user to execute the command (e.g npm install, make build). What the author is claiming is that a typical rust LSP setup will execute the arbitrary macro code simply by viewing the file in certain IDEs. Feel free to show me an example of this in makefiles or npm and I’m happy to retract.

There aren't a bunch of languages with proc-macros and IDEs. That'd be where you'll see a major intersection. (Maybe C++ has this problem with some ides?)

Languages with similar risks are ones where a Repl is is the key form of development. In those scenarios you are also one bad dependency from stolen info.

Re: Using Rust Macros to exfiltrate secrets

#34
post #24
post #6

Earlier quoted context omitted.

This is as huge a deal as "using ./configure && make install to exfiltrate secrets." It's a class of supply chain attack focusing on build time code evaluation. Almost every programming language has some kind of support for arbitrary code execution at build time, and any project of scale is going to require it. RCE isn't an interesting exploit when the system is literally designed to run code from somewhere else.

This isn’t build time though really, which I agree is a moment you would expect to run arbitrary code. This is “edit time.”

It is build time. Whether rust-analyzer should run build-time code at initialization is a different discussion.

Re: Using Rust Macros to exfiltrate secrets

#36
post #23
post #4

Earlier quoted context omitted.

Also, it’s not a new problem; a Makefile or configure script can run arbitrary code as well.

Apart from running make which of course runs the makefile, under what scenario does viewing a makefile run it?

Makefiles can actually be quite dynamic, so a program merely trying to figure out the list of target has to execute code. For example put this in a Makefile and do `make `, the file will be created (no need to press enter):

    VALUE := $(shell touch /tmp/something)

Re: Using Rust Macros to exfiltrate secrets

#37
post #19

I can't believe that people is comparing opening a project in a code editor with running a build script. The PoC doesn't even open a file, it just opens the directory. It's a pretty big difference, when you execute a build script you _expect_ to run code, when you open a directory in your editor you don't expect any side effect _at all_. My guess is that since the proc_macros returns a TokenStream, rust-analyzer have…

You'd have to sandbox the analyzer. Let it run arbitrary code but don't let it do IO. That can be pretty tricky to do for a language not designed to be sandboxed.

Safest way would probably be something hilarious like having the analyzer compiled to WASM and ran in node.js.

Re: Using Rust Macros to exfiltrate secrets

#38
post #16
post #4

Earlier quoted context omitted.

Also, it’s not a new problem; a Makefile or configure script can run arbitrary code as well.

Citation needed. Show me a Makefile + IDE combination that executed code by simply opening a file. I think you’re missing the language server part of this.

bash autocompletion will run arbitrary code from a Makefile. I wouldn't be surprised if many editors do too.

Re: Using Rust Macros to exfiltrate secrets

#39
post #3

This is a huge deal right? VSCode has to be one of the most popular editors and the standard way of setting up the Rust toolchain on a machine would get you in a state that makes you vulnerable to this.

It requires never actually running the program to be worse than the status quo in any language. If you run code it's trivially a code execution.

Re: Using Rust Macros to exfiltrate secrets

#40
post #8

For what it's worth, any VSCode extension that integrates with language tooling could be used to implement this.

This is an inherent problem of languages where execution is needed to understand its semantics. Most interpreted languages have this issue, and Rust has this issue due to proc-macros being Rust code that needs to be compiled and executed to process other Rust code.
Post reply on HN