版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、安全编程之缓冲区溢出,内容,缓冲区溢出初步(标准栈溢出) 总结 strcpy(stack,input); void bar() printf(nAh,Ive been hacked!n); void main(int argc,char *argv) foo(argv1); ,main: pushl %ebp movl %esp,%ebp subl $8,%esp addl $-12,%esp movl 12(%ebp),%eax addl $4,%eax movl (%eax),%edx pushl %edx call foo addl $16,%esp .L4: leave ret,foo
2、: pushl %ebp movl %esp,%ebp subl $24,%esp addl $-8,%esp movl 8(%ebp),%eax pushl %eax leal -12(%ebp),%eax pushl %eax call strcpy addl $16,%esp .L2: leave ret,How the program works,call Pushes Instruction Pointer (and Code Segment for far calls) onto stack and loads Instruction Pointer with the addres
3、s of proc-name. Code continues with execution at CS:IP. ret Transfers control from a procedure back to the instruction address saved on the stack. n bytes is an optional number of bytes to release. Far returns pop the IP followed by the CS, while near returns pop only the IP register. strcpy copy a
4、string without boundary check Activation record (stack based) Frame pointer Stack pointer Return address Grow downwards buffer Grow upwards,How to exploit it,Cover the return address with your shellcode address. When the foo return, it will execute your shellcode. Shellcode ? It may be the var funct
5、ion which print “Ive been hacked” on the screen. En, lets continue,Shellcode,Binary code (Machine code) The CPU can execute it directly. Generally, it return a shell like bash$, or bind a shell with a special TCP/UDP port Please refer to for details,Summary,Buffer grows upwards while the stack grows
6、 downwards. (buffer may overwrite the activation record) Protect the activation record. String functions in lib do not check the array boundary. Safe string functions like strncpy The shellcode executes on stack. Non-executable stack,Question char *buf = new charBUF_LEN; 0 x4xxxxxxx upwards BSS (uni
7、nitialized data) staic char bufBUF_LEN; static char* buf; buf = “/etc/passwd”; 0 x08xxxxxx upwards Initialized data char bufBUF_LEN = 1; 0 x08xxxxxx upwards,Data we will overwrite,Stack Data on stack Activation Record Heap Data on heap The management block of malloc or new BSS for (; len The buffer
8、which user supplied may overwrite the frame pointer (ebp).,Integer Overflow,Integer Overflow 0 xfffffff + 1 = ? 0 x9000000 * 2 = ? 0 x0 1 = ? signed problem unsigned and signed 0 xfffffffc = -4 %d %u,Integer Overflow,int num, i; object_t *objs; num = get_user_num(); if(!(objs = (object_t *)malloc(nu
9、m * sizeof(object_t) perror(“malloc”); exit(errno); for(i = 0; i num; i+) objsi = get_user_object(); ,signed and unsigned,int http_init() char *buf, buf21024, *t2, *t3; int n; #ifndef SILENCE printf(Content-type: text/html; charset=%snnn, CHARSET); printf(n); printf(n, CHARSET); #endif n=atoi(getsen
10、v(CONTENT_LENGTH); if(n5000000) n=5000000; buf=calloc(n+1, 1); if(buf=0) http_fatal(memory overflow); fread(buf, 1, n, stdin); ,Errors in Looping,while (cp reqend ,Summary,Where is the buffer Stack Heap/BSS What we can overwrite. (the data can change eip) Activation Record (ret, ebp, ) The data can
11、make a jump. Implement in GCC and Glibc Defending buffer overflow Non-executable stack, data, heap/BSS (optimize online) Return to Lib (Solar Design ) Safe compiler Secure programming,Question snprintf(dst, src, strlen(dst); strncat(dst, src, strlen(dst); strncat(dst, src, strlen(dst) - 1);,strncpy
12、NULL termination problem,/* * strncpy() NULL termination problems * kk_ * ./a.out perl -e print A x49 */ int main(int argc, char* argv) char buf150; char buf250; strcpy(buf1,This is buf2); strncpy(buf2, argv1, sizeof(buf2)-1); printf(%sn, buf2); ,strncat off-by-one problem,/* * strncat() off-by-one
13、problem * kk_ */ int main(int argc, char* argv) char buf50; strcpy(buf,This is buf2); strncat(buf, argv1, sizeof(buf)-strlen(buf); printf(length: %d content:%sn, strlen(buf), buf); ,Underflow problem,/* undeflow problem * strncpy() NULL teimination problem * kk_ */ int main(int argc, char* argv) cha
14、r buf50; /buf49 = 0; strncpy(buf, argv1, sizeof(buf)-1); printf(size:%x, strlen:%x remain:%xn, sizeof(buf), strlen(buf), sizeof(buf)-strlen(buf)-1); strncat(buf, argv2, sizeof(buf)-strlen(buf)-1); printf(length:%d content:%sn, strlen(buf), buf); ,misuse of return value in snprintf(),/* misuse of ret
15、urn value in snprintf() * kk_ * ./a.out perl -e print A x51 perl -e print B x20 */ int main(int argc, char* argv) char buf50; char *ptr; ptr = buf; /buf49-1 = 0; ptr += snprintf(ptr, sizeof(buf), %s, argv1); ptr += snprintf(ptr, sizeof(buf)-(ptr-buf), %s, argv2); printf(%sn, buf); ,snprintf dstsizeo
16、f(dst) - 1 = 0; strncat strncat(dst, src, sizeof(dst) strlen(dst) - 1); dstsizeof(dst) 1 = 0; Do not use these functions like qmail,Question & Answer,Next topic : non-x86 & (the Eight Diagrams),Buffer overflow on non-x86 arch.,SPARC/Solaris The return address of current address is saved in register.
17、 Computer Arch. : Register Windows Leaf functions and non-leaf functions PA-RISC/HP-UX Buffer grow upwards Stack grows upwards Leaf functions and non-leaf functions MIPS/VxWorks (Cisco IOS hacking) PowerPC/AIX MIPS/IRIX,Whats ideal hacking?,Not intrude Not blackhat & whitehat Not inside details “exp
18、loring the limits of what is possible, in a spirit of playful cleverness” Richard Stallman Hacking : How the world works. Hacking : Find the way to free world.,Wonderful hacking world,http:/lsd- The poor and great hacking in Argus System. http:/team- .au/silvio/,Reference,/StackGuard/discex00.pdf http:/www.phrack-
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 某电子厂来料检验细则
- 2026年10月梅岭街道锦旺社区招聘临时性公益性岗位2人考试模拟试题及答案解析
- 2027国家林业和草原局直属单位公开招聘应届毕业生282人(黑龙江19人)考试参考题库及答案解析
- 2026河北唐山弘慈医院招聘工作人员13名考试备考试题及答案解析
- 2026年10月广东珠海市教育局招聘直属学校事业编制教师178人考试参考题库及答案解析
- 2026天津市排球运动管理中心招聘高层次人才、急需紧缺人才2人笔试参考题库及答案解析
- 2026福建福州市江南智慧城市建设运营有限公司招聘3人笔试备考题库及答案解析
- 中国医学科学院基础医学研究所 北京协和医学院基础学院派遣人员招聘8人笔试备考题库及答案解析
- 2026年户外床行业洞察报告及未来五至十年发展趋势报告
- 2026年棕制品制造行业市场深度调研报告及未来五至十年技术路径与产业化前景
- 企业融资申请书范本及填写指南
- 藏羌碉楼营造技艺传承-洞察及研究
- DB35∕T 1036-2023 10kV及以下电力用户业扩工程技术规范
- 河北食品经营许可现场核查表及核查意见(食品销售)
- 数字智慧方案5445丨企业碳资产管理案例分享北京环境交
- 《奶牛的饲养管理》课件
- 中国文化概论教学课件
- 冷库储存生姜合同范例
- 气管切开套管的选择与更换
- GB/T 9799-2024金属及其他无机覆盖层钢铁上经过处理的锌电镀层
- 半球电压力锅说明书
评论
0/150
提交评论