Coder Social home page Coder Social logo

shellcoder's Introduction

Shellcoder: Write shellcode payloads in a flash!

minimum supported Rust version: 1.61.0

Documentation: docs.rs/shellcoder.

Feature flags

shellcoder comes with the following feature flags:

name description enabled by default
std Use the standard library. Gives access to I/O backed and Vec backed implementations. no

Add shellcoder to your library

To add shellcoder to your Rust library, you can use Cargo:

$ cargo add shellcoder

Or alternatively, edit your Cargo.toml and add the following line under the dependencies section:

shellcoder = "0.1.0"

Examples

The following code writes a simple shellcode that comprises two addresses separated by a 8-byte gap. It uses the static implementation, i.e. no dynamic memory allocation is performed.

use shellcoder::{
    Op as _,
    Shellcoder as _,
};
use shellcoder::r#static::Shellcoder;
use shellcoder::Result;

pub fn main() -> Result<()> {
  // We define a scratch buffer to be used by [`Shellcoder`].
  let mut scratch_buffer = [0u8; 0x18];

  // We instantiate a _shellcoder_, the _static_ one.
  let mut shellcoder = Shellcoder::new(&mut scratch_buffer);

  // We build the shellcode.
  let shellcode = shellcoder
    .write_le(0x10000abccu64)? // writes little-endian encoded 0x10000abcc.
    .fill(8, b'A')?            // moves the cursor 8 bytes ahead,
                               // filling the gap with 'A'
    .write_le(0x10000fffc)?    // writes little-endian encoded 0x10000fffc.
    .get();

  assert_eq!(shellcode, &[
    0xcc, 0xab, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
    0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
    0xfc, 0xff, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  ]);
  Ok(())
}

License

Apache2, see License.

shellcoder's People

Contributors

zadlg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.