首页
社区
课程
招聘
[求助] Linux x86下通过return-to-plt绕过ASLR,编译的程序与实例不同导致EIP不可控有什么办法?
2021-8-26 17:53 6669

[求助] Linux x86下通过return-to-plt绕过ASLR,编译的程序与实例不同导致EIP不可控有什么办法?

2021-8-26 17:53
6669

代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>
#include <string.h>
 
/* Eventhough shell() function isnt invoked directly, its needed here since 'system@PLT' and 'exit@PLT' stub code should be present in executable to successfully exploit it. */
void shell() {
 system("/bin/sh");
 exit(0);
}
 
int main(int argc, char* argv[]) {
 int i=0;
 char buf[256];
 strcpy(buf,argv[1]);
 printf("%s\n",buf);
 return 0;
}

编译命令:

 

#echo 2 > /proc/sys/kernel/randomize_va_space
$gcc -g -fno-stack-protector -o vuln vuln.c
$sudo chown root vuln
$sudo chgrp root vuln
$sudo chmod +s vuln
IDA反编译:

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
.text:080484BB lea     ecx, [esp+4]
.text:080484BF and     esp, 0FFFFFFF0h
.text:080484C2 push    dword ptr [ecx-4]
.text:080484C5 push    ebp
.text:080484C6 mov     ebp, esp
.text:080484C8 push    ecx
.text:080484C9 sub     esp, 114h
.text:080484CF mov     eax, ecx
.text:080484D1 mov     [ebp+i], 0
.text:080484D8 mov     eax, [eax+4]
.text:080484DB add     eax, 4
.text:080484DE mov     eax, [eax]
.text:080484E0 sub     esp, 8
.text:080484E3 push    eax                          
.text:080484E4 lea     eax, [ebp+buf]
.text:080484EA push    eax                            
.text:080484EB call    _strcpy
.text:080484F0 add     esp, 10h
.text:080484F3 sub     esp, 0Ch
.text:080484F6 lea     eax, [ebp+buf]
.text:080484FC push    eax                            
.text:080484FD call    _puts
.text:08048502 add     esp, 10h
.text:08048505 mov     eax, 0
.text:0804850A mov     ecx, [ebp+var_4]
.text:0804850D leave
.text:0804850E lea     esp, [ecx-4]
.text:08048511 retn

通过IDA可以看到我编译出来的程序在leave retn之间多了
mov ecx, [ebp+var_4]
lea esp, [ecx-4]
这两行代码,这是由于GCC版本不同的原因吗?通过传递“A"268,我发现程序栈BFD4AC64这个地址中的值BFD4AC00还处于被覆盖的范围,不过每次BFD4AC00这个值都是随机的因此导致执行lea esp, [ecx-4]取该地址里面的值的时候地址随机的因此无法确定该在哪个位置填写system_plt_addr、exit_plt_addr、system_plt_arg。同时我发现当我传递“A"264的时候对应BFD4AC64地址处的值即ECX寄存器将不会处于被覆盖的范围这是怎么回事?

 

```
BFD4AC44 41414141

 

BFD4AC48 41414141
BFD4AC4C 41414141
BFD4AC50 41414141
BFD4AC54 41414141
BFD4AC58 41414141
BFD4AC5C 41414141
BFD4AC60 42424242
BFD4AC64 BFD4AC00 [stack]:BFD4AC00
```


[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

上传的附件:
收藏
点赞0
打赏
分享
最新回复 (0)
游客
登录 | 注册 方可回帖
返回