ELF Binary Obfuscation
ELF Binary Obfuscation
Index
●
ELF Structure
●
Overview
●
ELF Header
●
Sections & Segments
●
ASLR
●
Dynamic Relocations
●
0Pack
●
The beginnings
●
0Pack in action
●
So what happened?
●
First idea
●
Solution
●
0Pack inner workings
2
Overview
3 Img: https://github.com/corkami/pics/blob/master/binary/elf101/elf101-64.svg
ELF Header
●
Equals to one or more memory pages
●
Permissions located in
program header table
Sections
●
Purely optional
●
Metadata to divide a segment
●
Can be loaded into memory
but doesn’t have to
5 Img: https://upload.wikimedia.org
Address Space Layout Randomization
Randomized base
addresses of shared
libraries and
segments of the
binary and stack
6 Img: http://www.daniloaz.com/en/differences-between-aslr-kaslr-and-karl/
Address Space Layout Randomization
7
Dynamic Relocations
●
Many different relocation
types exists
●
The other ones are mostly
unknown
Note: Upper 4 bytes of r_info are the index, the lower 4 bytes are for the type
My goal:
Building a simple ELF obfuscator for ASLR binaries...
10
0Pack in action
They parse
Debugger checks if
the symbol table
Entrypoint is 0 entrypoint is If true
to locate the main
NULL
function
Sets the
entrypoint
to the main
function
The debugger
sets the breakpoint at
the wrong address!
12 Img: http://www.embeddedlinux.org
So how do we get a working executable out of this?
Execution now
starts here
13
First idea
ELF Header seen as code
0x7f45 => jg 0x47
●
ELF magic translates to indirect
jump
●
Jumps into program header
●
Change program header value to
another jump?
14
Solution
Writes the
Symbol value + Addend
to the target location
Relocations now
can overwrite any bytes!
Convert shellcode to
R_X86_64_64
Relocations
17