大家好,將shellcode聲明爲char []數組和char *之間的區別
我想學習基本的shellcoding,我跑過好奇的東西,我希望有人能向我解釋。我用兩種方法編譯了下面的代碼:將shellcode聲明爲數組和char *。當我將shellcode聲明爲一個數組時,linux檢測到我正在嘗試執行數據,並且在第一條指令中出現了段錯誤。但是,當我將shellcode聲明爲char *時,所有的shellcode都會執行,並且我得到一個「Hello world!」。編譯器如何以不同的方式處理這兩個聲明,以及爲什麼一個終結於不受保護的內存中的shellcode?提前致謝。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* This declaration ends in a segfault */
//char shellcode[] =
/* This declaration ends in successful execution */
char* shellcode =
/* Shellcode prints "Hello world!" and exits */
"\xeb\x1f\x48\x31\xc0\x48\x31\xdb\x48\x31\xc9\x48\x31\xd2\xb0\x04\xb3\x01\x59\xb2\x0c\xcd\x80\x48\x31\xc0\xb0\x01\x48\x31\xdb\xcd\x80\xe8\xdc\xff\xff\xff\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64\x21";
int main()
{
void (*f)();
f = (void (*)())shellcode;
(void)(*f)();
}