My experiments in weaponizing Rust for implant construction and usual offensive operations.
Why Rust?
- It is faster than languages like C/C++
- It is multi-purpose language, bearing superb communities
- It has a great in-built dependency carry in combination keep an eye on known as Cargo
- It is LLVM primarily based completely which makes it a very good candidate for bypassing static AV detection
- Super easy move compilation to House space house home windows from *nix/MacOS, most simple calls so as to put all through the
mingw
toolchain, even though sure libraries cannot be compiled successfully in numerous OSes.
Examples in this repo
Compiling the examples in this repo
This repository does not provide binaries, you need to be gonna will have to lift in combination them yourself.
Arrange Rust
Simply download the binary and prepare.
This repo was once as soon as compiled in House space house home windows 10 so I might perhaps stick with it. As mentioned OpenSSL binaries can have depencency issues that can require OpenSSL and perl to be installed. For the TCP SSL consumer/server I love to suggest static carry in combination on account of dependencies on the hosts you’ll be able to execute the binaries. For making an issue, execute:cargo new <decide>
This may occasionally perhaps automatically create the structured downside folders with:
downside
├── Cargo.toml
└── src
└── primary.rs
Cargo.toml is the report that incorporates the dependencies and the configuration for the compilation. primary.rs is the main report that it will be compiled at the side of any possible directories that come with libraries.
For compiling the issue, switch into the issue checklist and execute:cargo carry in combination
This may occasionally perhaps use your default toolchain. If you want to carry in combination the whole “release” style execute:cargo carry in combination --release
For static binaries, in terminal previous to the carry in combination command execute:"C:Program Data (x86)Microsoft Visual Studio2019CommunityVCAuxiliaryBuildvcvars64.bat"
set RUSTFLAGS=-C target-feature=+crt-static
In case it does not in reality if truth be told in point of fact really feel easy with the intention to be informed my code one of the crucial very best ways it is written,
you are able to moreover you the beneath command inside the issue checklist to development it in a better meanscargo fmt
Positive examples would perhaps not lift in combination and get a hold of some error, since it’ll require a nightly
carry in combination of Rust with the most recent issues. To place in it do exactly:rustup default nightly
The easiest place to hunt out the dependencies or Crates as they are known as.
Transfer Compiling
Transfer-Compiling requires to use the instructions right kind correct proper right here By means of setting up different toolchains, you are able to move lift in conjunction with the beneath commandcargo carry in combination --target <toolchain>
To appear the installed toolchains for your device do:rustup toolchain tick list
For checking the entire available toolchains you are able to prepare for your device do:rustup objective tick list
For setting up a brand spanking new toolchain do:rustup objective add <toolchain_name>
Optimizing executables for size
This repo incorporates numerous configuration possible choices and ideas about reducing the report size. Static binaries are in most cases slightly massive.
Pitfalls I came upon myself falling into
Wary of bytes, do not forget them for strings in memory, I spent numerous my time then again windbg all the time helped resolving it.
Crowd pleasing Rust libraries
- WINAPI
- WINAPI2
- House space house home windows – That’s the loyal Microsoft one who I have not carried out one of these lot with
OPSEC
- Even supposing Rust has superb advantages it is slightly tricky to get used to it and it ain’t very intuitive.
- Shellcode technology is some other issue on account of LLVM. I have came upon a few ways to approach this.
Donut each and every so often does generate shellcode that works then again depending on how the issue is made, it’ll not.
At the entire, for shellcode technology the equipment which may also be made will have to be made to host all code in .text section, which ends up in this superb repo. There is a shellcode building in this downside that can show you one of the best ways you’ll be able to construction your code for successfull shellcode technology.
Along side, this downside moreover has a shellcode generator that grabs the .text section of a binary and and dumps the shellcode after executing some patches.
This downside grabs from a made up our minds on location the binary so I made a fork that receives the path of the binary as a subject matter right kind correct proper right here. - Even supposing you’re taking away all debug symbols, rust can however keep references to your home checklist inside the binary. The only means I’ve came upon to remove this is to transport the following flag:
--remap-path-prefix {your home checklist}={some random identifier}
. You are able to use bash variables to get your home checklist and generate a random placeholder:--remap-path-prefix "$HOME"="$RANDOM"
. (By means of Yamakadi) - Even supposing for the above there could also be another way to remove details about the home checklist by way of in conjunction with at the top of Cargo.toml
cargo-features = ["strip"]
. - Since Rust by way of default leaves numerous problems as strings inside the binary, I maximum continuously use this cargo.toml to keep away from them and along with cut back size
with carry in combination commandcargo carry in combination --release -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target x86_64-pc-windows-msvc
Other tasks I have have made in Rust
Projects in Rust that can be hepfull
- houdini – Helps make your executable self-delete