执行shell代码的典型结构如下-:(代码片段取自here)
char shellcode[] = ""; /* global array */
int
main (int argc, char **argv)
{
int (*ret)(); /* ret is a function pointer */
ret = (int(*)())shellcode; /* ret points to our shellcode */
/* shellcode is type caste as a function */
(int)(*ret)(); /* execute, as a function, shellcode[] */
exit(0); /* exit() */
}
为什么不使用asm(inline assembler)来执行 shellcode 呢?那么它比做指针杂技要简单得多,例如将数组转换为函数指针,然后将该数组作为函数执行?
使用汇编器有什么缺点吗?使用数组执行 shell 代码有什么特别的好处吗?