Advertisement
Madmouse

smallest ELF binary in 32bit assembly 84bytes

Jun 5th, 2015
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [bits 32]
  2. section .text
  3. global _start
  4.  
  5. org 0x08048000
  6. ehdr:                                      ; Elf32_Ehdr
  7.     db 0x7F, "ELF", 1, 1, 1, 0         ;   e_ident
  8. ;   times 8 db      0
  9. ; We can replace ^ this with the following for a code cave inside the elf header itself
  10. _start:
  11.     xor ebx, ebx
  12.     xor eax, eax
  13.     inc eax
  14.     int 0x80
  15.     db 0    ; the code in the cave is 7 bytes long, so we need one byte of padding
  16. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  17.     dw 2                               ;   e_type
  18.     dw 3                               ;   e_machine
  19.     dd 1                               ;   e_version
  20.     dd _start                          ;   e_entry
  21.     dd phdr - $$                       ;   e_phoff
  22.     dd 0                               ;   e_shoff
  23.     dd 0                               ;   e_flags
  24.     dw ehdrsize                        ;   e_ehsize
  25.     dw phdrsize                        ;   e_phentsize
  26.     dw 1                               ;   e_phnum
  27.     dw 0                               ;   e_shentsize
  28.     dw 0                               ;   e_shnum
  29.     dw 0                               ;   e_shstrndx
  30.     ehdrsize equ $ - ehdr
  31.  
  32. phdr:                                      ; Elf32_Phdr
  33.     dd 1                               ;   p_type
  34.     dd 0                               ;   p_offset
  35.     dd $$                              ;   p_vaddr
  36.     dd $$                              ;   p_paddr
  37.     dd filesize                        ;   p_filesz
  38.     dd filesize                        ;   p_memsz
  39.     dd 7                               ;   p_flags
  40.     dd 0x1000                          ;   p_align
  41.     phdrsize equ $ - phdr
  42.  
  43. filesize equ $ - $$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement