缓冲区溢出——《深入理解计算机系统》习题3.38详解

本文详细解析了《深入理解计算机系统》中的习题3.38,涉及到缓冲区溢出的概念。通过分析函数getbuf的汇编代码,展示了如何构造特定的十六进制字符串,使getbuf返回特定值。讨论了栈保护机制、汇编指令的使用,并提供了一个实验过程,包括使用gdb进行调试和确定关键栈内存布局。
摘要由CSDN通过智能技术生成

缓冲区溢出——《深入理解计算机系统》习题 3.38 详解

 

最近在攻读《深入理解计算机系统》( CS:APP) 一书,上面的实验题很有趣味。习题 3.38 说明了缓冲区溢出的基本原理,我颇费了一番心思才搞定了这道题,详解如下。

 

一、题目:

CS APP 的网站上下载文件 bufbomb.c ,地址http://csapp.cs.cmu.edu/public/1e/public/ics/code/asm/bufbomb.c

内容如下:

 

01 /* Bomb program that is solved using a buffer overflow attack */
02
03 #include <stdio.h>
04 #include <stdlib.h>
05 #include <ctype.h>
06
07 /* Like gets, except that characters are typed as pairs of hex digits.
08    Nondigit characters are ignored.  Stops when encounters newline */
09 char * getxs( char * dest)
10 {
11   int c;
12   int even = 1; /* Have read even number of digits */
13   int otherd = 0; /* Other hex digit of pair */
14   char *sp = dest;
15   while (( c = getchar()) != EOF && c != '/n') {
16     if ( isxdigit( c)) {
17       int val;
18       if ( '0' <= c && c <= '9')
19     val = c - '0';
20       else if ( 'A' <= c && c <= 'F')
21     val = c - 'A' + 10;
22       else
23     val = c - 'a' + 10;
24       if ( even) {
25     otherd = val;
26     even = 0;
27       } else {
28     *sp +
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值