사이드채널어택을 위한 Pintool 기본 셋팅

Pintool

핀툴은 인텔에서 만든 Dynamic Binary Instrumentation 툴입니다. 말그대로 바이너리를 동적으로 분석할 수 있는 다양한 예제 툴들이 존재하고 있습니다. 하지만 인텔 바이너리에서만 사용이 가능하다고 합니다.

핀툴에서 제공하는 기능 중에 사이드 채널 어택에 매우 유용하게 사용할 수 있는 기능이 바로 instruction을 카운트해주는 기능입니다!

Pintool 셋팅

https://software.intel.com/en-us/articles/pin-a-binary-instrumentation-tool-downloads

위 링크에서 OS별로 Pintool을 다운받을 수 있습니다.

핀툴을 받고나면 기본 구조는 아래와 같이 구성되어 있습니다.

purelledhand@purelledhand:~/tools/pin-3.6$ ls
doc  extlicense  extras  ia32  intel64  LICENSE  pin  pin.log  README  redist.txt  source

Simple Examples 경로

이 중에서 핀툴의 예제 파일들을 모아놓은 경로는 아래와 같습니다.
source/tools/SimpleExamples/

purelledhand@purelledhand:~/tools/pin-3.6$ ll source/tools/SimpleExamples/
total 380
drwxr-x---  2 purelledhand purelledhand  4096 Jan 28  2018 ./
drwxr-x--- 47 purelledhand purelledhand  4096 Feb  6 11:59 ../
-rw-r-----  1 purelledhand purelledhand  1918 Jan 28  2018 bsr_bsf_app.cpp
-rw-r-----  1 purelledhand purelledhand  2228 Jan 28  2018 bsr_bsf_asm.asm
-rw-r-----  1 purelledhand purelledhand  2230 Jan 28  2018 bsr_bsf_asm.s
-rw-r-----  1 purelledhand purelledhand  6095 Jan 28  2018 bsr_bsf.cpp
-rwxr-x---  1 purelledhand purelledhand   228 Jan 28  2018 bsr_bsf.reference*
-rwxr-x---  1 purelledhand purelledhand 11851 Jan 28  2018 callgraph.py*
-rw-r-----  1 purelledhand purelledhand  7607 Jan 28  2018 calltrace.cpp
-rw-r-----  1 purelledhand purelledhand  8723 Jan 28  2018 catmix.cpp
-rw-r-----  1 purelledhand purelledhand  8143 Jan 28  2018 coco.cpp
-rw-r-----  1 purelledhand purelledhand 11475 Jan 28  2018 dcache.cpp
-rw-r-----  1 purelledhand purelledhand 12898 Jan 28  2018 dcache.H
-rw-r-----  1 purelledhand purelledhand  9378 Jan 28  2018 edgcnt.cpp
-rw-r-----  1 purelledhand purelledhand  3330 Jan 28  2018 emuload.cpp
-rw-r-----  1 purelledhand purelledhand  8960 Jan 28  2018 extmix.cpp
-rw-r-----  1 purelledhand purelledhand 14540 Jan 28  2018 fence.cpp
-rwxr-x---  1 purelledhand purelledhand 13499 Jan 28  2018 flowgraph.py*
-rw-r-----  1 purelledhand purelledhand    57 Jan 28  2018 get_source_app.cpp
-rw-r-----  1 purelledhand purelledhand  6333 Jan 28  2018 get_source_location.cpp
-rw-r-----  1 purelledhand purelledhand  3604 Jan 28  2018 icount.cpp
-rw-r-----  1 purelledhand purelledhand  9064 Jan 28  2018 ilenmix.cpp
-rw-r-----  1 purelledhand purelledhand  5668 Jan 28  2018 inscount2_mt.cpp
-rw-r-----  1 purelledhand purelledhand  5094 Jan 28  2018 inscount2_vregs.cpp
-rw-r-----  1 purelledhand purelledhand  7850 Jan 28  2018 inscount_and_check_tls.cpp
-rw-r-----  1 purelledhand purelledhand  6079 Jan 28  2018 jumpmix.cpp
-rw-r-----  1 purelledhand purelledhand 10519 Jan 28  2018 ldstmix.cpp
-rw-r-----  1 purelledhand purelledhand   676 Jan 28  2018 makefile
-rw-r-----  1 purelledhand purelledhand  8398 Jan 28  2018 makefile.rules
-rw-r-----  1 purelledhand purelledhand  5042 Jan 28  2018 malloctrace.cpp
-rwxr-x---  1 purelledhand purelledhand   675 Jan 28  2018 objdump-routine.csh*
-rw-r-----  1 purelledhand purelledhand 14836 Jan 28  2018 opcodemix.cpp
-rw-r-----  1 purelledhand purelledhand  1759 Jan 28  2018 oper_imm_app.cpp
-rw-r-----  1 purelledhand purelledhand  2032 Jan 28  2018 oper_imm_asm.asm
-rw-r-----  1 purelledhand purelledhand  2029 Jan 28  2018 oper_imm_asm.s
-rw-r-----  1 purelledhand purelledhand  6509 Jan 28  2018 oper-imm.cpp
-rwxr-x---  1 purelledhand purelledhand  1043 Jan 28  2018 oper-imm.ia32.reference*
-rwxr-x---  1 purelledhand purelledhand  1051 Jan 28  2018 oper-imm.intel64.reference*
-rw-r-----  1 purelledhand purelledhand  7141 Jan 28  2018 pinatrace.cpp
-rw-r-----  1 purelledhand purelledhand  8359 Jan 28  2018 regmix.cpp
-rw-r-----  1 purelledhand purelledhand  2436 Jan 28  2018 regval_app.cpp
-rw-r-----  1 purelledhand purelledhand  4981 Jan 28  2018 regval.cpp
-rw-r-----  1 purelledhand purelledhand 12788 Jan 28  2018 topopcode.cpp
-rw-r-----  1 purelledhand purelledhand  7441 Jan 28  2018 toprtn.cpp
-rw-r-----  1 purelledhand purelledhand  5692 Jan 28  2018 trace.cpp
-rw-r-----  1 purelledhand purelledhand  4656 Jan 28  2018 xed-print.cpp
-rw-r-----  1 purelledhand purelledhand  3447 Jan 28  2018 xed-use.cpp

이 많은 예제중에서 instruction을 카운트하는 예제는 icount.cpp입니다.

컴파일

source/tools/MyPinTool에 컴파일 환경이 마련되어 있어 이 곳에서 파일을 컴파일하면 됩니다.

purelledhand@purelledhand:~/tools/pin-3.6$ ls source/tools/MyPinTool/
makefile  makefile.rules  MyPinTool.cpp  obj-intel64

makefile.rules 파일에서 TEST_ROOTS를 수정하여 컴파일 할 소스와 obj파일이름을 마음대로 변경할 수 있습니다.
저는 icount 예제만 사용할 것이기 때문에 따로 makefile.rules를 수정하지는 않고 MyPinTools.cpp파일을 통해서만 컴파일하고자 합니다.

make [TARGET=intel64] // 64-bit compile
make TARGET=ia32 // 32-bit compile

실행

실행은 pin 기본 루트 경로에 위치해있는 pin 바이너리를 통해서 할 수 있습니다.

purelledhand@purelledhand:~/tools/pin-3.6$ ./pin -t source/tools/MyPinTool/obj-intel64/MyPinTool.so -- ../../week5/crackme
PASSCODE : A
FAILED
Count 151993
Purelledhand

Purelledhand

잡지같은 블로그