计算机系统 实验四(课程实验LAB四)

实验中需要的几个控制语句:
-u userid,使用这个语句是要确保不同的人使用不同的 ID 做题,并攻击不同的地址。
-h 用于打印这几个操作的内容,
-n 用于 Level4 关卡,
-s 用于提交你的解决方案到服务器中

1.根据makecookie生成个人的身份数据

在这里插入图片描述

确定自己的userid为lihui,则自己的身份数据为0x5dfd1a11

2.level0

当 test 函数在调用 getbuf 函数时,本来这个程序会按照惯例返回 test 函数,题目要求当getbuf 函数执行结束时,返回到 smoke 函数中。
在这里插入图片描述

进入gdb模式,查看getbuf的汇编代码。
会在getbuf函数里读取字符串buf之后,会返回到test函数。输入字符串buf的存放位置为$epb-0x28,返回地址为%ebp+4,这里从buf的起始地址到返回地址总共有48个字节,前44个字节的内容无关重要,但最后4个字节要填入smoke函数的起始地址以覆盖旧的ebp。
查看smoke函数的反汇编代码
在这里插入图片描述

可以看出smoke的起始地址为0x08048e0a,如果输入0a,则会被系统认定为换行符\n,从而结束字符串输入,导致这个地址错误,所以最后肯定不能输入0a。
所以可以选择smoke起始地址的下一条地址即可。
在这里插入图片描述
在这里插入图片描述

3.level1

此题是让 test 函数返回到fizz,而不是test,然而,这次需要要传入自己的 cookie 作为参数。
查看fizz反汇编代码
在这里插入图片描述

可以看到在汇编代码<+17>的位置表明传递的参数在ebp+8的位置。参数value是需要和我们的cookie匹配的一个值。
fizz的起始地址为0x08048daf。
再对栈的变化进行分析:当从函数getbuf进入fizz函数时,没有使用对函数fizz的调用call,而是从上级函数的返回处进入到fizz,故没有对返回的地址进行入栈操作。而此时ebp的位置位与getbuf中的ebp+4,就是getbuf函数的返回地址处,然后再进行push %ebp操作,此时fizz的ebp就在getbuf函数返回的地址处,返回地址+8的位置为参数的位置。参数位置放入我们的cookie。

可以发现函数中将0x804d104中的值与0x8(%ebp)进行比较,通过gdb查看内存可知,0x804d104中存储的是我们的cookie的值,所以说,0x8(%ebp)中存储的应该是传入的参数的值。
在这里插入图片描述
在这里插入图片描述

4.level2

类似于前两关,使 bufbomb 的执行过程中,执行bang而非回到test,在这之前,你需要定义全局变量global_value为你的cookie值;
编写汇编代码完成相应要求,我们可以使用objdump或者gcc将自己的代码生成可以执行的机器码。
查看bang函数的汇编代码
在这里插入图片描述

由此可以看出bang函数的起始地址为0x08048d52
从汇编代码<+6>以及<+11>可以看出将0x804d10c传到%eax然后再与一个值作比较
在这里插入图片描述

可以看出一个地方存放的是一个全局变量的起始地址,另一个地方存放的是自己的
需要将global_value的值设置为cookie,进行汇编代码的编写
第一行先将cookie的值mov到global_value的地址中。另外,由于我们还需要跳转到bang()中。由于jmp、call等指令需要重定位,很难通过使用这两个指令来实现这个功能,所以我们将会用到ret指令。ret相当于pop %ip,也就是说,将栈顶的值作为下一条指令的地址。那么,我们只需要push bang()的地址,把栈顶更新为我们希望跳转到的地址,再进行ret,那么就可以实现跳转了。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

我们就可以看出产生的汇编代码,得出的机器码就是c7 05 0c d1 04 08 11 1a fd 5d 68 52 8d 04 08 c3
将这段机器码写到buf的头部,同时将getbuf返回地址改为buf的起始地址,当getbuf执行完后则会跳转到这执行我们写的指令。
在这里插入图片描述

对getbuf进行调试,可以发现call Gets时的eax寄存器保存的值为buf的地址,此时对寄存器eax查看值就能知道buf的起始地址0x556832d8
在这里插入图片描述
在这里插入图片描述

5.level3

要求程序要正常返回到test执行,并且改变返回值为cookie的值,且不能破坏test函数的栈状态。
需要写汇编代码并转化为机器码,使用gdb调试查看获取需要的信息。要修改返回值只需要改写eax寄存器的值即可。要保证栈的结构不被破坏需要保证old_ebp的值保存不被改写,并且getbuf函数返回地址正确。
在这里插入图片描述

查看getbuf的下一条指令的地址,得0x08048e50
在这里插入图片描述

查看getbuf的汇编代码,getbuf的起始地址为0x08049262,并且我们可以得到old_ebp的值为0x55683330
编写汇编代码
在这里插入图片描述

修改返回值为cookie的值
然后使用ret语句使函数返回到getbuf的下一条语句即地址0x08048e50处,继续向下执行。
在这里插入图片描述
在这里插入图片描述

可以得出机器码为b8 11 1a fd 5d 68 50 8e 04 08 c3
在这里插入图片描述

对getbuf进行调试,可以发现call Gets时的eax寄存器保存的值为buf的地址,此时对寄存器eax查看值就能知道buf的起始地址0x556832d8。
原本储存着旧%ebp的单元就会被00000000覆盖,从而无法恢复到原来的状态。于是,我们可以通过gdb来查看旧%ebp的值,并将它加入到我们的输入文件中,使得它在被覆盖时保持原值。旧%ebp的值为0x55683e70。旧%ebp的值存储在(%ebp)中,即返回地址0x4(%ebp)的下方。
在这里插入图片描述
在这里插入图片描述

6.level4

Getbuf 函数调用过程中,我们安放了使堆栈稳定的因素,因此 getbuf 堆栈框架在运行中趋于稳定,这使得你有机会写攻击代码来通晓 buf 的始地址,如果你试着在一个普通的程序中使用这个攻击代码,你会发现它有时能用,但其他情况下会出现分裂错误。
这一关里,我们要与原来背向而行,使堆栈的位置比平时更加不稳定。
当你使用-n 运行 bufbomb 时,它就会进入“硝基模式”,程序不调用 getbuf,而是调用 getbufn;
这个函数和 getbuf 类似,但是它限制了缓冲区大小为512个字符,你将会需要这个额外空间来创建可信的攻击程序,调用 getbufn的代码第一次在堆栈上分配一个随机大小的存储空间,所以如果你在getbufn两次连续调用过程中对 ebp 采样的话,你会发现他们相差 240;
另外,在硝基模式下运行时,bufbomb要求你提供你的字符串共 5 次,而且他也会执行 5 次,每次都有不同的堆栈偏移,你的 exploit 必须使它每次都返回你的cookie。
任务:您的任务与炸药级别的任务相同。再一次,这个级别的工作是提供利用将导致getbufn将cookie返回到测试的字符串,而不是值1。您可以请在测试代码中看到,这将导致程序运行“KABOOM!”你的攻击代码应该设置为你的cookie作为返回值,还原任何损坏的状态,在堆栈上推送正确的返回位置,并执行一个ret指令以真正返回testn。
实现方法:一种常见的手段就是在实际的攻击代码中插入一段很长的 nop 指令,只要攻击者能猜中这段程序中的某个地址,程序就会经过这个序列,到达攻击代码。
在这里插入图片描述

查看getbufn的代码
对五次执行情况下的ebp的值进行查看,找出五个ebp中最大的一个ebp的值,再将ebp-0x208算出来得到buf的起始地址,将此地址0x55683138记录下来,作为getbufn函数返回地址,作为开始实行攻击代码的起点。
在这里插入图片描述
在这里插入图片描述

testn的汇编
在这里插入图片描述

因为执行了一条push ebp指令和sub $0x24,%esp通过汇编代码可以看出old_ebp与esp的关系为:esp+0x28,从而可以得到old_ebp的值,从而恢复testn的ebp值。
得到getbufn的返回地址为0x08048ce2
汇编代码的编写
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

得出机器码 b8 11 1a fd 5d 8d 6c 24 28 68 e2 8c 04 08 c3

在这里插入图片描述
在这里插入图片描述

Y86 Tools (Student Distribution) Copyright (c) 2002, R. Bryant and D. O Hallaron, All rights reserved. May not be used, modified, or copied without permission. This directory contains the student distribution of the Y86 tools. It is a proper subset of the master distribution, minus the solution files found in the master distribution. yas Y86 assembler yis Y86 instruction (ISA) simulator hcl2c HCL to C translator ssim SEQ simulator ssim+ SEQ+ simulator psim PIPE simulator y86-code/ Examples programs and and benchmark testing scripts ptest/ Scripts for detailed automated regression testing 1. Building the Y86 tools The Y86 simulators can be configured to support TTY and GUI interfaces. A simulator running in TTY mode prints all information about its run-time behavior on the terminal. Hard to understand what s going on, but useful for automated testing, and doesn t require any special installation features. A simulator running in GUI mode uses a fancy graphical user interface. Nice for visualizing and debugging, but requires installation of Tcl/Tk on your system. To build the Y86 tools, perform the following steps: NOTE: If your instructor prepared this distribution for you, then you can skip Step 1 and proceed directly to Step 2. The Makefile will already have the proper values for GUIMODE, TKLIBS, and TKINC for your system. Step 1. Decide whether you want the TTY or GUI form of the simulators, and then modify ./Makefile in this directory accordingly. (The changes you make to the variables in this Makefile will override the values already assigned in the Makefiles in the seq and pipe directories.) Building the GUI simulators: If you have Tcl/Tk installed on your system, then you can build the GUI form by initializing the GUIMODE, TKLIBS, and TKINC variables, as appropriate for your system. (The default values work for Linux systems.) Assigning GUIMODE=-DHAS_GUI causes the necessary GUI support code in the simulator sources to be included. The TKLIBS variable tells gcc where to look for the libtcl.so and libtk.so libraries. And the TKINC variable tells gcc where to find the tcl.h and tk.h header files. Building the TTY simulators: If you don t have Tcl/Tk installed on your system, then build the TTY form by commenting out all three of these variables (GUIMODE, TKLIBS, and TKINC) in the Makefile. Step 2: Once you ve modified the Makefile to build either the GUI or TTY form, then you can construct the entire set of Y86 tools by typing unix> make clean; make 2. Files Makefile Builds the Y86 tools README This file misc/ Source files for the Y86 assembler yas, the Y86 instruction simulator yis, and the isa.c file that is used by the -t option of the processor simulators to check the results against the ISA simulation. seq/ Code for the SEQ and SEQ+ simulators. Contains HCL files for labs and homework problems that involve modifying SEQ. pipe/ Code for the PIPE simulator. Contains HCL files for labs and homework problems that involve modifying PIPE. y86-code/ Example .ys files from CS:APP and scripts for conducting automated benchmark teseting of the new processor designs. ptest/ Automated regression testing scripts for testing processor designs.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值