3
다음 코드에서 취약점을 찾으려고합니다. 버퍼 오버 플로우와 함께 악용 될 수 있다고 생각하지만 불행히도 어디서부터 시작해야할지 모르겠습니다.Exercise about Buffer Overflow
#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'의 값을 검사하지 않으므로 예상치 못한 위치에'value'를 쓰려고 스택보다 큰 값으로 프로그램을 호출 할 수 있습니다. [다음은 스택 기반 버퍼 오버 플로우에 대한 기사입니다.] (https://en.wikipedia.org/wiki/Stack_buffer_overflow). –