76
Jon McCoy www.DigitalBodyGuard.com Hacking .NET Applications: The Black Arts AppSec-DC 2012

Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

  • Upload
    dobao

  • View
    238

  • Download
    7

Embed Size (px)

Citation preview

Page 1: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

Jon McCoy

www.DigitalBodyGuard.com

Hacking .NET Applications:

The Black Arts AppSec-DC 2012

Page 2: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

AppSec-DC 2012

Hacking .NET Applications:

The Black Arts

Jon McCoy

www.DigitalBodyGuard.com

Page 3: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

.NET new and cross platform - Windows, OS-X, Linux, Android, IPhone, ARM

The attacks are not new nor only in .NET - C++, Java, ………….

Faster development time

Similar layout to JAVA

I happen to be good at .NET

WHY .NET

Page 4: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

HACKER VS ATTACKER

Page 5: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy
Page 6: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

NOT AMS LEVEL

Page 7: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

WHY NOT ASM?

Page 8: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

NOT IDA PRO

Page 9: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

NOT IDA PRO

Page 10: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

IL – Intermediate Language

Code of the Matrix |||| NEW ASM

Page 11: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

C# - 15

IL - 34

ASM - 77

LINES

C# - 13 LINES DECOMPILE

Page 12: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

HOW MUCH CODE DO YOU NEED TO READ`

C# - 15 IL - 34 ASM - 77

Page 13: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

NOT IDA PRO

Page 14: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy
Page 15: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

Attacking/Cracking

IN MEM |||| ON DISK

Page 16: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

ATTACKING .NET

ATTACK THE CODE ON DISK

Page 17: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

ATTACKING ON DISK

Page 18: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

GRAYWOLF

ON DISK EDIT

Page 19: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

ATTACK SECURITY

Microsoft

Media Center

Page 20: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

CRACK

DEMO GOD MODE

GSGE.CONFIGOPTIONS::.CCTOR() 439 LDC.I4.1

Page 21: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

CRACK

PASSWORD

Page 22: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

CRACK

PASSWORD

Return True;

Page 23: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

ATTACKING .NET APPLICATIONS: AT RUNTIME

Page 24: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

GRAYDRAGON

INJECTION

Page 25: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

ATTACKING .NET

ATTACK WHILE THE APP IS RUNNING

Page 26: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

ASM THE OLD IS NEW ATTACK VECTOR (not new)

Shell Code - ASM

.NET has pointers

NO .NET Security

THIS IS SCARY!!!!

NEVER LET ME CALL

UNMANNAGED

………..

Page 27: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

ASM THE OLD IS NEW ATTACK VECTOR

Page 28: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

ASM THE OLD IS NEW ATTACK VECTOR

Page 29: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

Run and Inject

SECURITY

SYSTEMS

Page 30: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

DEMO

Page 31: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

101 - ATTACK ON DISK

Decompile - Get code/tech

Infect - Change the target's code

Remold/Recompile - WIN

Exploit - Take advantage

Connect/Open - Access Code

Page 32: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

THE WEAK SPOTS

Flip The Check

Set Value is “True”

Cut The Logic

Return True

Access Value

Page 33: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

FLIP THE CHECK SET VALUE TO “TRUE”

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

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

Page 34: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

RETURN TRUE

bool IsRegistered()

{

Return TRUE;

........................

}

Page 35: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

CUT THE LOGIC

string sqlClean(string x)

{

Return x;

}

Page 36: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

HACK THE LOGIN

DEMO PASS THE KEY SHOW THE KEY

Page 37: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

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 38: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

PUBLIC/PRIVATE KEY

If you can beat them

Why join them

Key = “F5PA11JS32DA”

Key = “123456ABCDE”

Page 39: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

SERVER CALL

1. Fake the Call

2. Fake the Request

3. Fake the Reply

4. Win

Call Web Server = www.LocalHost.com

“Send”

SystemID = 123456789

*Registered = True*

Reg Code = f3V541

Page 40: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

REG CODE REPLAY

Name:

Code: ==

JON DOE

98qf3uy !=

*C 5G9P3

FAIL

Page 41: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

Name:

Code:

*C

5G9P3

REG CODE REPLAY

Page 42: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

Name:

Code: ==

JON DOE

5G9P3 ==

*C 5G9P3

WIN

REG CODE REPLAY

Page 43: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

COMPLEX MATH

1. Chop up the Math

2. Attack the Weak

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

4. Profit

Page 44: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

HACK THE KEY

DEMO APPSEC-USA 2011

999ca10a050f4bdb31f7e1f39d9a0dda

Page 45: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

Static Crypto Key

Vector init = 0

Clear TXT Password Storage

Encrypted Data

Page 46: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

WHAT STOPS THIS?

What is the security?

Page 47: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

PROTECTION ON DISK

Signed code (1024 bit CRYPTO)

Strong Names

Try to SHUTDOWN

Tampering

Protection – Security

Verify the creator

ACLs……… M$ stuff

Page 48: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

PRIVET KEY SIGNING Signed code is based on

Private Key - 1024 bit

Signed Hash of Code

………..

Identify and Verify the Author

Page 49: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

PROTECTION ON DISK

Protection - Security by 0b$cur17y Code Obfuscation

Shells / Packers / Encrypted(code)

Logic Obfuscation

Unmanaged calls…to C/C++/ASM

Try to SHUTDOWN

Decompilation

Page 50: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy
Page 51: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy
Page 52: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

CRACK - FAIL

DEMO FAIL

Page 53: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

PROTECTION ON DISK 0bfu$ca7ed

DEMO FAIL

Page 54: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

REVIEW DOTFUSCATOR

Obfuscation will only

slows the attacker

Obfuscation applied

programmatically is not

100% effective

Causes low or no

Bugs

Does no add

vulnerabilities

Phone Home

If Tampered

Page 55: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy
Page 56: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

UNPROTECTED / PROTECTED

Page 57: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

THE BEST DEFENSE IS A GOOD SNIPER

If you know the enemy and know

yourself, you need not fear the

results of a hundred battles. - Sun Tzu

Page 58: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

PROTECTION ON DISK

Shells

Pack/Encrypt the EXE

Page 59: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

IT CAN BE THAT EZ

What is the security? What is the security?

’T ‘T

Page 60: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy
Page 61: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

STRONG NAME HACKING

Page 62: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

PRIVET KEY SIGNING Signed code is based on

Private Key - 1024 bit

Signed Hash of Code

………..

SIGNED CODE CHECKING IS

OFF BY DEFAULT

ATTACK VECTOR

Page 63: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

FAKE SIGNED DLL

Page 64: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

FAKE SIGNED DLL

[HKEY_LOCAL_MACHINE

\SOFTWARE\Microsoft\.NETFramework]

"AllowStrongNameBypass"=dword:00000000

Turn Key Checking ON

Page 65: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

FAKE SIGNED DLL

ERROR

Page 66: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

FAKE SIGNED DLL

Page 67: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

VISUAL STUDIO Exploit – Run arbitrary code

First noted in 2004

Demo PowerShell - Matrix

Get developer Keys Attack the SVN & DB

ATTACK VECTOR

www.pretentiousname.com/misc/win7_uac_whitelist2.html

Page 68: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

YOU’RE NOT A HACKER WHY SHOULD YOU CARE?

Defend your Applications

Defend your Systems

Verify your Tools\Programs

Page 69: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

LOOK INSIDE

Page 70: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

DON’T LOOK

Page 71: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

SECURITY

The Login security check is

Does A == B

Does MD5%5 == X

Is the Pass the Crypto Key

Page 72: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

DATA LEAK

The Data sent home is

Application Info

User / Registartion Info

Security / System Info

Page 73: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

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 74: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

CRYPTO

The Crypto is

DES 64

Tripple DES 192

Rijndael AES 256

Home MIX (secure/unsecure)

Page 75: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

FIN

Page 76: Hacking NET Applications: The Black Arts - OWASP · PDF fileAppSec-DC 2012 Hacking. NET Applications: The Black Arts Jon McCoy

www.DigitalBodyGuard.com [email protected]

MORE INFORMATION @:

FIN = 1