Successfully reported this slideshow.
Your SlideShare is downloading. ×

Object Oriented Code RE with HexraysCodeXplorer

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad

Check these out next

1 of 61 Ad

Object Oriented Code RE with HexraysCodeXplorer

Download to read offline

In recent time we see a large spike of complex threats with elaborate object-oriented architecture among which the most notorious examples are: Stuxnet, Flamer, Duqu.

The approaches to analysis of such malware are rather distinct compared to the malware developed using procedural programming languages.

This presentation will take an in-depth look at challenges related to reversing object-oriented code with respect to modern malware and demonstrate approaches and tools employed for reversing object-oriented code.

In recent time we see a large spike of complex threats with elaborate object-oriented architecture among which the most notorious examples are: Stuxnet, Flamer, Duqu.

The approaches to analysis of such malware are rather distinct compared to the malware developed using procedural programming languages.

This presentation will take an in-depth look at challenges related to reversing object-oriented code with respect to modern malware and demonstrate approaches and tools employed for reversing object-oriented code.

Advertisement
Advertisement

More Related Content

Slideshows for you (20)

Viewers also liked (20)

Advertisement

Similar to Object Oriented Code RE with HexraysCodeXplorer (20)

Recently uploaded (20)

Advertisement

Object Oriented Code RE with HexraysCodeXplorer

  1. 1. Object Oriented Code RE with HexRaysCodeXplorer Eugene Rodionov @vxradius Alex Matrosov @matrosov
  2. 2. Agenda * Object Oriented Code Reversing Challenges -- virtual methods -- templates * Reversing Object Oriented Malware -- Flamer -- Sednit * HexRaysCodeXplorer in use
  3. 3. Modern C++ Malware for Targeted Attacks
  4. 4. Why reversing C++ code is a hard problem? Virtual Methods & Templates
  5. 5. Virtual Methods class Cat { private: int _weight; public: Cat(int weight) : _weight(weight) {}; int eat(int food) { return _weight += food; }; }; int _tmain(int argc, _TCHAR* argv[]) { Cat* cat = new Cat(130); int newWeigth = cat->eat(20); } class Animal { protected: int _weight; public: Animal(int weight) : _weight(weight) {}; virtual int eat(int food) = 0; }; class Cat : Animal { public: Cat(int weight) : Animal(weight) {}; virtual int eat(int food) { return _weight += food; }; }; int _tmain(int argc, _TCHAR* argv[]) { Animal* cat = new Cat(130); int newWeight = cat->eat(20); } vs
  6. 6. Virtual Methods class Cat { private: int _weight; public: Cat(int weight) : _weight(weight) {}; int eat(int food) { return _weight += food; }; }; int _tmain(int argc, _TCHAR* argv[]) { Cat* cat = new Cat(130); int newWeigth = cat->eat(20); } class Animal { protected: int _weight; public: Animal(int weight) : _weight(weight) {}; virtual int eat(int food) = 0; }; class Cat : Animal { public: Cat(int weight) : Animal(weight) {}; virtual int eat(int food) { return _weight += food; }; }; int _tmain(int argc, _TCHAR* argv[]) { Animal* cat = new Cat(130); int newWeight = cat->eat(20); } vs
  7. 7. Virtual Function Tables Class A vfPtr attr_1 attr_2 A::vfTable A::a1() A::a2() A::a3() RTTI Object Locator signature pTypeDescriptor pClassDescriptor meta
  8. 8. Virtual Function Tables Class A vfPtr attr_1 attr_2 A::vfTable A::a1() A::a2() A::a3() RTTI Object Locator signature pTypeDescriptor pClassDescriptor meta
  9. 9. Virtual Function Tables * lead to indirect method calls -- difficult to analyze statically * initialized in constructors -- need to track back object creation
  10. 10. C++ Templates * extra code to analyze -- another way to create polymorphic types * problematic to recognize standard library code (FLIRT) -- playing with compiler optimization options std::vector<int> std::vector<char> std::vector<std::string> std::vector<custom_type>
  11. 11. 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
  12. 12. Reversing Object Oriented Malware Practical Approaches: REconstructing Flamer Framework
  13. 13. REconstructing Flamer Framework Vector<Command Executor> DB_Query ClanCmd Vector<Task> IDLER CmdExec Vector<DelayedTasks> Euphoria Share Supplier Vector<Consumer> Mobile Consumer Cmd Consumer MunchSniffer FileFinder FileCollect Driller GetConfig LSS Sender Frog Beetlejuice Lua Consumer Media Consumer http://www.welivesecurity.com/2012/08/02/flamer-analysis-framework-reconstruction/
  14. 14. REconstructing Flamer Framework Vector<Command Executor> DB_Query ClanCmd Vector<Task> IDLER CmdExec Vector<DelayedTasks> Euphoria Share Supplier Vector<Consumer> Mobile Consumer Cmd Consumer MunchSniffer FileFinder FileCollect Driller GetConfig LSS Sender Frog Beetlejuice Lua Consumer Media Consumer http://www.welivesecurity.com/2012/08/02/flamer-analysis-framework-reconstruction/
  15. 15. Identifying Used Types * Smart pointers * Strings * Vectors to maintain objects * Custom data types: -- tasks -- triggers -- and etc.
  16. 16. Data Types Being Used: Smart pointers struct SMART_PTR { void *pObject; // pointer to the object int *RefNo; // reference counter };
  17. 17. Data Types Being Used: Smart pointers
  18. 18. Data Types Being Used: Vectors struct VECTOR { void *vTable; // pointer to the virtual table int NumberOfItems; // self-explanatory int MaxSize; // self-explanatory void *vector; // pointer to buffer with elements }; * Used for handling objects: -- tasks -- triggers
  19. 19. Data Types Being Used: Strings struct USTRING_STRUCT { void *vTable; // pointer to the table int RefNo; // reference counter int Initialized; wchar_t *UnicodeBuffer; // pointer to unicode string char *AsciiBuffer; // pointer to ASCII string int AsciiLength; // length of the ASCII string int Reserved; int Length; // Length of unicode string int LengthMax; // Size of UnicodeBuffer };
  20. 20. Approaching Flamer * Identify Object Constructors * Reconstruct Object Attributes * Reconstruct Object Methods Type reconstruction Control Flow Graph Reconstruction
  21. 21. Identifying Object Constructors
  22. 22. REconstructing Object’s Attributes
  23. 23. REconstructing Object’s Attributes
  24. 24. REconstructing Object’s Methods
  25. 25. REconstructing Object’s Methods
  26. 26. REconstructing Object’s Methods
  27. 27. Reversing Object Oriented Malware Practical Approaches: REconstructing XAgent Framework
  28. 28. XAgent Framework Communication Channels Vector<IAgentChannel> AgentKernel Local Storage Cryptor Agent Modules Vector<IAgentModule> AgentKernel Module FileSystem Channel Controller DNameNode Module Remote KeyLogger Process Retranslator Module WinHttp http://www.welivesecurity.com/2014/10/08/sednit-espionage-group-now-using-custom-exploit-kit/
  29. 29. Object Interconnection: IAgentModule struct IAgentModule { LPVOID receiveMessage; LPVOID sendMessage; LPVOID getModuleId; LPVOID setModuleId; LPVOID executeModule; }; AgentKernel Module FileSystem Module Remote Keylogger Process Retranslator Module IAgentModule
  30. 30. Exploring RTTI* * recover type names * reconstruct class hierarchy * identify object virtual function tables * IDA ClassInformer plugin
  31. 31. Exploring RTTI* * recover type names * reconstruct class hierarchy * identify object virtual function tables * IDA ClassInformer plugin
  32. 32. XAgent: LocalDataStorage Local DataStorage Registry reader/writer File reader/writer
  33. 33. XAgent: Cryptor
  34. 34. XAgent: Cryptor encrypted message salt (4 bytes) RC4key plain text
  35. 35. XAgent: IReservedApi
  36. 36. XAgent: Identifying Used Types * Strings: std::string * Containers to maintain objects: -- std::vector -- std::list
  37. 37. XAgent: Identifying Used Types * Strings: std::string * Containers to maintain objects: -- std::vector -- std::list
  38. 38. HexRaysCodeXplorer
  39. 39. HexRaysCodeXplorer since 2013 * CodeXplorer V1.0 released on REcon’2013 * First third-party plugin for Hex-Rays Decompiler * v1.0 supports IDA v6.4 and Decompiler for x86 v1.8
  40. 40. HexRaysCodeXplorer Features * Hex-Rays decompiler plugin x86/x64 * The plugin was designed to facilitate static analysis of: -- object oriented code -- position independent code * The plugin allows to: -- partially reconstruct object type -- navigate through decompiled virtual methods
  41. 41. Hex-Rays Decompiler Plugin SDK * 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
  42. 42. * Type citem_t is a base class for: -- cexpr_t – expression type -- cinsn_t – statement type * Expressions have attached type information * Statements include: -- block, if, for, while, do, switch, return, goto, asm * 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 cexpr_t cinsn_t
  43. 43. * Type citem_t is a base class for: -- cexpr_t – expression type -- cinsn_t – statement type * Expressions have attached type information * Statements include: -- block, if, for, while, do, switch, return, goto, asm * 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 cexpr_t cinsn_t
  44. 44. DEMO time :)
  45. 45. HexRaysCodeXplorer: Gapz Position Independent Code
  46. 46. HexRaysCodeXplorer: Virtual Methods IDA’s ‘Local Types’ is used to represent object type
  47. 47. HexRaysCodeXplorer: Virtual Methods IDA’s ‘Local Types’ is used to represent object type
  48. 48. HexRaysCodeXplorer: Virtual Methods * Hex-Rays decompiler plugin is used to navigate through the virtual methods
  49. 49. HexRaysCodeXplorer: Object Type REconstruction * Hex-Rays’s ctree structure may be used to partially reconstruct object type * Input: -- pointer to the object instance -- object initialization routine entry point * Output: -- C structure-like object representation
  50. 50. HexRaysCodeXplorer: Object Type REconstruction * citem_t objects: -- memptr, idx, memref -- call, ptr, asg
  51. 51. HexRaysCodeXplorer: Object Type REconstruction * citem_t objects: -- memptr, idx, memref -- call, ptr, asg
  52. 52. HexRaysCodeXplorer: Object Type REconstruction // reference of DWORD at offset 12 in buffer a1 *(DWORD *)(a1 + 12) = 0xEFCDAB89;
  53. 53. HexRaysCodeXplorer: v1.7 [NSEC Edition] Automatic virtual table identification + Type reconstruction
  54. 54. HexRaysCodeXplorer: v1.7 [NSEC Edition] * Automatic virtual table identification
  55. 55. HexRaysCodeXplorer: v1.7 [NSEC Edition] * Automatic virtual table identification
  56. 56. HexRaysCodeXplorer: v1.7 [NSEC Edition] * Automatic virtual table identification * Support for IDA Pro x64 * Bugfixes
  57. 57. DEMO time :)
  58. 58. HexRaysCodeXplorer: Next plans * Switch to IdaPython
  59. 59. Why python?
  60. 60. HexRaysCodeXplorer: Next plans * Switch to IdaPython * Further research & development: -- find cross-references to object attributes -- handling nested structures -- code similarity based on data flow analysis
  61. 61. Thank you for your attention! http://REhints.com @Rehints https://github.com/REhints/HexRaysCodeXplorer

×