Top Banner
Breaking Protection 1 Breaking Protection
136

Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview Here, we discuss cracking examples Examples are not from real software o.

Dec 19, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 1

Breaking Protection

Page 2: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 2

Overview Here, we discuss cracking examples Examples are not from real software

o “Crackme” --- program designed for studying cracking/protection techniques

Why learn cracking?o So that you can better protect softwareo “…protection technologies developed by

people who have never attempted cracking are never effective!”

Page 3: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 3

Patching Consider the following application

o KeygenMe-3 by Bengaly

QuickTime™ and aTIFF (Uncompressed) decompressor

are needed to see this picture.

No useful info here

What to do? Enter some data

and see what happens

Page 4: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 4

Patching Get invalid serial number message:

QuickTime™ and aTIFF (Uncompressed) decompressor

are needed to see this picture.

Now what? OllyDbg, of course…

Page 5: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 5

Patching Looking for message box

QuickTime™ and aTIFF (Uncompressed) decompressor

are needed to see this picture.

Page 6: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 6

Patching What about

lpk.dll?

QuickTime™ and aTIFF (Uncompressed) decompressor

are needed to see this picture.

Page 7: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 7

Patching Imports/exports

QuickTime™ and aTIFF (Uncompressed) decompressor

are needed to see this picture.

Page 8: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 8

Patching References to MessageBoxA

QuickTime™ and aTIFF (Uncompressed) decompressor

are needed to see this picture.

OK, now what?

Page 9: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 9

Patching Third

MsgBoxA reference

Page 10: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 10

Patching Now patch it in OllyDbg…

QuickTime™ and aTIFF (Uncompressed) decompressor

are needed to see this picture.

…success

QuickTime™ and aTIFF (Uncompressed) decompressor

are needed to see this picture.

Page 11: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 11

Keygenning Spse program asks for ID & serial number Such a program may have keygen algorithm

o Generate a “key” or serial number based on ID Attacker might want access to keygen

algorithm Why?

o To generate many valid ID/serial number pairso Why isn’t 1 such pair sufficient?

Page 12: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 12

Ripping Keygen Algorithm Goal is to create working copy of

keygen algorithm Just for creating valid ID/serial number

pairs This code can be “ripped” from the

application Following example is from…

o KeygenMe-3 by Bengaly

Page 13: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 13

Ripping Keygen Algorithm Code Part 1

Page 14: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 14

Ripping Keygen Algorithm

CodePart 2

Page 15: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 15

Ripping Keygen Algorithm Code Part 3

Page 16: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 16

Ripping Keygen Algorithm Take a

look at Key4.00401388

Page 17: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 17

Ripping Keygen Algorithm Code for keygen

algorithm… Uppercase asm is

ripped from app Note: there is no

need to understand the details!

Page 18: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 18

Ripping Keygen Algorithm Insert previous code into console app

And try it out…

QuickTime™ and aTIFF (Uncompressed) decompressor

are needed to see this picture.

Page 19: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 19

Advanced Cracking: Defender

Application developed to demonstrate protection techniqueso “…similar to what you would find in

real-world commercial protection…” Difficult, but not impossible

o “…all it takes is a lot of knowledge and a lot of patience”

Page 20: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 20

Defender Interface Launch without command-line options

QuickTime™ and aTIFF (Uncompressed) decompressor

are needed to see this picture.

Page 21: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 21

Defender Interface Launched with “random” username/serial number

QuickTime™ and aTIFF (Uncompressed) decompressor

are needed to see this picture.

Page 22: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 22

Defender: Linked Modules Load into OllyDbg and look at Executable

Modules windowo Gives exe modules that are statically linked

QuickTime™ and aTIFF (Uncompressed) decompressor

are needed to see this picture.

Just standard stuff here

Page 23: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 23

Defender: Imports/Exports Imports/exports

Only API called is IsDebuggerPresent?o This is very strange

QuickTime™ and aTIFF (Uncompressed) decompressor

are needed to see this picture.

Page 24: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 24

Defender: DUMPBIN

Anything?

Still just one API?

What about summary?

Page 25: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 25

DUMPBIN /HEADERS Try long listing --- find the following

……………………………………………………………

Page 26: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 26

DUMPBIN /HEADERS And…

……………………………………………………………

Page 27: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 27

DUMPBIN /HEADERS And…

……………………………………………………………

Page 28: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 28

DUMPBIN /HEADERS And…

……………………………………………………………

Page 29: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 29

Strange Section Names May be indication that program is

packed What to do? Try unpacking Will only work if it is standard

packer

Page 30: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 30

Defender: PEiD Try PEiD for common packers Nothing interesting…

QuickTime™ and aTIFF (Uncompressed) decompressor

are needed to see this picture.

Page 31: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 31

Defender: Initialization Want to figure out where “Bad key,

try again” msg comes fromo But, Defender does not call any

API???o So, no obvious place to set break

point What to do? Look at initialization routine…

Page 32: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 32

Initialization Disassembly I

Page 33: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 33

Initialization Disassembly II

Page 34: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 34

Initialization Disassembly III

Page 35: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 35

Initialization Disassembly IV

Page 36: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 36

Initialization Disassembly V

Page 37: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 37

Initialization Consider this code

fs register for thread-related infoo What’s at offset “+30”?

Page 38: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 38

Initialization For any thread fs:0 is “Thread

Environment Block” (TEB) What to do? Look up the TEB data stucture…

Page 39: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 39

TEB

At +30 we have PEBo Process Environment Block

Just like TEB, but for a processo Program access +c in PEB

So, program accesses PEB via TEB

Page 40: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 40

PEB

What is at +c in PEB?o _PEB_LDR_DATA

Go look at that data structure…

Page 41: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 41

_PEB_LDR_DATA Program get +c here too

LIST_ENTRY Look at data structure (next slide)

Page 42: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 42

LIST_ENTRY Goes to offset +0 here

o That is, LIST_ENTRY again

Page 43: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 43

LIST_ENTRY Goes to offset +18 here

o That is, DllBase

Page 44: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 44

What Does it all Mean? After all of that, program has found

base of some DLL Dump loader data structures

o InLoadOrderModuleList from PEB_LDR_DATA

o Next slide…

Page 45: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 45

Initialization

Page 46: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 46

Initialization Bottom line? The function at 00402EA8 obtains

in-memory address of NTDLL.DLL Program must communicate with

OSo And this is a highly obfuscated way to

(begin to) do so!

Page 47: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 47

Initialization Then what? Next, goes to function at

004033D1 Listing starts on next slide…

Page 48: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 48

Function at 004033D1

Page 49: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 49

Function at 004033D1

Page 50: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 50

Function at 004033D1

Page 51: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 51

Function at 004033D1

Page 52: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 52

Function at 004033D1

Boxed part represents 12 pages of “data”

Why all of this data embedded in code???

Page 53: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 53

Function at 004033D1 “Data” is probably encrypted code

o Goes from 4034DD to 403CE5 What about unencrypted parts? Looks like a big if-then-else

o But one clause looks like it’s “dead” So look at the “live” branch…

Page 54: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 54

Function at 004033D1 Note XOR at 403431

o Appear to be XORing within a loopo Note that XORing a constant value

Beginning at 4033DD we see 4034DD put into [ebp-20h], via the stacko What’s special about address 4034DD??

At 403410, use [ebp-20h] to get initial address for XORing

Aha --- the decryption loop!

Page 55: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 55

Decrypted Code Use OllyDbg and breakpt at end of

decryption loop (40346B) Then OllyDbg shows the following

Tell OllyDbg to re-analyze codeo Reveals many pages of decrypted code

Page 56: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 56

Decrypted Code Code digs thru NTDLL’s PE header

o Gets export directory For each export, “performs an

interesting … bit of arithmetic on each function name string”

Code is on next slide…

Page 57: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 57

Unusual Calculation

Debugger: [ebp-68] is len. of current stringo [ebp-64] has its

address Then for each char in

string, shifts left by its index, modulo 24

What the… ? It’s a “checksum”

Page 58: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 58

NTDLL After all chars have been processed…

What’s going on here? Looking for an export entry (NTDLL)

that has “checksum” 39DBA17A Put a breakpoint on line after JNZ…

o …and [ebp-64] shows you what was found

Page 59: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 59

Allocate Memory It turns out that it calls

o NtAllocateVirtualMemory Which is (undocumented) native

API equivalent of document APIo VirtualAlloc

It’s for allocating memory pages

Page 60: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 60

Read Time-stamp Counter Code to call NtAllocateVirtualMemory

What is RDTSC?o “Read time-

stamp counter”o A 64-bit

counter, incremented at each tick

Page 61: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 61

Parameters Timestamp bits ANDed with constant 2nd parameter

to memory alloc. function

Look at function prototypeo Undocumented

Page 62: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 62

Base Address 2nd param points to “base address” This is where

memory will be allocated

Page 63: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 63

Allocate Memory What just happened? Generated a “random” number

using timer Use this random number as

location (base address) for allocated memory

Interesting idea!

Page 64: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 64

Parameters Consider also 4th parameter

o This gives the allocated block size Loaded from [ebp-4] Code on next slide involved with

find block size…

Page 65: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 65

Parameters Consider 4th parameter Recall [ebp+8] is

NTDLL base addr Accesses PE hdr Ptr to PE hdr

stored in [ebp-74]

Get offset +1c

Page 66: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 66

Parameters PE header

==> What’s at +1c?

o That is, at +4 in OptionalHeader

SizeOfCode

Page 67: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 67

Size Calculation Code below related to size calculation Value read from [ebp-7c] points into

NTDLL headero Beginning of NTDLL’s export directory

Q: What’s at offset +18? A: NumberOfFunctions

Page 68: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 68

Block Size Final preparation of block size

So computed block size is… o NTDLLcodesize + NumExports * 8 + 8

Why? Not clear at this point…

Page 69: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 69

Checksum Another strange checksum

o This time, NTDLL’s export list Includes following 2 lines:

First, is function’s checksum Second is function’s RVA

Page 70: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 70

Interesting Code More “interesting” code

Page 71: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 71

Memory Copy Code on previous slide is a

common “sentence” in assembly code

A memory copyo REP MOV repeatedly copies DWORDS

from address at ESI to address at EDI until ECX is 0

So, what is being copied?

Page 72: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 72

Memory Copy ESI is loaded with [ebp+8] Why is that familiar? NTDLL’s base address Then increment by value at

[eax+2c]o BaseOfCode

EDI gets addr of new memory block

Page 73: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 73

What Just Happened? To recap… Memory allocated at random

location In this memory, write a table of

o Checksums of NTDLL exported functions

o Corresponding RVAs Finally, write a copy of entire

NTDLL code section

Page 74: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 74

Data Structure

Representation of description on previous slide

Page 75: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 75

What’s Next? After this, next function starts with…

Followed by…

Page 76: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 76

Searching For… What does this do?

Goes thru export table… …looking for checksum 190BC2 That is, looking for a specific API

Page 77: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 77

Found It —But What Is It? This is what happens when entry found

Where have we (just) seen offset +4?

Apparently, that’s the RVAo Gets added to “base address” of

NTDLL

Page 78: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 78

Leaving User Mode Later, we have this…

…which (eventually) calls this

SYSENTER is “kernel-mode switch”o So cannot follow with OllyDbg

Page 79: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 79

What Now? How to determine which system call? Three choices…

o Switch to kernel mode debugger (SoftICE)o Find RVA from checksum table (it’s probably

the same as actual RVA in NTDLL)o Find system call based on order in

checksum list (and hope order wasn’t changed)

Author chooses first option — SoftICE

Page 80: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 80

System Call First, it goes into KiSystemService

o All system calls go thru this functiono Look for CALL EBX, which transfers to actual

system callo In this case, it’s NtAllocateVirtualMemoryo Again???

Then back to user mode… …and program calls NtCreateThread

Page 81: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 81

Thread and Then… After creating thread, calls

“function” 006DEF20 Find that this is NtDelayExecution

o Equivalent to SleepEx This should “cause new thread to

execute immediately” Then calls “function” 403A41

Page 82: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 82

Function 403A41 Function call just skips ahead 30 bytes Those 30 bytes consist of…

Function’s only purpose is to avoid “executing” this string!

Then searches for 2 more “functions”o 6DEF20 and 1974C

Page 83: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 83

SoftICE Disappears Before getting to function 1974C,

SoftICE disappearso Defender has quit

Apparently, secondary thread has killed primary threado Secondary thread that was just

created

Page 84: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 84

Reversing Secondary Thread

This code is encrypted, like before Set breakpoint after it’s decrypted Obtain code on next few slides…

Page 85: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 85

Function at 00402FFE (I)

More dead code at line 4030C7?

Note RDTSC at line 403007

Page 86: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 86

Function at 00402FFE (II) Note second

RDTSC

Subtracted from first RDTSC ???

Page 87: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 87

Function at 00402FFE (III)

Infinite loop at line 4030C2?

Comparison with constant at line 403077…

What “function” is 1BF08AE?

Page 88: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 88

“Function” at 1BF08AE Stepping into this, the compare

(almost) always fails This code is checking a to see if

process is pausedo Recall the 2 calls to RTDSC

If paused, process is terminated What’s the purpose?

Page 89: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 89

Defeating “Killer” Thread Patch code to avoid check…

However, you cannot save this changeo So, must do this in each debug session

Why can’t you save this change?o Not clear at this point… we’ll see later

Page 90: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 90

“Function” 1974C This one is not a call into kernel Instead, code contained in NTDLL How to determine what API?

o Use RVA or its order in tableo Author uses order in export table

Finds result on next slide…

Page 91: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 91

Loading KERNEL32.DLL

What is LdrLoadDll? Native API version of LoadLibrary What DLL is it loading? We saw a name earlier:

KERNEL32.DLL

Page 92: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 92

Loading KERNEL32.DLL As with NTDLL, Defender

generates checksum/RVA table Then inserts code section of

KERNEL32.DLL

Page 93: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 93

After Loading KERNEL3.DLL

Another “function” skips 30 bytes or so What are those bytes?

Defender’s welcome messageo Ready to be printed out!

Page 94: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 94

KERNEL32.DLL Next, obfuscated call to something

in KERNEL32.DLL What could this be?

No need to work too hard… …this must be printing welcome msg

Page 95: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 95

Re-Encrypting At end of this function, we have

JMP is far away, but we’ve been there…

Page 96: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 96

Re-Encrypting

Page 97: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 97

Re-Encrypting Dead code … NOT! This code very similar to

decryptiono Convincing “dead code”?

But actually encryption codeo Computes checksum of encrypted

codeo Jumps to end of encrypted code

Why re-encrypt???

Page 98: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 98

Back at the Entry Point

Blah

Page 99: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 99

Back at the Entry Point Blah

Page 100: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 100

Parsing Parameters

Blah

Page 101: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 101

Parsing Parameters

Blah

Page 102: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 102

Parsing Parameters

Blah

Page 103: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 103

Processing Username Blah

Page 104: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 104

Processing Username Blah

Page 105: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 105

User Info Formula used to validate user

input

Page 106: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 106

User Info Blah

Page 107: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 107

User Info Blah

Page 108: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 108

User Info Blah

Page 109: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 109

Unlocking Code

Page 110: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 110

Brute-Forcing

Page 111: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 111

Brute-Forcing Blah

Page 112: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 112

Brute-Forcing Blah

Page 113: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 113

Brute-Forcing Blah

Page 114: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 114

Brute-Forcing Blah

Page 115: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 115

Brute-Forcing Blah

Page 116: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 116

Brute-Forcing Blah

Page 117: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 117

Brute-Forcing Blah

Page 118: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 118

Brute-Forcing Blah

Page 119: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 119

Brute-Forcing Blah

Page 120: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 120

Brute-Forcing

Blah

Page 121: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 121

Brute-Forcing Blah

Page 122: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 122

Brute-Forcing Blah

Page 123: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 123

Brute-Forcing Blah

Page 124: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 124

Brute-Forcing Blah

Page 125: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 125

Brute-Forcing Blah

Page 126: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 126

Brute-Forcing Blah

Page 127: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 127

Brute-Forcing

Page 128: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 128

Cracking Defender: Summary

Page 129: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 129

Protections in Defender

Page 130: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 130

Localized Encryption

Page 131: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 131

Obfuscation

Page 132: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 132

Time-Stamp Thread

Page 133: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 133

Decryption Keys

Page 134: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 134

Inlining

Page 135: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 135

Conclusions

Page 136: Breaking Protection 1 Breaking Protection Breaking Protection 2 Overview  Here, we discuss cracking examples  Examples are not from real software o.

Breaking Protection 136

Assignment Rip keygen code from “keygen.exe”

o http://www.cs.sjsu.edu/~stamp/CS286/progs/keygen.exe.zip

Make a separate app that generates valid serial number for given ID/username

Test on each of following ID/usernameso aaaaao qwerto qwerty