Transcript
Page 1: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

Be a Binary Rockst rAn Introduction to Program Analysis with

Binary Ninja

Page 2: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

What this talk is not about

Page 3: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

What this talk is about

Page 4: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

Fuzzing….

Current state of the art.

Binary.

Source Code.

Problem

Reading/ scripting

disassembly

Reading code

Analysis of Bitcode

Static Analysis with Bindead, REIL, BAP.

Dynamic Instrumentation

Static and Dynamic Analysis

Compilers

Source code analyzer

McSema

Page 5: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

IDA isn’t perfect

Page 6: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

Problems.

Binary.

Source Code.

Problem

● Lack of robust tooling options

● Reading code continues to be useful

● Increase in compiler strength and LLVM tooling (lots of cool projects in this area!)

● Most tools lack semantic reasoning

● Decompilers widely used but difficult to automatically reason over

● Majority of program analysis frameworks are hard to use - they lack usable frameworks for interaction with your own analysis

● No really good options to lift binaries to interactive, workable IL frameworks

Page 7: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

Binary, interactive

IL frameworks.

Page 8: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

Binary Ninja & Binja IL

Page 9: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

Binja: Tree Based Structure● Binary Ninja IL

Organized into expressions: LowLevelILInstruction

● LLILI’s are infinite length tree-based instructions

● Infix notation. Destination operand is the left hand operand(e.g. x86 ``mov eax, 0`` vs. LLIL ``eax =

0``)

● Side effect free

● Recursive descent analysis

Page 10: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

Binja: Tree Based Structure

● Symbolic analysis (abstract interpretation) to find bounds of a jump table

● Determine function ends, aborts, etc using disassembly and their own IL.

Page 11: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

binja_memcpy.py: IL/bin/bash

Page 12: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

binja_memcpy.py: IL/bin/bash

Page 13: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

binja_memcpy.py: IL/bin/bash

Register States!

Page 14: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

binja_memcpy.py: API

Page 15: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

binja_memcpy.py: API

Page 16: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

binja_memcpy.py: API

Page 17: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

binja_memcpy.py: API

Page 18: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

binja_memcpy.py: Output

Page 19: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

Binja API● Python, C and C++ API (idiomatic!)

● Missing some analysis features, built into LLVM (i.e. integrated CFG traversal, Uses, SSA, reg/ var

distinction)● Branches: Basic block/ Function edges (outgoing)

● Get the register states, some naive range analysis

● api.binary.ninja/search.html

Page 20: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

Symbolic Execution● Very accurate

● Takes time, data, and memory, often not feasible

● IDEA! Reasoning only about what we can about

● Apply complex data to abstract domains !

● Domains: type, sign, range, color etc….

Page 21: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

Practical(Academia) & Program Analysis ● Sets of concrete

values are abstracted imprecisely

● Galois Connection formalizes Concrete <-> Abstract

Page 22: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

Abstraction!int x = 5

int y = argc + x

int za

Page 23: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

Abstract Interpretatio

n

int x = 5

int y = argc + x

int z

aint

Abstract domain: Type

Page 24: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

Abstraction Interpretatio

n

int x = 5

int y = argc + x

a

int z

int

= +

= +

Sign Analysis

Page 25: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

Practical(Academia) & Program Analysis ● X ‘s value is

imprecise● Compilers perform

imprecise abstractionint x; int[] a = new int[10]; a[2 * x] = 3; 1. Add precision - i.e.

declare abstract value [0, 9]1. Symbolically execute with abstract domain/ values

● Requires control-flow analysis

Page 26: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

Abstract Domains & Sign Analysisint a,b,c; a = 42;b = 87;if (input) {

c = a + b;} else {

c = a - b;}

● Map variables to an abstract value

Page 27: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

Abstract Domains & Sign Analysis● Binary Ninja plugin

● Path sensitive - construct lattices of abstract values

● Under approximate

● One abstract state per CFG node

● Avoid loss in precision for fractions.

Page 28: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

Demo!● Analyze example

program ● PHP CVE-2016-6289

Page 29: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

Scripts!● memcpy, headless

python API script

● depth-first-search, path sensitive CFG template

● sign analysis, abstract domain plugin

https://github.com/quend/ abstractanalysis

Page 30: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

Contact me● Sophia d’Antoine

○ IRC: @quend○ [email protected]○ Binary Ninja Slack

Page 31: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

Conclusion● Thanks!

○ Vector35○ Trail of Bits○ Ryan Stortz

(@withzombies)● Resources

○ binary.ninja/○ github.com/quend/abstractanalysis○ santos.cs.ksu.edu/schmidt/Escuela03/WSSA/talk1p.pdf○ Static Program Analysis Book!

cs.au.dk/~amoeller/spa/spa.pdf

remember: prune this before analysing

Page 32: [CB16] Be a Binary Rockstar: An Introduction to Program Analysis with Binary Ninja by Sophia D’Antoine

Agenda1) IDA isn’t perfect2) Binary Ninja IL3) Practical(Academia) and program analysis

a) Abstract Interpretation 4) Binary Ninja plugin demo5) Conclusion


Recommended