nedospasov defcon russia 23

18
FPGA для анализа хардвара DEFCON RUSSIA DCG#7812 Дмитрий Недоспасов <[email protected]>

Upload: defconrussia

Post on 06-Aug-2015

181 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Nedospasov defcon russia 23

FPGA для анализа хардвара DEFCON RUSSIA DCG#7812

Дмитрий Недоспасов <[email protected]>

Page 2: Nedospasov defcon russia 23

Кратко обо мне…• Закончил аспирантуру в TU Berlin, тема новые виды анализа чипов

• Работаю совместно с Olivier THOMAS и Texplained SARL во Фрации

• Еще работаю как фрилансер и тренер “IC RE 101” и “Keep it Synple Stupid”

• Преподаю “Hardware Security” в TU Berlin

• Буду в конце года делать стартап под более совершенствуемого конкурента Yubikey

• Twitter: @nedos

• Email: [email protected]

Page 3: Nedospasov defcon russia 23

WTFPGA?• Программируемая пользователем вентильная матрица

• Не программируют в “классическом” смысле

• Вместо этого реализуется логическая схема

• Это не замена софту и микроконтроллерам но имеет некие преимущества

Page 4: Nedospasov defcon russia 23

Hardware Basics

Logic Gates

4

IC SECURITY 101TEXPLAINED NON-CONFIDENTIALPAGE 20

ASSIGNMENT 2.3

Half Adder A B SUM CARRY0 0 0 00 1 1 01 0 1 01 1 0 1

Full Adder A B C_IN SUM C_OUT0 0 0 0 00 1 0 1 01 0 0 1 01 1 0 0 10 0 1 1 00 1 1 0 11 0 1 0 11 1 1 1 1

NORA B Y0 0 10 1 01 0 01 1 0

NANDA B Y0 0 10 1 11 0 11 1 0

ANDA B Y0 0 00 1 01 0 01 1 1

XORA B Y0 0 00 1 11 0 11 1 0

ORA B Y0 0 00 1 11 0 11 1 1

NOTA Y0 11 0

Page 5: Nedospasov defcon russia 23

Hardware Basics

Karnaugh Map for Combinational Logic

๏ Boolean results are transferred from a truth table not Karnaugh map

๏ Writing minimal boolean expressions

5

Figure Source: Wikipedia

Page 6: Nedospasov defcon russia 23

Hardware Basics

Logic Synthesis by Karnaugh Map

6Figure Source: Wikipedia

Page 7: Nedospasov defcon russia 23

Place & RouteSynthesis

22 www.xilinx.com Synthesis and Simulation Design Guide10.1

Chapter 2: FPGA Design FlowR

Design Flow DiagramFigure 2-1, “Design Flow Overview Diagram,” shows an overview of the design flow steps.

Figure 2-1: Design Flow Overview Diagram

X10303

Entering your Designand Selecting Hierarchy

Functional Simulationof your Design

Synthesizing and Optimizingyour Design

Adding DesignConstraints

Evaluating your Design Sizeand Performance

Placing and Routingyour Design

Downloading to the Device,In-System Debugging

Generating a Bitstream

Creating a PROM, ACEor JTAG File

Evaluating your Design's Coding Styleand System Features

Timing Simulationof your Design

Static TimingAnalysis

Дизайн

Simulation

Page 8: Nedospasov defcon russia 23

Hardware Description Languages• Я для начинающих настоятельно рекомендую Verilog

• Verilog очень часто используется и поддерживается как промежуточный формат между различными тулз

• Главное, что надо помнить когда читаешь HDL, что блок синтезируется как логическая цепочка из вентилей и выполняется постоянно!

• В императивном программирование каждая строка кода выполняется одна за другой, а в синтезе HDL все выполняются одновременно.

• Чаще всего используется стиль с blocking assignemnts (<=), а это означает что последнее присвоение это то значение которая будет в регистре при следующем цикле

module  counter  (     input  wire  clk,     input  wire  rst,     input  wire  enable,     output  reg  [31:0]  count  );  

always  @(posedge  clk)  begin     if  (  rst  )     begin       count    <=  32'b0;     end     else     begin       count  <=  count;       if  (  enable  )       begin         count    <=  count  +  1'b1;       end     end  end  

endmodule

Page 9: Nedospasov defcon russia 23

Конечный Автомат

Utilizing Programmable Logic

UART START

UART DATA

UART STOP

UART IDLE

Default assignmentsetu cnt <= (etu cnt + 1);

dout <= dout;

rdy <= rdy;

data <= data;

state <= state;

bit cnt <= bit cnt;

en

etu cnt <= 9’d0;

bit cnt <= 3’d0;

rdy <= 1’b0;

dout <= 1’b0;

data <= data out;

state <= ‘UART DATA;

etu full

etu cnt <= 9’d0;

bit cnt <= (bit cnt + 1);

dout <= data[0];

data <= {data[0], data[7:1]};

bit cnt == 3’d7

state <= ‘UART STOP;

etu full

etu cnt <= 9’d0;

dout <= 1’b1;

state <= ‘UART IDLE;

etu full

rdy <= 1’b1;

state <= ‘UART START;

Figure 7: UART transmitter state machine.

• С помощью always @ (posedge clk) и блокирующего присвоения (<=) синтезируется секвенциальная логика

• С помощью assign и не блокирующего присвоения синтезируется комбинационная логика

• Синтез комбинационной логики одно из мощнещих преимуществ HDL-а так как комбинационная логика реагирует моментально на сигнал

• Например можно выделить предикаты в логике: assign etu_full = (etu_cnt == `UART_FULL_ETU);

Page 10: Nedospasov defcon russia 23

Задания

Papilio Pro (Xilinx Spartan 6) LPC1343 ARM Cortex M3

Page 11: Nedospasov defcon russia 23

MITM

• Платы реализовывают перекресток. Светофоры посылают что они переключись на красный свет.

Page 12: Nedospasov defcon russia 23

MITM: DoS

assign tx1 = enable ? rx1 : 1’b1;

assign tx2 = enable ? rx2 : 1’b1;

Page 13: Nedospasov defcon russia 23

MITM: DoS

Utilizing Programmable Logic

Exercise 2.2: UART Transmiter

S

0 1 2 3 4 5 6 7

S

d[0] d[1] d[2] d[3] d[4] d[5] d[6] d[7]

Figure 5: UART timing diagram.

In this exercise will we will create a module capable of transmitting bytes of data using the UARTserial protocol. UART is one of the simplest serial protocols and is commonly used for debugging andcommunication between di↵erent ICs on a PCB. UART is identical to RS-232 except for the voltageleves used the signaling. The speed of the serial communications, i.e. the baud rate or the frequencyof each character, is predetermined. Generally in UART implementations, the line is held high whilethe protocol is in the idle state. To signal the start of a transfer a start character is transmited duringwhich the signal is held low, i.e. a logical 0. Next 5 - 8 data bits are transmited: a high signal statecorresponds to a logical 1, a low signal state corresponds to a logical 0. This may be followed by aparity bit, depending on the configuration. At the end of the transmission one or two stop characters

are transmitted.

uart tx

SysClk clk

SysRst rst

en en

data out[7:0] data out[7:0]8

doutdout

rdyrdy

Figure 6: module uart tx

Questions:

Q1: Assume we have 100MHz system clock. For a 9600 baud UART what is the delay in clock cyclesbetween charcters?

Q2: Consider the signals necessary for a UART transmitter, see Figure 6. Why is the rdy signalnecessary?

Q3: Draw a UART transmitter state machine in Figure 7.

Utilizing Programmable Logic

Exercise 2.2: UART Transmiter

S

0 1 2 3 4 5 6 7

S

d[0] d[1] d[2] d[3] d[4] d[5] d[6] d[7]

Figure 5: UART timing diagram.

In this exercise will we will create a module capable of transmitting bytes of data using the UARTserial protocol. UART is one of the simplest serial protocols and is commonly used for debugging andcommunication between di↵erent ICs on a PCB. UART is identical to RS-232 except for the voltageleves used the signaling. The speed of the serial communications, i.e. the baud rate or the frequencyof each character, is predetermined. Generally in UART implementations, the line is held high whilethe protocol is in the idle state. To signal the start of a transfer a start character is transmited duringwhich the signal is held low, i.e. a logical 0. Next 5 - 8 data bits are transmited: a high signal statecorresponds to a logical 1, a low signal state corresponds to a logical 0. This may be followed by aparity bit, depending on the configuration. At the end of the transmission one or two stop characters

are transmitted.

uart tx

SysClk clk

SysRst rst

en en

data out[7:0] data out[7:0]8

doutdout

rdyrdy

Figure 6: module uart tx

Questions:

Q1: Assume we have 100MHz system clock. For a 9600 baud UART what is the delay in clock cyclesbetween charcters?

Q2: Consider the signals necessary for a UART transmitter, see Figure 6. Why is the rdy signalnecessary?

Q3: Draw a UART transmitter state machine in Figure 7.

Page 14: Nedospasov defcon russia 23

PIN

• Через UART вводится PIN

• При не правильном вводи PIN-а диоды на плате начинают мигать

• Диоды мигают 5 секунд

• Надо убрать эту задержку

Page 15: Nedospasov defcon russia 23

PIN

assign reset = led_in;

Page 16: Nedospasov defcon russia 23

Тайминг пароля

• В embedded системах навсегда есть strcmp

• Часто разработчики пишут свой strcmp особенно если пароль определенной длины

• Пароль проверяется по одной букве

Page 17: Nedospasov defcon russia 23

Тайминг пароля

“Password12345678”

“Password12345678”

“Password Incorrect”

cycles = 832

Page 18: Nedospasov defcon russia 23

Спасибо за внимание

• Точно будет этот тренинг на REC0N и Toorcon

• Скорее всего мы его с 0x90 постараемся сделать на ЗН

• Очень хочу в какой-то момент под него сделать Kickstarter

• Могу сделать он-сайт: Dmitry Nedospasov <[email protected]>