Application Security Tom Chothia Computer Security, Lecture 14.

Slides:



Advertisements
Similar presentations
Practical Malware Analysis
Advertisements

Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
Introduction.  Professor  Adam Porter 
Code Composer Department of Electrical and Computer Engineering
Computer Security: Principles and Practice EECS710: Information Security Professor Hossein Saiedian Fall 2014 Chapter 10: Buffer Overflow.
Dec 5, 2007University of Virginia1 Efficient Dynamic Tainting using Multiple Cores Yan Huang University of Virginia Dec
RIVERSIDE RESEARCH INSTITUTE Helikaon Linux Debugger: A Stealthy Custom Debugger For Linux Jason Raber, Team Lead - Reverse Engineer.
1BA3 G Lacey Lecture 51 Evaluating mathematical expressions  How do computers evaluate x + y or any mathematical expression ?  Answer : “Reverse Polish.
CS266 Software Reverse Engineering (SRE) Applying Anti-Reversing Techniques to Java Bytecode Teodoro (Ted) Cipresso,
1 CHAPTER 8 BUFFER OVERFLOW. 2 Introduction One of the more advanced attack techniques is the buffer overflow attack Buffer Overflows occurs when software.
Lab 9 Java Bytecode & The Jasmin Assembler
JETT 2003 Java.compareTo(C++). JAVA Java Platform consists of 4 parts: –Java Language –Java API –Java class format –Java Virtual Machine.
Introduction to Computer Programming CSC 1401: Introduction to Programming with Java Lecture 2 Wanda M. Kunkle.
Chapter 4 H1 Assembly Language: Part 2. Direct instruction Contains the absolute address of the memory location it accesses. ld instruction:
Consider With x = 10 we may proceed as (10-1) = 9 (10-7) = 3 (9*3) = 27 (10-11) = -1 27/(-1) = -27 Writing intermediates on paper.
Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
Memory & Storage Architecture Seoul National University Computer Architecture “ Bomb Lab Hints” 2nd semester, 2014 Modified version : The original.
OllyDbg Debuger.
CS 0008 Day 2 1. Today Hardware and Software How computers store data How a program works Operators, types, input Print function Running the debugger.
Code Generation Introduction. Compiler (scalac, gcc) Compiler (scalac, gcc) machine code (e.g. x86, arm, JVM) efficient to execute i=0 while (i < 10)
Code Injection and Software Cracking’s Effect on Network Security Group 5 Jason Fritts Utsav Kanani Zener Bayudan ECE 4112 Fall 2007.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 18: 0xCAFEBABE (Java Byte Codes)
Compiler Construction Lecture 17 Mapping Variables to Memory.
CSC 8505 Compiler Construction IR Example: Java Bytecode (looking inside class files)
Introduction to InfoSec – Recitation 2 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
CSCI 273: Processing An Introduction. Programming Languages –An abstract "human understandable" language for telling the computer what to do –The abstract.
Krakatoa: Decompilation in Java “Does Bytecode Reveal Source?” Todd A. Proebsting Scott A. Watterson The University of Arizona Presented by Karl von Randow.
Java Bytecode What is a.class file anyway? Dan Fleck George Mason University Fall 2007.
Java Programming Introduction & Concepts. Introduction to Java Developed at Sun Microsystems by James Gosling in 1991 Object Oriented Free Compiled and.
Binary Auditing Geller Bedoya Michael Wozniak. Background  Binary auditing is a technique used to test the security and discover the inner workings of.
1 Introduction to JVM Based on material produced by Bill Venners.
Roopa.T PESIT, Bangalore. Source and Credits Dalvik VM, Dan Bornstein Google IO 2008 The Dalvik virtual machine Architecture by David Ehringer.
Comparing and Branching ifs and loops part A. JMP instruction Consider the forever loop: for ( ; ; ) { … } How can we accomplish this in Assembler?
EECS 354 Network Security Reverse Engineering. Introduction Preventing Reverse Engineering Reversing High Level Languages Reversing an ELF Executable.
CSCI Processing CSCI Introduction to Algorithm Design An Introduction.
Introduction to Information Security מרצים : Dr. Eran Tromer: Prof. Avishai Wool: מתרגלים : Itamar Gilad
Computing System Fundamentals 3.1 Language Translators.
Disclaimer The Content, Demonstration, Source Code and Programs presented here is "AS IS" without any warranty or conditions.
Stealing Passwords Remotely & Malware Analysis PacITPros May 8, 2012.
More on MIPS programs n SPIM does not support everything supported by a general MIPS assembler. For example, –.end doesn’t work Use j $ra –.macro doesn’t.
Operating Systems Security
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
Introduction to Reverse Engineering
Review on Program Challenge CSc3210 Yuan Long.
RealTimeSystems Lab Jong-Koo, Lim
CS 536 © CS 536 Spring Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 15.
Code Analysis and Optimization Pat Morin COMP 3002.
Shellcode COSC 480 Presentation Alison Buben.
Lecture 1b- Introduction
Static and dynamic analysis of binaries
Assembly Language Programming of 8085
Microprocessor T. Y. B. Sc..
CS216: Program and Data Representation
Machine code Recall that all a computer recognises is binary code.
1. Introduction A microprocessor executes instructions given by the user Instructions should be in a language known to the microprocessor Microprocessor.
143A: Principles of Operating Systems Lecture 4: Calling conventions
Java package classes Java package classes.
Malware Incident Response  Dynamic Analysis - 2
Introduction Enosis Learning.
Computer Architecture “Bomb Lab Hints”
Introduction Enosis Learning.
Java Byte Codes (0xCAFEBABE) cs205: engineering software
Introduction to Algorithm Design
Lecture 19: 0xCAFEBABE (Java Byte Codes) CS201j: Engineering Software
Fundamentals of Computer Organisation & Architecture
Byte Code Verification
Some Assembly (Part 2) set.html.
CSC 497/583 Advanced Topics in Computer Security
Credits and Disclaimers
Return-to-libc Attacks
Presentation transcript:

Application Security Tom Chothia Computer Security, Lecture 14

See example application

Introduction Compiled code is really just data… –which can be edit and inspected. By examining low level code protections can be removed and the function of programs altered. Good protection tends to slow down this process, not stop it.

This lecture and next: Java Byte code: –High level overview –Inspecting the byte code –Decompiling back to Java x86 assembly: –High level overview –Inspecting and altering binaries in IDA Buffer overflow attacks.

Java Byte Code Java compiles to Java Byte Code. –Type: “javap -c ” to see the byte code. Every computer must have its own Java Virtual Machine (JVM) which runs the byte code. Every different OS must have it’s own JVM

Java Program.java Windows Computer Linux Computer Mobile Phone

Java Program.java Windows Computer Windows JVM Linux Computer Linux JVM Mobile Phone JVM

Java Program.java Java Byte Code.class Windows Computer Windows JVM Linux Computer Linux JVM Mobile Phone JVM Compile Java to Byte Code Using “ javac ”

Java Program.java Java Byte Code.class Windows Computer Windows JVM Linux Computer Linux JVM Mobile Phone JVM Compile Java to Byte Code Using “ javac ” Run Byte Code On JVM using “ java ”

Multi-platform. Byte code of a for loop program.

A Stack Machine A stack machine has a stack to hold data and a small number of registers. Data pushed onto the stack or “popped” off. The registers are fast, but there are only a few of them. Stack 2:1:3:

Java Byte Code iconst_0 : push 0 onto the stack istore_1: pop the top of the stack as variable 1 goto: jump to line: iload_1: push variable 1 onto the stack iadd: add the top two numbers on the stack. if_icmpge: if 1 st item on stack =< 2 nd jump Ifeq: if 1 st item on stack > 2 nd jump to line

A Stack Machine Example code starts off by loading 0s into registers 1 and 2. These are i & j in the code. 0: iconst_1 1: istore_1 2: iconst_1 3: istore_2 Stack 2:1:3: 1 11

A Stack Machine Next the code checks the for loop guard: 4: iload_2 5: iconst_4 6: if_icmpge 26 Stack 2:1:3: The program doesn’t jump

A Stack Machine The for loop body. 9: iload_1 10: iload_2 11: iadd 12: istore_1 13: getstatic … 16: iload_1 17: invokevirtual... Stack 2:1:3: : 2

A Stack Machine The loop continues:... 4: iload_2 5: iconst_4 6: if_icmpge 26 … 20: iinc 2, 1 23: goto 4 26: return Stack 2:1:3: : 22: 2

A Stack Machine The loop continues:... 4: iload_2 5: iconst_4 6: if_icmpge 26 … 20: iinc 2, 1 23: goto 4 26: return Stack 2:1:3: : 42: 3

A Stack Machine The loop continues:... 4: iload_2 5: iconst_4 6: if_icmpge 26 … 20: iinc 2, 1 23: goto 4 26: return Stack 2:1:3: : 72: 4

Back to the password checking program.

Harder program

Decompilation Wouldn’t it be much easier to work with the source code, rather than the byte code? JD-GUI is a Java de-compiler, it transforms Java Byte Code into Java Code. Not perfect, e.g. confuses 0,1 and true, false.

Bypassing the password check. De-compilation makes it much easier to understand what a program is doing. It also makes it easy to alter and recompile the code. All code that is used to protect the code can be removed.

Binaries Binaries are written in assembly Much lower level than Java byte code, Assembly compiled for one type of machine won’t run on another. But the same techniques apply.

C program Windows Computer Linux Computer Mac Computer

C program Windows Computer Linux Computer Mac Computer gcc on windows Window Assembly

C program Windows Computer Linux Computer Mac Computer gcc on windows gcc on linux Window Assembly Linux Assembly

C program Windows Computer Linux Computer Mac Computer gcc on windows gcc on linux Window Assembly Linux Assembly Mac Assembly gcc on Mac

Some x86 Commands PUSH: add to top of stack CALL: execute a function RET, RETN, RETF: end a function and restart calling code. POP: read and remove from top of stack JMP: jump to some code (like writing to EIP) MOV: move value between registers MOV r1,r2 = PUSH r1 POP r2

Jumps To jump in x86 you first compare the values and then jump. TEST: does a bitwise “and”. CMP: subtracts 2 values The result isn’t stored but flags are set. Following TEST: JZ: jump if result was 0 JNZ: jump if result isn’t zero JE: jump if equal JNE: jump if not equal JL: jump if less than.

For Loop Program x86:

Can we De-Compile? Not really … –There is no clear distinction between data and code. –Code can be constructed dynamically. –Parts of the code can rewrite other parts. So it’s quite easy to stop fully automated disassembly.

IDA pro IDA pro is an Interactive DisAssembler. It helps a human understand binaries. This is the best tool for malware binary analysis, security analysis of firmware and reverse engineering. There is are free & demo versions: –

Function preamble: sets up the stack space Set I & j to 1: i is at stack location: exp+18 j is at stack location: exp+1C For loop check: Compare i to 3, Add i to j Print j Add 1 to i End

Common Techniques Look for strings. Identify key tests and check the values in the register using a debugger. Swap JEQ and JNEQ. Jump over the instructions that perform checks.

Defenses Dynamically construct the key –Attacker can run code. Encrypt the binary, –Your program must include the key in plain text, so the attacker can find it. Obfuscate the code, e.g. mix data and code, so it’s not clear which is which –Can slow down attacks by months or years! (e.g. Skype).

Defense Require online activation. –Activation can be completely disabled, users don’t like this. Require online content, e.g. WoW, BlueRay Hardware based protection, i.e., store part of the code in tamper restritant hardware.

Summary Machine code can be inspected and edited. Many tools exist to inspect, debug and decompile code. Most software protection can be removed. But slowing this down by months or years can save a business.

Next Lecture Buffer overflow attacks More on x86 assembly. More on IDA