Rust Shellc0der
Shellc0der - A Rust Shellcode Encoder
First of all, the source-code can be found here.
This encoder supports several ways of changing the original shellcode:
- Block Reordering
- Payload Encoding
- Instruction Substitution
- Dead Code Insertion
The default functionality is the following:
-
- Divide the shellcode into blocks and reorder them
-
- Encode the full payload
-
- Generate unique decoder stub, insert dead code, switch instructions, …
-
- Combine the stub and the encoded payload and write it to the output file
Block Reordering
Block reordering works in the following way:
-
- Disassemble the payload (using capstone)
-
- Check for all JMP, Loop, JCC instructions and patch the destination by inserting newl generated labels
-
- Devide the instructions in blocks of X instructions each.
-
- The first and the last block stay the same
-
- The middle-blocks are randomly shuffled and glued together with
JMP
instructions
- The middle-blocks are randomly shuffled and glued together with
It looks somewhat like that:
Payload Encoding
The basic structure of the encoded shellcode looks like this:
-
- The initial shellcode gets encoded via XOR, in the following way:
Note: Every Block is a single byte
-
- A random decoder-stub is generated, that is setup in front of the encoded payload
-
- The registers used in the stub are randomly generated on each run
-
- Additionally, dead code snippets (random snippets & random # of snippets) are inserted into the stub
-
- Steps 1-4 can be repeated for arbitrary rounds, as seen below:
Credits
The inspiration came from:
- ShikataGaNai by Metasploit-Framework
- https://github.com/EgeBalci/sgn