pub trait Shellcoder: Debug {
// Required method
fn add<O>(&mut self, op: impl Borrow<O>) -> Result<&mut Self>
where O: Op;
// Provided methods
fn advance(&mut self, n: usize) -> Result<&mut Self> { ... }
fn fill(&mut self, len: usize, chr: u8) -> Result<&mut Self> { ... }
fn int_be<I>(&mut self, i: I) -> Result<&mut Self>
where I: EncodableInteger { ... }
fn int_le<I>(&mut self, i: I) -> Result<&mut Self>
where I: EncodableInteger { ... }
fn push_buffer(&mut self, buffer: impl AsRef<[u8]>) -> Result<&mut Self> { ... }
}
Expand description
Generic interface for shellcoders.
This is the generic interface for writing shellcodes.
§Examples
Writes a simple shellcode that exposes two addresses 8 bytes apart:
ⓘ
use shellcoder::{Op as _, Shellcoder as _};
use shellcoder::alloc::Shellcoder;
use shellcoder::ops;
let mut shellcoder = Shellcoder::new();
let shellcode = shellcoder
.int_le(0x100000fbau64)?
.advance(8)?
.int_le(0x10000fcdeu64)?
.as_bytes();
assert_eq!(shellcode, &[
0xba, 0x0f, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xde, 0xfc, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00]);
Writes a shellcode that copies another buffer, with doing no dynamic allocation.
ⓘ
use shellcoder::{Op as _, Shellcoder as _};
use shellcoder::r#static::Shellcoder;
use shellcoder::ops;
fn get_buffer() -> &'static [u8] {
b"pwnd"
}
let some_payload: &[u8] = get_buffer();
let mut scratch_buffer = [0u8; 42];
let shellcode = Shellcoder::new(&mut scratch_buffer)
.push_buffer(some_payload)?
.get();
assert_eq!(&shellcode[..4], b"pwnd");
Required Methods§
Sourcefn add<O>(&mut self, op: impl Borrow<O>) -> Result<&mut Self>where
O: Op,
fn add<O>(&mut self, op: impl Borrow<O>) -> Result<&mut Self>where
O: Op,
Pushes an operation, and returns the number of bytes that have been written.
§Errors
error::Error::OutputBufferTooSmall
: the provided output buffer is too small to contain the result of the operation.- [
Error:Io
]: an I/O error occurred.
Provided Methods§
Sourcefn advance(&mut self, n: usize) -> Result<&mut Self>
fn advance(&mut self, n: usize) -> Result<&mut Self>
Advances the cursor by n bytes, filling gaps with zeroes.
§Errors
error::Error::OutputBufferTooSmall
: the provided output buffer is too small to contain the result of the operation.- [
Error:Io
]: an I/O error occurred.
Sourcefn fill(&mut self, len: usize, chr: u8) -> Result<&mut Self>
fn fill(&mut self, len: usize, chr: u8) -> Result<&mut Self>
Fills with a certain number of bytes.
§Errors
error::Error::OutputBufferTooSmall
: the provided output buffer is too small to contain the result of the operation.- [
Error:Io
]: an I/O error occurred.
Sourcefn int_be<I>(&mut self, i: I) -> Result<&mut Self>where
I: EncodableInteger,
fn int_be<I>(&mut self, i: I) -> Result<&mut Self>where
I: EncodableInteger,
Pushes an integer in big endian.
§Errors
error::Error::OutputBufferTooSmall
: the provided output buffer is too small to contain the result of the operation.- [
Error:Io
]: an I/O error occurred.
Sourcefn int_le<I>(&mut self, i: I) -> Result<&mut Self>where
I: EncodableInteger,
fn int_le<I>(&mut self, i: I) -> Result<&mut Self>where
I: EncodableInteger,
Pushes an integer in little endian.
§Errors
error::Error::OutputBufferTooSmall
: the provided output buffer is too small to contain the result of the operation.- [
Error:Io
]: an I/O error occurred.
Sourcefn push_buffer(&mut self, buffer: impl AsRef<[u8]>) -> Result<&mut Self>
fn push_buffer(&mut self, buffer: impl AsRef<[u8]>) -> Result<&mut Self>
Pushes a buffer.
§Errors
error::Error::OutputBufferTooSmall
: the provided output buffer is too small to contain the result of the operation.- [
error::Error:Io
]: an I/O error occurred.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.