在此处输入标题


#一 修改领接变量

##1.1 原理
函数的局部变量在栈中,一个挨着一个排列,如果有缓冲区,那么可能 就存在数组越界的可能,比如破坏相邻的变量值,或者破坏EBP,返回地址等。

##1.2 示例

1
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
28
29
30
31
32
33
34
35
36
#include "stdafx.h"
#include <iostream>
using namespace std;
#define PASSWORD "12345"

int verify(char * psw)
{
int auth;
char buffer[8];
auth = strcmp(PASSWORD, psw);
strcpy(buffer, psw);//缓冲区溢出点
return auth;
}



int main(int argc, _TCHAR* argv[])
{
int flag = 0;
char psw[1024];
while (1)
{
cout << "输入密码" << endl;
cin >> psw;
flag = verify(psw);
if (flag)
{
cout << "密码错误" << endl;
}
else
{
cout << "验证成功" << endl;
}
}
return 0;
}

我们来观察auth的地址以及buffer的地址
&auth:0x0019FAC8
image_1b0f8sops9vb1mq61bov1bi36hi9.png-3.4kB

&buffer:0x0019FAC0
image_1b0f8uh2l14ro2vk1na519k8dnfm.png-3.4kB

image_1b0f90e2r14v1v12iio1btv3jb13.png-3kB

很容易发现auth刚好在buffer的下方,这样我们可以利用这个缓冲区,来替换auth的内容。

我们试着输入abcdefghijk:
image_1b0f96qeb1j1u12hug0o1j6910il1g.png-1.2kB
在执行过strcpy之后,我们观察内存:
image_1b0f96qeb1j1u12hug0o1j6910il1g.png-1.2kB

很容易发现,0x0019FAC8 中间的值被修改了。

那我们只要构造,让溢出的时候,让其为0即可

12.png-1.6kB

在此处输入标题

标签(空格分隔): 网络安全


#一 修改领接变量

##1.1 原理
函数的局部变量在栈中,一个挨着一个排列,如果有缓冲区,那么可能 就存在数组越界的可能,比如破坏相邻的变量值,或者破坏EBP,返回地址等。

##1.2 示例

1
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
28
29
30
31
32
33
34
35
36
#include "stdafx.h"
#include <iostream>
using namespace std;
#define PASSWORD "12345"

int verify(char * psw)
{
int auth;
char buffer[8];
auth = strcmp(PASSWORD, psw);
strcpy(buffer, psw);//缓冲区溢出点
return auth;
}



int main(int argc, _TCHAR* argv[])
{
int flag = 0;
char psw[1024];
while (1)
{
cout << "输入密码" << endl;
cin >> psw;
flag = verify(psw);
if (flag)
{
cout << "密码错误" << endl;
}
else
{
cout << "验证成功" << endl;
}
}
return 0;
}

我们来观察auth的地址以及buffer的地址
&auth:0x0019FAC8
image_1b0f8sops9vb1mq61bov1bi36hi9.png-3.4kB

&buffer:0x0019FAC0
image_1b0f8uh2l14ro2vk1na519k8dnfm.png-3.4kB

image_1b0f90e2r14v1v12iio1btv3jb13.png-3kB

很容易发现auth刚好在buffer的下方,这样我们可以利用这个缓冲区,来替换auth的内容。

我们试着输入abcdefghijk:
image_1b0f96qeb1j1u12hug0o1j6910il1g.png-1.2kB
在执行过strcpy之后,我们观察内存:
image_1b0f96qeb1j1u12hug0o1j6910il1g.png-1.2kB

很容易发现,0x0019FAC8 中间的值被修改了。

那我们只要构造,让溢出的时候,让其为0即可

12.png-1.6kB