99
Jon McCoy www.DigitalBodyGuard.com Hacking .NET Applications: The Black Arts

Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy Hacking. NETApplications: The Black Arts

  • Upload
    lenhu

  • View
    216

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

Jon McCoy

www.DigitalBodyGuard.com

Hacking .NET Applications:

The Black Arts

Page 2: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

Why .NET

Countermeasures

Skill Level Needed

Will this work on every

.NET application

BACKGROUND

Page 3: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

How-To Attack .NET Applications

Tools and Methodology of Attacking

Overcome “secure” .NET Applications

Building KeyGen/Crack/Hacks/Malware

Reverse Engenerring for Protection

THIS WILL COVER

Page 4: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

Attacking/Cracking

IN MEM ||| ON DISK

Page 5: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

ATTACK OVERVIEW

Attack on DiskAccess Logic

Debug

Recompile

Attack in Memory/RuntimeInject Target App

Edit/Control Structure

Decompile

Infect Logic

Hook Logic

Navigate Structure

Page 6: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

Attack The Source

Find the weak spot

Subvert the Logic/State

In Memory OR On Disk

Control what you need

Do your Reconnaissance

Page 7: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

ATTACKING ON DISK

Page 8: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

DEMOGrayWolf – IL_Spy – Reflector

101 - DECOMPILERS

Page 9: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

101 - ATTACK ON DISK

Decompile - Get code/tech

Infect - Change the target's code

Remold Application - WIN

Exploit - Take advantage

Connect/Open - Access Code

Page 10: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

THE WEAK SPOTS

Flip The Check

Set Value is “True”

Cut The Logic

Return True

Access Value

Page 11: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

FLIP THE CHECKSET VALUE TO “TRUE”

bool Registered = false;bool Registered = true;bool Registered = false;

If(a!=b)If(a==b)If(a==b)

Page 12: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

RETURN TRUE

bool IsRegistered()

{

Return “TRUE”;

}

Page 13: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

RETURN TRUE

bool IsValidKey(string x)

{

Return “TRUE”;

}

Page 14: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

CUT THE LOGIC

string sqlClean(string x)

{

Return x;

}

Page 15: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

ACCESS VALUE

bool ValidPassword(int x)

{

ShowKey(Pass);

Return (x==Pass);

}

Page 16: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

ATTACK SECURITY

Microsoft

Media Center

Page 17: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

CRACK

PASSWORD

Page 18: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

CRACK

PASSWORD

Return True;

Page 19: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

CRACK

DEMO

Page 20: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

REGISTRATION CHECK

KeyGens

Cracks

Page 21: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

CRACK THE KEY

Public/Private

3/B==Name*ID*7

Call Server

Demo = True;

Complex Math

==

==

==

==

== Complex Math

Change Key

ASK what is /B?

Hack the Call

Set Value

1% of the time the KeyGen is given

Page 22: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

PUBLIC/PRIVATE KEY

If you can beat them

Why join them

Key = “F5PA11JS32DA”

Key = “123456ABCDE”

Page 23: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

SERVER CALL

1. Fake the Call

2. Fake the Request

3. Fake the Reply

4. Win

“Send”

SystemID = 123456789

*Registered = True*

Reg Code = f3V541

Page 24: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

REG CODE REPLAY

Name:

Code: ==

JON DOE

98qf3uy!=

*C5G9P3

FAIL

Page 25: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

Name:

Code:

*C

5G9P3

REG CODE REPLAY

Page 26: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

Name:

Code: ==

JON DOE

5G9P3==

*C5G9P3

WIN

REG CODE REPLAY

Page 27: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

COMPLEX MATH

1. Chop up the Math

2. Attack the Weak

3. ??????????

4. Profit

Page 28: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

DEMO

CRACK A KEY

Page 29: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

IL – Intermediate Language

Code of the Matrix |||| NEW ASM

Page 30: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

IT CAN’T BE THAT EZ

NO

Page 31: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

PROTECTION ON DISK

Protection - Security by 0b$cur17yCode Obfuscation

Shells / Packers / Encrypted(code)

Logic Obfuscation

Unmanaged calls………….

Try to SHUTDOWN

Decompilation

Page 32: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

PROTECTION ON DISK0bfu$ca7ed

Page 33: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

PROTECTION ON DISK

Signed code (1024 bit CRYPTO)

Strong Names

Try to SHUTDOWN

Tampering

Protection – Security by security

Verify the creator

ACLs……… M$ stuff

Page 34: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

STRONG NAME

Example Strong Name:

Simple Name

Public Key TokenStrongName: EXESample, Version=1.0.4203.24068,

Culture=neutral, PublicKeyToken=2a79b79e3c411f38

EXESample, Version=1.0.4203.24068,

Culture=neutral, PublicKeyToken=2a79b79e3c411f38

Version

Culture

Most of the time PublicKeyToken=null

Page 35: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

PRIVET KEY SIGNINGSigned code is based on

Private Key - 1024 bit

Signed Hash of Code

………..

Identify and Verify the Author

Page 36: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

UNPROTECTED/PROTECTED

Page 37: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

IT CAN BE THAT EZ

YESNONO

’T‘T

Page 38: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

PRIVET KEY SIGNINGSigned code is based on

Private Key - 1024 bit

Signed Hash of Code

………..

SIGNED CODE CHECKING IS

OFF BY DEFAULT

ATTACK VECTOR

Page 39: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

STRONG NAME HACKING

PublicKeyToken=

b77a5c561934e089

PublicKeyToken=683127632be2c302

Page 40: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

STRONG NAME HACKING

Page 41: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

FAKE SIGNED DLL

Page 42: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

FAKE SIGNED DLL

[HKEY_LOCAL_MACHINE

\SOFTWARE\Microsoft\.NETFramework]

"AllowStrongNameBypass"=dword:00000000

Turn Key Checking ON

Page 43: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

FAKE SIGNED DLL

ERROR

Page 44: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

FAKE SIGNED EXE

Page 45: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

FAKE SIGN DLL/EXE

Page 46: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

GLOBAL ASSEMBLY CASH--THE GAC--

What is the GAC?

How to access the GAC?

Attacking from the GAC?

ATTACK VECTOR

Page 47: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

GLOBAL ASSEMBLY CASH

C:\Windows\assembly\

Page 48: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

GLOBAL ASSEMBLY CASH

C:\Windows\assembly\

Page 49: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

GLOBAL ASSEMBLY CASHGAC

\GAC – Installed/Sandbox

\GAC_32 – 32bit-(x86)

\GAC_64 – 64bit-(x64)

\GAC_MSIL – MSIL(ANY)

Page 50: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

NATIVE IMAGE(NI) GAC

\NativeImages_v2.0.50727_32

\NativeImages_v2.0.50727_64

\NativeImages_v4.0.30319_32

\NativeImages_v4.0.30319_64

VER 1.1 - is dead

VER 2.0 & 3.5

VER 4.0

VER 3.0 - is dead

Page 51: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

GAC

C:\Windows\assembly\

C:\Windows\winsxs\

C:\Windows\Microsoft.NET

So much GAC!!!!!!!!!!!!!!!!!!!

Page 52: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

ATTACK THE GAC

Page 53: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

ATTACK FROM THE GAC

Page 54: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

ATTACK FROM THE GAC

NativeImages

GAC

Page 55: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

ATTACK THE GAC

1. Delete the Native Image

2. Replace File in GAC

3. Hack Target from GAC

Page 56: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

ATTACK FROM THE GAC

Page 57: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

ATTACK FROM FRAMEWORK

.NET Framework

Page 58: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

ASM THE OLD IS NEWATTACK VECTOR

Shell Code - ASM

UNmanaged

NO .NET Security

Exicute ASM Attack with

Unmanaged Calls or Reflection

………..

Page 59: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

FAKE SIGNED DLL

Page 60: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

THE OLD IS NEW AGAIN

ASM-SHELLS

Attack from a lower level

Brake the “safe” security

ASM-Shells.… shells…

Attack the Runtime

The Power of ASM

Page 61: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

VISUAL STUDIOExploit – Run arbitrary code

First noted in 2004

DemoPowerShell - Matrix

Get developer KeysAttack the SVN & DB

Virus Malware

Page 62: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

Attacking/Cracking

IN MEM |||| ON DISK

Page 63: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

ATTACKING .NET APPLICATIONS: AT RUNTIME

Page 64: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

WHY AT RUNTIME

SECURITY

SYSTEMS

Hacks

Cracks

Malware

Backdoors

Page 65: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

Inject at Runtime

GrayDragonC++

DLL

.NET

DLL

Page 66: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

Inject At Runtime

Page 67: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

Inject At Runtime

Page 68: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

ATTACKING APPS

Gain Full Access

Reverse Engineer

Attack (in MEM)

Take out the “Security”

Control the Program

Page 69: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

PAST TALKS

Hacking .NET Application: A Runtime Attack

Control the RuntimeControl the Application

Page 70: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

DEMO: GOD MODE

Inject and Control

Page 71: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

SO YOU’RE NOT A HACKERWHY SHOULD YOU CARE?

Defend your Applications

Defend your Systems

Verify your Tools\Programs

Page 72: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

VERIFY YOUR APPLICATIONS

What is the Crypto & KEY

What info is it sending home

Does it have Backdoors?

Is your data Secure?

Page 73: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

REVERSE ENGINEERING

What is going on?

What technology is used?

Any MaLWare?

Threat Level?

What is the security?

Page 74: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

Take Control

Don't be helpless

Know you Threats

LOOK INSIDE

Page 75: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

DON’T LOOK

Keys

Crypto

DBBackDoors

Good Code

TechnologyWeak Spots

Data Leaks

Reg Code

Bad Code

MalWare

Passwords

Page 76: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

SECURITY

The Login security check is

Does A == B

Does MD5%5 == X

Is the Pass the Crypto Key

Page 77: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

DATA LEAK

The Data sent home is

Application Info

User / Registartion Info

Security / System Info

Page 78: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

KEY

The Crypto Key is

A Hard Coded Key

The Licence Number

A MD5 Hash of the Pass

6Salt 6MD5 Hash of the Pass

Page 79: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

CRYPTO

The Crypto is

DES 64

Tripple DES 192

Rijndael AES 256

Home MIX (secure/unsecure)

Page 80: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts
Page 81: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

So your malware

How do you hide

Page 82: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

Fake (Signed DLL Protection)

Protection (Obfuscated Code)

Attack (Unmanaged Calls)

Protection (Shell Crypto)

Page 83: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

Intelligent names

Code style

Don’t use loops

Don’t use one area for your Vars

Use Timers

Link to Events

REUSE The TARGET

Call back into your target

Spread out your Vars and Code

Access the normal program

Page 84: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts
Page 85: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

Protect Me! 2010

Androsa FileProtector

Page 86: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

Protect Me! 2010

Page 87: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

Androsa FileProtector

Page 88: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts
Page 90: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

DEMO

Page 91: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

PROTECTION FOR WHO?

Infect Obfuscated App

0bfu$ca73

Page 92: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

WHAT M$ DID RIGHT

Un-obfuscated Code ∑ Good for user security

∑ User can see what they are running

.NET Framework Security∑ Targeted Security Access

∑ Protect the Computer from the app

Giving Reduced Rights Inside Code∑ Put venerable code in a box

∑ Mitigate & Segment Risk

RIGHT

Page 93: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

MixModeCode – Bad for security∑ This allows ASM\C++\C code

∑ This breaks out of .NET security

GAC & Native Image Override∑ Removes ability to secure code

Not Hash Checking Code ∑ Good for hackers

WHAT M$ DID RIGHTWRONG

Page 94: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

ATTACKING APPS

Read my papers: Reflections Hidden Power &

Attacking .NET at Runtime

Watch 2010 Presentations on Attacking .NET

DefCon 18, AppSec-DC, DojoCon

Look up Presentations and Research from

Andrew Willson, Erez Ezule, Arndet Mandent

Use tools: Visual Studio/MonoDev

Reflector/GrayWolf/ILspy/…/ILASM/ILDASM

Page 95: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

FIN

Page 96: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

www.DigitalBodyGuard.com

MORE INFORMATION @:

FIN = 1

Page 97: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

HACKER VS ATTACKER

Page 98: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

101 - Recon

File LocationC:\Windows\ehome\ehshell.dll

StrongName KEYd:\w7rtm.public.x86fre\internal\strongnamekeys\fake\windows.snk

Registry CurrentUser OR LocalMachineSOFTWARE\Microsoft\Windows\CurrentVersion\Media Center\

Web Host Addresswww.microsoft.com/WindowsMedia/Services/2003/10/10/movie

Page 99: Hacking.NET Applications: The Black Arts - DEF CON · Jon McCoy  Hacking. NETApplications: The Black Arts

101 - Recon

EHSHELL

Windows Media Center

.NET Framework

Ver 3.5

Un-0bfu$ca7edCrash Reporting

Watson

Coded in C#