69
Runtime Decompilation The ‘GreyBox’ process for Exploiting Software By: Greg Hoglund [email protected]

The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

RuntimeDecompilation

The ‘GreyBox’ process forExploiting Software

By: Greg [email protected]

Page 2: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Introduction

¡ This presentation is an overview ofthe lab process used by HBGary™to locate and exploit software bugs

¡ The value is reduced timeinvestment and formalizing a ‘blackart’

Page 3: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

The Deconstructionist

¡ Taking a system apart is aboutuncovering mysteries

¡ Having secret knowledge attractsthe human psyche at the deepestlevel

¡ There is an age old battle betweenthose that create systems and thosewho take them apartl i.e, crytoanalysis

Page 4: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Why Exploit Software?

¡ Exploits are worth moneyl A vulnerability can be worth over $100K

¡ The vendor costs are huge for a publicvulnerability

l An exploit costs less than physical ‘bugs’

¡ Exploits are worth livesl An exploit is safer than physical penetration

¡ Exploits are strategicl Disable or control the information systems of

your enemies decision cycle

Page 5: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Survivability

¡ Exploits have a lifetime¡ Every use of an exploit has the

potential to compromise the asset¡ Exploits depend on bugs and your

enemy may also find the same bug¡ The public may find the same bug¡ Once public, many exploits can be

protected against or detected via anIDS

Page 6: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

In order to maintain a battleadvantage, your offensive

information capability must includea lab process for finding andexploiting new software bugs

Page 7: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Chapter One

The Bugs!

Page 8: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

The Bugs

1. Buffer Overflowsa. Lack of bounds checkingb. Arithmetic errors

2. Parsing Problemsa. Input filters and normalization

3. General State Corruption4. Race Conditions

Page 9: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Buffer Overflows

¡ Old News, but still most commontodayl Because of speed, most server

software is still developed in c/c++

¡ Will remain common until oldcompiler technologies areabandonedl Strongly typed languages, such as C#,

eliminate simple string overflows

Page 10: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Parsing Problems

¡ Not solved by better compilers¡ Solved only by good algorithms¡ To eliminate parsing problems

requires standardized algorithmsl Similar to peer review on crypto

systems

¡ This will never happenl Parsing problems here to stay

Page 11: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

General State Exploits

¡ States control decisions¡ Users can cause state transitions¡ Some states are insecure by nature¡ State exploits are found by sending

commands in the exact order andcontext to arrive at the insecurestate

¡ Only solved by provably correctsystemsl Humans are never going to build

provably correct systems

Page 12: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Race Conditions

¡ State problems are going to bedifficult to measure and control

¡ When state is managed over manynodes, the problem becomes evenharderl When state must be synchronized

among nodes, we have race conditionsl The problem is compounded greatlyl This is the ‘buffer overflow’ of the

future

Page 13: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Chapter Two

What is the‘GreyBox’ process?

Page 14: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

GreyBox:Combining both static analysisand runtime fault injection tomaximize coverage of asoftware programs’ state-space. Typically used todetect and isolate fault statesin a software system.

Page 15: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

White Box

¡ In theory, operating with full knowledgeabout the inner workings of the systeml At best, we only have an approximate

understanding of the builder’s intent

¡ White box analysis involves “deadlistings”static disassemblies of the binaryl Source code is an added advantage, like

having really good documentation for thedeadlisting

¡ The software is not being executed

Page 16: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

First Pass

¡ When confronted with a new binary, theHBGary team fires the binary throughBugScan™

¡ We obtain a report within minutes toassess whether the programmers usesecure coding practicesl Typically they do not

¡ We use the BugScan report to prioritizewhich binaries will be analyzed firstl Binaries with bad reports are hit first

Page 17: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Manage the Deadlisting

¡ IDA-Pro allows you to manage andcomment a large deadlisting

Page 18: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Is it actually exploitable?

¡ Depends on many variables in theenvironment

¡ All automatic analysis tools havethis problem

¡ It almost always takes an expertreverse engineer to determine if acondition is exploitable

Page 19: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Does it matter?

¡ Even if a vulnerability cannot bereached today – what can you sayabout tommorow?

¡ What if interface changes?¡ What if code gets used from other

locations?¡ Is the original author going to be

maintaining this code in 10 years?

Page 20: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Automatic Bug Detection

¡ The bug must have a definedpattern, it must be schematic innature

¡ Effective when certain conditionsexistl Availability of type informationl Separation of data and codel All instructions can be recoveredl Data that drives control flow can be

mapped

Page 21: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Branching Decisions

¡ Many branches are made based onvalues that are calculated atruntime

¡ The static analyzer must emulateexecution to determine these values

¡ At some point, the emulationbecomes computationally equivalentto running the program in the firstplace. How much emulation isenough?

Page 22: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Backtraces reach dead ends

¡ We backtrace up to 64 steps from avulnerable functionl Every branch is exercised

¡ Back traced cross references can beused to connect input with a codelocationl For example, does a previous function

take input from the network?

¡ Many times a static backtrace dead-endsl Windows message handler

Page 23: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Black Box

¡ All we see are the outputs from thesoftware – no inner workings

¡ Requires deep protocol knowledge

¡ ‘Fuzzers’:l Hailstorm and Spike

Page 24: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Black Box is not stand alone

¡ Black box testers take FOREVER tocomplete their input sequences.

¡ If the program is slow, thiscompounds the problem

¡ Amounts to ‘brute forcing’¡ Finding bugs with pure brute force

is mostly luck

Page 25: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Blackbox State

¡ Typical network software is highlystateful

¡ A client must be able to maintain acomplex state in order tocommunicate effectively with thetarget

¡ Modeling highly stateful clients fromscratch is very time consuming andprone to error

Page 26: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Instrumented Clients

¡ Using a real client programeliminates most of the state issues

¡ You don’t need to rebuild the wheel¡ Fault injection is inserted in-transit

by modifying the code within theclient program

¡ The client program becomes ahostile mutant

Page 27: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Fault Injection Clients

¡ If the protocol is proprietary youhave two choicesl Modify in the middle the packets

¡ Only works is protocol is not overlycomplex and not encrypted – beware ofauthentication/encryption

l Instrument proprietary client¡ Requires difficult call-hooking, time

consuming

Page 28: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Hooking clients

¡ Find location where pointer is held inregister

¡ Put breakpoint on this location and modifythe given string in memory l Cannot BO string w/o corruption

¡ Or, replace the pointer with anotherpointerl May cause state problems in some clients

¡ Using ‘debugger’ technology makes thiswhole process easier – no EXE patchingrequired

Page 29: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

GreyBox

¡ Combine black-box injection withcode analysis

¡ If you use a program debugger,your performing grey-box analysis

¡ Performed at runtime so softwarecan be observed

¡ All instructions which are executedcan be obtained. All data involvedat these points can be tracked

Page 30: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Interactive

¡ Grey-box testing is an interactiveprocess between a skilled engineerand the target program

¡ Tools used include SoftIce, OllyDbg,Aegir, Fenris, GDB, Tempest, andthe MS-Visual C debugger*

*IDA-Pro has an integrated debugger, but the currentversion is not evolved enough for industrial levelwork

Page 31: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Fenris www.bindview.com

Page 32: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Chapter Three

How to useBug Scan™

Page 33: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Easy Stuff – Introducing BugScan!

¡ BugScan is extremely simple touse

¡ Submit binary and get report¡ Report cannot verify is conditions

are actually exploitablel But it takes 30 seconds, not 30 hoursl Defensive stance – don’t wait for

someone to attack before you protectyourself

Page 34: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Submit a File

Page 35: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

View the Report

Page 36: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Latest BugScan Reports from the Field

TO BE REVEALED AT CONFERENCE

Page 37: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

FREE BUGSCAN for BLACKHAT

¡ Use this logon to scan any binary,free for blackhat attendees for thenext 60 days

l HTTP://www.hbgary.com/freeblackhat

Page 38: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Chapter Four

HowHBGaryUses GreyBox

Page 39: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Hard Stuff

¡ Designed for expertsl Not a product!

¡ Requires reverse engineering skillsnot limited to:l Runtime debuggingl Assembly codel Protocolsl Technical knowledge of programming

bugs

Page 40: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Introducing TEMPEST

Free technology available for

download from

www.hbgary.com

Page 41: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

TEMPEST

¡ Connect the inputs with the bugs¡ Verify the exploit¡ Build a working exploit¡ Offensive stance – find working

injection vectors¡ Defines a WORKFLOW

Page 42: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Static backtrace from suspect locations

sprintf call

Blocks of code thatlead to sprintf

Page 43: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

‘Self Learning Coverage’

¡ We start with user-supplied data¡ We can detect when decisions are

calculated from user input¡ We can freeze and restore the

program at any point and test newvalues

¡ Thus, we can map how user-controlled values influence statetransitions

Page 44: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Location Coverage

¡ As program is used, if a code blockis visited it will be highlighted‘grey’*

Code

Block

Breakpoint

Page 45: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Process Snapshots

0x00000000

0xFFFFFFFF

VirtualQueryEx

MEM_COMMIT&&NOT PAGE_READONLY&&NOT PAGE_EXECUTE_READ&&NOT PAGE_GUARD&&NOT PAGE_NOACCESS

Page 46: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Fly-By’s & Drill Downs

¡ If we hit code blocks ‘above’ asuspect location we are alerted topotential operations that will causethe target to be exercised

¡ Coverage helps us tune our inputdata to drill down to a targetlocationl This is the fundamental advantage

Page 47: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Tracing

SelectedCode Block

The code blockexits to all thesepoints

Page 48: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Trillian IRC DLL

Signed/Unsignedmismatch insubroutineat 0x1000FE40

Page 49: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Boron Tagging

¡ Traces from known points¡ Breakpoints on suspect calls¡ Can be used as a strategy to skip

large sections of the graphl These become ‘clusters’l We cannot create a spanning tree

graph unless everything is connected

Page 50: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Leap Frogging

recv( … )Change page protectionin order to track access

mov edx, [esi]

lea edx,[esi]

mov [ecx], eax

Page 51: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Leapfrog with Boron

¡ Read memory to find all boronstrings

¡ Set memory breakpoints on allthese locations

¡ Locations are typically re-used¡ Doesn’t always work because

memory is cleared after use

Page 52: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Data Flow Analysis

EAXEDI

HEAP

STACK

HEAP

STACK

Page 53: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Registers

Heap orstack

Write

Read

Page 54: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Graphing Problems

¡ Graph complexity increases with thenumber of back traces

¡ Using tempest on more than a fewtarget points at a time results in ahuge, unwieldy graph

Page 55: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Advanced Graphing

¡ Different graphing algorithms canbe used

¡ Hyperbolic graphs serve better forbrowsing a large number of nodes

Page 56: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

All code paths leading to sprintf call in commercial FTP server,information obtained statically

Page 57: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

WALRUS

www.caida.org

Page 58: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Filtering the set

¡ Don’t worry about sprintf if theformat string doesn’t contain %s

¡ Don’t worry about off by ones if thesize parameter is less than thestack correction

¡ Don’t worry about anything if thesource data is not obtained fromoutside the function

Page 59: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

ID locationsusing static

analysis

Backtrace frompotentially vulnerableAPI call or location

Static traces

Page 60: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

ID locationsusing static

analysis Static traces

FUZZ

Locations whichare visited aretagged grey

Page 61: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

This is a HIT

- This causesa work item tobe exercised.

Page 62: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Is user-supplied data used in the suspect call?

Page 63: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

ID locationsusing static

analysis Static traces

FUZZ

Faults?

Page 64: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Faults?

UnresolvedBranches?

Use Data FlowAnalysis todetermine if

branch iscalculated fromuser-controlled

data

Incompletebranchcoverage

Modify inputfuzzer to

compensate

Page 65: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

This location is the nearest fly-by. Tosolve the problem we must visit thislocation and determine what data is beingused to make the branching decision.

In most cases, the value is not directlycontrolled by the fuzzer. This means thatwe must trace back further to determine ifthe value is calculated from user input.This is both tedious and time consuming.

wsprintf that uses%s **

** this graph generated from commercial proxy server (vendor not revealed)

Page 66: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Conclusion

¡ There exists a process to connectuser-input to potentialvulnerabilities

¡ By tracing data and control flow atruntime, a fuzzer can be tuned totarget a location

¡ Only a certain percentage of thosebugs identified statically will beexploitable

Page 67: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Closing Remarks

BugScan is a commercial productthat can be obtained from

www.hbgary.com

Spike is free and can be obtainedfrom

www.immunitysec.com

Page 68: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Closing Remarks

¡ The Tempest debugging system isused internally by HBGary and isnot a commerical product

¡ Many components of the tempestsystem are open source and can beobtained for study

www.hbgary.com

Page 69: The ÔGreyBoxÕ process for Exploiting Software · GreyBox: Combining both static analysis and runtime fault injection to maximize coverage of a software programsÕ state-space. Typically

Thank You

Greg HoglundHBGary, LLC.

[email protected]