{"uuid": "d3096da9-c2e6-44d8-ba7e-660d4d8b9a42", "vulnerability_lookup_origin": "1a89b78e-f703-45f3-bb86-59eb712668bd", "author": "2a075640-a300-48a4-bb44-bc6130783b9b", "vulnerability": "CVE-2018-18311", "type": "published-proof-of-concept", "source": "https://t.me/novitoll_ch/12", "content": "*ret2libc. Part 2* Long Read.\n_\"Most libraries contain enough gadgets to provide a Turing complete programming language\"_\n\nTL;DR: ret2libc - \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \"\u043f\u0440\u044b\u0433\u043d\u0443\u0442\u044c \u0432 GNU libc \u0438 \u043d\u0430\u0439\u0442\u0438 system('/bin/sh')\", \u0430 \u0446\u0435\u043b\u044b\u0439 \u043c\u0438\u0440 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0437\u0430\u0449\u0438\u0442\u044b (Full ASLR [PaX PIE \u0432\u043e\u0442 \u044d\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0438 \u043c\u043e\u0449\u043d\u0430\u044f \u0437\u0430\u0449\u0438\u0442\u0430]) \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0430\u0442\u0430\u043a\u0438. \u0418\u043d\u044c \u0438 \u042f\u043d\u044c. Stack buffer overflow \u0435\u0449\u0435 \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043d\u0435 \u0434\u043e\u0448\u043b\u0438 \u0435\u0449\u0435 \u0434\u043e \u0440\u0430\u0437\u0431\u043e\u0440\u0430 stack-clash. \u0414\u0430\u043b\u044c\u0448\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u043f\u043e heap-buffer-overflow \u0438 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0441\u0432\u0435\u0436\u0438\u0439 *CVE-2018-18311* Perl 5 (integer overflow)[1]. Stay tuned.\n\n\u0411\u0438\u0447 buffer overflow - \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0438\u043b\u0438 \u0441\u043b\u0430\u0431\u043e\u0441\u0442\u044c \u0432 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 boundaries checking.\n\n_\"1. Go to Africa. 2. Put an elephant in Cairo. 3. Start at the Cape of Good Hope...\"_ @ Byte magazine, September 1989\n\n\u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c ret2libc, \u0432\u043e\u0442 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0442\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u043d\u0430 \u0442\u0430\u043a\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b, \u0449\u0435\u043b\u043a\u0430\u044f \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0430\u043c \u0432 \u0412\u0438\u043a\u0438\u043f\u0435\u0434\u0438\u0438:\n- Buffer overflow protection -&gt; Canary protection.\n&gt; Sentinel value (which is not to be confused with a canary value)\n- \"Sentinel value\"\n&gt; A sentinel value is sometimes known as an \"Elephant in Cairo\"\n, \u0433\u0434\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0445\u043e\u0442\u043d\u0438\u043a\u0438 \u043d\u0435 \u0443\u0448\u043b\u0438 \u0432 \u0421\u0440\u0435\u0434\u043d\u0438\u0437\u0435\u043c\u043d\u043e\u0435 \u043c\u043e\u0440\u0435, \u0432 \u043f\u043e\u0438\u0441\u043a\u0430\u0445 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u043d\u0430 \u043d\u0430 \u0441\u0435\u0432\u0435\u0440, \u043d\u0443\u0436\u043d\u043e \"\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c\" \u0441\u043b\u043e\u043d\u0430 \u0432 \u041a\u0430\u0438\u0440\u0435, \u0438\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u043d\u0443\u0436\u0435\u043d \\0 \u0434\u043b\u044f char[] mystring, \u043d\u0443\u0436\u0435\u043d NULL \u0434\u043b\u044f LinkedList \u0438 \u0442\u0434.\n\n\u0412\u0440\u043e\u0434\u0435 \u0431\u044b \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u0449\u0443\u0449\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u0440\u0430\u0437 LiveOverflow (Fabian) \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b \u043f\u0440\u043e ret2libc \u0437\u0430 10 \u043c\u0438\u043d\u0443\u0442, \u0438 \u044f \u0441\u0430\u043c \u0441\u043c\u043e\u0433 \u0432 protostar \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u043a\u0435 (`Linux 2.6.32-5-686, i686 GNU/Linux`) \u0437\u0430\u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0435\u0437 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f execstack stack6 \u0447\u0435\u0440\u0435\u0437 ret2libc, \u043f\u043e\u043b\u0443\u0447\u0438\u0432 root \u0431\u0438\u043d\u0430\u0440\u043d\u0438\u043a\u0430 \u0441 SUID, \u0442\u043e \u044f \u043c\u043e\u0433\u0443 \u0441\u043c\u0435\u043b\u043e \u0438\u0434\u0442\u0438 \u0432\u043f\u0435\u0440\u0435\u0434, \u0441\u0447\u0438\u0442\u0430\u044f \"\u0434\u0430, \u044f \u0437\u043d\u0430\u044e \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 ret2libc...\", \u043d\u043e _\"The devil is in the detail\"_. Fuck yeah, shit is true.\n\n### Canaries &amp; gcc -fstack-protector ###\n&gt; Canaries are known values that are placed between a buffer and control data on the stack to monitor buffer overflow.\n\n\u041d\u0430\u0447\u0430\u043b\u043e\u0441\u044c \u0432\u0441\u0435 \u0441 1998-\u0433\u043e \u0433\u043e\u0434\u0430 \u043d\u0430 USENIX Security Symposium \u043a\u043e\u0433\u0434\u0430 \u0440\u0435\u0448\u0438\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c StackGuard \u0432 GCC[2]. \u0418 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0435\u0433\u043e \u0432 \u043c\u0435\u0439\u043d\u0441\u0442\u0440\u0438\u043c, \u0434\u0430\u043b\u044c\u0448\u0435 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f \u043a\u0430\u043a \u0432 ProPolice, \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e \u0432\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0435 \u043a\u0430\u043a -fstack-protector \u0432 GCC.\n\n\u0411\u043e\u043b\u044c\u0448\u0435 \u0437\u0430\u0449\u0438\u0442\u044b - \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u0432\u0435\u043a\u0442\u043e\u0440 \u0430\u0442\u0430\u043a\u0438. \u0412 \u041b\u0438\u043d\u0443\u043a\u0441\u0435 \u0435\u0441\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 CONFIG_STACKPROTECTOR=y (`$ cat /boot/config-$(uname -r) | grep STACKPROTECTOR`), \u043a\u043e\u0442\u043e\u0440\u044b\u0439, AFAIU, \u0434\u0435\u043b\u0430\u0435\u0442 \u043e\u0444\u0444\u0441\u0435\u0442 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0442\u044d\u043a \u0444\u0440\u0435\u0439\u043c\u0430 \u0440\u0430\u043d\u0434\u043e\u043c\u043d\u044b\u043c unsigned long __stack_chk_guard \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 BOOT \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 random seed. \u0422\u043e \u0435\u0441\u0442\u044c, \u044d\u0442\u043e \u0435\u0449\u0435 \u0432\u0434\u043e\u0431\u0430\u0432\u043e\u043a \u043a \u0437\u0430\u0449\u0438\u0442\u0435 Stack guard page (256UL&lt; padding (\u0434\u043e 0x080484f9: ret) + libc_syscall + 4-bytes-junk (32-bit) + (optional: + nopslide*100) + libc_bin_sh\n\n\u0412 \u0438\u0442\u043e\u0433\u0435, \u043c\u044b \u043d\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043d\u0430\u0448\u0435\u0433\u043e \u0448\u0435\u043b\u043b\u043a\u043e\u0434\u0430, \u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u043e\u0442 \u0430\u0434\u0440\u0435\u0441 /bin/sh, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u0432 GNU libc (\u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043d\u0430\u0434\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0444\u0444\u0441\u0435\u0442).\nBoom! Arbitrary code execution.\n\n### ret2libc improvements. ###\n- ret2libc. Aug, 10, 1997. by Solar Designer. \u042d\u0442\u043e \u043c\u044b \u0443\u0436\u0435 \u043f\u0440\u043e\u0448\u043b\u0438 \u0432\u044b\u0448\u0435.\n- ret2strcpy. Jan, 30, 1998, by Rafal Wojtczuk.\n- ret2plt. Jan, 30, 1998, by Rafal Wojtczuk. \u0423\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435 ret2strcpy \u0441 \u0443\u0447\u0435\u0442\u043e\u043c ASCII Armored Address Space (AAAS), \u0442\u043e \u0435\u0441\u0442\u044c, \u0441\u0442\u044d\u043a \u0430\u0434\u0440\u0435\u0441\u0430 \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c NULL byte, \u0447\u0442\u043e \u043f\u0440\u0438 strcpy(), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u0441 src \u0432 dest \u0434\u043e NULL \u0431\u0430\u0439\u0442\u0430, \u043c\u043e\u0436\u0435\u0442 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0432 \u0440\u0430\u043d\u0434\u043e\u043c\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435 (\u043e\u0431\u044b\u0447\u043d\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442) \u0441\u0442\u0440\u0438\u043d\u0433\u0438, \u0447\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0448\u0438\u043c eip \u0430\u0434\u0440\u0435\u0441\u043e\u043c. \u0421\u0442\u0430\u0442\u044c\u044f \u0441 explot-db[6]\n- ret2reg. \u0412\u043e\u0442 \u044d\u0442\u043e \u0445\u0437 \u043e\u0442\u043a\u0443\u0434\u0430 \u0432\u044b\u0448\u043b\u043e, \u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a bypass ASLR, \u043f\u0443\u0442\u0435\u043c \"\u043d\u0430\u0434\u0435\u0436\u0434\u044b\", \u0447\u0442\u043e \u0432 \u043a\u043e\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u0447\u0442\u043e-\u0442\u043e \u043d\u0430\u043f\u043e\u0434\u043e\u0431\u0435\u0435 jmp *%eax, \u0442.\u0435. \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c", "creation_timestamp": "2019-02-08T06:11:34.000000Z"}