angr学习笔记(4) (寄存器符号化)
angr系列
00_angr_find
01_angr_avoid
02_angr_find_condition
03_angr_symbolic_registers
04_angr_symbolic_stack
05_angr_symbolic_memory
06_angr_symbolic_dynamic_memory
07_angr_symbolic_file
08_angr_constraints
09_angr_hooks
10_angr_simprocedures
13_angr_static_binary
文章目錄
- angr系列
- 00_angr_find
- 01_angr_avoid
- 02_angr_find_condition
- 03_angr_symbolic_registers
- 04_angr_symbolic_stack
- 05_angr_symbolic_memory
- 06_angr_symbolic_dynamic_memory
- 07_angr_symbolic_file
- 08_angr_constraints
- 09_angr_hooks
- 10_angr_simprocedures
- 13_angr_static_binary
- 偽代碼分析
- 過程分析
- 腳本:
- 驗證
偽代碼分析
匯編代碼為:
這里的話,我們需要把start_address放在0x0804898C
然后從右往左填參數(shù),ebp+var_10為第三個輸入?yún)?shù),ebp+var_14為第二個輸入?yún)?shù),ebp+var_18為第一個輸入?yún)?shù),也就是說,寄存器返回值中,eax是第一個輸入?yún)?shù),ebx是第二個輸入?yún)?shù),edx是第三個輸入?yún)?shù),緊接著往下:
.text:0804896E push offset aEnterThePasswo ; "Enter the password: " .text:08048973 call _printf .text:08048978 add esp, 10h .text:0804897B call get_user_input .text:08048980 mov [ebp+var_14], eax .text:08048983 mov [ebp+var_10], ebx .text:08048986 mov [ebp+var_C], edx .text:08048989 sub esp, 0Ch .text:0804898C push [ebp+var_14] .text:0804898F call complex_function_1 .text:08048994 add esp, 10h .text:08048997 mov ecx, eax .text:08048999 mov [ebp+var_14], ecx .text:0804899C sub esp, 0Ch .text:0804899F push [ebp+var_10] .text:080489A2 call complex_function_2 .text:080489A7 add esp, 10h .text:080489AA mov ecx, eax .text:080489AC mov [ebp+var_10], ecx .text:080489AF sub esp, 0Ch .text:080489B2 push [ebp+var_C] .text:080489B5 call complex_function_3 .text:080489BA add esp, 10h .text:080489BD mov ecx, eax .text:080489BF mov [ebp+var_C], ecx .text:080489C2 cmp [ebp+var_14], 0 .text:080489C6 jnz short loc_8048過程分析
調(diào)用的函數(shù)為claripy.BVS(),該函數(shù)實際存在于claripy.ast.bv.py文件中。它的作用就是創(chuàng)建一個為符號向量(即,一個變量)。
函數(shù)參數(shù):
另一個創(chuàng)建符號變量的函數(shù)為claripy.BVV(),用于創(chuàng)建一個位向量 (即,一個具體值)(后面會說)。
函數(shù)參數(shù):
def BVV(value, size=None, **kwargs):創(chuàng)建符號變量后,需要指定符號執(zhí)行的起始狀態(tài),也就是從程序的哪個部分開始執(zhí)行符號執(zhí)行
最后再來對變量進行求解:
password1=found_state.solver.eval(pass1)password2=found_state.solver.eval(pass2)password3=found_state.solver.eval(pass3)腳本:
import angr import sys import claripydef main(argv):bin_path=argv[1]p=angr.Project(bin_path)start_addr=0x08048980init_state=p.factory.blank_state(addr=start_addr)pass1=claripy.BVS('pass1',32)pass2=claripy.BVS('pass2',32)pass3=claripy.BVS('pass3',32)init_state.regs.eax=pass1init_state.regs.ebx=pass2init_state.regs.edx=pass3sm=p.factory.simulation_manager(init_state)def is_good(state):return b'Good Job.' in state.posix.dumps(1)def is_bad(state):return b'Try again.' in state.posix.dumps(1)sm.explore(find=is_good,avoid=is_bad)if sm.found:found_state=sm.found[0]password1=found_state.solver.eval(pass1)password2=found_state.solver.eval(pass2)password3=found_state.solver.eval(pass3)print("Solution:{} {} {}".format(password1,password2,password3))else:raise Exception("No solution found")if __name__=='__main__':main(sys.argv) 3120549966 3438690280 2413091161十六進制顯示:
print("Solution:{:x} {:x} {:x}".format(password1,password2,password3)) b9ffd04e ccf63fe8 8fd4d959驗證
password1=found_state.solver.eval(pass1)password2=found_state.solver.eval(pass2)password3=found_state.solver.eval(pass3)這里通過求解的方式,而不是通過下方這種打印出 標準輸入值
print("stdin:",found_state.posix.dumps(0));這種方式打印出來是空,因為我們沒有執(zhí)行scanf那一個函數(shù),而是直接跳過了。
總結(jié)
以上是生活随笔為你收集整理的angr学习笔记(4) (寄存器符号化)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: angr学习笔记(3)
- 下一篇: angr学习笔记(5)(栈符号化)