Shellcode in C program

前端 未结 4 1567
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 06:01

In Demystifying the Execve Shellcode is explained a way to write an execve shellcode:

#include
#include

unsigned char code[]          


        
4条回答
  •  醉酒成梦
    2020-11-30 06:30

      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.

提交回复
热议问题