 |
非安全编程演示之格式化字符串篇version1.1 |
|
| 非安全编程演示之格式化字符串篇version1.1 |
|
| 作者:未知 文章来源:网络收集 点击数: 更新时间:2006-3-29 15:24:02
|
|
版权:Core Security Team 目录: 简介 Fs1.c分析 Fs2.c分析 Fs3.c分析 Fs4.c分析 Fs5.c分析 结论 参考
译者注: 本文由Core Security发布,通过gera的Insecure Programming中的5个例子说明格式化 字符串漏洞。alert7前辈曾经由这5个例子写了《非安全编程演示之格式化字符串篇》,所 以我也就使用了同样的名字。翻译中的错误之处还请各位高手斧正。
简介
在这篇文章中,Core Security将展示c语言程序中程序员常犯的一些错误。通过gera举的 5个例子来说明format string(格式化字符串)这类型的问题。我们将确切指出程序中的bug, 并将阐述这种错误为什么是危险的,并针对每一个例子都将有一个exploit。在这篇文章中, 测试的平台是 Linux Slackware 8.0 server(IA32),编译器是 GNU GCC 2.95.3:
user@CoreLabs:~$ uname -a Linux CoreLabs 2.4.5 #31 SMP Sat Mar 2 03:04:23 EET 2002 i586 unknown
user@CoreLabs:~$ gcc -v Reading specs from /usr/lib/gcc-lib/i386-slackware-linux/2.95.3/specs gcc version 2.95.3 20010315 (release)
user@CoreLabs:~$ cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 5 model : 2 model name : Pentium 75 - 200
user@CoreLabs:~$
我们假设读者有c编程经验,并且有stack overflow,format string,GOT等的基础知识。在 本文中将不再一一赘述这些溢出的原理。如果不熟悉,请阅读文末的参考里的文章。
这篇文章以后的更新版本里也许会包括其他平台上的format string信息,大家可以在 www.core-sec.com下载到最新版本。
有任何问题,请联系:info@core-sec.com
fs1.c分析
这个例子的代码如下 /* fs1.c * * specially crafted to feed your brain by gera@core-sdi.com */
/* Don't forget, * * more is less, * * here's a proof */
int main(int argv,char **argc) { short int zero=0; int *plen=(int*)malloc(sizeof(int)); char buf[256];
// The next line is added by Core Security to ease exploitation. printf("%p\n", &zero);
strcpy(buf,argc[1]); printf("%s%hn\n",buf,plen); while(zero); }
这个例子没有离奇的地方。下面是printf()的man page中所说:
n The number of characters written so far is stored into the integer indicated by the int * (or variant) pointer argument. No argument is converted.
h A following integer conversion corresponds to a short int [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] 下一页
|
|
[ 收藏此页到: 天天|和讯|博采|ViVi|狐摘|我摘|天极 ] 文章录入:kinda 责任编辑:kinda |
|
上一篇文章: Thebat!139脱壳详情及对Asprotect加壳保护的一点小结(4千字) 下一篇文章: UNIX防止非法用户注册的技术 |
| 【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |