admin 管理员组

文章数量: 1184232

 

测试环境:redhat

 

程序跑飞原因分析

  •  Buffer overflows (缓冲区溢出)
  •  Integer overflows (整数翻转)
  •  Signedness issues (符号)
  •  Invalid memory references (非法指针)
  •  Infinite loops (死循环)

 

程序崩溃分析:

指针,空指针使用(NULL),非法指针(0x00000000)

栈溢出, strcpy拷贝长字符串到局部变量

格式化串, printf漏写或多写变量

堆溢出, malloc会保存一些控制数据(元数据)在分配给用户的内存块前/后位置。

 

#include<stdio.h>

#include<stdlib.h>

 

intmain(int argc, char** argv){

char *buf;

char *buf2;

buf =(char*)malloc(1024);

buf2 =(char*)malloc(1024);

printf("buf=%pbuf2=%p\n", buf, buf2);

 

strcpy(buf,argv[1]);

free(buf2);

printf("afterfree buf2.\n");

free(buf);

}

 

[wuchao@localhostbasicheap]$ gcc -o basicheap  basicheap.c

[wuchao@localhostbasicheap]$ ./basicheap  `perl -e 'print"A" x 5000'`

buf=0x8f44008buf2=0x8f44410

Segmentationfault (core dumped)

 

0x8f44410 - 0x8f44008 = 0x408 (十进制1032),所以有8字节的元数据。

 

参考资料:

The Art of File Format Fuzzing

黑客攻防技术宝典:系统实战篇(第2版)

 

本文标签: 原因 程序