HexRaysCodeXplorer: object oriented RE for fun and profit Alexander Matrosov @matrosov

Eugene Rodionov @vxradius

Agenda  C++ Code Reconstruction Problems

 Show problems on real examples (Flamer)  HexRaysCodeXplorer v1.5 [H2HC Edition]

C++ Code Reconstruction Problems  Object identification Type reconstruction

 Class layout reconstruction    

Identify constructors/destructors Identify class members Local/global type reconstruction Associate object with exact method calls

 RTTI reconstruction  Vftable reconstruction  Associate vftable object with exact object  Class hierarchy reconstruction

C++ Code Reconstruction Problems Class A vfPtr a1() A::vfTable

a2()

meta RTTI Object Locator signature pTypeDescriptor pClassDescriptor

A::a1() A::a2()

C++ Code Reconstruction Problems

REconstructing Flamer Framework

An overview of the Flamer Framework Vector

Vector DB_Query

ClanCmd

FileCollect

Driller

GetConfig

Munch

FileFinder

Mobile Consumer

Cmd Consumer

Vector IDLER

CmdExec

Sniffer

Lua Consumer Vector Media Consumer

Euphoria

Share Supplier

LSS Sender

Frog

Beetlejuice

http://www.welivesecurity.com/2012/08/02/flamer-analysis-framework-reconstruction/

An overview of the Flamer Framework Vector

Vector DB_Query

ClanCmd

FileCollect

Driller

GetConfig

Munch

FileFinder

Mobile Consumer

Cmd Consumer

Vector IDLER

CmdExec

Sniffer

Lua Consumer Vector Media Consumer

Euphoria

Share Supplier

LSS Sender

Frog

Beetlejuice

http://www.welivesecurity.com/2012/08/02/flamer-analysis-framework-reconstruction/

An overview of the Flamer Framework Vector

Vector DB_Query

ClanCmd

FileCollect

Driller

GetConfig

Munch

FileFinder

Mobile Consumer

Cmd Consumer

Vector IDLER

CmdExec

Sniffer

Lua Consumer Vector Media Consumer

Euphoria

Share Supplier

LSS Sender

Frog

Beetlejuice

http://www.welivesecurity.com/2012/08/02/flamer-analysis-framework-reconstruction/

Identify Smart Pointer Structure

o Smart pointers

o Strings o Vectors to maintain the objects o Custom data types:    

wrappers tasks, triggers and etc.

Data Types Being Used: Smart pointers typedef struct SMART_PTR { void *pObject; // pointer to the object int *RefNo; // reference counter };

Identify Smart Pointer Structure

Data Types Being Used: Vectors struct VECTOR { void *vTable; int NumberOfItems; int MaxSize; void *vector; };

// // // //

pointer to the table self-explanatory self-explanatory pointer to buffer with elements

o Used to handle the objects:  tasks  triggers  etc.

Identify Exact Virtual Function Call in Vtable

Identify Exact Virtual Function Call in Vtable

Identify Custom Type Operations

Data Types Being Used: Strings struct USTRING_STRUCT { void *vTable; int RefNo; int Initialized; wchar_t *UnicodeBuffer; char *AsciiBuffer; int AsciiLength; int Reserved; int Length; int LengthMax; };

// pointer to the table // reference counter

// pointer to unicode string // pointer to ASCII string // length of the ASCII string // Length of unicode string // Size of UnicodeBuffer

Identify Objects Constructors

Identify Objects Constructors

REconstructing Object’s Attributes

REconstructing Object’s Attributes

REconstructing Object’s Methods

REconstructing Object’s Methods

HexRaysCodeXplorer

HexRaysCodeXplorer v1.0: released in 2013 at REcon

HexRaysCodeXplorer Features

o Hex-Rays decompiler plugin o The plugin was designed to facilitate static analysis of:  object oriented code  position independent code

o The plugin allows to:  navigate through decompiled virtual methods  partially reconstruct object type

Hex-Rays Decompiler Plugin SDK

o At the heart of the decompiler lies ctree structure:  syntax tree structure  consists of citem_t objects  there are 9 maturity levels of the ctree structure

Hex-Rays Decompiler Plugin SDK

o At the heart of the decompiler lies ctree structure:  syntax tree structure  consists of citem_t objects  there are 9 maturity levels of the ctree structure

Hex-Rays Decompiler Plugin SDK citem_t

o Type citem_t is a base class for:  

cexpr_t – expression type cinsn_t – statement type

cexpr_t

cinsn_t

o Expressions have attached type information o Statements include:  block, if, for, while, do, switch, return, goto, asm

o Hex-Rays provides iterators for traversing the citem_t objects within ctree structure:  ctree_visitor_t  ctree_parentee_t

Hex-Rays Decompiler Plugin SDK citem_t

o Type citem_t is a base class for:  

cexpr_t – expression type cinsn_t – statement type

cexpr_t

cinsn_t

o Expressions have attached type information o Statements include:  block, if, for, while, do, switch, return, goto, asm

o Hex-Rays provides iterators for traversing the citem_t objects within ctree structure:  ctree_visitor_t  ctree_parentee_t

DEMO time :)

HexRaysCodeXplorer: Gapz Position Independent Code

HexRaysCodeXplorer: Virtual Methods  The IDA’s ‘Local Types’ is used to represent object type

HexRaysCodeXplorer: Virtual Methods  Hex-Rays decompiler plugin is used to navigate through the virtual methods

HexRaysCodeXplorer: Virtual Methods  Hex-Rays decompiler plugin is used to navigate through the virtual methods

HexRaysCodeXplorer: Object Type REconstruction

o Hex-Rays’s ctree structure may be used to partially reconstruct object type based on its initialization routine (constructor) o Input:  pointer to the object instance  object initialization routine entry point

o Output:  C structure-like object representation

HexRaysCodeXplorer: Object Type REconstruction

citem_t objects to monitor:  memptr  idx  memref

 call (LOBYTE, etc.)

HexRaysCodeXplorer: Object Type REconstruction

// reference of DWORD at offset 12 in buffer a1 *(DWORD *)(a1 + 12) = 0xEFCDAB89;

HexRaysCodeXplorer v1.5 [H2HC Edition]

o New citem_t objects to monitor:     

memptr idx memref call (LOBYTE, etc.) ptr, asg, …

HexRaysCodeXplorer v1.5 [H2HC Edition]

o New citem_t objects to monitor:     

memptr idx memref call (LOBYTE, etc.) ptr, asg, …

o Type propagation for nested function calls

HexRaysCodeXplorer v1.5 [H2HC Edition]

o Features of v1.5 [H2HC Edition] :  Better Type Reconstruction • •

   

Improvements for parsing citem_t objects with PTR and ASG statements Recursive traversal of Ctree to reconstruct Types hierarchy

Navigate from Pseudo code window to Disassembly line Hints for Ctree elements which point to Disassembly line Support for x64 version of Hex-Rays Decompiler Some bug fixes by user requests

DEMO time :)

HexRaysCodeXplorer: -> What are the next goals? o Develop the next version on IdaPython

o Focus on the following features:     

Type reconstruction (C++, Objective-C) Type Navigation (C++, Objective-C) Vtables parsing based on Hex-Rays API Ctree graph navigation improvements Patterns for possible vuln detection

Why python?

Python Arsenal Contest  Best exploit dev tool/plugin/lib

 Best forensics tool/plugin/lib  Best reversing tool/plugin/lib  Best fuzzing tool/plugin/lib

 Best malware analysis tool/plugin/lib http://2014.zeronights.org/contests/python-arsenal-contest.html

Thank you for your attention! HexRaysCodeXplorer http://REhints.com

@REhints

https://github.com/REhints/HexRaysCodeXplorer

RTTI reconstruction - GitHub

Mobile. Consumer. Cmd. Consumer. Munch. Sniffer. FileFinder. FileCollect. Driller ... o Custom data types: ✓ wrappers ... Identify Custom Type Operations ...

2MB Sizes 20 Downloads 260 Views

Recommend Documents

CopperDroid - On the Reconstruction of Android Malware ... - GitHub
Oct 11, 2014 - Android apps written (mostly) in Java and run in a Java-like. (Dalvik) VM as .... THE BINDER PROTOCOL. IPC/RPC. The Binder protocol enables fast inter-process communication between Apps or between Apps and the system. It also allows ..

Schematic Surface Reconstruction - Semantic Scholar
multiple swept surfaces, of which the transport curves lie in horizontal planes. This section will introduce the basic reconstruction framework that initializes a set ...

Schematic Surface Reconstruction - Changchang Wu
This paper introduces a schematic representation for architectural scenes together with robust algorithms for reconstruction from sparse 3D point cloud data. The.

ODT data reconstruction
ODT data reconstruction is an issue related to the coupling of the one-dimensional ..... velocity, u cell average u. −. , u. + f. −. , f. +. Fromm slope cell boundary, k.

Reconstruction Urdu-Lec-6.pdf
قومی شاعر، جدید مسلم فالسفر، مفکر، دانشور اور قانون دان. کےعالوہ بانیان ... The Conception of God and the Meaning of Prayer ... Reconstruction Urdu-Lec-6.pdf.

Market Reconstruction 2.0: Visualization at Scale - FIS
24 Mar 11:52:33 | |- id: string. |. |. | |- Parent: ..... at http://frozeman.de/blog/2013/08/why-is-svg-so-slow/ ... Market Reconstruction 2.0: Visualization at Scale 24.

Reconstruction of Threaded Conversations in Online Discussion ...
tive of topic detection and tracking (Allan 2002) and dis- .... The decision trees' big advantage is its ability to handle .... It can not handle big amounts of data in an.

Active learning via Neighborhood Reconstruction
State Key Lab of CAD&CG, College of Computer Science,. Zhejiang ..... the degree of penalty. Once the ... is updated by the following subproblems: ˜anew.

Online PDF America s Reconstruction
... and world stock market news business news financial news and more James Earl ... anthropology human rights jobs public Earth’ s ancient oceans were rife .... lithographs, and political cartoons, as well as objects such as sculptures, ...

Gene Regulatory Network Reconstruction Using ...
Dec 27, 2011 - functional properties [5,6] all use the representation of gene regulatory networks. Initially, specific ..... bluntly implemented using a general linear programming solver. The use of a dedicated ..... php/D5c3. Directed networks of ..

Image Reconstruction in the Gigavision Camera
photon emission computed tomography. IEEE Transactions on Nuclear Science, 27:1137–1153, June 1980. [10] S. Kavadias, B. Dierickx, D. Scheffer, A. Alaerts,.

mobilizing capacity for reconstruction and development - Human ...
4.9 Paying the Price of Conflict: A Strategic Challenge ...... which deals with governance, democracy and the rule ..... money monthly to a member of the club.

Oversampled Linear-Phase Perfect Reconstruction ...
Email: {ytanaka, ikehara}@tkhm.elec.keio.ac.jp. Truong Q. ... Email: [email protected]. Abstract—This ..... image coding,” IEEE Trans. Signal Process., vol.

Distance Matrix Reconstruction from Incomplete Distance ... - CiteSeerX
Email: drinep, javeda, [email protected]. † ... Email: reino.virrankoski, [email protected] ..... Lemma 5: S4 is a “good” approximation to D, since.

Reconstruction of Orthogonal Polygonal Lines
algorithm has a low computational complexity and can be used for restoration of orthogonal polygonal lines with many vertices. It was developed for a raster- to-vector conversion system ArcScan for ArcGIS and can be used for interactive vectorization