[关闭]
@rg070836rg 2017-11-14T16:16:31.000000Z 字数 1142 阅读 2400

网络安全第四次实验 陈实 SA17011008

USTC网络安全


  1. SA17011008 陈实 20171114 实验 4

一、实验内容

  1. 32Linux系统下的C函数如下:
  2. void foo01()
  3. {
  4. char buff[16];
  5. char Lbuffer[] = "01234567890123456789========ABCD";
  6. strcpy (buff, Lbuffer);
  7. }
  8. void foo02()
  9. {
  10. char Lbuffer[] = "01234567890123456789========ABCD";
  11. char buff[16];
  12. strcpy (buff, Lbuffer);
  13. }
  14. foo01()和foo02()替换buffer_overflow.c中的foo(), 通过GDB调试,
  15. 说明foo01()和foo02()是否存在缓冲区溢出漏洞。

二、实验环境

  1. ubuntu 16.04

三、实验内容

3.1 准备工作

①关闭地址随机化

  1. sudo sysctl -w kernel.randomize_va_space=0

image.png-37.1kB
②关闭栈随机化设置

  1. sudo /sbin/sysctl -w kernel.randomize_va_space=0

image.png-15.8kB

3.2 测试buffer_overflow.c

①编写并编译运行

  1. #include <stdio.h>
  2. #include <string.h>
  3. char Lbuffer[] = "01234567890123456789========ABCD";
  4. void foo()
  5. {
  6. char buff[16];
  7. strcpy (buff, Lbuffer);
  8. }
  9. int main()
  10. {
  11. foo();
  12. return 0;
  13. }

image.png-29kB

②GDB调试

  1. gdb buf
  2. r

image.png-104.7kB

③ 反编译main&foo

  1. disas main

image.png-49.3kB

  1. disas foo

image.png-55.8kB

3.3 测试foo1()

①编写并编译运行foo1

  1. #include <stdio.h>
  2. #include <string.h>
  3. void foo1()
  4. {
  5. char buff[16];
  6. char Lbuffer[] = "01234567890123456789========ABCD";
  7. strcpy (buff, Lbuffer);
  8. }
  9. int main()
  10. {
  11. foo1();
  12. return 0;
  13. }

image.png-31.9kB

②调试
image.png-84.7kB
发生错误

3.4 测试foo2()

①编写并编译运行foo2

  1. #include <stdio.h>
  2. #include <string.h>
  3. void foo02()
  4. {
  5. char Lbuffer[] = "01234567890123456789========ABCD";
  6. char buff[16];
  7. strcpy (buff, Lbuffer);
  8. }
  9. int main()
  10. {
  11. foo02();
  12. return 0;
  13. }

image.png-24kB

②调试
image.png-95.9kB
未发生错误

四、实验总结

通过本次实验,对缓冲区溢出攻击的原理有了更进一步的理解,需要更进一步的去了解shellcode原理与攻击。

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注