Modern Netlist Reversing Towards a Hardware Decompiler Dr

  • Slides: 44
Download presentation
Modern Netlist Reversing Towards a Hardware Decompiler Dr. Andrew Zonenberg (@azonenberg) Senior Security Consultant,

Modern Netlist Reversing Towards a Hardware Decompiler Dr. Andrew Zonenberg (@azonenberg) Senior Security Consultant, IOActive Robert Ou (@rqou_) Graduate Student, University of California at Berkeley IOActive, Inc. Copyright © 2017. All Rights Reserved.

About Me • Ph. D Computer Science (RPI) • FPGA dev and IC RE

About Me • Ph. D Computer Science (RPI) • FPGA dev and IC RE since 2010 • Created and taught first full course on semiconductor reverse engineering ever offered by a university • Embedded pentesting at IOActive since 2015 IOActive, Inc. Copyright © 2017. All Rights Reserved.

The Vision IOActive, Inc. Copyright © 2017. All Rights Reserved.

The Vision IOActive, Inc. Copyright © 2017. All Rights Reserved.

The Vision • We want IDA Pro for silicon! • The state of the

The Vision • We want IDA Pro for silicon! • The state of the art in HW RE is decades behind SW – – “Disassemblers” are rare “Decompilers” are unheard of Some cool academic papers / commercial in-house tools Almost no publicly available tooling IOActive, Inc. Copyright © 2017. All Rights Reserved.

How to Do It • One de-synthesizer per architecture doesn’t scale • Use an

How to Do It • One de-synthesizer per architecture doesn’t scale • Use an IR-based flow Arch 1 Untechmap IR Arch 2 Arch N IOActive, Inc. Copyright © 2017. All Rights Reserved. Behavioral Verilog Feature Extraction

Initial Target Architectures • One product term CPLD and one LUT based FPGA –

Initial Target Architectures • One product term CPLD and one LUT based FPGA – Xilinx Cool. Runner-II – Silego Green. PAK 4 • Small devices, easy to test • Known bitstream structures – We reversed CR-II (fully, since my REcon ‘ 15 talk) – Green. PAK is documented by vendor • (partially) supported by open toolchains IOActive, Inc. Copyright © 2017. All Rights Reserved.

ASICs • • • We eventually want to be able to RE arbitrary silicon

ASICs • • • We eventually want to be able to RE arbitrary silicon Some research at IOA is going in this direction Nothing worth showing off yet Lots of fun linear algebra etc … but FPGAs let us skip that! IOActive, Inc. Copyright © 2017. All Rights Reserved.

ASIC front end (wishlist only ) IOActive, Inc. Copyright © 2017. All Rights Reserved.

ASIC front end (wishlist only ) IOActive, Inc. Copyright © 2017. All Rights Reserved.

ASIC front end (by hand) IOActive, Inc. Copyright © 2017. All Rights Reserved.

ASIC front end (by hand) IOActive, Inc. Copyright © 2017. All Rights Reserved.

Silego Green. PAK 4 (SLG 46620) • Tiny mixed signal FPGA • FPGA fabric:

Silego Green. PAK 4 (SLG 46620) • Tiny mixed signal FPGA • FPGA fabric: 26 variable-sized LUTs, 12 FFs • Oscillators • Analog hard IP: Comparators (w/ vref), ADC, DAC • Digital hard IP: counters, sh. regs, compare/PWM IOActive, Inc. Copyright © 2017. All Rights Reserved.

Silego Green. PAK 4 front end (beta) IOActive, Inc. Copyright © 2017. All Rights

Silego Green. PAK 4 front end (beta) IOActive, Inc. Copyright © 2017. All Rights Reserved.

Xilinx Cool. Runner-II (XC 2 C 32 A) • Straightforward PLA-based CPLD • 2

Xilinx Cool. Runner-II (XC 2 C 32 A) • Straightforward PLA-based CPLD • 2 function blocks, each with: – – 16 GPIOs 16 macrocells w/ XOR, FF 80 x 56 AND array 56 x 16 OR array • Global clock/reset trees • One extra input IOActive, Inc. Copyright © 2017. All Rights Reserved.

Xilinx Cool. Runner-II front end (alpha) IOActive, Inc. Copyright © 2017. All Rights Reserved.

Xilinx Cool. Runner-II front end (alpha) IOActive, Inc. Copyright © 2017. All Rights Reserved.

Lattice 40 (ice 40 lp 1 k) • • • On die OTP 16

Lattice 40 (ice 40 lp 1 k) • • • On die OTP 16 x 10 tiles of 8 LUT 4 s 4 Kb block RAMs PLLs Supported by open Ice. Storm toolchain IOActive, Inc. Copyright © 2017. All Rights Reserved.

Lattice 40 front end (alpha) • • Use icebox_vlog. py to convert to low

Lattice 40 front end (alpha) • • Use icebox_vlog. py to convert to low level Verilog Read generated Verilog and untechmap Not primary development focus for now As we scale to larger devices, will get more testing IOActive, Inc. Copyright © 2017. All Rights Reserved.

Native netlist • A sea of standard cells • No structure whatsoever • Unused

Native netlist • A sea of standard cells • No structure whatsoever • Unused FPGA cells removed IOActive, Inc. Copyright © 2017. All Rights Reserved.

Native netlist IOActive, Inc. Copyright © 2017. All Rights Reserved.

Native netlist IOActive, Inc. Copyright © 2017. All Rights Reserved.

Intermediate Representation • Replace LUTs and library cells with generic equivalents • Generic Boolean

Intermediate Representation • Replace LUTs and library cells with generic equivalents • Generic Boolean logic • Preserve analog/mixed signal IP as instances IOActive, Inc. Copyright © 2017. All Rights Reserved.

Intermediate Representation IOActive, Inc. Copyright © 2017. All Rights Reserved.

Intermediate Representation IOActive, Inc. Copyright © 2017. All Rights Reserved.

De-synthesis • Find isomorphisms in IR netlist • Replace them with more abstract equivalents

De-synthesis • Find isomorphisms in IR netlist • Replace them with more abstract equivalents • Use existing coarse-grained synthesis algorithms! IOActive, Inc. Copyright © 2017. All Rights Reserved.

Shift registers • Already in Yosys for coarse-grained synthesis • But works on raw

Shift registers • Already in Yosys for coarse-grained synthesis • But works on raw netlists too! • Find chains of DFF w/ same clk/reset* * DFFCE needs more work IOActive, Inc. Copyright © 2017. All Rights Reserved.

Adders • Find half/full adders and chain them • Caveat - Addition is commutative!

Adders • Find half/full adders and chain them • Caveat - Addition is commutative! (see pin 7) IOActive, Inc. Copyright © 2017. All Rights Reserved.

Multi-bit gates • Combine chains of 2 -input gates into larger gates • Yosys

Multi-bit gates • Combine chains of 2 -input gates into larger gates • Yosys considers these reductions of a single vector • Wide gates = comparators etc IOActive, Inc. Copyright © 2017. All Rights Reserved.

Toggle flipflops • DFF + XOR = TFF • Extracting these makes other structures

Toggle flipflops • DFF + XOR = TFF • Extracting these makes other structures easier to find IOActive, Inc. Copyright © 2017. All Rights Reserved.

TFF-Based Counters • Chained TFFs = binary counter IOActive, Inc. Copyright © 2017. All

TFF-Based Counters • Chained TFFs = binary counter IOActive, Inc. Copyright © 2017. All Rights Reserved.

TFF-Based Counters • Current pass always produces POUT • Comparator not yet absorbed into

TFF-Based Counters • Current pass always produces POUT • Comparator not yet absorbed into OUT port IOActive, Inc. Copyright © 2017. All Rights Reserved.

TFF-Based Counters • Non power-of-two needs more work IOActive, Inc. Copyright © 2017. All

TFF-Based Counters • Non power-of-two needs more work IOActive, Inc. Copyright © 2017. All Rights Reserved.

Bus detection • Some blocks have inherent ordering on outputs • Infer multi-bit buses

Bus detection • Some blocks have inherent ordering on outputs • Infer multi-bit buses from these • Heuristic: if one input to block is a bus, so is the other IOActive, Inc. Copyright © 2017. All Rights Reserved.

Bus detection IOActive, Inc. Copyright © 2017. All Rights Reserved.

Bus detection IOActive, Inc. Copyright © 2017. All Rights Reserved.

De. Morgan for reductions • If &() or |() has lots of inverted inputs,

De. Morgan for reductions • If &() or |() has lots of inverted inputs, push the inverter • This optimization is useful for synthesis too! IOActive, Inc. Copyright © 2017. All Rights Reserved.

How about some less trivial tests? • Feature extraction works decently on larger designs

How about some less trivial tests? • Feature extraction works decently on larger designs • We’re still working on visualizations • Current renderer (Yosys “show” -> xdot) scales poorly – – Long run time to place graph elements Non-interactive, can’t move nodes or rename them Doesn’t show parameters or attributes well Very poor handling of high fanout nets IOActive, Inc. Copyright © 2017. All Rights Reserved.

LED chaser (GP 4) IOActive, Inc. Copyright © 2017. All Rights Reserved.

LED chaser (GP 4) IOActive, Inc. Copyright © 2017. All Rights Reserved.

LED chaser (GP 4) IOActive, Inc. Copyright © 2017. All Rights Reserved.

LED chaser (GP 4) IOActive, Inc. Copyright © 2017. All Rights Reserved.

10 base. T autonegotiation (GP 4) IOActive, Inc. Copyright © 2017. All Rights Reserved.

10 base. T autonegotiation (GP 4) IOActive, Inc. Copyright © 2017. All Rights Reserved.

8 N 1 UART TX (ice 40) IOActive, Inc. Copyright © 2017. All Rights

8 N 1 UART TX (ice 40) IOActive, Inc. Copyright © 2017. All Rights Reserved.

Original UART (TX+RX) pre-techmap • Clearly we have a ways to go! IOActive, Inc.

Original UART (TX+RX) pre-techmap • Clearly we have a ways to go! IOActive, Inc. Copyright © 2017. All Rights Reserved.

Graphviz doesn’t handle clocks well IOActive, Inc. Copyright © 2017. All Rights Reserved.

Graphviz doesn’t handle clocks well IOActive, Inc. Copyright © 2017. All Rights Reserved.

Like Pulling Bitstreams • Firmware update files (if cleartext) • If encrypted, DPA usually

Like Pulling Bitstreams • Firmware update files (if cleartext) • If encrypted, DPA usually works – “Improved Side-Channel Analysis Attacks on Xilinx Bitstream Encryption of 5, 6, and 7 Series”, COSADE ‘ 16 • Hardware defeats of lock bits (if on chip) • Conjecture: Reading antifuses by FIB VC + CV? IOActive, Inc. Copyright © 2017. All Rights Reserved.

Longer Term Roadmap • Add an interactive GUI • Support for extracting hierarchy and

Longer Term Roadmap • Add an interactive GUI • Support for extracting hierarchy and processes – Most likely human-guided w/ automated implementation – Draw approximate hierarchy and use min-cut? • Support for more FPGA/CPLD devices • Implement ASIC front end • More advanced analytics IOActive, Inc. Copyright © 2017. All Rights Reserved.

Longer Term Roadmap • Traceability back to physical layout (for invasive) • Physical IP

Longer Term Roadmap • Traceability back to physical layout (for invasive) • Physical IP recognition for ASIC – Find known SRAM, efuse, PLLs, etc – Ideally: ML classifier for unknown physical IP? • “FLIRT” for IP cores – NP-complete in general case – Can we use randomization, spatial partitioning, etc? – Won’t find everything, but is it good enough? IOActive, Inc. Copyright © 2017. All Rights Reserved.

Get The Code • https: //github. com/azonenberg/yosys/ My fork of Yosys with additional RE-focused

Get The Code • https: //github. com/azonenberg/yosys/ My fork of Yosys with additional RE-focused passes ISC license • https: //github. com/azonenberg/openfpga Bitstream support / PAR for Cool. Runner + Green. PAK LGPL IOActive, Inc. Copyright © 2017. All Rights Reserved.

Acknowledgements • John Mc. Master – wet lab for XC 2 C samples •

Acknowledgements • John Mc. Master – wet lab for XC 2 C samples • Clifford Wolf – lots of new Yosys features IOActive, Inc. Copyright © 2017. All Rights Reserved.

Fun with XC 2 C 32 A “suicide bitstream” IOActive, Inc. Copyright © 2017.

Fun with XC 2 C 32 A “suicide bitstream” IOActive, Inc. Copyright © 2017. All Rights Reserved.

Questions? IOActive, Inc. Copyright © 2017. All Rights Reserved.

Questions? IOActive, Inc. Copyright © 2017. All Rights Reserved.