MCPcopy Index your code
hub / github.com/b1tg/rust-windows-shellcode

github.com/b1tg/rust-windows-shellcode @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
29 symbols 34 edges 4 files 1 documented · 3% updated 5y ago★ 310
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Write Windows Shellcode in Rust

Project overview

Windows shellcode project is located in shellcode/, it can build into a PE file with only .text section and has no external dependencies.

shellcode.exe in pe-bear

Then we can dump the .text section and do some patches to make it position-independent. this idea was from hasherezade's project masm_shc.

How to build it

(Only tested on Win10 x64)

Build shellcode binary

rustup default nightly-x86_64-pc-windows-msvc
cd shellcode/
cargo build --release

If everthing goes well, we will get shellcode\target\x86_64-pc-windows-msvc\release\shellcode.exe

Dump .text section and do some patches

We patch at the start of .text section, make it jump to entry point. In this way, we can have some strings store in the merged section, or we have to use u8 and u16 bytes array on stack to represent string.

cd ..
cargo run

We will get shellcode\target\x86_64-pc-windows-msvc\release\shellcode.bin, this is the final shellcode file.

Test shellcode

Test the shellcode use your favorite shellcode loader, i use my own little tool rs_shellcode for demonstration.

git clone https://github.com/b1tg/rs_shellcode
cd rs_shellcode/
cargo build
./target/debug/rs_shellcode.exe -f "shellcode\target\x86_64-pc-windows-msvc\release\shellcode.bin" 

This demo shellcode will popup a message box and print some log use OutputDebugStringA, you can check it out in debugview or windbg.

run shellcode

References

  • https://github.com/mcountryman/min-sized-rust-windows
  • https://github.com/hasherezade/masm_shc
  • https://github.com/Trantect/win_driver_example
  • https://not-matthias.github.io/kernel-driver-with-rust/
  • https://github.com/pravic/winapi-kmd-rs
  • https://github.com/johnthagen/min-sized-rust

Core symbols most depended-on inside this repo

get_func_by_name
called by 3
shellcode/src/main.rs
compare_raw_str
called by 2
shellcode/src/utils.rs
show_disassemble
called by 2
src/main.rs
get_module_by_name
called by 1
shellcode/src/main.rs
u16_ptr_len
called by 0
shellcode/src/utils.rs
compare_str_u16
called by 0
shellcode/src/utils.rs
str_to_u16_ptr
called by 0
shellcode/src/utils.rs
compare_str_u8
called by 0
shellcode/src/utils.rs

Shape

Class 14
Function 12
Enum 3

Languages

Rust100%

Modules by API surface

shellcode/src/binds.rs17 symbols
shellcode/src/utils.rs6 symbols
shellcode/src/main.rs4 symbols
src/main.rs2 symbols

For agents

$ claude mcp add rust-windows-shellcode \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact