BinCAT
Purrfecting binary static analysis
June 16th 2017 - REcon
Philippe Biondi, Raphaël Rigo, Sarah Zennou, Xavier Mehrenberger
BinCAT Purrfecting binary static analysis June 16th 2017 - REcon - - PowerPoint PPT Presentation
BinCAT Purrfecting binary static analysis June 16th 2017 - REcon Philippe Biondi, Raphal Rigo, Sarah Zennou, Xavier Mehrenberger Plan Introduction Demo Under the hood Conclusion 2 Biondi, Mehrenberger, Rigo, Zennou :: BinCAT Plan
BinCAT
Purrfecting binary static analysis
June 16th 2017 - REcon
Philippe Biondi, Raphaël Rigo, Sarah Zennou, Xavier MehrenbergerPlan
Introduction Demo Under the hood Conclusion
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT2
Plan
Introduction Demo Under the hood Conclusion
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT3
BinCAT (Binary Code Analysis Toolkit)
Binary analyzer
extensible x86 . . . x86 . . . static theory backed IDA in- tegration forward / backward analysis computed properties . . . types CFG with indirect jumps taint analysis values . . . Biondi, Mehrenberger, Rigo, Zennou :: BinCAT4
BinCAT (Binary Code Analysis Toolkit)
Binary analyzer
extensible x86 . . . x86 . . . static theory backed IDA in- tegration forward / backward analysis computed properties . . . types CFG with indirect jumps taint analysis values . . . Biondi, Mehrenberger, Rigo, Zennou :: BinCAT5
BinCAT (Binary Code Analysis Toolkit)
Binary analyzer
extensible x86 . . . x86 . . . static theory backed IDA in- tegration forward / backward analysis computed properties . . . types CFG with indirect jumps taint analysis values . . . Biondi, Mehrenberger, Rigo, Zennou :: BinCAT6
BinCAT (Binary Code Analysis Toolkit)
Binary analyzer
extensible x86 . . . x86 . . . static theory backed IDA in- tegration forward / backward analysis computed properties . . . types CFG with indirect jumps taint analysis values . . . Biondi, Mehrenberger, Rigo, Zennou :: BinCAT7
BinCAT (Binary Code Analysis Toolkit)
Binary analyzer
extensible x86 . . . x86 . . . static theory backed IDA in- tegration forward / backward analysis computed properties . . . types CFG with indirect jumps taint analysis values . . . Biondi, Mehrenberger, Rigo, Zennou :: BinCAT8
BinCAT (Binary Code Analysis Toolkit)
Binary analyzer
extensible x86 . . . x86 . . . static theory backed IDA in- tegration forward / backward analysis computed properties . . . types CFG with indirect jumps taint analysis values . . . Biondi, Mehrenberger, Rigo, Zennou :: BinCAT9
BinCAT (Binary Code Analysis Toolkit)
Binary analyzer
extensible x86 . . . x86 . . . static theory backed IDA in- tegration forward / backward analysis computed properties . . . types CFG with indirect jumps taint analysis values . . . Biondi, Mehrenberger, Rigo, Zennou :: BinCAT10
BinCAT (Binary Code Analysis Toolkit)
Binary analyzer
extensible x86 . . . x86 . . . static theory backed IDA in- tegration forward / backward analysis computed properties . . . types CFG with indirect jumps taint analysis values . . . Biondi, Mehrenberger, Rigo, Zennou :: BinCAT11
BinCAT (Binary Code Analysis Toolkit)
Binary analyzer
extensible inter- mediate language . . . x86 . . . static theory backed IDA in- tegration forward / backward analysis computed properties . . . types CFG with indirect jumps taint analysis values . . . Biondi, Mehrenberger, Rigo, Zennou :: BinCAT12
BinCAT (Binary Code Analysis Toolkit)
Binary analyzer
extensible inter- mediate language . . . x86 . . . static theory backed IDA in- tegration forward / backward analysis computed properties . . . types CFG with indirect jumps taint analysis values . . . Biondi, Mehrenberger, Rigo, Zennou :: BinCAT13
Plan
Introduction Demo Under the hood Conclusion
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT14
Example: keygenme
$ ./get_key Usage: ./get_key company department name licence
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT15
Example: keygenme
$ ./get_key Usage: ./get_key company department name licence $ ./get_key company department name wrong_serial
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT16
Example: keygenme
$ ./get_key Usage: ./get_key company department name licence $ ./get_key company department name wrong_serial Licence=>[025E60CB08F00A1A23F236CC78FC819CE6590DD7] Invalid serial wrong_serial
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT17
Example: keygenme
$ ./get_key Usage: ./get_key company department name licence $ ./get_key company department name wrong_serial Licence=>[025E60CB08F00A1A23F236CC78FC819CE6590DD7] Invalid serial wrong_serial $ ./get_key company department name 025E60CB0[...]
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT18
Example: keygenme
$ ./get_key Usage: ./get_key company department name licence $ ./get_key company department name wrong_serial Licence=>[025E60CB08F00A1A23F236CC78FC819CE6590DD7] Invalid serial wrong_serial $ ./get_key company department name 025E60CB0[...] Licence=>[025E60CB08F00A1A23F236CC78FC819CE6590DD7] Thank you for registering !
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT19
Keygenme: data flow
argv[0] department company name CRC CRC CRC CRC
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT20
Keygenme: data flow
argv[0] department company name CRC CRC CRC CRC mul
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT21
Keygenme: data flow
argv[0] department company name CRC CRC CRC CRC mul sprintf
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT22
Keygenme: data flow
argv[0] department company name CRC CRC CRC CRC mul sprintf
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT23
Keygenme: data flow
argv[0] department company name CRC CRC CRC CRC mul sprintf SHA-1
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT24
Keygenme: data flow
argv[0] department company name CRC CRC CRC CRC mul sprintf SHA-1 hex encode
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT25
Keygenme: data flow
argv[0] department company name CRC CRC CRC CRC mul sprintf SHA-1 hex encode license
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT26
Demo 1: BinCAT usage
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT27
Demo 2: Tainting
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT28
Plan
Introduction Demo Under the hood Conclusion
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT29
Architecture
IDA plugin IDA
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT30
Architecture
IDA plugin IDA bincat binary
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT31
Architecture
IDA plugin IDA bincat binary config, binary...
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT32
Architecture
IDA plugin local mode IDA bincat binary config, binary... results, logs
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT33
Architecture
IDA plugin remote mode IDA bincat binary Web server REST REST
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT34
Architecture
IDA plugin remote mode IDA bincat binary Web server REST REST
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT35
Control flow graph reconstruction
state1 state2 state3 state4
IP=0x08041236 EAX=0x00000000 EBX=0x87654321 mem[0x1000]=|323130| IP=0x08041238 EAX=0x00000000 EBX=0x87654321 mem[0x1000]=|303132| IP=0x0804123A EAX=0x12345678 EBX=0x87654321 mem[0x1000]=|303132| IP=0x0804143D EAX=0x12345678 EBX=0x8765432? mem[0x1000]=|303132| EIP=0x0804123C EAX=0x0007FFFF ZF=1 mem[0x1000]=|303132| Biondi, Mehrenberger, Rigo, Zennou :: BinCAT36
Control flow graph reconstruction
state1 state2 state3 state4
IP=0x08041236 EAX=0x00000000 EBX=0x87654321 mem[0x1000]=|323130| IP=0x08041238 EAX=0x00000000 EBX=0x87654321 mem[0x1000]=|303132| IP=0x0804123A EAX=0x12345678 EBX=0x87654321 mem[0x1000]=|303132| IP=0x0804143D EAX=0x12345678 EBX=0x8765432? mem[0x1000]=|303132| EIP=0x0804123C EAX=0x0007FFFF ZF=1 mem[0x1000]=|303132|IP=0x0804123A EAX=0x12345678 EBX=0x87654321 mem[0x1000]=|303132| EIP=0x0804123C EAX=0x0007FFFF ZF=1 mem[0x1000]=|303132|
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT37
Control flow graph reconstruction
state1 state2 state3 state4
IP=0x08041236 EAX=0x00000000 EBX=0x87654321 mem[0x1000]=|323130| IP=0x08041238 EAX=0x00000000 EBX=0x87654321 mem[0x1000]=|303132| IP=0x0804123A EAX=0x12345678 EBX=0x87654321 mem[0x1000]=|303132| IP=0x0804143D EAX=0x12345678 EBX=0x8765432? mem[0x1000]=|303132| EIP=0x0804123C EAX=0x0007FFFF ZF=1 mem[0x1000]=|303132|Decoder P C , c
t e x t , s e g m e n t s
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT38
Control flow graph reconstruction
state1 state2 state3 state4
IP=0x08041236 EAX=0x00000000 EBX=0x87654321 mem[0x1000]=|323130| IP=0x08041238 EAX=0x00000000 EBX=0x87654321 mem[0x1000]=|303132| IP=0x0804123A EAX=0x12345678 EBX=0x87654321 mem[0x1000]=|303132| IP=0x0804143D EAX=0x12345678 EBX=0x8765432? mem[0x1000]=|303132| EIP=0x0804123C EAX=0x0007FFFF ZF=1 mem[0x1000]=|303132|Decoder intermediate language
eax ← (eax + 0x1); zf ← eax=0 ? 1: 0; sf ← (eax >> 0x1f)=1 ? 1: 0; . . .inc eax
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT39
Control flow graph reconstruction
state1 state2 state3 state4
IP=0x08041236 EAX=0x00000000 EBX=0x87654321 mem[0x1000]=|323130| IP=0x08041238 EAX=0x00000000 EBX=0x87654321 mem[0x1000]=|303132| IP=0x0804123A EAX=0x12345678 EBX=0x87654321 mem[0x1000]=|303132| IP=0x0804143D EAX=0x12345678 EBX=0x8765432? mem[0x1000]=|303132| EIP=0x0804123C EAX=0x0007FFFF ZF=1 mem[0x1000]=|303132|Decoder intermediate language
eax ← (eax + 0x1); zf ← eax=0 ? 1: 0; sf ← (eax >> 0x1f)=1 ? 1: 0; . . .inc eax
eax ← (eax + 0x1); zf ← eax=0 ? 1: 0; sf ← (eax >> 0x1f)=1 ? 1: 0; . . .
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT40
Control flow graph reconstruction
state1 state2 state3 state4
IP=0x08041236 EAX=0x00000000 EBX=0x87654321 mem[0x1000]=|323130| IP=0x08041238 EAX=0x00000000 EBX=0x87654321 mem[0x1000]=|303132| IP=0x0804123A EAX=0x12345678 EBX=0x87654321 mem[0x1000]=|303132| IP=0x0804143D EAX=0x12345678 EBX=0x8765432? mem[0x1000]=|303132| EIP=0x0804123C EAX=0x0007FFFF ZF=1 mem[0x1000]=|303132|Decoder intermediate language
eax ← (eax + 0x1); zf ← eax=0 ? 1: 0; sf ← (eax >> 0x1f)=1 ? 1: 0; . . .State generator
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT41
Control flow graph reconstruction
state1 state2 state3 state4
IP=0x08041236 EAX=0x00000000 EBX=0x87654321 mem[0x1000]=|323130| IP=0x08041238 EAX=0x00000000 EBX=0x87654321 mem[0x1000]=|303132| IP=0x0804123A EAX=0x12345678 EBX=0x87654321 mem[0x1000]=|303132| IP=0x0804143D EAX=0x12345678 EBX=0x8765432? mem[0x1000]=|303132| EIP=0x0804123C EAX=0x0007FFFF ZF=1 mem[0x1000]=|303132|Decoder State generator state5
EIP=0x0804123D EAX=0x00080000 ZF=0 mem[0x1000]=|303132| Biondi, Mehrenberger, Rigo, Zennou :: BinCAT42
Control flow graph reconstruction
state1 state2 state3 state4
IP=0x08041236 EAX=0x00000000 EBX=0x87654321 mem[0x1000]=|323130| IP=0x08041238 EAX=0x00000000 EBX=0x87654321 mem[0x1000]=|303132| IP=0x0804123A EAX=0x12345678 EBX=0x87654321 mem[0x1000]=|303132| IP=0x0804143D EAX=0x12345678 EBX=0x8765432? mem[0x1000]=|303132| EIP=0x0804123C EAX=0x0007FFFF ZF=1 mem[0x1000]=|303132|Decoder State generator state5
EIP=0x0804123D EAX=0x00080000 ZF=0 mem[0x1000]=|303132|IP=0x0804123A EAX=0x12345678 EBX=0x87654321 mem[0x1000]=|303132| EIP=0x0804123C EAX=0x0007FFFF ZF=1 mem[0x1000]=|303132|
EIP=0x0804123D EAX=0x00080000 ZF=0 mem[0x1000]=|303132|
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT43
Control flow graph reconstruction
state1 state2 state3 state4 state5
IP=0x08041236 EAX=0x00000000 EBX=0x87654321 mem[0x1000]=|323130| IP=0x08041238 EAX=0x00000000 EBX=0x87654321 mem[0x1000]=|303132| IP=0x0804123A EAX=0x12345678 EBX=0x87654321 mem[0x1000]=|303132| IP=0x0804143D EAX=0x12345678 EBX=0x8765432? mem[0x1000]=|303132| EIP=0x0804123C EAX=0x0007FFFF ZF=1 mem[0x1000]=|303132| EIP=0x0804123D EAX=0x00800000 ZF=0 mem[0x1000]=|303132|Decoder State generator state5
EIP=0x0804123D EAX=0x00080000 ZF=0 mem[0x1000]=|303132|i f n e w
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT44
Formal correctness: static analysis by abstract interpretation
represent sets of values/taint/types ex: 0 ≡ {0}, ? ≡ {integers}, Struct ≡ {C structs}
45
Formal correctness: static analysis by abstract interpretation
represent sets of values/taint/types ex: 0 ≡ {0}, ? ≡ {integers}, Struct ≡ {C structs}
s1: esi = 0x1000, uint32* while esi < 0x8000
46
Formal correctness: static analysis by abstract interpretation
represent sets of values/taint/types ex: 0 ≡ {0}, ? ≡ {integers}, Struct ≡ {C structs}
s1: esi = 0x1000, uint32* s2: esi = 0x1004, uint32* s′
2 = s1∇s2esi = 0x????????, uint32* while esi < 0x8000
47
Formal correctness: static analysis by abstract interpretation
represent sets of values/taint/types ex: 0 ≡ {0}, ? ≡ {integers}, Struct ≡ {C structs}
s1: esi = 0x1000, uint32* s2: esi = 0x1004, uint32* s′
2 = s1∇s2esi = 0x????????, uint32* s3: esi = 0x????????, uint32* s′
3 = s′ 2∇s3esi = 0x????????, uint32* while esi < 0x8000
48
Formal correctness: static analysis by abstract interpretation
represent sets of values/taint/types ex: 0 ≡ {0}, ? ≡ {integers}, Struct ≡ {C structs}
s1: esi = 0x1000, uint32* s2: esi = 0x1004, uint32* s′
2 = s1∇s2esi = 0x????????, uint32* s3: esi = 0x????????, uint32* s′
3 = s′ 2∇s3esi = 0x????????, uint32* s2 s3 sn ⊑ ⊑ ⊑ while esi < 0x8000
ultimately stationary
execution trace
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT49
Formal correctness: static analysis by abstract interpretation
represent sets of values/taint/types ex: 0 ≡ {0}, ? ≡ {integers}, Struct ≡ {C structs}
s1: esi = 0x1000, uint32* s2: esi = 0x1004, uint32* s′
2 = s1∇s2esi = 0x????????, uint32* s3: esi = 0x????????, uint32* s′
3 = s′ 2∇s3esi = 0x????????, uint32* s2 s3 sn ⊑ ⊑ ⊑ while esi < 0x8000
ultimately stationary
execution trace
recovery
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT50
Empirical testing
51
Empirical testing
52
Empirical testing
abstract operations, etc.
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT53
Empirical testing
abstract operations, etc. = ⇒ lots of unit tests
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT54
Empirical testing
abstract operations, etc. = ⇒ lots of unit tests
55
Empirical testing
abstract operations, etc. = ⇒ lots of unit tests
56
Empirical testing
abstract operations, etc. = ⇒ lots of unit tests
57
Analyzer’s performance
Example: keygenme
QEMU tests:
58
Plan
Introduction Demo Under the hood Conclusion
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT59
Conclusion
Binary analyzer
extensible intermediate language x86 static theory backed IDA in- tegration forward / backward analysis computed properties types CFG with indirect jumsp taint analysis values Biondi, Mehrenberger, Rigo, Zennou :: BinCAT60
Current features improvements (planned)
BinCAT extensible inter- mediate language x86 statique base théorique IDA in- tegration forward / backward analysis computed properties reconstruction du CFG avec sauts indirects résolus types taint valeursbackward analysis
models
61
Future features
BinCAT extensible intermediate language x86 x86-64 ARM statique base théorique intégré à IDA analyses avan- t/arrière computed properties reconstruction du CFG avec sauts indirects résolus reconstruction de types values taint analysis62
Thanks!
Full paper (link in README):
https://www.sstic.org/media/SSTIC2017/SSTIC-actes/bincat_purrfecting_ binary_static_analysis/SSTIC2017-Article-bincat_purrfecting_binary_ static_analysis-biondi_rigo_zennou_mehrenberger.pdfhttps://github.com/airbus-seclab/bincat docker run -p 5000:5000 airbusseclab/bincat tutorial in doc/tutorial.md
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT63
x86 coverage
ADD PUSH ES POP ESOR PUSH CS 2 bytes
ADC PUSH SS POP SSSBB PUSH DS POP DS AND ES: DAASUB CS: DAS XOR SS: AAACMP DS: AAS
INCDEC
PUSHPOP
PUSHA POPA BOUND ARPL FS: GS: OPSIZE: ADSIZE: PUSH IMUL PUSH IMUL INSB INSW OUTSB OUTSWJNO JNO JB JNB JZ JNZ JBE JA JS JNS JP JNP JL JNL JLE JNLE
Grp1 Grp1 Grp1 TEST XCHGMOV LEA MOV POP
NOP XCHG EAX CWD CDQ CALL WAIT PUSHF POPF SAHF LAHF
MOV EAX MOVS CMPS TEST STOS LODS SCAS
SHIFT RETN LES LDS MOV ENTER LEAVE RETF INT3 INT INTO IRETD
Grp2 AAM AAD SALC XLATFPU
LOOPNZ LOOPZ LOOP JCXZ IN OUT CALL JMP JMPF JMPS IN OUTLOCK: INT1 REPNE: REP: HLT CMC Grp3 CLC STC CLI STI CLD STD Grp4 Grp5
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT64
x86 coverage - Second table Grp6 Grp7 LAR LSL
CLTS INVD WBINVD
UD2 NOP
SSE PrefetchSSE1 HINT NOP
MOV CR DR
SSE
WRMSR RDTSC RDMSR RDPMC SYSENTER SYSEXIT GETSECSMX MOVBESSE
CMOV
MMX SSE
MMX SSE VMX
MMX SSE
JNO JNO JB JNB JZ JNZ JBE JA JS JNS JP JNP JL JNL JLE JNLE
SETNO SETNO SETB SETNB SETZ SETNZ SETBE SETA SETS SETNS SETP SETNP SETL SETNL SETLE SETNLE PUSH FS POP FS CPUID BT SHLD PUSH GS POP GS RSM BTS SHRD FENCE IMULCMPXCHG LSS BTR LFS LGS MOVZX POPCNT UD BTx BTC BSF BSR MOVSX
XADDSSE CMPXCHGBSWAP
MMX SSE MMX SSE
MMX SSE
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT65
Currently implemented lattices
⊤ . . . ⊥ 7
. . . . . . very precise less precise ⊑ ⊤ untainted tainted ⊥ ⊤ int struct . . . . . . int32 uint32 ⊥ very precise less precise ⊑
Biondi, Mehrenberger, Rigo, Zennou :: BinCAT66