免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2020 | 回复: 4
打印 上一主题 下一主题

相同的程序,每次运行时,栈都是从同一个地址开始的吗? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-01-13 22:39 |只看该作者 |倒序浏览
估计我没有说清楚..
是这样的  有下面一个程序
//sp.c

unsigned long find_sp(void){
  __asm__("movl %esp, %eax");
}
int main(int argc,char* argv[]){
char* buff;
int   len;
long sp;
len=atoi(argv[1]);
buff=malloc(len);
sp=find_sp();
printf("sp is 0x%x\n",sp);
free(buff);
exit(0);

}

然后我每次运行 ,输入相同的参数 我觉得打印结果应该是一样的吧   然而输出的结果每次都不同

比如
./sp 300

请问是怎么回事呢

谢谢大家

论坛徽章:
0
2 [报告]
发表于 2007-01-13 23:21 |只看该作者
在linux中,栈的起始地址是动态变化的,与当前运行的程序和栈的情况有关

论坛徽章:
0
3 [报告]
发表于 2007-01-13 23:45 |只看该作者
楼主:请问您用 2.6 版本的内核吗?谢谢。

论坛徽章:
0
4 [报告]
发表于 2007-01-14 00:27 |只看该作者
我是看了这段话时 发现的  我用linux时间不长 最近在学溢出   看的很晕

原文如下:

One of the most difficult tasks you face when trying to execute user-supplied shellcode is identifying the starting address of your shellcode. Over the years, many different methods have been contrived to solve this problem. We will cover the most popular method that was pioneered in the paper, "Smashing the Stack."

One way to discover the address of our shellcode is to guess where the shellcode is in memory. We can make a pretty educated guess, because we know that for every program, the stack begins with the same address. If we know what this address is, we can attempt to guess how far from this starting address our shellcode is.

It is fairly easy to write a simple program to tell us the location of the stack pointer (ESP). Once we know the address of ESP, we simply need to guess the distance, or offset, from this address. The offset will be the first instruction in our shellcode.






我的是red hat 9
Kernel 2.4.20-8

论坛徽章:
0
5 [报告]
发表于 2007-01-14 00:38 |只看该作者
原帖由 朱熹之 于 2007-1-13 23:21 发表
在linux中,栈的起始地址是动态变化的,与当前运行的程序和栈的情况有关

恩,这些信息都是动态的
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP