CensoredUsername / dynasm-rs

A dynasm-like tool for rust.
https://censoredusername.github.io/dynasm-rs/language/index.html
Mozilla Public License 2.0
716 stars 52 forks source link

How to choose assembler for shellcode generation #57

Closed cireu closed 3 years ago

cireu commented 3 years ago

I'm using dynasm-rs to generate shellcode and inject to another process, the memory block for code is in remote process allocated via VirtualAllocEx. if I use default Assembler its memory is allocated by Rust, Should I use VecAssembler and supply base address in remote process manually?

CensoredUsername commented 3 years ago

Sounds like you've figured it out already! You can either determine the address you want to load in advance, assemble to a VecAssembler with that starting address, then use VirtualAllocEx and friends to copy the buffer into executable memory in that process, or you can have VirtualAllocEx to allocate a large enough area, take its return address and use that for VecAssembler to assemble to. For any address-dependent code you'll ofc have to work with where stuff will be in the process you're poking into.

The normal assemblers are built with the idea of running the code in the same process so those will indeed not help you very much.

cireu commented 3 years ago

Thanks for you answer ;)