Luca stealer - why your Rust code is dogshit (part 1; anti-emulation)
Howdy y’all, this is my first (and probably) last series of blog posts, but I had to type this out, considering how fucking horrible the code for Luca Stealer is. This post is about the anti-emulation.
Disclaimer: the code provided here shall not be used maliciously, and is for old versions of the crates talked about. I’m also not adding async/await, as I have other things to do and it’d take too much work for my lazy dum dum ADHD brain.
The detect function
We’re starting with their detect function:
Surprisingly, this part is actually pretty good. But instead, I’d let the users select what functions they want by using function pointers (as it has the less friction for both configuring and development). For example, doing this:
And then the process::exit(0) goes in main. Simple as that, and easily better.
Server OS detection
Now let’s dive into the real deal, starting with their server OS detection function.
…This is tremendously stupid. These variable names are too complex, he barely uses any rust functions, and is making variables when he doesn’t need them.
Starting with namespace path and hostname, the functions describe themselves, so you don’t need to make them a variable. Also, “wmi_con” could be renamed to the better name, “connection”. You don’t even need match, you can use the let-else syntax, stable since Rust 1.65.
I also dislike the way results was made (unwrap, use let-else once again), but I don’t have much experience with that part, so I might leave it alone for the most part. You could also save a character and make the code cleaner by changing the “\\ROOT\\CIMv2” to r”ROOT\CIMv2” (because r”\ROOT\CIMv2” is buggy, just like the original). You can also use into_values to not need to dereference, which in my opinion looks ugly. Also, both the hostname and the .into() are useless, so I removed them.
My finished product is this:
Hash process detection
Moving on, let’s talk about the hash process detection.
Their code goes like this:
If I didn’t know this was authored by a human, I’d think ChatGPT wrote this.. This looks like it was made by GPT 4’s distant cousin, JBR -4… There’s so much to improve:
Don’t refresh all, make a system with processes refreshed
Don’t use get(0), use first()
Rename arg to path
Use map and Path::new to create the path
Instead of “file_name”, name the variable just “name”
Use let-else and continue to reduce nesting
Use if_some_and instead of match… are you addicted to match or..?
My finished product is this:
Detection by WIM tempererature
Finally, I’m tired of writing, and by chance, this file just has one last function:
Everything that I hate in this function I’ve already talked about, so let’s cut the chase and finish this rewrite.
So, what did we learn today..? Rust and cargo are our best friends; You code differently in rust comparted to other languages; Add more customizability without repetition; Don’t return true if a variable is true or false if it’s false… just return the variable; For the love of god, don’t specify everything and the kitchen sink in your variable names
Full code
Here’s the full code, which at the end of the series, might also be posted on GitHub:
I might continue this if I feel like it…
If I missed something, please tell me.
Oh, and I’m just STARTING with a recode, you don’t wanna see what I’m gonna do after seriously getting comfy with the codebase… <3