Top Banner
Nibin Varghese iViZ Security, Kolkata Reverse Engineering for Exploit Writers
17

Nibin - Reverse Engineering for exploit writers - ClubHack2008

May 20, 2015

Download

Technology

ClubHack
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: Nibin - Reverse Engineering for exploit writers - ClubHack2008

Nibin VargheseiViZ Security, Kolkata

Reverse Engineering for Exploit Writers

Page 2: Nibin - Reverse Engineering for exploit writers - ClubHack2008

Agenda

Exploitation OverviewReverse Engineering ToolsCase Study MS08-067

Page 3: Nibin - Reverse Engineering for exploit writers - ClubHack2008

Exploitation Overview

Software vulnerabilities existReliable exploitation techniques exist

Stack overflowHeap overflow

Exploit mitigationPrevent or impede a class of vulnerabilitiesPatch the vulnerabilityDisable the serviceGeneric mitigations

Page 4: Nibin - Reverse Engineering for exploit writers - ClubHack2008

Reverse Engineering Tools

IDA ProBindiff Plugin for IDAOllydbg or Immunity Debugger or WindbgDebugging SymbolsSysinternals tool suiteAny scripting language to write PoC

(Python, Ruby etc)

Page 5: Nibin - Reverse Engineering for exploit writers - ClubHack2008

MS08-067

Windows Server Service VulnerabilityOut of band releaseDetails:

Error in netapi32.dll when processing directory traversal character sequence in path names. This can be exploited to corrupt stack memory by example sending RPC requests containing specially crafted path names to the Server service component – secunia.com

Page 6: Nibin - Reverse Engineering for exploit writers - ClubHack2008
Page 7: Nibin - Reverse Engineering for exploit writers - ClubHack2008

Structure of X86 stack frame

Local Variables Saved EBP Saved IP Arguments

Stack grows towards lower addresses

Page 8: Nibin - Reverse Engineering for exploit writers - ClubHack2008

Classical Overflow

Local Variables Saved EBP Saved IP Arguments

Return address overwritten with address of shellcode

Page 9: Nibin - Reverse Engineering for exploit writers - ClubHack2008

Reverse engineering the patch

Demo

Page 10: Nibin - Reverse Engineering for exploit writers - ClubHack2008

The Bug

Decompiled by Alexander SotirovVisual demo of the bug

Page 11: Nibin - Reverse Engineering for exploit writers - ClubHack2008

The Bug(contd..)

ptr_path

\\computername\\..\\..\\AAAAAAAAAAAAAAAAAAAAAAAAA

ptr_previous_slash ptr_current_slash

1. ptr_path points to the beginning of the buffer

2. Parses to find current slash and previous slash‘\\’

3. Finds “..”, so the current slash pointer moves forward

4. Data from Current slash pointer is copied to ptr_path

5. If the pointer is at the beginning of the buffer, a pointer moves backward to find previous slash“\\”.

5a. Results in access violation if no “\\” are found5b. Copies to the new destination if “\\” is found

\\..\\AAAAAAAAAAAAAAAAAAAAAAAAA

Lower Address

Higher Address

Page 12: Nibin - Reverse Engineering for exploit writers - ClubHack2008

path

Return Address of vulnerable_function

Saved EBP

Netapi32!NetpwPathCanonicalize

vulnerable_function( wchar *path ) wcscpy(dst,src)

Return Address of wcscpy

Saved EBP

1. ptr_path points to the beginning of the buffer

2. Parses to find current slash and previous slash‘\\’

3. Finds “..”, so the current slash pointer moves forward

4. Data from Current slash pointer is copied to ptr_path

5. If the pointer is at the beginning of the buffer, a pointer moves backward to find previous slash“\\”.

5a. Results in access violation if no “\\” are found5b. Copies to the new destination if “\\” is found

\\..\\AAAAAA

\\..\\AAAAAAAAAAA

(ptr1 – 1)ptr2ptr1ptr_path

\\c\\..\\..\\AAAAAAAAAAA

AAAA

AAAA

AAAA

Shell CodeShell Code

Page 13: Nibin - Reverse Engineering for exploit writers - ClubHack2008

The Bug (contd..)

Not a classical buffer overflowThe destination buffer is large enough to

copy the contents from sourceThe hunt for “\\” if the pointer points to the

beginning of the buffer makes it a BUG

Page 14: Nibin - Reverse Engineering for exploit writers - ClubHack2008

Ready for PoC

Identify the vector of exploitation3 possible ways

o wcslen of patho Predictable location of “\\” in the stack after

repeated interactiono Metasploit way of calculating the device_length

Page 15: Nibin - Reverse Engineering for exploit writers - ClubHack2008

Mass Exploitation

If no NX, return to stack and execute shellcode

If NX enabled, disable DEP/NX by abusing Win32 API NtSetInformationProcess and return to stack and execute shellcode. Refer Skape and Skywing paper on Uninformed Journal

“Bypassing Windows Hardware-enforced Data Execution Prevention”

In Vista, ASLR makes return addresses unpredictable.

Page 16: Nibin - Reverse Engineering for exploit writers - ClubHack2008

Thank You

Thanks to Research Team@iViZ Security Thanks to Clubhack 08 organizersThanks to all the attendees

Page 17: Nibin - Reverse Engineering for exploit writers - ClubHack2008

Ready for Phase 2 ?