网络攻击与防御技术西南交通大学信息科学与技术学院黄文培2019-21)缓冲区溢出的概念2)程序的内存组织与缓冲区溢出类型3)缓冲区溢出攻击的三个案例4)缓冲区溢出攻击的防范第三章缓冲区溢出攻击3.1缓冲区溢出的概念缓冲区读写缓冲区通信缓冲区显示缓冲区键盘缓冲区charstr[128];3.1缓冲区溢出的概念1988年,Cornell大学的Morris的Finger蠕虫病毒2001年,红色代码蠕虫病毒2003年,Slammer病毒“震荡波”、“狙击波”3.2程序的内存组织与缓冲区溢出类型intx=100;intmain(){inta=2;floatb=2.5;staticy;int*ptr=(int*)malloc(2*sizeof(int));ptr[1]=5;ptr[2]=6;free(ptr);return1;}3.2程序的内存组织与缓冲区溢出类型栈(Stack)堆(Heap)3.2程序的内存组织与缓冲区溢出类型(TextSegment,文本段)(DataSegment)(BSSSegment)BSS段溢出堆溢出栈溢出3.3基于BSS段的缓冲区溢出攻击buf1buf20021713800217148diff3.3基于BSS段的缓冲区溢出攻击buf1buf2BBBBBBBBBBBBBBB\0AAAAAAAAAAAAAAA\0buf1buf2BBBBBBBBBBBBBBB\0BBBBBBBBAAAAAAA\0溢出前溢出后3.4基于修改邻接变量的栈缓冲区溢出攻击#definePASSWORD"1234567“intverify_password(char*password){intauthenticated;charbuffer[8];//addlocalbufftobeoverflowedauthenticated=strcmp(password,PASSWORD);strcpy(buffer,password);//overflowedhere!returnauthenticated;}main(){……}#definePASSWORD"1234567“main(){intvalid_flag=0;charpassword[1024];while(1){printf("pleaseinputpassword:");scanf("%s",password);valid_flag=verify_password(password);if(valid_flag){printf("incorrectpassword!\n\n");}else{printf("Congratulation!Youhavepassedtheverification!\n")break;}}}3.4基于修改邻接变量的栈缓冲区溢出攻击函数的参数逆序进栈将eip寄存器里面的内容进栈作为函数的返回地址(ret)堆栈的基指针(ebp)压入堆栈跳转子程序内的局部变量放入堆栈3.4基于修改邻接变量的栈缓冲区溢出攻击2)漏洞攻击分析1)参数入栈2)返回地址入栈3)跳转4)调整栈帧5)子程序的局部变量压入堆栈EBPvalid_flag=verify_password(password);3.4基于修改邻接变量的栈缓冲区溢出攻击2)漏洞攻击分析intverify_password(char*password){intauthenticated;charbuffer[8];//addlocalbufftobeoverflowedauthenticated=strcmp(password,PASSWORD);strcpy(buffer,password);//overflowedhere!returnauthenticated;}3.4基于修改邻接变量的栈缓冲区溢出攻击3)实验验证Windows7VS2010Debug版本3.4基于修改邻接变量的栈缓冲区溢出攻击3)实验验证3.4基于修改邻接变量的栈缓冲区溢出攻击3)实验验证3.4基于修改邻接变量的栈缓冲区溢出攻击3)实验验证3.4基于修改邻接变量的栈缓冲区溢出攻击3)实验验证3.4基于修改邻接变量的栈缓冲区溢出攻击3)实验验证intverify_password(char*password){intauthenticated;charbuffer[8];//addlocalbufftobeoverflowedauthenticated=strcmp(password,PASSWORD);strcpy(buffer,password);//overflowedhere!returnauthenticated;}3.4基于修改邻接变量的栈缓冲区溢出攻击3)实验验证qqqqqqqnull“qqqqqqq”>“1234567”authenticated=116进制:0x000000013.4基于修改邻接变量的栈缓冲区溢出攻击3)实验验证qqqqqqqnull01000000“qqqqqqq”>“1234567”authenticated=116进制:0x000000013.4基于修改邻接变量的栈缓冲区溢出攻击3)实验验证3.4基于修改邻接变量的栈缓冲区溢出攻击3)实验验证3.4基于修改邻接变量的栈缓冲区溢出攻击3)实验验证3.4修改函数返回地址的栈缓冲区溢出攻击intverify_password(char*password){intauthenticated;charbuffer[8];//addlocalbufftobeoverflowedauthenticated=strcmp(password,PASSWORD);strcpy(buffer,password);//overflowedhere!returnauthenticated;}3.4修改函数返回地址的栈缓冲区溢出攻击1)攻击实验简介guestroot3.4修改函数返回地址的栈缓冲区溢出攻击2)实验环境准备Windows7操作系统IntelCPU、2G以上内存VirtualBox-5.1Ubu...