我无法在堆栈上找到变量。我正在使用 Fedora 25 x64,但使用 32 位程序,顺便说一句。
C程序:
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
char* text1 = "AAAAAAAAAAAAA";
int target;
char* text2 = "BBBBBBBBBBBBB";
void vuln(char *string)
{
printf(string);
if(target) {
printf("you have modified the target :)\n");
}
}
int main(int argc, char **argv)
{
vuln(argv[1]);
printf("Program name: %s", argv[0]);
}
/* 在进入 main 并执行 x/500wx $esp 以检查 gdb 中的堆栈后,这是一个片段:
0xffffcc00: 0x00000000 0x00000000 0x00000000 0xf7fe0ca0
0xffffcc10: 0xf7df12af 0xf7fd765f 0x00000000 0x00000000
0xffffcc20: 0x00000000 0x00000000 0x00000000 0x0d696910
0xffffcc30: 0x00000000 0x00000000 0xf7fe0b79 0xf7de1ef0
0xffffcc40: 0x00000961 0xf7fd13d8 0x7c96f087 0xf7fe1399
0xffffcc50: 0x00000001 0x00000004 0xf7deb534 0x00000961
0xffffcc60: 0xf7deb604 0xf7fd13d8 0xffffccbc 0xffffccb8
0xffffcc70: 0x00000003 0x00000000 0xf7ffcfcc 0xf7fd764c
0xffffcc80: 0xf7deb534 0x7c96f087 0xf7deb604 0xf7de1f12
0xffffcc90: 0x03e4b784 0xffffccb8 0xffffcd48 0x00000961
0xffffcca0: 0x00000000 0x00000000 0x00000000 0x00000000
0xffffccb0: 0x00000000 0x00000000 0x00000000 0x00000000
(gdb) print &text1
$2 = (char **) 0x804a01c <text1>
(gdb) print text1
$3 = 0x8048544 'A' <repeats 13 times>
(gdb)
如您所见,我的 text1 变量的地址在该0x804区域中,而我的堆栈在该区域中,0xffffcc这就是我完全迷失的原因。您可能会看到我正在尝试做的事情,但我正在尝试定位 0x414141 和目标,然后是 0x42424242,但是在 esp 附近的堆栈区域中的任何地方都没有 41s 或 42s。我目前正在对格式字符串漏洞进行自我教育,但此时,我什至无法在堆栈中找到变量。有什么我想念的吗?谢谢。

