#start analyses binary filename = "h" proj = angr.Project(filename,load_options={'auto_load_libs': False}) # find main function cfg = proj.analyses.CFGFast() for addr,b in cfg.kb.functions.items(): if (b.name == "main"): main_address = addr print(b) print("[+] main_address: "+hex(main_address)) break # binary has a hard function to solve by symbolic execution # we need to find it # we can find it's size always is 444 before_address = 0 bb_address = 0 next_address = 0
num =0 for addr,b in cfg.kb.functions.items(): if (addr > main_address): break if addr - before_address == 444: hard_function_address = before_address next_address = bb_address print("[+] hard_function_address: "+hex(before_address)) print("[+] next_function_address: "+hex(next_address)) num += 1 else: bb_address = before_address before_address = addr
if num !=1: print("[-] hard function's num is not equal 1") exit(0) # before the hard function # we use symbolic execution to solve the problem target_address = hard_function_address
state = proj.factory.entry_state() simgr = proj.factory.simgr(state) simgr.explore(find=target_address) tmp_result = simgr.found[0].posix.dumps(0) #print(tmp_result) tmp_result = tmp_result.split(b'\x00'*10)[0] print(tmp_result) # now we get the solve of the binary before hard function # the we need to analyse the hard function,we define the function: hard_function_solve() defcount_num(function_content,num): one = function_content[num] if one == 0: two_num = num+28 three_num = num+84 four_num = three_num + 36 else: two_num = num+36 if function_content[two_num] == 0: three_num = num+84 four_num = three_num + 36 else: three_num = num+92 if function_content[three_num] == 0: four_num = three_num + 28 else: four_num = three_num + 36 return [function_content[num],function_content[two_num],function_content[three_num],function_content[four_num]]
defhard_function_analyse(hard_address): f_b = open(filename,"rb") function_content = f_b.read()[hard_address-0x400000:hard_address-0x400000+444] print("content_len:"+str(len(function_content))) #1 step if function_content[199] == 0x10: difference_1 = 1 elif function_content[199] == 0x14: difference_1 = 0 else: print("[-] 1 step can not get option") #2 step if function_content[383] == 0x10: difference_2 = 1 elif function_content[383] == 0x14: difference_2 = 0 else: print("[-] 2 step can not get option")
one = count_num(function_content,24) two = count_num(function_content,208) print(one) print(two) for i in range(255): for j in range(255): for n in range(255): for m in range(255): int_arr = [i,j,n,m] v1_1 = abs(int_arr[one[0]] ** 2 - int_arr[one[1]] ** 2) v1_2 = abs(int_arr[one[2]] ** 2 - int_arr[one[3]] ** 2) if (v1_2 > v1_1) != difference_1: continue else: v2_1 = abs(int_arr[two[0]] ** 2 - int_arr[two[1]] ** 2) v2_2 = abs(int_arr[two[2]] ** 2 - int_arr[two[3]] ** 2) if (v2_2 > v2_1) == difference_2: print(int_arr) return bytes((i,j,n,m))