KEYSTONE: the last missing framework for Reverse Engineering
www.keystone-engine.org NGUYEN Anh Quynh <aquynh -at- gmail.com> RECON - June 19th, 2016
1 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
KEYSTONE: the last missing framework for Reverse Engineering - - PowerPoint PPT Presentation
KEYSTONE: the last missing framework for Reverse Engineering www.keystone-engine.org NGUYEN Anh Quynh <aquynh -at- gmail.com> RECON - June 19th, 2016 1 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
1 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ Nanyang Technological University, Singapore ◮ Researcher with a PhD in Computer Science ◮ Operating System, Virtual Machine, Binary analysis, etc ◮ Capstone disassembler: http://capstone-engine.org ◮ Unicorn emulator: http://unicorn-engine.org ◮ Keystone assembler: http://keystone-engine.org 2 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
3 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
4 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ Ex: inc EAX → 40
◮ Binary rewrite ◮ Binary searching 5 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ Label, macro, directive, etc ◮ Instruction: menemonic + operands ⋆ Emit machine code accordingly ⋆ Instruction-Set-Architecture manual referenced is needed 6 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
7 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ Embedded into tool without resorting to external process
◮ X86, Arm, Arm64, Mips, PowerPC, Sparc, etc
◮ *nix, Windows, Android, iOS, etc
◮ Keep up with latest CPU extensions
◮ Python, Ruby, Go, NodeJS, etc 8 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ Yasm: X86 only, no longer updated ◮ Intel XED: X86 only, miss many instructions & closed-source ◮ Other important archs: Arm, Arm64, Mips, PPC, Sparc, etc? 9 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ Use existing assembler tool to compile assembly from file ◮ Call linker to link generated object file ◮ Use ELF parser to parse resulted file for final encoding
10 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ Arm, Arm64, Mips, PowerPC, Sparc, X86 (+X86_64) + more
◮ Low-level framework to support all kind of OS and tools ◮ Core in C++, with API in pure C, and support multiple binding
11 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ 99 contributors, 4 project sponsors
◮ Only Python binding available at this time
◮ More bindings by beta testers: NodeJS, Ruby, Go & Rust
12 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
13 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ Arm, Arm64, Mips, PowerPC, Sparc, X86 (+X86_64) + more
14 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ Started as a personal project 15 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
16 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
17 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ X86, Arm, Arm64, Mips, PowerPC, Sparc, Hexagon, SystemZ, etc
◮ Native compile on Windows, Linux, macOS, BSD, Android, iOS, etc 18 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
19 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
20 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ Only useable for LLVM modules, not for external code ◮ Closely designed & implemented for LLVM ◮ Very actively maintained & updated by a huge community
21 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ X86: maintained by Intel (arch creator). ◮ Arm+Arm64: maintained by Arm & Apple (arch creator & Arm64’s
◮ Hexagon: maintained by Qualcomm (arch creator) ◮ Mips: maintained by Imgtec (arch creator) ◮ SystemZ: maintained by IBM (arch creator) ◮ PPC & Sparc: maintained by highly active community
22 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
23 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ No need to rewrite complicated parsers ◮ No need to fork llvm-tblgen 24 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ Cut too little result in keeping lots of redundant code ◮ Cut too much would change the code structure, making it hard to sync
◮ Take the assembler core & make minimal changes 25 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
26 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ Supported libs ◮ Parser ◮ TableGen ◮ etc
◮ libkeystone.[so, dylib] or keystone.dll ◮ libkeystone.a, or keystone.lib 27 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ Ex on X86: inc [_var1] → 0xff, 0x04, 0x25, A, A, A, A
28 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
29 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ Parse phase ◮ Code emit phase 30 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ We want other syntaxes like Nasm, Masm, etc
31 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ Do not give up on bad-formed assembly
32 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
33 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ open & close Keystone instance ◮ customize runtime instance (allow to change assembly syntax, etc) ◮ assemble input code ◮ memory management: free allocated memory
34 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
35 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
36 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
37 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
38 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ Compile assembly input with Keystone ◮ Feed the output encoding to Unicorn for emulation 39 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ Encode assembly with Keystone ◮ Decode hexcode to with Capstone 40 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
41 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ Future of Keystone is guaranteed by LLVM active development! 42 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
43 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ Multi-arch + multi-platform ◮ Clean/simple/lightweight/intuitive architecture-neutral API ◮ Implemented in C++, with API in C language & multiple bindings
◮ Thread-safe by design ◮ Open source in dual license ◮ Future update guaranteed for all architectures
44 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
45 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
◮ Homepage: http://keystone-engine.org ◮ Github: http://github.com/keystone-engine/keystone ◮ Mailing list: http://freelists.org/list/keystone-engine ◮ Twitter: @keystone_engine
46 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
47 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering
48 / 48 NGUYEN Anh Quynh KEYSTONE: the last missing framework for Reverse Engineering