Copy Link
Add to Bookmark
Report

2.14 84 byte aarch64 ELF

eZine's profile picture
Published in 
tmp0ut
 · 2 years ago

~ netspooky


I hadn't seen a golfed aarch64 binary so I decided to write one. It works the same as old golfed ELFs in kernels < 5.8. aarch64 instructions are fixed width, which made it a bit more challenging. Shoutout to ixi & the fox.


[: BASE64 POC :]

base64 -d <<< f0VMRuH//xAICIDSEAAAFAIAtwABAAAABAAAAAEAAAAcAAAAAAAAAAAA\ 
AAAAAAAAAQAAAEAAOAABAADU8v//FwAAAADy//8XAAAAAIIAgNL6//8X > aarch64.elf;

┌ ELF Header ─────┐
┌─────────┬───────────┤ 00: e_ident │
┌─ 00: 7f 45 4c 46 .ELF ─┐ │ │
│ ┌┬────────────────────┤ 04: ei_class │
│ ││ ┌┬─────────────────┤ 05: ei_data │
│ ││ ││ ┌┬──────────────┤ 06: ei_version │
┌ aarch64 Code ─────┐ │ ││ ││ ││ ┌┬───────────┤ 07: ei_osabi │
│ 04: adr x1, #0x0 ├──────────┬─────────┐ │ │ │
│ ; 0x0 is the │ │ 04: e1 ff ff 10 .... │ │ │
│ ; address of │ │ ┌┬────────────────────┤ 08: ei_abivers │
│ ; the string. │ │ ││ ┌──────┬───────────┤ 09: ei_pad │
│ 08: mov x8, #0x40 ├──────────┬─────────┐ │ │ │
│ ; The write │ │ 08: 08 08 80 d2 .... │ │ │
│ ; syscall. │ │ ┌─────────┬───────────┤ 0C: ei_pad │
│ 0C: b 0x40 ├──────────┬─────────┐ │ │ │
│ ; Jump down │ │ 0C: 10 00 00 14 .... │ │ ; EXEC │
│ ; to address │ │ ┌───┬─────────────────┤ 10: e_type │
│ ; 0x4C │ │ │ │ ┌───┬───────────┤ 12: e_machine │
│ │ │ 10: 02 00 b7 00 .... │ │ ; aarch64 │
│ ; This program │ │ ┌─────────┬───────────┤ 14: e_version │
│ ; moves address │ │ 14: 01 00 00 00 .... │ │ │
│ ; 0x00, which is │ │ ┌─────────┬───────────┤ 18: e_entry │
│ ; the ELF's magic │ │ 18: 04 00 00 00 .... │ │ ;100000004 │ ┌ Program Header ─┐
│ ; bytes. │ │ ┌─────────┬────────────────────────────────┤ 1C: p_type │
│ ; │ │ ┌─────────┬───────────┤ 1C: e_entry │ │ ; PT_LOAD │
│ ; It then sets │ │ 1C: 01 00 00 00 .... │ │ │ │ │
│ ; up a write │ │ ┌─────────┬────────────────────────────────┤ 20: p_flags │
│ ; syscall and │ │ ┌─────────┬───────────┤ 20: e_phoff │ │ ; PF_R │
│ ; prints using │ │ 20: 1c 00 00 00 .... │ │ ; 0x1C │ │ │
│ ; file descriptor │ │ ┌─────────┬────────────────────────────────┤ 24: p_offset │
│ ; 0, stdin. │ │ ┌─────────┬───────────┤ 24: e_phoff │ │ ; 0 │
│ ; │ │ 24: 00 00 00 00 .... │ │ │ │ │
│ ; x0 contains the │ │ ┌─────────┬────────────────────────────────┤ 28: p_offset │
│ ; file descriptor │ │ ┌─────────┬───────────┤ 28: e_shoff │ │ │
│ ; and is 0 when │ │ 28: 00 00 00 00 .... │ │ ; 0 │ │ ; 0 │
│ ; initialized. │ │ ┌─────────┬────────────────────────────────┤ 2C: p_vaddr │
│ ; │ │ ┌─────────┬───────────┤ 2C: e_shoff │ │ ;100000000 │
│ ; It prints │ │ 2C: 00 00 00 00 .... │ │ │ │ │
│ ; once and hangs, │ │ ┌─────────┬────────────────────────────────┤ 30: p_vaddr │
│ ; because write │ │ ┌─────────┬───────────┤ 30: e_flags │ │ │
│ ; returns the │ │ 30: 01 00 00 00 .... │ │ ; 1 │ │ │
│ ; number of bytes │ │ ┌─────────┬────────────────────────────────┤ 34: p_paddr │
│ ; written, 4 in │ │ ┌───┬─────────────────┤ 34: e_ehsize │ │ ; junk │
│ ; this case, and │ │ │ │ ┌───┬───────────┤ 36: e_phentsize │ │ │
│ ; tries to write │ │ 34: 40 00 38 00 @.8. │ │ ; 0x38 │ │ │
│ ; again to 4, a │ │ ┌─────────┬────────────────────────────────┤ 38: p_paddr │
│ ; non-existent fd │ │ ┌───┬─────────────────┤ 38: e_phnum │ │ │
│ │ │ │ │ ┌───┬───────────┤ 3A: e_shentsize │ │ │
│ 38: svc #0x0 ├──────────┬─────────┐ │ │ │ │ │
│ ; Call the │ │ 38: 01 00 00 d4 .... │ │ │ │ │
│ ; kernel │ │ ┌─────────┬────────────────────────────────┤ 3C: p_filesz │
│ │ │ ┌───┬─────────────────┤ 3C: e_shnum │ │ ; junk │
│ │ │ │ │ ┌───┬───────────┤ 3E: e_shstrndx │ │ │
│ 3C: b 0x4 ├──────────┬─────────┐ │ │ │ │ │
│ ; Jump back │ │ 3C: f2 ff ff 17 .... │ └─────────────────┘ │ │
│ ; to 0x4 │ │ ┌─────────┬────────────────────────────────┤ 40: p_filesz │
│ │ │ 40: 00 00 00 00 .... │ │ │
│ ; Only works on │ │ ┌─────────┬────────────────────────────────┤ 44: p_memsz │
│ ; kernels < 5.8 │ │ 44: f2 ff ff 17 .... │ │ ; junk │
│ ; See EBM4 for │ │ ┌─────────┬────────────────────────────────┤ 48: p_memsz │
│ ; more info. │ │ 48: 00 00 00 00 .... │ │ │
│ │ │ ┌─────────┬────────────────────────────────┤ 4C: p_align │
│ 4C: mov x2, #0x4 ├──────────┬─────────┐ │ │ ; junk │
│ ; *buf length │ │ 4C: 82 00 80 d2 .... │ │ │
│ │ │ ┌─────────┬────────────────────────────────┤ 50: p_align │
│ 50: b 0x38 ├──────────┬─────────┐ │ │ │
└──── ; Go 2 0x38 ──┘ └─ 50: fa ff ff 17 .... ─┘ └─────────────────┘

← previous
next →
loading
sending ...
New to Neperos ? Sign Up for free
download Neperos App from Google Play
install Neperos as PWA

Let's discover also

Recent Articles

Recent Comments

Neperos cookies
This website uses cookies to store your preferences and improve the service. Cookies authorization will allow me and / or my partners to process personal data such as browsing behaviour.

By pressing OK you agree to the Terms of Service and acknowledge the Privacy Policy

By pressing REJECT you will be able to continue to use Neperos (like read articles or write comments) but some important cookies will not be set. This may affect certain features and functions of the platform.
OK
REJECT