Skip to main content

Python package to create shellcdoes from elfs supported arch (mips, arm (32bit), i386 32bit, i386 64bit, aarch64)

Project description

Elf to shellcode

Convert standard elf files to standalone shellcodes. Please read the following documentation and view the examples for this project to work properly

Project links

Github

Pypi

Supported architectures

  • mips
  • i386 (32bit)
  • i386 (64bit)
  • arm (32bit)
  • aarch64 (arm 64 bit)

Installation:

pip install elf_to_shellcode
Python version support
  • python3

How does this work ?

The python library parses the elf and create a simple relocatable file format Then the mini loader is inserted as the entry point of the elf the mini loader will load the relocatable format and execute it. There are no special requirements, the library contain the compiled mini loaders.

  classDiagram
    ShellcodeEntryPoint --|> MiniLoader
    ShellcodeEntryPoint: Shellcode to jump into the mini loader
    MiniLoader --|> Relocation table
    MiniLoader: Contain all the logic for parsing the relocation table
    MiniLoader: fully os independent
    Relocation table --|> SHELF
    Relocation table : Contain table required for shellcode runtime relocation
    SHELF: Shellcode elf - This is the compiled binary we convert into shellcode
    SHELF: This binary is stripped into only opcodes
    SHELF: fully relocatable using the relocation table

This project is intended to convert elf to os independent shellcodes. Therefor the loader never allocate memory and the shellcode format is not packed. You can just execute it, eg ...

((void (*)()) shellcode)();

note that __libc_start_main perform syscalls therefor if you want your shellcode to be fully os independent you must compile with -nostartfiles follow the examples below

Creating a shellcode

Some compilation flags are required for this to work properly. You must compile the binary with -fPIE and -static take a look at the provided examples below (makefile).

shellcode is a stripped binary with no symbols and no elf information only opcodes, in order to make the shellcode this library require a binary with elf information. so make sure you are not stripping the binary before using this library

simplified make command for mips big endian

gcc example.c -fno-stack-protector -fPIE -fpic -static -nostartfiles --entry=main -o binary.out
python -m elf_to_shellcode --input binary.out                                     

Examples:

Makefile

Example.c

Testing your shellcode

You can use the provided shellcode Loader to test you shellcodes

qemu-mips ./shellcode_loader ./myshellcode.out

Output example

Shellcode size = 66620
Allocating shellcode buffer, size = 69632
Mapping new memory, size = 69632
Jumping to shellcode, address = 0x7f7ee000
Hello from shellcode !

Advanced concepts and features

for following links only work on the github page

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

elf_to_shellcode-2.2.8.tar.gz (7.1 MB view details)

Uploaded Source

File details

Details for the file elf_to_shellcode-2.2.8.tar.gz.

File metadata

  • Download URL: elf_to_shellcode-2.2.8.tar.gz
  • Upload date:
  • Size: 7.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.8.3 requests/2.27.1 setuptools/44.1.1 requests-toolbelt/0.10.1 tqdm/4.64.1 CPython/2.7.18

File hashes

Hashes for elf_to_shellcode-2.2.8.tar.gz
Algorithm Hash digest
SHA256 1ee8ee6428f608fd4ec7c1a521ec7b22464287ca2f904b85d7674a3c2fb80841
MD5 b6951f9405e236e85bf4a8d774b8ecbf
BLAKE2b-256 25117bbc0bde9738c88511b6a93b74be4825dddbcbf41c472e940aac860fb8ec

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page