HEXRAYS TOOLBOX (HXTB)는 기본 프로세서 아키텍처와 독립적 인 바이너리에서 코드 패턴을 찾고 찾는 데 사용할 수있는 강력한 IDAPYTHON 스크립트 세트입니다.
아래 애니메이션에 의해 설명 된 쿼리는 Android의 WhatsApp (CVE-2019-3568, LibWhatsApp.so)에 영향을 미치는 취약성이 Hexrays Toolbox를 사용하여 어떻게 위치 할 수 있는지에 대한 예입니다. 이것은 idapython lambda 함수를 사용하여 찾을 원하는 코드 패턴을 공식화하여 수행됩니다. 예제 스크립트를 찾으십시오
.

대상 아키텍처 당 유효한 IDA 라이센스 및 유효한 헥스 레이 디 컴파일러 라이센스가 필요합니다.
Hexrays Toolbox를 사용하는 방법에는 여러 가지가 있습니다.
interactive.py , IDA 명령 줄 인터페이스와 함께 사용할 편의 기능을 추가하는 스크립트automation.py , 배치 모드에서 주어진 파일 세트에서 HXTB 쿼리를 처리하고 실행하는 스크립트 IDA 내에서 포함 된 hxtb_shell.py 스크립트를 실행하면 HXTB 쿼리를 개발,로드 및 실행하는 데 사용할 수있는 GUI 창이 엽니 다. 아래 스크린 샷은 HXTB 쉘로로드 된 쿼리의 모습을 보여줍니다.

HXTB-Shell은 또한 HRDEVHELPER 플러그인의 컨텍스트 뷰어가 만든 Python 표현식을 수용합니다. 그것들은 그것에서 복사하고 hxtb-shell gui에 직접 붙여 넣을 수 있습니다.

HXTB-SHELL로로드 할 수있는 추가 예제 쿼리는 HEXRAYS TOOLBOX에 포함 된 hxtbshell_queries 하위 폴더에서 찾을 수 있습니다.
ida (Alt-F7)와 함께 hxtb.py 로드하면 find_expr() 및 find_item() 과 같은 기능이 IdapyThon CLI 및 Script Interpreter (Shift-F2) 모두에서 사용할 수 있습니다. 무엇보다도 이러한 기능을 사용하여 현재로드 된 IDA 데이터베이스에서 쿼리를 실행할 수 있습니다. 아래에 표시된 몇 가지 예를 확인하십시오.
find_item(ea, q)
find_expr(ea, q)
Positional arguments:
ea: address of a valid function within
the current database
q: lambda function
custom lambda function with the following arguments:
1. cfunc: cfunc_t
2. i/e: cinsn_t/cexpr_t
Returns:
list of query_result_t objects
Example:
find_expr(here(), lambda cf, e: e.op is cot_call)
-> finds and returns all function calls within a current function.
The returned data is a list of query_result_t objects (see hxtb.py).
The returned list can be passed to an instance of the ic_t class,
which causes the data to be displayed by a chooser as follows:
from idaapi import *
import hxtb
hxtb.ic_t(find_expr(here(), lambda cf,e:e.op is cot_call))
Please find the cfunc_t, citem_t, cinsn_t and cexpr_t structures
within hexrays.hpp for further help and details.
cot_eq
/
x / y
(anything) cot_num --- n.numval() == 0
from idaapi import *
from hxtb import find_expr
query = lambda cfunc , e : e . op is cot_eq and e . y . op is cot_num and e . y . numval () == 0
r = find_expr ( here (), query )
for e in r :
print ( e ) cot_call
/
x /
cot_obj
from idaapi import *
from hxtb import find_expr
query = lambda cfunc , e : e . op is cot_call and e . x . op is cot_obj
r = find_expr ( here (), query )
for e in r :
print ( e )
cot_call --- arg1 is cot_var
/ arg1 is on stack
x /
cot_obj --- name(obj_ea) == 'memcpy'
from idaapi import *
from hxtb import find_expr
r = []
query = lambda cfunc , e : ( e . op is cot_call and
e . x . op is cot_obj and
get_name ( e . x . obj_ea ) == 'memcpy' and
len ( e . a ) == 3 and
e . a [ 0 ]. op is cot_var and
cfunc . lvars [ e . a [ 0 ]. v . idx ]. is_stk_var ())
for ea in Functions ():
r += find_expr ( ea , query )
for e in r :
print ( e ) cot_call --- arg2 ('fmt') contains '%s'
/
x /
cot_obj --- name(obj_ea) == 'sprintf'
from idaapi import *
from hxtb import find_expr
r = []
query = lambda cfunc , e : ( e . op is cot_call and
e . x . op is cot_obj and
get_name ( e . x . obj_ea ) == 'sprintf' and
len ( e . a ) >= 2 and
e . a [ 1 ]. op is cot_obj and
is_strlit ( get_flags ( get_item_head ( e . a [ 1 ]. obj_ea ))) and
b'%s' in get_strlit_contents ( e . a [ 1 ]. obj_ea , - 1 , 0 , STRCONV_ESCAPE ))
for ea in Functions ():
r += find_expr ( ea , query )
for e in r :
print ( e ) from idaapi import *
from hxtb import ic_t
query = lambda cfunc , e : ( e . op in
[ cot_asgsshr , cot_asgsdiv ,
cot_asgsmod , cot_sge ,
cot_sle , cot_sgt ,
cot_slt , cot_sshr ,
cot_sdiv , cot_smod ])
ic_t ( query )
from idaapi import *
from hxtb import ic_t
ic_t ( lambda cf , i : i . op is cit_if )
from idaapi import *
from hxtb import ic_t , query_db
ic_t ( query_db ( lambda cf , i : is_loop ( i . op )))
from hxtb import ic_t , query_db , find_child_expr
from ida_hexrays import *
find_copy_query = lambda cfunc , i : ( i . op is cot_asg and
i . x . op is cot_ptr and
i . y . op is cot_ptr )
find_loop_query = lambda cfunc , i : ( is_loop ( i . op ) and
find_child_expr ( cfunc , i , find_copy_query ))
ic_t ( query_db ( find_loop_query ))