壳牌code与C程序 [英] Shellcode in C program

查看:176
本文介绍了壳牌code与C程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

链接<一个href=\"http://hackoftheday.securitytube.net/2013/04/demystifying-execve-shell$c$c-stack.html\">http://hackoftheday.securitytube.net/2013/04/demystifying-execve-shell$c$c-stack.html
突出的方式来写一个execve的外壳code。

 #包括LT&;&stdio.h中GT;
#包括LT&;&string.h中GT;unsigned char型code [] =
\"\\x31\\xc0\\x50\\x68\\x6e\\x2f\\x73\\x68\\x68\\x2f\\x2f\\x62\\x69\\x89\\xe3\\x50\\x89\\xe2\\x53\\x89\\xe1\\xb0\\x0b\\xcd\\x80\";主要()
{    的printf(壳牌code长度:%d个\\ N的strlen(code));    INT(* RET)()=(INT(*)())code;    RET();
}

这是什么,行int (* RET)()=(INT(*)())code;


解决方案

  INT(* RET)()=(INT(*)())code;
  ~~~~~~~~~~~~ ~~~~~~~~~~~~~~
        1 2  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
               3


  1. 它定义 RET 作为一个指针指向一个函数,没有参数()并返回 INT 。所以,那些()表示的函数参数的定义。


  2. 这是用于铸造 code 来的指针,它没有参数的函数()并返回 INT


  3. 强制类型转换 code 作为一个函数,并将其分配给 RET 。之后,你可以调用 RET();


&NBSP;

  unsigned char型code [] =\\ X31 \\ XC0 \\ X50 \\ X68 \\ x6e \\ X2F \\ ...

这是机器指令序列重新用十六进制值psented $ P $。它将被注入到code作为一个函数。

The link http://hackoftheday.securitytube.net/2013/04/demystifying-execve-shellcode-stack.html highlights a way to write an execve shellcode.

#include<stdio.h>
#include<string.h>

unsigned char code[] = 
"\x31\xc0\x50\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80";

main()
{

    printf("Shellcode Length: %d\n", strlen(code));

    int (*ret)() = (int(*)())code;

    ret();
}

What does the line int (*ret)() = (int(*)())code; do?

解决方案

  int (*ret)() = (int(*)())code;
  ~~~~~~~~~~~~   ~~~~~~~~~~~~~~
        1              2

  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
               3

  1. It defines ret as a pointer to a function which has no parameter () and returns int. So, Those () indicates the definition of parameters of a function.

  2. It's for casting code to a pointer to a function which has no parameter () and returns int.

  3. Casts code as a function and assigns it to ret. After that you can call ret();.

 

unsigned char code[] =  "\x31\xc0\x50\x68\x6e\x2f\...

It is a sequence of machine instructions represented by hex values. It will be injected to the code as a function.

这篇关于壳牌code与C程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆