我目前正在學習剝削藝術的剝削。開發部分的第一個代碼基本上教會了我一個非常基本的溢出。這是從書的代碼:緩衝區溢出不溢出
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
int value = 5;
char buffer_one[8], buffer_two[8];
strcpy(buffer_one, "one"); /* Put "one" into buffer_one. */
strcpy(buffer_two, "two"); /* Put "two" into buffer_two. */
printf("[BEFORE] buffer_two is at %p and contains \'%s\'\n", buffer_two, buffer_two);
printf("[BEFORE] buffer_one is at %p and contains \'%s\'\n", buffer_one, buffer_one);
printf("[BEFORE] value is at %p and is %d (0x%08x)\n", &value, value, value);
printf("\n[STRCPY] copying %d bytes into buffer_two\n\n", strlen(argv[1]));
strcpy(buffer_two, argv[1]); /* Copy first argument into buffer_two. */
printf("[AFTER] buffer_two is at %p and contains \'%s\'\n", buffer_two, buffer_two);
printf("[AFTER] buffer_one is at %p and contains \'%s\'\n", buffer_one, buffer_one);
printf("[AFTER] value is at %p and is %d (0x%08x)\n", &value, value, value);
}
與argv的執行後[1] = 1234567890我
[BEFORE] buffer_two is at 0x7ffc97c28ac0 and contains 'two'
[BEFORE] buffer_one is at 0x7ffc97c28ad0 and contains 'one'
[BEFORE] value is at 0x7ffc97c28adc and is 5 (0x00000005)
[STRCPY] copying 9 bytes into buffer_two
[AFTER] buffer_two is at 0x7ffc97c28ac0 and contains '1234567890'
[AFTER] buffer_one is at 0x7ffc97c28ad0 and contains 'one'
[AFTER] value is at 0x7ffc97c28adc and is 5 (0x00000005)
[後] buffer_one應該包含 「90」,而不是 「一」。我注意到我的偏移量是16字節而不是8字節(0x7ffc97c28ac0和0x7ffc97c28ad0),這就是爲什麼如果不溢出到buffer_one。任何想法我應該看看,這是一個非常嚴重的問題?
這本書是否指導你編譯x64?它是否指定了特定的編譯器,版本和標誌? – Dai
您使用的編譯器可能會將數據從作者使用的編譯器中分離出來。你也可能會注意到你拷貝了9個字節的程序 - 你認爲它應該拷貝了10個字節。 –
只是基本的'gcc -o overflow_example overflow_example.c',我在'-fno-stack-protector'中加入了,因爲沒有它,它檢測到堆棧粉碎。 – ledao