The Attack Lab: Understanding Buffer Overflow Bugs
在2个程序上对不同的安全漏洞生成5次攻击。这才是信息安全吗(xd
官方说明文档中指出了需要做的几个phase
Phase_1
源码
test函数的源码如下所示
1 2 3 4 5 6
voidtest() { int val; val = getbuf(); printf("No exploit. Getbuf returned 0x%x\n", val); }
该函数调用了getbuf函数
我们的攻击目标是改变程序第五行打印字符串这一行为,让程序返回到touch1。
touch1的c代码如下
1 2 3 4 5 6 7
voidtouch1() { vlevel = 1; /* Part of validation protocol */ printf("Touch1!: You called touch1()\n"); validate(1); exit(0); }
反汇编test
1 2 3 4 5 6 7 8 9 10 11 12
Dump of assembler code for function test: 0x0000000000401968 <+0>: sub $0x8,%rsp 0x000000000040196c <+4>: mov $0x0,%eax 0x0000000000401971 <+9>: call 0x4017a8 <getbuf> 0x0000000000401976 <+14>: mov %eax,%edx 0x0000000000401978 <+16>: mov $0x403188,%esi 0x000000000040197d <+21>: mov $0x1,%edi 0x0000000000401982 <+26>: mov $0x0,%eax 0x0000000000401987 <+31>: call 0x400df0 <__printf_chk@plt> 0x000000000040198c <+36>: add $0x8,%rsp 0x0000000000401990 <+40>: ret End of assembler dump.
反汇编getbuf
1 2 3 4 5 6 7 8
Dump of assembler code for function getbuf: 0x00000000004017a8 <+0>: sub $0x28,%rsp 0x00000000004017ac <+4>: mov %rsp,%rdi 0x00000000004017af <+7>: call 0x401a40 <Gets> 0x00000000004017b4 <+12>: mov $0x1,%eax 0x00000000004017b9 <+17>: add $0x28,%rsp 0x00000000004017bd <+21>: ret End of assembler dump.
voidtouch2(unsigned val) { vlevel = 2; /* Part of validation protocol */ if (val == cookie) { printf("Touch2!: You called touch2(0x%.8x)\n", val); validate(2); } else { printf("Misfire: You called touch2(0x%.8x)\n", val); fail(2); } exit(0); }
Phase 3 also involves a code injection attack, but passing a string as argument.
1 2 3 4 5 6 7 8 9 10 11 12
voidtouch3(char *sval) { vlevel = 3; /* Part of validation protocol */ if (hexmatch(cookie, sval)) { printf("Touch3!: You called touch3(\"%s\")\n", sval); validate(3); } else { printf("Misfire: You called touch3(\"%s\")\n", sval); fail(3); } exit(0); }
touch3调用了hexmatch,其c语言表示为:
1 2 3 4 5 6 7 8 9
/* Compare string to hex represention of unsigned value */ inthexmatch(unsigned val, char *sval) { char cbuf[110]; /* Make position of check string unpredictable */ char *s = cbuf + random() % 100; sprintf(s, "%.8x", val); returnstrncmp(sval, s, 9) == 0; }