안녕 모두,쉘 코드를 char [] 배열로 선언 할 때와 char *를 선언 할 때의 차이점은 무엇입니까?
나는 기본적인 쉘 코딩을 배우려고 노력하고 있고, 나는 누군가가 나에게 설명 할 수 있기를 바란다는 궁금증에 빠져있다. 다음 코드를 두 가지 방법으로 컴파일했습니다 : 쉘 코드를 배열 및 char *로 선언하십시오. 쉘 코드를 배열로 선언하면 linux가 데이터를 실행하려고한다는 것을 감지하고 첫 번째 명령에서 segfault를 얻습니다. 그러나 쉘 코드를 char *로 선언하면 모든 쉘 코드가 실행되고 "Hello world!"가 표시됩니다. 컴파일러는 어떻게이 두 선언을 다르게 취급합니까? 그리고 보호되지 않는 메모리에있는 쉘 코드로 끝나는 이유는 무엇입니까? 미리 감사드립니다. 당신이 char[]
로 선언하면
#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)();
}