Skip to main content

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

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

Supported architectures

  • mips

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

Examples:

Makefile

Main.c

Compiling with libc

Libc has destructors and constructors this project doesn’t fully support libc. take a look at the provided example (which uses libc) and note that some function won’t work properly.

eg…

printf is using fwrite which uses the FILE * struct for stdout. this file is opened post libc initialization (in one of the libc constructors). __start is responsible for calling libc constructors and we don’t use __start (for other reasons). therefor you can’t use printf in the shellcode, but you can implement it using snprintf and write

Converting the elf to shellcode:

from elf_to_shellcode.relocate import make_shellcode

shellcode = make_shellcode(
    binary_path="/tmp/binary.out",
    arch="mips",
    endian="big"
)

with open("myshellcode.out", 'wb') as fp:
    fp.write(shellcode)

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 !

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-1.2.tar.gz (5.0 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: elf_to_shellcode-1.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for elf_to_shellcode-1.2.tar.gz
Algorithm Hash digest
SHA256 3a25bbb586a3e06a1eaa702b1c958a6fe915ed5f7812ac0749b44b553f115f65
MD5 838347ad9dad6fe002be1d2fda07fa25
BLAKE2b-256 79c1241817db6d4abaa87ca57e62225b10e0f2cf582c10c348ab6b5d42a82788

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page