1  | SA17011008 陈实 2017年11月14日 实验 4  | 
一、实验内容
1  | 32位Linux系统下的C函数如下:  | 
二、实验环境
1  | ubuntu 16.04  | 
三、实验内容
##3.1 准备工作
①关闭地址随机化1
sudo sysctl -w kernel.randomize_va_space=0

②关闭栈随机化设置1
sudo  /sbin/sysctl -w kernel.randomize_va_space=0

##3.2 测试buffer_overflow.c
①编写并编译运行1
2
3
4
5
6
7
8
9
10
11
12
13#include <stdio.h>
#include <string.h>
char Lbuffer[] = "01234567890123456789========ABCD";
void foo()
{
    char buff[16];
    strcpy (buff, Lbuffer);
}
int main()
{
    foo();
    return 0;
}

②GDB调试1
2
3gdb buf
r

③ 反编译main&foo1
disas main

1
disas foo

##3.3 测试foo1()
①编写并编译运行foo11
2
3
4
5
6
7
8
9
10
11
12
13
14#include <stdio.h>
#include <string.h>
void foo1()
{
    char buff[16];
    char Lbuffer[] = "01234567890123456789========ABCD";
    strcpy (buff, Lbuffer);
}
int main()
{
    foo1();
    return 0;
}

②调试
发生错误
##3.4 测试foo2()
①编写并编译运行foo21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <stdio.h>
#include <string.h>
void foo02()
{
char Lbuffer[] = "01234567890123456789========ABCD";
char buff[16];
strcpy (buff, Lbuffer);
} 
int main()
{
    foo02();
    return 0;
}

②调试
未发生错误
#四、实验总结
通过本次实验,对缓冲区溢出攻击的原理有了更进一步的理解,需要更进一步的去了解shellcode原理与攻击。