iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🦀

Searching for Rust Binaries

に公開

Introduction

https://twitter.com/dwizzzleMSFT/status/1578532292662005760

A while ago, I saw a tweet like this. It mentions how "Microsoft has quietly released a Rust-made DLL inside Windows."
Since Rust adoption in production isn't mainstream yet, companies using it often proactively share information to gain attention. However, there might actually be many cases where it's being used secretly like this. So, I thought about ways to find software where Rust is being used under the hood.

Investigating Rust-made Binaries

In the tweet mentioned above, the binary was identified as Rust-based by looking at source code paths and filenames embedded in it. However, this information isn't always preserved in typical binaries, and searching for the static string "rust" could lead to false positives. Therefore, I wanted to find a more general approach.

Searching through a Rust binary for "rust" reveals several function names in addition to source code paths. One of them is rust_panic.
This is the panic handler called when a panic occurs in a Rust program, and it's likely included in most Rust binaries. Using symbol names of functions inserted by the Rust compiler as a clue seems like a solid approach.

One case where this might fail—based on my local testing—is when LTO (Link Time Optimization) is used, as symbol names might no longer be identifiable. Additionally, it's technically possible to export a symbol named rust_panic in a C binary, so false positives can happen.

With that in mind, I decided to search the symbol tables of ELF/PE binaries for Rust-like symbol names. While there are several candidates, I settled on rust_panic and rust_eh_personality for now (since I found some binaries that had the latter but not the former).

rustified

https://github.com/dalance/rustified

This is the program I built. Since there were perfect crates for this purpose—the elf crate and the exe crate—I used them to create a program that searches for the symbol names mentioned above in the ELF and PE symbol tables.

Searching for Them

Windows

I immediately looked for the file mentioned in the original tweet, and I indeed found it.
(There seem to be two versions of it.)

C:\Program Files\rustified
.\WindowsApps\Microsoft.YourPhone....\DWriteCore.dll (function "rust_panic" is found)
.\WindowsApps\Microsoft.YourPhone....\DWriteCore.dll (function "rust_panic" is found)

By the way, this WindowsApps folder is not accessible by default, even for administrators, so you need to explicitly grant access permissions beforehand.

Android

Since I was at it, I decided to look for another one. I'll try to find the Rust usage in Android 13 mentioned in the following article.

https://security.googleblog.com/2022/12/memory-safe-languages-in-android-13.html

First, download the Android 13 factory image for Google Pixel.

https://developers.google.com/android/images

This time, I used the image for the Pixel 7 Pro.
After extracting the zip, I mount the system.img.

$ sudo mount -t ext4 -o ro,loop system.img system

Next, I extract the following UWB stack package from the system directory.

system/apex/com.google.android.uwb.apex

This is in the Android Pony EXpress (APEX) container format, which essentially contains an ext4 image inside a zip archive.

Unzip and mount it.

$ unzip com.google.android.uwb.apex
$ unzip original_apex
$ sudo mount -t ext4 -o ro,loop apex_payload.img mnt

Then, you can extract the contents as follows.

mnt/lib64/libuwb_uci_jni_rust.so

The filename looks obviously Rust-like, but I'll check it just in case.

$ rustified
./libuwb_uci_jni_rust.so (function "rust_eh_personality" is found)

And with that, I was able to successfully confirm this one as well.

Discussion