3
我试图在下面的代码中发现漏洞,我只是猜测它可以被缓冲区溢出利用,但不幸的是我不知道从哪里开始。关于缓冲区溢出的练习
#include <stdio.h>
#include <stdlib.h>
#define TABLELEN 7
int table[] = {2, 3, 5, 7, 11, 13, 17};
void loadTable(int *hashtable) {
int i;
for (i = 0; i < TABLELEN; i++) {
hashtable[i] = table[i];
}
}
int main(int argc, char *argv[])
{
int array[8];
int index;
int value;
if (argc < 3) {
fprintf(stderr, "Not enough args\n");
return -1;
}
loadTable(array);
index = (int) strtol(argv[1], NULL, 10);
value = (int) strtoul(argv[2], NULL, 16);
printf("Updating table value at index %d with %d: previous value was %d\n",
index, value, array[index]);
array[index] = value;
printf("The updated table is:\n");
for (index = 0; index < TABLELEN; index++) {
printf("%d: %d\n", index, array[index]);
}
return 0;
}
我想找到方法来利用数组大小是8,但只有7个元素已被声明的部分。我不是在寻找确切的解决方案,但任何帮助将不胜感激
由于在使用之前没有检查'index'的值,可以调用一个高于7的值来在一个意外的位置写入'value'来破坏堆栈。 [这是一篇关于基于堆栈的缓冲区溢出的文章](https://en.wikipedia.org/wiki/Stack_buffer_overflow)。 –