reverse engineering 101

109
Reverse Engineering 101 Yasin SÜRER http://twitter.com/yasinsurer

Upload: redrumz

Post on 02-Jan-2016

61 views

Category:

Documents


1 download

DESCRIPTION

Reverse Engineering 101, Gazi University, May, 20, 2013, Ankara/Turkey.

TRANSCRIPT

Page 1: Reverse Engineering 101

Reverse Engineering 101

Yasin SÜRERhttp://twitter.com/yasinsurer

Page 2: Reverse Engineering 101

Jargon

A zero-day (or zero-hour or day zero) attack or threat is an attack that exploits a previously unknown vulnerability in a computer application.

An exploit is a piece of software, a chunk of data, or sequence of commands that takes advantage of a bug

A shellcode is a small piece of code used as the payload in the exploitation of a software vulnerability

A rootkit is a stealthy type of software, often malicious, designed to hide the existence of certain processes or programs from normal methods of detection and enable continued privileged access to a computer.

Page 3: Reverse Engineering 101

Attacker Mindset

Vulnerability ResearchFind the vulnerability, and developing weaponized-exploits.

Exploit DevelopmentZero-day attack uses advanced-exploitation technique

Understanding undocumented system functions

malware authors; Rootkit, worm, keylogger, spyware etc.

Page 4: Reverse Engineering 101

Defensive Perspective

Patch and Vulnerability AnalysisDeveloping signatures against zero-day threats for IDS/IPS appliance

Binary Code AnalysisFinding new zero-day vulnerabilities to take advantage on defensive perspective

Advanced Exploit Development

Penetration Test and Vulnerability assesment.

Malware AnalysisAnti-Virus, Anti-Spyware and Digital Forensics companies

Page 5: Reverse Engineering 101

Real-World Crime Example

May 2008 in New York for the Dave & Busters case

May 2008 in Massachusetts for the TJ Maxx case

August 2009 in New Jersey in connection with the Heartland Payment case.

Page 6: Reverse Engineering 101
Page 7: Reverse Engineering 101

State-Sponsored Attack Example

The group obtained a sponsor who paid them 2000 RMB ($325) per month

Their sponsor is likely the People's Liberation Army (PLA)

Tan Dailin attacks on US Department of Defense in May and June 2006

GinWui Rootkit (Manipulate Service, Start and Kill Process etc.)

iDefense says,35 zero-day Microsoft Office Exploit

Page 8: Reverse Engineering 101

State-Sponsored Attack Example

Page 9: Reverse Engineering 101

Advanced Persistent Threat

Page 10: Reverse Engineering 101

‘’We do not call those types of threats as Advanced Persistent Threat since they use widely known, old-school tactics’’

Microsoft

Page 11: Reverse Engineering 101

US Department of DefenseOffensive Contractors

Page 12: Reverse Engineering 101
Page 13: Reverse Engineering 101
Page 14: Reverse Engineering 101
Page 15: Reverse Engineering 101
Page 16: Reverse Engineering 101
Page 17: Reverse Engineering 101
Page 18: Reverse Engineering 101
Page 19: Reverse Engineering 101
Page 20: Reverse Engineering 101
Page 21: Reverse Engineering 101
Page 22: Reverse Engineering 101
Page 23: Reverse Engineering 101

Reverse Engineering

Page 24: Reverse Engineering 101

What is Reverse Engineering ?

Static Analysis or ReversingStatic program analysis is the analysis of computer software that is

performed without actually executing programs

Dynamic Analysis or Reversing Dynamic program analysis is the analysis of computer software that is

performed by executing programs on a real or virtual processor.

Page 25: Reverse Engineering 101

x86 Architecture & Assembly

Page 26: Reverse Engineering 101

Arithmetic Instructions

mov eax, 5 ; eax=5

mov ebx, 3 ; ebx=3

add eax, ebx ; eax = eax + ebx

sub ebx, 2 ; ebx = ebx -2

Page 27: Reverse Engineering 101

Accessing Memory

cmp eax, 2 ; compare eax with 2

je label ; if(eax == 2)

ja label ; if(eax > 2)

jb label ; if(eax < 2)

jbe label ; if(eax <= 2)

jne label ; if(eax != 2)

jmp label ; jump label

Page 28: Reverse Engineering 101

Function Calls

call function ; store return addr on the stack

; and jump to function!

func:

push esi ; save esi

pop esi ; restore esi

ret ; read return addr from the stack

; and jump to it.

Page 29: Reverse Engineering 101

Modern CompilerNative Language

Intermediate Representation

Low-level Intermediate representation

x86 Assembly

Page 30: Reverse Engineering 101

Binary Reverse Engineering

How the compiler works and to translate it into machine code

Understanding operating system structures

Understanding executable (PE/ELF) file formats We need to think like the compiler, but in reverse!

Page 31: Reverse Engineering 101

Toolbag

Page 32: Reverse Engineering 101

Reverser Toolbag (1)

IDA Disassembler from Hex-Rays

IDA is a disassembler for computer software which generates assembly

language source code from machine-executable codeOllyDbg is Free Debugger

OllyDbg is an x86 debugger that emphasizes binary code analysis, which

is useful when source code is not availableWindbg from Microsoft

It can be used to debug user mode applications, drivers, and the

operating system itself in kernel mode.

Page 33: Reverse Engineering 101

Reverser Toolbag (2)

Virtual Machines (Virtualbox, VMWare, Hyper-V)

A virtual machine (VM) is a software implemented abstraction of the underlying hardware, which is presented to the application layer of the system.

Packet Sniffers (Wireshark, tcpdump)

The sniffer captures packets, if needed, decodes the packet's raw data, showing the values of various fields in the packet

Sysinternals Suite

technical resources and utilities to manage, diagnose, troubleshoot, and monitor

a Microsoft Windows environment.

Page 34: Reverse Engineering 101

PEiD

Page 35: Reverse Engineering 101

IDA Pro

Page 36: Reverse Engineering 101

IDA Pro (2)

Page 37: Reverse Engineering 101

IDA Pro (3)

Page 38: Reverse Engineering 101

IDA Pro (4)

Page 39: Reverse Engineering 101

OllyDbg

Page 40: Reverse Engineering 101

OllyDbg (2)

Page 41: Reverse Engineering 101

Windbg

Page 42: Reverse Engineering 101

Windbg (2)

Page 43: Reverse Engineering 101

Intro to Windbg

• r: display current register content

• t: trace-step (until call)

• pt: single-step (until-ret)

• g: process run (go!)

• .hh: help command. (for example .hh t)

• lm: list modules

Page 44: Reverse Engineering 101

Sysinternal: Process Explorer

Page 45: Reverse Engineering 101

Sysinternal: Process Monitor

Page 46: Reverse Engineering 101

Sysinternal: Autoruns

Page 47: Reverse Engineering 101

ImpREC

Page 48: Reverse Engineering 101

LordPE

Page 49: Reverse Engineering 101

Anti-Reverse Engineering

Anti-Debugging, the implementation of one or more techniques within

computer code that ‘’hinders attempts’’ at reverse engineering or debugging a target process

Anti-Dumping, describes the process of taking an executable that has been protected and after the executable has been decrypted into memory

Code obfuscation is the deliberate act of creating obfuscated code, i.e. source or

machine code that is difficult for humans to understand.

Executable compression is any means of compressing an executable file and combining the compressed data with decompression code into a single

executable

Page 50: Reverse Engineering 101

Executable Compression(Packed Executables)

Page 51: Reverse Engineering 101

Packed Executable

Page 52: Reverse Engineering 101

Packed Executable

Page 53: Reverse Engineering 101

Packed Executable

Page 54: Reverse Engineering 101

Packed Executable

Page 55: Reverse Engineering 101

Packed Executable

Page 56: Reverse Engineering 101

Anti-Debugging

Page 57: Reverse Engineering 101

Anti-Debugging

Page 58: Reverse Engineering 101

Anti-Debugging

Page 59: Reverse Engineering 101

Anti-Debugging

Page 60: Reverse Engineering 101

Anti-Debugging

Page 61: Reverse Engineering 101

Anti-Debugging

Page 62: Reverse Engineering 101

FATMAL(Real-World Example)

Page 63: Reverse Engineering 101

FATMAL

Page 64: Reverse Engineering 101

Loader

Page 65: Reverse Engineering 101

Loader

Page 66: Reverse Engineering 101

Payload

InstallBot()

Page 67: Reverse Engineering 101

Payload

Page 68: Reverse Engineering 101

Payload

Page 69: Reverse Engineering 101

Payload

Page 70: Reverse Engineering 101

Payload

Page 71: Reverse Engineering 101

Payload

Page 72: Reverse Engineering 101

Who could be behind the FATMAL attack?

Page 73: Reverse Engineering 101
Page 74: Reverse Engineering 101
Page 75: Reverse Engineering 101

Memory Analysis- Sality -

Page 76: Reverse Engineering 101

Memory Analysis

Page 77: Reverse Engineering 101

Memory Analysis

Page 78: Reverse Engineering 101

Memory Analysis

Page 79: Reverse Engineering 101

Memory Analysis

Page 80: Reverse Engineering 101

Memory Analysis

Page 81: Reverse Engineering 101

Resources

Page 82: Reverse Engineering 101
Page 83: Reverse Engineering 101

Analysis of Mobile Threats

Page 84: Reverse Engineering 101

Mobile Market

49%

19%

13%

11%

5%3%

Android

iPhone

BlackBerry

Windows Phone

Symbian

Other

Page 85: Reverse Engineering 101

Mobile Threats

79

19

0.30.70.30.7

AndroidSymbian Windows MobileiPhoneBlackBerryJ2ME

Page 86: Reverse Engineering 101

Mobile Threats

66.10.71

2.70.3

5.6

7

11.2

3.7

TrojanDownloaderSpyAdwareBackdoorHacktoolMonitoringRiskwareSpywareApplication

Page 87: Reverse Engineering 101

Android

Android is a Linux-based operating system, runs on custom Linux.

Google I/O statshot, 900 million Android devices activated

Google play hits 600.000 application, 20 billion total installs.

Manufacturers; Samsung, HTC, Asus, Amazon, Sony, Toshiba, Acer…

Page 88: Reverse Engineering 101

Android AppsAndroid Market

APK/ZIP

Metadata (manifest, images)

Dex File (classes.dex)

Page 89: Reverse Engineering 101

Android Architecture

Page 90: Reverse Engineering 101

Geinimi

Page 91: Reverse Engineering 101

Geinimi

Page 92: Reverse Engineering 101

Geinimi

Page 93: Reverse Engineering 101

Geinimi

Page 94: Reverse Engineering 101

Geinimi

Page 95: Reverse Engineering 101

Geinimi

Page 96: Reverse Engineering 101

Geinimi

Page 97: Reverse Engineering 101

5 years of silence…

Page 98: Reverse Engineering 101

The ProGuard tool shrinks, optimizes, and obfuscates your code by removing

unused code and renaming classes, fields, and methods with semantically obscure names.

DexGuard is our specialized optimizer and obfuscator for Android. Create apps that

are faster, more compact, and more difficult to crack.

Page 99: Reverse Engineering 101

Obfuscation

Page 100: Reverse Engineering 101

Obfuscation

Page 101: Reverse Engineering 101

Obfuscation

Page 102: Reverse Engineering 101

Modifying The bytecode

Page 103: Reverse Engineering 101

Android Application

Page 104: Reverse Engineering 101

Modifying the byte-code

JNI

Native Code

Dalvik bytecode

Modified!

Page 105: Reverse Engineering 101

Processor

Page 106: Reverse Engineering 101
Page 107: Reverse Engineering 101

so what…

Page 108: Reverse Engineering 101

Malware writers is getting ready to implement x86 techniques for

Android.

Page 109: Reverse Engineering 101

Questions…