Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/novafacing/cargo-shellcode
Cargo subcommand to build a crate into shellcode
https://github.com/novafacing/cargo-shellcode
Last synced: 19 days ago
JSON representation
Cargo subcommand to build a crate into shellcode
- Host: GitHub
- URL: https://github.com/novafacing/cargo-shellcode
- Owner: novafacing
- Created: 2024-08-15T20:48:50.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2024-08-15T22:22:11.000Z (about 1 month ago)
- Last Synced: 2024-08-16T21:12:43.451Z (about 1 month ago)
- Language: C++
- Homepage: https://crates.io/crates/cargo-shellcode
- Size: 2.92 MB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# cargo-shellcode
Compile your Rust project[^1] into shellcode for use in CTF or exploit development!
The subcommand runs an LLVM pass over your code which inlines all functions into the entrypoint,
and moves all globals into stack space. This allows you to write mostly-normal-looking code which
can be used as shellcode.![Example](asset/hello-world.gif)
## Install
```sh
cargo install cargo-shellcode
```You will need to have LLVM installed (e.g. `dnf install llvm llvm-libs llvm-devel`).
## Usage
To build your crate as shellcode:
```sh
cargo shellcode build
```Optionally, you can specify where to output the shellcode:
```sh
cargo shellcode build -o shellcode.bin
```To run your shellcode (note: this is pretty unsafe!):
```sh
cargo shellcode run
```Or to run a specific shellcode file:
```sh
cargo shellcode run shellcode.bin
```## Crate Layout
Not just any crate can be compiled down to shellcode. In general, you'll need to follow these rules:
* The entrypoint must be called `_start` or `main`
* Your code must be `#![no_std]` and `#![no_main]`, and compatible with `-nostartfiles` (i.e. a freestanding binary)
* Globals/constants may only be used by one function. Basically:
* Do not use `static` variables
* Put all `const` values in the function that uses them, not in global scopeFor an example of a crate that does something non-trivial that can be compiled to shellcode, check out [the examples](examples/hello-world/src/main.rs).
## Acknowledgements
This project (in particular the global variable inlining) is partially taken from and inspired by
[SheLLVM](https://github.com/SheLLVM/SheLLVM). Thanks![^1]: Some caveats apply, see [crate layout](#crate-layout).