exploitation of windows .net framework -...

35
Exploitation Of Windows .NET Framework Nanika [email protected] 1

Upload: others

Post on 25-Aug-2020

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

Exploitation Of Windows .NET Framework

Nanika

[email protected]

1

Page 2: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

I am Nanika

2

Page 3: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

• APT ?

• No Exploit in .NET?

• Only EXE Attack?

• always Finds the New Attack TREND

• 趨勢始終來自於弱點

.NET Framework

3

Page 4: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

.Net framework Security Improvements

4

Page 5: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

.NET Architecture

5

Page 6: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

WPF

• Windows Presentation Foundation (WPF) browser-hosted applications

• Default Enable DEP

Security Zone Behavior Getting Full Trust

Local computer Automatic full trust No action is needed.

Intranet and trusted sites Prompt for full trust Sign the XBAP with a certificate so that the user sees the source in the prompt.

Internet Fails with "Trust Not Granted"

Sign the XBAP with a certificate.

6

Page 7: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

Trust Site

7

Page 8: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

Debug WPF

• To configure Microsoft Visual Studio 2005 to debug an XBAP that calls a Web service:

• With a project selected in Solution Explorer, on the Project menu, click Properties.

• In the Project Designer, click the Debug tab. • In the Start Action section, select Start external program and enter

the following: • C:\WINDOWS\System32\PresentationHost.exe • In the Start Options section, enter the following into the Command

line arguments text box: • -debug filename • The filename value for the -debug parameter is the .xbap filename;

for example: • -debug c:\example.xbap

8

Page 9: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

ClickOnce Deployment Task ClickOnce Windows

Installer

Install Files X X

Create Shortcuts X X

Associate File Extensions X X

Install Services X

Install to GAC X

Manage ODBC X

Manage COM+ X

Write to Registry X

Advertising X

Self-Repair X

File/Folder/Registry Permissions X

Install-time User Interaction X

Install for All Users X

Custom Actions at Install/Uninstall X

Installation Conditions/System Interrogation

X

Auto-Update and Scheduling X

Forced Updates X

Security Sandboxing X

Download/Install Assemblies on Demand

X

Rollback to Previous Version X

9

Page 10: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

ClickOnce INTERNET or Full Trust

10

Page 11: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

Examples of permissions not available in the Internet zone

FileIOPermission This permission controls the ability to read and write files on disk. Consequently, applications in the Internet zone cannot read files on the user's hard disk.

RegistryPermission This permission controls the ability to read/write to the registry. Consequently, applications in the Internet zone cannot access or control state in the user's registry.

SecurityPermission.UnmanagedCode This permission controls the ability to call native Win32 functions.

http://msdn.microsoft.com/en-us/library/aa480229.aspx

11

Page 12: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

.XBAP/.Application

12

Page 13: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

Warring

13

Page 14: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

• .NET framework

Start the exploitation

14

Page 15: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

Exploit

ClickOnce

(INTERNET)

ClickOnce

(FULLTRUST) WEB

LOCAL

COMPRESS

FILE

15

Page 16: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

ClickOnce (INTERNET)+WEB with MS12-035

• 00000025 mov eax,dword ptr ds:[037B20C4h]

• 0000002b mov dword ptr [ebp-40h],eax

• 0000002e mov ecx,dword ptr [ebp-3Ch]//ecx=0x41414141

• 00000031 mov eax,dword ptr [ecx]

• 00000033 mov eax,dword ptr [eax+28h]

• 00000036 call dword ptr [eax]

16

Page 17: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

Exploit

• byte[] proc = new byte[] { • EIP, • 0x0d, 0x0d, 0x0d, 0x0d, • 0x0d, 0x0d, 0x0d, 0x0d, • 0x0d, 0x0d, 0x0d, 0x0d, • 0x0d, 0x0d, 0x0d, 0x0d, • 0x0d, 0x0d, 0x0d, 0x0d, • 0x0d, 0x0d, 0x0d, 0x0d, • 0x0d, 0x0d, 0x0d, 0x0d, • 0x0d, 0x0d, 0x0d, 0x0d, • 0x0d, 0x0d, 0x0d, 0x0d, • Proc point, • 0x0d, 0x0d, 0x0d, 0x0d,

17

Page 18: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

.NET Native API Alloc (full trust)

• [DllImport("kernel32")]

• private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr,UInt32 size, UInt32 flAllocationType, UInt32 flProtect);

• UInt32 exec = VirtualAlloc(0, (UInt32)proc.Length, 0x1000, 0x40);

• byte[] byteArrays = BitConverter.GetBytes(exec);

18

Page 19: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

.NET Alloc (full trust)

• int sz = 0x1000;

• IntPtr ptr = Marshal.AllocHGlobal(sz);

• uint exec = (uint)ptr.ToInt32();

• byte[] byteArrays = BitConverter.GetBytes(exec);

19

Page 20: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

Byte[] to uint (full trust)

• unsafe

• {

• fixed (byte* p = proc)

• {

• IntPtr ptr = (IntPtr)p;

• }

• }

20

Page 21: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

GCHandle.Alloc (full trust)

• GCHandle pinnedArray = GCHandle.Alloc(proc, GCHandleType.Pinned);

• IntPtr pointer = pinnedArray.AddrOfPinnedObject();

• pinnedArray.Free();

21

Page 22: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

Exploit MS12-035

• Heap spraying

• Find no ASLR module

• ROP

• Run Shellcode

• Use COM technical bypass HIPS(blackhat 2011)

• Demo

22

Page 23: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

Local Compress File Attack Internet Attack mush add trust site no warning

Attack (ClickOnce INTERNET)

• .NET limit by Windows Presentation Foundation Security Sandbox

• .XBAP

• .Applacation

• html

23

Page 24: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

Why AntiVirus can not Detect?

• ALL AV Focus in Internet Explore Process

• The Heap Spraying Detect only in Browser Process

• The Script Decode not work in WPF process

• Static Detect XBAP ?

24

Page 25: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

Patched Affect

• MS11-044 INTERNET check

• MS12-035 INTERNET and LOCAL check

25

Page 26: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

Remote Attack on MS11-044

• Web Attack Demo

26

Page 27: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

Patched MS11-044 Attack bypass

• LocalComputer

• RAR

27

Page 28: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

Attack (ClickOnce FULL TRUST)

• .NET can control everything

• .XBAP

• .Applacation

• Html

• Process.Start(“calc.exe”);

WEB Attack mush add trust site and warning

28

Page 29: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

MS12-035

• Local Warning

29

Page 30: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

Attack Only .NET no patch Patched MS11-044 Patched MS12-035

WEB+(ClickOnce full trust)

Must add IE trust site and Warning

Must add IE trust site and Warning

Must add IE trust site and Warning

Local Compress File+(ClickOnce full trust)

No Warning

No Warning

Warning

WEB+(ClickOnce INTERNET)

No Warning

Warning

Warning

Local Compress File+(ClickOnce INTERNET)

No Warning

No Warning

Warning

30

Page 31: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

Design

XBAP

Sandbox Limit

Internet

warning

Trust Site or Local

31

Page 32: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

Any thing Warning!?

• Remember UAC ?

• Any XBAP warning

• Sandbox with warning bypass depend on user’s decide now.

32

Page 33: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

Do you install .Net framework?

33

Page 34: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

Summery

• .NET Remote Attack

• .NET Local Attack

• Patched Affect

• TREND always Finds the New Attack TREND

34

Page 35: Exploitation Of Windows .NET Framework - HITCONhitcon.org/2012/download/0720A7_Nanika_ExploitationOf... · 2012. 7. 6. · WPF •Windows Presentation Foundation (WPF) browser-hosted

• Thanks

35