小编dan*_*ani的帖子

将shellcode声明为char []数组和char*之间的区别?

大家好,

我正在尝试学习基本的shell编码,我遇到了一些奇怪的事情,我希望有人可以向我解释.我已经用两种方式编译了以下代码:将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)();
}
Run Code Online (Sandbox Code Playgroud)

c arrays pointers shellcode

9
推荐指数
1
解决办法
1715
查看次数

标签 统计

arrays ×1

c ×1

pointers ×1

shellcode ×1