Hijacking Arbitrary.NET Application Control Flow. Topher Timzen



Similar documents
Cross-platform IL code manipulation library for runtime instrumentation of.net applications

Monitoring.NET Framework with Verax NMS

Deep Dive into.net Malwares

Interpreters and virtual machines. Interpreters. Interpreters. Why interpreters? Tree-based interpreters. Text-based interpreters

PuttyRider. With great power comes great responsibility. # Pivoting from Windows to Linux in a penetration test. Adrian Furtunã, PhD adif2k8@gmail.

Jonathan Worthington Scarborough Linux User Group

How to create/avoid memory leak in Java and.net? Venkat Subramaniam

Format string exploitation on windows Using Immunity Debugger / Python. By Abysssec Inc

ASL IT SECURITY XTREME XPLOIT DEVELOPMENT

Title: Bugger The Debugger - Pre Interaction Debugger Code Execution

Glossary of Object Oriented Terms

Introducing the.net Framework 4.0

.NET Overview. David Smith. Today s s Topics. Why am I here? A tool. Microsoft s s Vision for.net

Dynamic Web Programming BUILDING WEB APPLICATIONS USING ASP.NET, AJAX AND JAVASCRIPT

SECURITY B-SIDES: ATLANTA STRATEGIC PENETRATION TESTING. Presented by: Dave Kennedy Eric Smith

OPERATING SYSTEM SERVICES

Developing Microsoft SQL Server Databases 20464C; 5 Days

BSIDES Las Vegas Secret Pentesting Techniques Shhh...

Sandy. The Malicious Exploit Analysis. Static Analysis and Dynamic exploit analysis. Garage4Hackers

Monitoring ASP.Net Servers

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

ITDUMPS QUESTION & ANSWER. Accurate study guides, High passing rate! IT dumps provides update free of charge in one year!

Java Interview Questions and Answers

General Introduction

.NET Reverse Engineering. Erez Metula, CISSP Application Security Department Manager Security Software Engineer 2B Secure

The Java Virtual Machine and Mobile Devices. John Buford, Ph.D. Oct 2003 Presented to Gordon College CS 311

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

MSc Computer Science Dissertation

.NET and J2EE Intro to Software Engineering

Software security. Buffer overflow attacks SQL injections. Lecture 11 EIT060 Computer Security

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08

Automating Mimicry Attacks Using Static Binary Analysis

Garbage Collection: Automatic Memory Management in the Microsoft.NET Framework

Java Application Developer Certificate Program Competencies

Chapter 1. Dr. Chris Irwin Davis Phone: (972) Office: ECSS CS-4337 Organization of Programming Languages

Bypassing Browser Memory Protections in Windows Vista

Parasitics: The Next Generation. Vitaly Zaytsev Abhishek Karnik Joshua Phillips

Diving into a Silverlight Exploit and Shellcode - Analysis and Techniques

Return-oriented programming without returns

20464C: Developing Microsoft SQL Server Databases

1/20/2016 INTRODUCTION

FATKit: A Framework for the Extraction and Analysis of Digital Forensic Data from Volatile System Memory p.1/11

Eugene Tsyrklevich. Ozone HIPS: Unbreakable Windows

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Crystal Reports.Net 1.1 Patch

Static detection of C++ vtable escape vulnerabilities in binary code

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

C Compiler Targeting the Java Virtual Machine

Developing Microsoft SQL Server Databases

Operating Systems and Networks

Application Domains and Contexts and Threads, Oh My!

Web Application Report

Course 20464: Developing Microsoft SQL Server Databases

Memory Allocation. Static Allocation. Dynamic Allocation. Memory Management. Dynamic Allocation. Dynamic Storage Allocation

Java Programming. Binnur Kurt Istanbul Technical University Computer Engineering Department. Java Programming. Version 0.0.

Cloud Computing. Up until now

ASP.NET MVC Secure Coding 4-Day hands on Course. Course Syllabus

Developing Microsoft SQL Server Databases (20464) H8N64S

Instrumentation Software Profiling

Custom Penetration Testing

System Structures. Services Interface Structure

Application Development,.NET

Security & Exploitation

API Monitoring System for Defeating Worms and Exploits in MS-Windows System

SAML v1.1 for.net Developer Guide

7.1 Our Current Model

Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz

EC-Council CAST CENTER FOR ADVANCED SECURITY TRAINING. CAST 619 Advanced SQLi Attacks and Countermeasures. Make The Difference CAST.

Penetration Testing: Lessons from the Field

Hacking Techniques & Intrusion Detection. Ali Al-Shemery arabnix [at] gmail

Source Code Security Analysis Tool Functional Specification Version 1.0

Melde- und Analysestelle Informationssicherung MELANI Torpig/Mebroot Reverse Code Engineering (RCE)

Storing Encrypted Plain Text Files Using Google Android

Automated Virtual Cloud Management: The need of future

Introduction. Application Security. Reasons For Reverse Engineering. This lecture. Java Byte Code

Lecture 10: Dynamic Memory Allocation 1: Into the jaws of malloc()

CORE SECURITY. Exploiting Adobe Flash Player in the era of Control Flow Guard. Francisco Falcon Black Hat Europe 2015 November 12-13, 2015

Sitecore Health. Christopher Wojciech. netzkern AG. Sitecore User Group Conference 2015

EC-Council E C S P.NET. EC-Council. EC-Council Certified Secure Programmer (.NET)

Language Evaluation Criteria. Evaluation Criteria: Readability. Evaluation Criteria: Writability. ICOM 4036 Programming Languages

Enterprise Application Security Workshop Series

Monitoring, Tracing, Debugging (Under Construction)

Java Garbage Collection Basics

Penetration Testing Workshop

Bypassing Memory Protections: The Future of Exploitation

Y R O. Memory Forensics: A Volatility Primer M E M. Mariano Graziano. Security Day - Lille1 University January Lille, France

A Practical Method to Diagnose Memory Leaks in Java Application Alan Yu

Experimental Evaluation of Distributed Middleware with a Virtualized Java Environment

Objectif. Participant. Prérequis. Remarque. Programme. C# 3.0 Programming in the.net Framework. 1. Introduction to the.

SkyRecon Cryptographic Module (SCM)

Buffer Overflows. Code Security: Buffer Overflows. Buffer Overflows are everywhere. 13 Buffer Overflow 12 Nov 2015

Transcription:

Hijacking Arbitrary.NET Application Control Flow Topher Timzen

#whoami Topher Timzen Security Researcher, Intel Security Trainer @TTimzen TopherTimzen.com

Overview.NET? Runtime Attacks Modify Control Flow Machine Code Editing Managed Heap

Why are we Here? Tools Released Use.NET to attack Using Objects on the Heap

CLR Attacks Controlling the Common Language Runtime Accessing raw objects on Managed Heap Manipulate AppDomains Controlling all Loaded Code Controlling Just-In-Time Compilation

Attack With ASM Manipulate Resources Attack methods at ASM level Hybrid C# -> ASM -> C# call chains Alter application control flow

Runtime.NET Process CLR (2.0/4.0) & AppDomains Assemblies (.EXE and.dll(s)) Objects Properties Fields Instance Methods Classes Methods Logic

The Tools Gray Frost & Gray Storm

Gray Frost

Gray Frost Payload delivery system C++.NET CLR Bootstrapper Creates or injects 4.0 runtime Capability to pivot into 2.0 runtime Contains raw payload

Gray Frost Payload delivery system C++.NET CLR Bootstrapper Creates or injects 4.0 runtime Capability to pivot into 2.0 runtime Contains raw payload 2 Rounds GrayFrostCpp GrayFrostCSharp C# Payload

Round 1.NET Process

Round 1 GrayFrostCpp Mscoree

GrayFrostCpp Round 1

Round 1 GrayFrostCpp GrayFrostCSharp

Round 2.NET Process

Round 2.NET Process GrayFrostCSharp

Round 2.NET Process GrayFrostCSharp payload void main()

Round 2.NET Process Payload

Pivoting Between Runtimes.NET Process

Pivoting Between Runtimes GrayFrostCpp Mscoree

Pivoting Between Runtimes GrayFrostCpp

Pivoting Between Runtimes GrayFrostCpp GrayFrostCSharp

Pivoting Between Runtimes GrayFrostCpp GrayFrostCSharp

Pivoting Between Runtimes GrayFrostCpp

Pivoting Between Runtimes GrayFrostCpp GrayFrostCSharp

Gray Storm

Gray Storm Reconnaissance and In-memory attack payload Features Attacking the.net JIT Attacking.NET at the ASM level ASM and Metasploit payloads Utilize objects on the Managed Heap

Gray Storm Usage

Controlling the JIT Method Tables contain address of JIT stub for a class s methods. During JIT the Method Table is referenced We can control the address Lives after Garbage Collection

Controlling the JIT

Controlling the JIT

Controlling the JIT

Control Flow Attacks.NET uses far and relative calls 0xE8; Call [imm] (x86) 0xFF 0x15; Call dword segmentregister[imm] (x86) relcall = dstaddress - (currentlocation+ lenofcall)

ASM Payloads Address of a method known through Reflection Overwrite method logic with new ASM Steal stack parameters Change events

ASM Payloads Change return TRUE to return FALSE Password validation Key & Licensing validation SQL Sanitization Destroy security Mechanisms Overwrite logic Update Mechanisms

ASM Payloads

ASM Payloads Metasploit Hand Rolled Portable Environment Block (PEB) changes

Portable Environment Block http://www.tophertimzen.com/blog/shellcodedotnetpeb/

Object Hunting in Memory

Managed Heap Storage point for.net Objects New reference objects added to heap Garbage Collector removes dead objects

Managed Heap Storage point for.net Objects New reference objects added to heap Garbage Collector removes dead objects Let s manipulate it!

Structure

Structure Example System.Double

Object Hunting in Memory Objects are IntPtrs Point to Object Instance on Managed Heap All instantiated objects of the same class share the same Method Table

Object Hunting in Memory Objects are IntPtrs Point to Object Instance on Managed Heap All instantiated objects of the same class share the same Method Table Win Reflection Object Hunting

Finding Objects at Runtime i. Construct an object and find location of Managed Heap ii. Signature instantiated type iii. Scan Managed Heap for object pointers iv. Convert object pointers to raw objects

Finding Objects at Runtime i. Construct an object and find location of Managed Heap ii. Signature instantiated type iii. Scan Managed Heap for object pointers iv. Convert object pointers to raw objects

Construct an Object Use Reflection to invoke a constructor Can instantiate any object Being mindful that some constructors can invoke a lot of code If a constructor takes other objects, nullify them https://gist.github.com/tophertimzen/010b19fdbde77f251414

Find Location of Managed Heap STACK L 024e9fe8 (Object) 00000005 00000001 H 00000000 IntPtr IntPtr = 024e9fe8 = 5 https://gist.github.com/tophertimzen/812aa20dbe23cb42756d

Find Location of Managed Heap L H STACK 024e9fe8 (Object) 00000005 00000001 00000000 IntPtr IntPtr = 024e9fe8 = 5 Managed Heap https://gist.github.com/tophertimzen/812aa20dbe23cb42756d

Find Location of Managed Heap STACK L 024e9fe8 (Object) 00000005 00000001 H 00000000 IntPtr IntPtr = 024e9fe8 = 5 https://gist.github.com/tophertimzen/812aa20dbe23cb42756d

Find Location of Managed Heap STACK L 024e9fe8 (Object) 00000005 00000001 H 00000000 IntPtr = 024e9fe8 https://gist.github.com/tophertimzen/812aa20dbe23cb42756d

Finding Objects at Runtime i. Construct an object and find location of Managed Heap ii. Signature instantiated type iii. Scan Managed Heap for object pointers iv. Convert object pointers to raw objects

Signature Instantiated Type Object Instances contain a Method Table pointer to their corresponding type. (x86) 0:009> dd 024e9fe8 024e9fe8 00774828 0000038c 00000001 00000000 Bytes 0-3 are the Method Table (MT) Bytes 4-7 in MT is Instance Size

Signature Instantiated Type Object Instances contain a Method Table pointer to their corresponding type. (x64) 0:008> dd 00000000024e9fe8 00000000`0286b8e0 ea774828 000007fe Bytes 0-7 are the Method Table (MT) Bytes 8-11 in MT is Instance Size

Finding Objects at Runtime i. Construct an object and find location of Managed Heap ii. Signature instantiated type iii. Scan Managed Heap for object pointers iv. Convert object pointers to raw objects

Scan Managed Heap Scan down incrementing by size of object Scan linearly up to top of heap Compare object s Method Table to the reference If they match, get IntPtr address of object

Scan Managed Heap Scan down incrementing by size of object Scan linearly up to top of heap Compare object s Method Table to the reference If they match, get IntPtr address of object Use ASM!

GrayStorm/objectHunter Using ASM!

Finding Objects at Runtime i. Construct an object and find location of Managed Heap ii. Signature instantiated type iii. Scan Managed Heap for object pointers iv. Convert object pointers to raw objects

Convert Object ptr -> raw obj L H STACK Refer (System.IntPtr) pointer(024ea00c ) https://gist.github.com/tophertimzen/1da2b0aab6245ed1c27b

Convert Object ptr -> raw obj L H STACK Refer pointer(024ea00c (System.IntPtr) ) pointer(024ea00c ) https://gist.github.com/tophertimzen/1da2b0aab6245ed1c27b

Convert Object ptr -> raw obj L H STACK Refer (GrayStorm.testClass) pointer(024ea00c ) https://gist.github.com/tophertimzen/1da2b0aab6245ed1c27b

Superpowers and Things? Change Keys Change Fields / Properties Call Methods With arguments!

Automation

Automation GrayFrost can be used with automated payloads

Automations == <3

Constructing Attack Chains

How to construct attack chains Gray Wolf / IL Decompiler Find Methods, Fields & Properties of interest Locate meaningful objects Discover high level control flow Gray Storm Debugging functionality Breakpoint at constructors or methods from Method Pointers Use with WinDbg Utilize DLL Hijacking!

Hybrid.NET/ASM Attacks Hybrid C#/ASM code in.net Encrypting.NET payloads and unwinding Encrypting ASM Payloads

Payload System C# is easy Can use Gray Frost in any application Low and High level gap is easy

.NET Hacking Space Small Few tools Mostly hacking WoW Lots of PowerShell Lots of decompilers and not many attackers!

Conclusion Arbitrary.NET applications can be injected and changed New.NET attack possibilities New tools that support automation Get Gray Frost and Storm github.com/graykernel

Questions? Contact Me @TTimzen https://www.tophertimzen.com Get Gray Frost and Storm github.com/graykernel White Papers Hijacking Arbitrary.NET Application Control Flow Acquiring.NET Objects from the Managed Heap