Control Flow Integrity Recap Buffer overflow Mitigation techniques - - PowerPoint PPT Presentation

control flow integrity recap
SMART_READER_LITE
LIVE PREVIEW

Control Flow Integrity Recap Buffer overflow Mitigation techniques - - PowerPoint PPT Presentation

Control Flow Integrity Recap Buffer overflow Mitigation techniques WOX/DEP Return-to-libc RoP (Return-oriented Programming) StackGuard (insert canaries on stack) PointGuard (encrypt the pointers) ASLR CFI


slide-1
SLIDE 1

Control Flow Integrity

slide-2
SLIDE 2

Recap

  • Buffer overflow
  • Mitigation techniques

– WOX/DEP – Return-to-libc – RoP (Return-oriented Programming) – StackGuard (insert canaries on stack) – PointGuard (encrypt the pointers) – ASLR – CFI (Control-Flow Integrity)

slide-3
SLIDE 3

The Problem

  • There are vulnerabilities or flaws, which can be

found in software. An adversary exploits these flaws to get control over the program’s flow.

  • Once control over program is achieved, it is easy

to change program’s flow to a particular address where malicious code is stored.

  • Buffer overflow is an example of such attack

where return address of a procedure is

  • verwritten and program flow is switched to an

address where malicious code is present.

slide-4
SLIDE 4

Control-Flow Integrity (CFI)

Software execution must follow its execution path

slide-5
SLIDE 5

Why CFI?

  • Change in execution path of a program can be

used by an adversary to execute malicious code stored in memory (e.g., buffer overflow)

  • CFI enforces integrity of a program’s execution

flow path

  • An undefined change in the path of execution

by an adversary can be detected using CFI

  • CFI efficiently detects and mitigates buffer
  • verflow, RoP, return-to-libc attacks, etc.
slide-6
SLIDE 6
  • CFI enforcement is practical

– It is compatible with existing software – Can be done efficiently using software rewriting in commodity systems

slide-7
SLIDE 7

Control-Flow Integrity

  • It reinforces a program to follow the path of

execution defined by Control-Flow Graph

  • CFI enforcement guarantees that the program

execution path cannot be changed by the adversary and program’s flow integrity is maintained

  • CFI provides a useful foundation for enforcing

further security policies [Abadi et al]

– Protected shadow call stack – Access control of memory regions

slide-8
SLIDE 8

CFI implementation types

  • CFCSS: Control-Flow checking by Software

Signatures

  • CCFIR: Compact Control-Flow Integrity and

Randomization

  • CFLC: Control-Flow Lazily Check
  • CCFI: Cryptographically enforced CFI
  • Practical limitations: some of these do not/

cannot capture recursive function calls

slide-9
SLIDE 9

CFI through Label Checking

Swapnil Raut, MTech, IIT Bombay

slide-10
SLIDE 10

CFI through Label Checking

  • This implementation consists of label checking

and generating regular expression of a program, which actually represents the Control-Flow Graph (CFG) of that program.

– Regular expression is derived from CFG – Label check is done to identify correct destination function when the function is called by a caller – Label is a unique random number added to the start

  • f destination

– Before jumping from caller to callee, labels are checked

slide-11
SLIDE 11

Implementation Outline

  • All the strings generated from regular

expression will be considered valid paths of program execution

  • Any other execution path is considered as

invalid and error is produced

  • If labels do not match at jump, error is

produced

slide-12
SLIDE 12
slide-13
SLIDE 13

What is CFI?

❏ Control-Flow Integrity(CFI) is one the mitigation techniques against these attacks ❏ It reinforces a program to follow the path of execution defined by Control-Flow Graph(CFG) ❏ This CFI reinforcement guarantees that program execution path can not be changed by the adversary and a program flow integrity is maintained

slide-14
SLIDE 14

Stack Corruption Techniques

❏ CFI implementation can be bypassed by exploiting stack-based vulnerabilities ❏ Corrupting callee-saved registers ❏ Corrupting system call return address ❏ Disclosing the shadow stack address

slide-15
SLIDE 15

CFI Implementation Techniques

❏ Compact Control Flow Integrity and Randomization ❏ Cryptographically Enforced Control Flow Integrity ❏ Control Flow Checking by Software Signature

slide-16
SLIDE 16

CCFIR Technique

❏ It performs enforcement by redirecting control-flow transfer through new code section called "Springboard" ❏ This mitigation technique is used to secure function pointer and return address ❏ Even if adversary changes the address of target, it becomes impossible to change the execution path

slide-17
SLIDE 17

CCFIR Technique

slide-18
SLIDE 18

CCFIR Drawback

❏ It has compatibility issue ❏ Call from protected to unprotected module will fail ❏ Rewriting every module is not possible all the time

slide-19
SLIDE 19

CCFI Technique

❏ It protects function pointer and return address with the help of MAC ❏ MAC(K,pointer , class ) where K is secrete key, pointer is function pointer or return address and class is to identify whether it is function pointer or return address ❏ Whenever address is stored in memory, MAC is calculated and stored in

  • memory. During runtime MAC is recomputed and compared with stored MAC
slide-20
SLIDE 20

CCFI Drawback

❏ If adversary changes stack return address, old and new MAC will not match and it indicates error ❏ However if adversary knows old value of MAC and function pointer, control-flow will jump to adversary function

slide-21
SLIDE 21

CFISS Technique

❏ This mitigation technique uses software signature ❏ Program is divided into nodes(blocks) and all nodes are assigned random unique number ❏ signature is XOR of source and destination block and stores at compile time ❏ During runtime this signature is calculated and compared with stored signature of node

slide-22
SLIDE 22

OUR APPROACH OF CFI IMPLEMENTATION

❏ Our CFI implementation mainly includes label checking to check for correct destination and generating regular expression of program to validate path of execution ❏ During runtime complete path or history of execution is maintained ❏ Undefined change in the path of execution by adversary can be detected with the help of regular expression

slide-23
SLIDE 23

CFI Implementation

❏ Deriving Control Flow Graph(CFG) of program ❏ Label checking for CFI ❏ Deriving regular expression of CFG ❏ Checking for CFI violation

slide-24
SLIDE 24

Deriving CFG of program

❏ egypt-tool version 1.1.0 is for deriving graph from program ❏ It delegates the source code analysis to GCC ❏ Its perl script ❏ gengraph -o graph -t png main.c

slide-25
SLIDE 25

Deriving CFG of program

slide-26
SLIDE 26

Processing DOT file

digraph call graph { "main" -> "f" [ style = solid ]; "main" -> "g" [ style = solid ]; "f" -> "m" [ style = solid ]; }

slide-27
SLIDE 27

Label checking for CFI

❏ Labels are used to identify correct destination function ❏ We consider three new instructions for CFI instrumentation.

❏ Label ID ❏ Call ID DST ❏ ret ID

slide-28
SLIDE 28

Label checking for CFI

slide-29
SLIDE 29

Deriving regex of CFG

❏ Brzozowski’s algorithm is used to generate regular expression from Control Flow Graph ❏ Algorithm is divided into two parts: one is to convert CFG to Deterministic Finite Automata(DFA) and second part is to convert DFA to regular expression

slide-30
SLIDE 30

Checking for CFI violation

❏ Control Flow Integrity enforces control flow of program to follow CFG defined path ❏ CFI violation can be defined as undefined change in the control-flow of execution or calling a function which is not a part of program ❏ Execution path which is not a part of regular expression is consider as invalid path of control flow. ❏ We have used Regular expression to detect CFI violation

slide-31
SLIDE 31

Checking for CFI violation

Function call jump CFI violation Function return jump CFI violation

slide-32
SLIDE 32

Future Work

❏ We will analyse the performance of our CFI implementation. Performance analysis is the key factor of any CFI implementation ❏ We will check our system with various attacks. Strength of CFI technique is depend on how well it tackles the attacks ❏ We have seen various CFI Implementation techniques. We will try to integrate

  • ur approach of CFI with CCFIR CFI Implementation technique in order

Strengthen it

slide-33
SLIDE 33

Assumptions

  • Unique IDs: ID conflict may create problem while

label checking therefore IDs used in CFI must be unique.

  • Non writable code: If code memory is writable,

CFI implementation code can be corrupted therefore Code memory must not be writable.

  • Non executable DATA: If data section is

executable, the adversary can add executable malicious code to data section.

slide-34
SLIDE 34

Concept

  • We consider three new instruction for CFI

instrumentation . 1) Label ID 2) call ID DST 3)ret ID

  • call ID DST calls Destination which has Label ID at

start of it’s code. ret ID is used to return to caller

slide-35
SLIDE 35

CFG and CFI Instrumentation

  • CFG in which dash lines represent direct call,

solid lines represent call from source instruction, and dotted lines represent return to caller.

  • Destinations are belong to equivalent class if

they have edge from same source. we assign unique label to each equivalent class of destination

slide-36
SLIDE 36

CFG and CFI Instrumentation

slide-37
SLIDE 37

CFG and CFI Instrumentation

  • Label 10, 20, and 30 are assigned to

procedure1(), procedure2(), and procedure3() respectively.

  • When call 30 R is executed, Label at

destination that is 30 and Label present in call instruction is compared. If comparison fails, it indicates cfi-failure

slide-38
SLIDE 38

CFI Instrumentation

slide-39
SLIDE 39

CFI Instrumentation

  • At source, ecx register contains destination

address.

  • Destination ID data is retrieved from ecx and

compared with Source ID data.

  • Jump instruction is executed only if both ID

data are matched

slide-40
SLIDE 40

CFI Instrumentation

slide-41
SLIDE 41

CFI AND STACK CORRUPTION TECHNIQUES

  • Corrupting Callee-Saved Registers
  • Corrupting System call Return Address
  • Disclosing the Shadow stack Address
slide-42
SLIDE 42

References & Reading

  • Stack smashing

http://insecure.org/stf/smashstack.html

  • return-to-libc

http://www.cis.syr.edu/~wedu/seed/Labs/Vulnerability/Return_to_libc/Return_to_libc.pdf http://blog.fkraiem.org/2013/10/26/return-to-libc/ http://cseweb.ucsd.edu/~hovav/papers/s07.html

  • ROP (return oriented programming)

https://www.blackhat.com/presentations/bh-usa- 08/Shacham/BH_US_08_Shacham_Return_Oriented_Programming.pdf https://cseweb.ucsd.edu/~hovav/dist/rop.pdf http://www.scs.stanford.edu/brop/

  • https://www.microsoft.com/en-us/research/publication/control-flow-integrity/
  • Using Control-Flow Techniques in a Security Context: A Survey on Common Prototypes and their

Common Weakness http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=5948809&tag=1