rustclr 🦀
rustclr
is a powerful library for hosting the Common Language Runtime (CLR) and executing .NET binaries directly with Rust, among other operations.
Table of Contents
Features
- ✅ Run .NET binaries in memory with full control over runtime configurations
- ✅ Fine-grained control over the CLR environment and runtime initialization
- ✅ Configure output redirection to capture .NET program output
Installation
Add rustclr
to your project by updating your Cargo.toml
:
Or manually add the dependency:
[]
= "<version>"
Usage
Running a .NET Assembly with Configured Flags
The following flags provide full control over your CLR environment and the execution of your .NET assemblies:
.with_runtime_version(RuntimeVersion::V4)
: Sets the .NET runtime version (e.g., RuntimeVersion::V2, RuntimeVersion::V3, RuntimeVersion::V4). This flag ensures that the assembly runs with the specified CLR version..with_output_redirection(true)
: Redirects the output from the .NET assembly's console to the Rust environment, capturing all console output..with_domain("DomainName")
: Sets a custom AppDomain name, which is useful for isolating different .NET assemblies..with_args(vec!["arg1", "arg2"])
: Passes arguments to the .NET application, useful for parameterized entry points in the assembly.
Using rustclr
to load and execute a .NET assembly, redirect its output and customize the CLR runtime environment.
use fs;
use ;
Running PowerShell Commands
rustclr
also provides a high-level interface to execute PowerShell
commands from Rust using the built-in .NET System.Management.Automation
namespace.
use Error;
use PowerShell;
Configuration with RustClrEnv and ClrOutput
For more fine-grained control, rustclr provides the RustClrEnv
and ClrOutput
components:
RustClrEnv
: Allows for low-level customization and initialization of the .NET runtime environment, which is useful if you need to manually control the CLR version, MetaHost, runtime information, and application domain. This struct provides an alternative way to initialize a CLR environment without executing an assembly immediately.
use ;
ClrOutput
: Manages redirection of standard output and error streams from .NET to Rust. This is especially useful if you need to capture and process all output produced by .NET code within a Rust environment.
use ;
Additional Resources
For more examples, check the examples folder in the repository.
CLI
rustclr
also includes a command-line interface (CLI) for running .NET assemblies with various configuration options. Below is a description of the available flags and usage examples.
The CLI accepts the following options:
-f, --file
: Specifies the path to the .NET assembly file to be executed (required).-i, --inputs
: Provides string arguments to be passed to the .NET program's entry point. This flag can be repeated to add multiple arguments.-r, --runtime-version
: Sets the .NET runtime version to use. Accepted values include"v2"
,"v3"
, and"v4"
. Defaults to"v4"
.-d, --domain
: Allows setting a custom name for the application domain (optional).
Example Command
clr.exe -f Rubeus.exe -i "triage" -i "/consoleoutfile:C:\Path" -r v4 -d "CustomDomain"
CLI Help
Host CLR and run .NET binaries using Rust
Usage: clr.exe [OPTIONS] --file <FILE>
Options:
-f, --file <FILE> Path to the .NET assembly file
-i, --inputs <INPUTS> String arguments for the .NET program
-r, --runtime-version <RUNTIME_VERSION> Specify .NET runtime version [default: v4]
-d, --domain <DOMAIN> Set custom application domain name
-h, --help Print help
-V, --version Print version
Contributing to rustclr
To contribute to rustclr, follow these steps:
- Fork this repository.
- Create a branch:
git checkout -b <branch_name>
. - Make your changes and commit them:
git commit -m '<commit_message>'
. - Push your changes to your branch:
git push origin <branch_name>
. - Create a pull request.
Alternatively, consult the GitHub documentation on how to create a pull request.
References
License
This project is licensed under the MIT License. See the LICENSE file for details.