在进行真正的格式化字符串攻击之前,我们需要了解一些基础知识,方便更好的理解该类漏洞。 个人感觉我们还需要一些堆栈相关的基础知识才能更好的理解并运用格式化字符串漏洞。接下来我们就一起看一下栈相关的知识: 说到栈我们不得不提的就是函数调用与参数传递,因为栈的作用就是动态的存储函数之间的调用关系,从而保证在被调用函数返回时能够回到母函数中继续执行。栈 其实是一种数据结构,栈中的数据是先进后出(First In Last Out),常见的操作有两种:
bingtangguan@ubuntu:~/Desktop/format$ gdb ./format1 GNU gdb (Ubuntu 7.8-1ubuntu4) 7.8.0.20141001-cvs Copyright (C) 2014 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i686-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./format1...(no debugging symbols found)...done. >>> start Temporary breakpoint 1 at 0x8048429 Starting program: /home/bingtangguan/Desktop/format/format1 ─── Output/messages ──────────────────────────────────────────────────────────── Temporary breakpoint 1, 0x08048429 in main () ─── Assembly ─────────────────────────────────────────────────────────────────── 0x08048425 main+10 push %ebp 0x08048426 main+11 mov %esp,%ebp 0x08048428 main+13 push %ecx 0x08048429 main+14 sub $0x24,%esp 0x0804842c main+17 movl $0x1,-0xc(%ebp) 0x08048433 main+24 movl $0x2,-0x10(%ebp) 0x0804843a main+31 movl $0x3,-0x14(%ebp) ─── Expressions ──────────────────────────────────────────────────────────────── ─── History ──────────────────────────────────────────────────────────────────── ─── Memory ───────────────────────────────────────────────────────────────────── ─── Registers ────────────────────────────────────────────────────────────────── eax 0x00000001 ecx 0xbffff070 edx 0xbffff094 ebx 0xb7fc1000 esp 0xbffff054 ebp 0xbffff058 esi 0x00000000 edi 0x00000000 eip 0x08048429 eflags [ PF SF IF ] cs 0x00000073 ss 0x0000007b ds 0x0000007b es 0x0000007b fs 0x00000000 gs 0x00000033 ─── Source ───────────────────────────────────────────────────────────────────── ─── Stack ────────────────────────────────────────────────────────────────────── [0] from 0x08048429 in main+14 (no arguments) ─── Threads ──────────────────────────────────────────────────────────────────── [1] id 3590 name format1 from 0x08048429 in main+14 ──────────────────────────────────────────────────────────────────────────────── >>> break printf Breakpoint 2 at 0xb7e652f0: file printf.c, line 28. >>> r Starting program: /home/bingtangguan/Desktop/format/format1 ─── Output/messages ──────────────────────────────────────────────────────────── Breakpoint 2, __printf (format=0x8048510 "%s %d %d %d %x\n") at printf.c:28 28 printf.c: No such file or directory. ─── Assembly ─────────────────────────────────────────────────────────────────── 0xb7e652f0 __printf+0 push %ebx 0xb7e652f1 __printf+1 sub $0x18,%esp 0xb7e652f4 __printf+4 call 0xb7f3d90b <__x86.get_pc_thunk.bx> 0xb7e652f9 __printf+9 add $0x15bd07,%ebx ─── Expressions ──────────────────────────────────────────────────────────────── ─── History ──────────────────────────────────────────────────────────────────── ─── Memory ───────────────────────────────────────────────────────────────────── ─── Registers ────────────────────────────────────────────────────────────────── eax 0xbffff03f ecx 0xbffff070 edx 0xbffff094 ebx 0xb7fc1000 esp 0xbffff00c ebp 0xbffff058 esi 0x00000000 edi 0x00000000 eip 0xb7e652f0 eflags [ PF ZF IF ] cs 0x00000073 ss 0x0000007b ds 0x0000007b es 0x0000007b fs 0x00000000 gs 0x00000033 ─── Source ───────────────────────────────────────────────────────────────────── Cannot access "/build/buildd/glibc-2.19/stdio-common/printf.c" ─── Stack ────────────────────────────────────────────────────────────────────── [0] from 0xb7e652f0 in __printf+0 at printf.c:28 arg format = 0x8048510 "%s %d %d %d %x\n" [1] from 0x08048466 in main+75 (no arguments) ─── Threads ──────────────────────────────────────────────────────────────────── [1] id 3594 name format1 from 0xb7e652f0 in __printf+0 at printf.c:28