Control Flow Deobfuscation via Abstract Interpretation © Rolf Rolles, 2010.

Slides:



Advertisements
Similar presentations
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 2: Data types and addressing modes dr.ir. A.C. Verschueren.
Advertisements

Machine Instructions Operations 1 ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-1.ppt Modification date: March 18, 2015.
NEG Instruction Change operand content into two’s complement (negative value) and stored back into its operand mov bl, b neg bl; bl = mov.
Octavian Cret, Kalman Pusztai Cristian Vancea, Balint Szente Technical University of Cluj-Napoca, Romania CREC: A Novel Reconfigurable Computing Design.
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Computer Organization & Assembly Language
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 5 Arithmetic and Logic Instructions.
9-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
Shift and Rotate Instructions
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 6: Logic/Shift Instructions Partially adapted from Computer Organization and Design, 4.
Bit Operations C is well suited to system programming because it contains operators that can manipulate data at the bit level –Example: The Internet requires.
Binary Operations Math/Logical. Binary Math Decimal Addition Example ) Add = 15 Write down 5, carry ) Add 3 +
1 Arithmetic and Logical Operations - Part II. Unsigned Numbers Addition in unsigned numbers is the same regardless of the base. Given a pair of bit sequences.
1 Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers Binary numbers (base 2)
Ch. 7 Logic, Shift and Rotate instr.
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
Lecture 11 Last notes on interrupts and exam review Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
Machine Instruction Characteristics
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Low Level Programming Lecturer: Duncan Smeed Low Level Program Control Structures.
Chapter 8 Problems Prof. Sin-Min Lee Department of Mathematics and Computer Science.
Multiplication of signed-operands
Bits and Bytes. BITWISE OPERATORS Recall boolean logical operators in Java… boolean logical operators: &, |, ^ not: ! Show truth tables.
ICS312 Set 9 Logic & Shift Instructions. Logic & Shift Instructions Logic and Shift Instructions can be used to change the bit values in an operand. The.
Dr. José M. Reyes Álamo 1.  Review: ◦ Statement Labels ◦ Unconditional Jumps ◦ Conditional Jumps.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Execution of an instruction
Module : Algorithmic state machines. Machine language Machine language is built up from discrete statements or instructions. On the processing architecture,
Arithmetic Flags and Instructions
Fixed & Floating Number Format Dr. Hugh Blanton ENTC 4337/5337.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
1 Arithmetic and Logic Operations Patt and Patel Ch. 2 & 3.
N, Z, C, V in CPSR with Adder & Subtractor Prof. Taeweon Suh Computer Science Education Korea University.
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Assembly 05. Outline Bit mapping Boolean logic (review) Bitwise logic Bit masking Bit shifting Lookup table 1.
Appendix C Basics of Digital Logic Part I. Florida A & M University - Department of Computer and Information Sciences Modern Computer Digital electronics.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Logical and Bit Operations Chapter 9 S. Dandamudi.
EEL 3801 Part V Conditional Processing. This section explains how to implement conditional processing in Assembly Language for the 8086/8088 processors.
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
Chapter 7 Bit Manipulation. 7.1 Logical Operations.
LECTURE 4 Logic Design. LOGIC DESIGN We already know that the language of the machine is binary – that is, sequences of 1’s and 0’s. But why is this?
Microprocessor & Assembly Language Arithmetic and logical Instructions.
Integer Operations Computer Organization and Assembly Language: Module 5.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Microprocessor & Assembly Language
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Bitwise and Logical Manipulations Assembly Language Programming University of Akron Dr. Tim Margush.
Windows Programming Lecture 06. Data Types Classification Data types are classified in two categories that is, – those data types which stores decimal.
I NTEL 8086 M icroprocessor بسم الله الرحمن الرحيم 1.
Data Transfers, Addressing, and Arithmetic
Homework Reading Labs PAL, pp
Microprocessor Systems Design I
Chapter 3 Bit Operations
EE3541 Introduction to Microprocessors
Instruction System - Bit Manipulation Instruction
INSTRUCTION SET.
Assembly Language Programming Part 2
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
Arithmetic Logical Unit
Shift & Rotate Instructions)
Homework Reading Machine Projects Labs PAL, pp
Shift & Rotate Instructions)
Chapter 5 Arithmetic and Logic Instructions
Microprocessor and Assembly Language
Computer Organization and Assembly Language
Shift and Rotate Instructions.
CS-401 Computer Architecture & Assembly Language Programming
Presentation transcript:

Control Flow Deobfuscation via Abstract Interpretation © Rolf Rolles, 2010

Obfuscated Target Example 1-3: Manipulations to ss are anti-debugging 4-5: edx = flags 6: Mask off everything but TF 7-8: Shift TF into ZF position 9: Push flags again 10: Mask off ZF from #9 11: OR flags with the TF in the ZF position 12: Restore flags 13: JZ false_branch (if TF was set) Jump is taken if the code is being traced, not taken if the code is not being traced.

Obfuscated Control Flow Graph Left-hand side: a control flow graph with obfuscation Right-hand side: deobfuscated control flow graph

What does “breaking” this construct mean? 1.Determining in which direction each TF- based jump goes. 2.Feeding that information into a higher-level analysis, e.g. a disassembler with a graphing component, to automatically prune the half- dead branches and the relevant dead code. We focus on #1.

A Syntactic Pattern for this Construct 1) Through observation of the binary, the construct always begins with manipulations to ss 2) This is immediately followed by a pushf 3) There are various manipulations to the flags register (bitwise and linear arithmetic), perhaps across multiple registers 4) A conditional jump

Syntactic Patterns in General They suck: in AV, in IDS, and in anything you could think of calling principled computer security I don’t care what it looks like, I care what it does: how can we describe anti-tracing checks at their most base level, with no reference to how it is actually accomplished?

A Very Generic Semantic Pattern A bit in a quantity (e.g., the TF bit resulting from a pushf) is declared to be a constant (e.g., zero), and then this bit is used in further manipulations of that quantity. – Reminiscent of the constant propagation problem, except on the bit-level

Problem: Unknown Bits Supposing that only certain bits are known to be constant, how do we handle the non- constant ones? What happens when we and, or, xor, inc, dec, neg, not, shl, shr, sar, ror, rol, rcr, rcl, mul, imul, div, and/or idiv quantities that contain non- constant bits?

Solution: Fantasyland Let’s pretend that bits have three values instead of two: – Zero – One – Maybe/Half Model registers (and memory) as (arrays of) three-valued bitvectors. How does this affect the bitwise/integer operations available within the language?

Bitwise Operations: XOR, AND, OR, NOT These operators work exactly like you would expect. XOR0½1 00½1 ½½½½ 11½0 AND0½ ½0½½ 10½1 OR0½1 00½1 ½½½ NOT0½1 1½0

Bitwise Operations: Shifts, Rotates ½01½01½0 01½01½00 0½01½01½ ½½01½01½ A BOOL3-bitvector Bitvector << 1 Bitvector >> 1 Bitvector SAR 1 Rotate operations are decomposed into combinations of shifts and ORs, so they are covered as well.

Integer Operations: Addition How concrete addition works: At each bit position, there are 2 3 possibilities for A[i], B[i], and the carry-in bit. The result is C[i] and the carry-out bit. Carry-Out A[i] B[i] Carry-In Result

Integer Operations: Addition In abstract addition, A[i], B[i], and carry-in are BOOL3 terms, so we have 3 3 possibilities at each bit position. The derivation of the rules for bitwise abstract addition is straightforward. Notice that the system is smart enough to determine that the addition of two N-bit integers is at most N+1 bits. Carry-Out000½½½ A[i]000½½½ B[i]000½½½ Carry-In00½½½0 Result00½½½½

Integer Operations: Negation Neg(x) is equivalent to Not(x)+1. We have previously given the rules for NOT and addition, therefore we have a rule for NEG as well.

Integer Operations: Subtraction Subtraction is the same thing as addition, where the minuend is NOT-ed and the initial carry-in is set to one instead of zero. Therefore, subtraction is trivially implemented based on the algorithms we have already discussed.

Integer Operations: Unsigned Multiplication Consider B = A * 0x1230 0x1230 = = => B = A * ( ) => B = A * A * A * A * 2 4 => B = (A << 12) + (A << 9) + (A << 5) + (A << 4) Addition and shifts by constants have previously been covered

Integer Operations: Unsigned Multiplication In the abstract world, when the corresponding RHS bit is ½, we are either multiplying by 0 or 1, so we replace all 1 bits in the LHS with ½. * = + = ½½ ½ ½½ 0000½½½0 000½½½½½

Integer Operations: Signed Multiplication Similar to unsigned multiplication, with one- bit sign extensions at each intermediary step, and negation of the last partial product. Read any book on digital logic for a more thorough explanation.

Relational Operations: Equals / Not Equals Given two BOOL3 bitvectors A and B: – If both are entirely constant, perform the comparison directly. – If there exists j such that A[j] ≠ ½, B[j] ≠ ½, and A[j] ≠ B[j], then the quantities cannot be equal, so A = B is false, and A ≠ B is true. – If there are no mismatches, and there are ½ bits, then we cannot make the determination, so we return ½.

That’s It We described an abstract domain, the “bitvectors over BOOL3” domain, for quantities referenced within the language We described abstract semantics for operators defined over the abstract quantities

Deobfuscation Of This Construct Tell your program analysis framework to assume that the TF is not set during the pushf instruction Analyze the code under the assumption of the partial constantness of the EFLAGS register with respect to the TF bit Rewrite all conditional jumps that result from the value of the TF bit as unconditional jumps

Limitations Bring-your-own memory model – Current memory model is unsound but effective Transfer functions in their current formulation are not monotonic – Can only be applied locally to each basic block, instead of globally across the entire flow graph