Advertisement
Madmouse

smallest ELF binary in 64bit assembly 120 bytes

Jun 5th, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [bits 64]
  2. section .text
  3. global _start
  4.  
  5. org 0x08048000
  6. ehdr:                                      ; Elf64_Ehdr
  7.     db 0x7F, "ELF", 2, 1, 1, 0         ;   e_ident
  8. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9. ;   times 8 db      0
  10. ; We can replace ^ this with the following for a code cave inside the elf header itself
  11. _start:
  12.     mov al, 60
  13.     xor rdi, rdi
  14.     syscall
  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 62                              ;   e_machine
  19.     dd 1                               ;   e_version
  20.     dq _start                          ;   e_entry
  21.     dq phdr - $$                       ;   e_phoff
  22.     dq 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. phdr:                                      ; Elf64_Phdr
  32.     dd 1                               ;   p_type
  33.     dd 7                               ;   p_flags
  34.     dq 0                               ;   p_offset
  35.     dq $$                              ;   p_vaddr
  36.     dq $$                              ;   p_paddr
  37.     dq filesize                        ;   p_filesz
  38.     dq filesize                        ;   p_memsz
  39.     dq 0x1000                          ;   p_align
  40.     phdrsize equ $ - phdr
  41. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  42.  
  43.  
  44. filesize equ $ - $$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement