Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

META - vtable detection for C++, ObjectiveC, Dlang and Swift binaries #17134

Open
6 of 16 tasks
pinkflawd opened this issue Feb 26, 2017 · 35 comments
Open
6 of 16 tasks

META - vtable detection for C++, ObjectiveC, Dlang and Swift binaries #17134

pinkflawd opened this issue Feb 26, 2017 · 35 comments
Assignees
Labels
C++ C++ analysis related issues DWARF DWARF symbols and types debug information PDB PDB and CodeView debug symbols formats from Microsoft types Parsing, propagating and inferring simple and complex types

Comments

@pinkflawd
Copy link
Contributor

pinkflawd commented Feb 26, 2017

What should be done (in C, as part of radare2):

  • Parsing vtables
  • Parsing RTTI
  • av commands to view that data
  • Parsing SEH
  • Parsing .eh_frame
  • Connecting classes with their methods
  • Class inheritance - nesting data structs
  • Constructors and destructors autorecognition
  • try/catch/finally recognition and marking
  • arguments recognition
  • ASCII/graphviz graph of class inheritance/structure inheritance
  • Tests with sources for C++, ObjC and Swift, for radare2-regressions

See code at

Examples of similar features in another programs:


Attached binary is malware written in C++, lots of vtables, not detected with av command.
password is infected

banito.zip password: "infected"
2018-asplos.pdf

@Maijin
Copy link
Contributor

Maijin commented Feb 26, 2017

@Maijin
Copy link
Contributor

Maijin commented Mar 1, 2017

See implementation here https://github.com/REhints/HexRaysCodeXplorer

image

@pinkflawd
Copy link
Contributor Author

This blog describes how MS VC++ works quite well http:https://www.openrce.org/articles/full_view/23

The problem with MS VC++ binaries is, that they don't necessarily come with information on their class structure, there is just something called RTTI, which, at least for malware, is almost always stripped. Finding vtables within the binary is done either sweeping the code section for .. well things that look like vtable structures, or, as done by CodeExplorer, starting from the code and searching for constructors and hoping to find a vtable offset within the arguments.
Neat would be, trying to recover not only vtables, but entire object structures. This would require lots of constructor detection, parsing, and I think guessing, though.

I'm sure there are more thorough ways of doing this, will think about it and update this thread.

@XVilka
Copy link
Contributor

XVilka commented Mar 2, 2017

I'm renaming this issue in the [META] for all vtables and C++ metainformation.

@XVilka XVilka changed the title vtable detection for VC++ binaries [META] vtable detection for C++ binaries Mar 2, 2017
@XVilka
Copy link
Contributor

XVilka commented Mar 2, 2017

@codeuchiha for your reference

@PankajKataria
Copy link
Contributor

PankajKataria commented Mar 2, 2017

Thank you @XVilka @pinkflawd @Maijin for providing resources, however I am stuck at parsing RTTI for GCC it will very helpful if some one can point out resources for that too. @pinkflawd yes RTTI (runtime type infromations) structures are present in both cases(MVSC or GCC), it's a way of storing class information and it's inheritance hierarchy by the compiler. I have described the approach we used to find virtual tables for elf files here : https://goo.gl/CDDEI5

@pinkflawd
Copy link
Contributor Author

Cool, thanks for the link!
As for GCC RTTI or RTTI in general I know this presentation http:https://www.hexblog.com/wp-content/uploads/2012/06/Recon-2012-Skochinsky-Compiler-Internals.pdf - contains some info. A note though, not sure how it is with benign binaries, but malware doesn't usually come with RTTI information.

@PankajKataria
Copy link
Contributor

PankajKataria commented Mar 2, 2017

@pinkflawd I totally agree that the binary doesn't always comes with RTTI structures, but we are first aiming to develop for the case where RTTI is present and then will keep improving including different scenarios and Thank you for the link.

@pinkflawd
Copy link
Contributor Author

sure sure :)

@Maijin Maijin changed the title [META] vtable detection for C++ binaries META - vtable detection for C++ binaries Mar 8, 2017
@XVilka
Copy link
Contributor

XVilka commented Aug 2, 2017

Also a scripts from our lovely Binary Ninja https://github.com/trailofbits/binjascripts/tree/master/vtable-navigator

@XVilka
Copy link
Contributor

XVilka commented Sep 14, 2017

Adding one more for vtables/C++ metainfo parsing - https://github.com/igogo-x86/HexRaysPyTools

@awhawks
Copy link

awhawks commented Sep 23, 2017

This from REcon 2011 look useful as well - Practical C++ Decompilation

@XVilka
Copy link
Contributor

XVilka commented Oct 4, 2017

@XVilka XVilka changed the title META - vtable detection for C++ binaries META - vtable detection for C++, ObjectiveC, Dlang and Swift binaries Oct 6, 2017
@XVilka
Copy link
Contributor

XVilka commented Oct 6, 2017

@XVilka
Copy link
Contributor

XVilka commented Oct 6, 2017

@XVilka
Copy link
Contributor

XVilka commented Dec 13, 2017

@radare
Copy link
Collaborator

radare commented Dec 16, 2017

@XVilka
Copy link
Contributor

XVilka commented Dec 22, 2017

@XVilka
Copy link
Contributor

XVilka commented Dec 29, 2017

@Maijin
Copy link
Contributor

Maijin commented Jan 13, 2018

@XVilka
Copy link
Contributor

XVilka commented Feb 13, 2018

Future implementers - note, that current code in libr/core/anal_vt.c is flawed since it targets x86 only. The detection should be crossplatform.

@XVilka
Copy link
Contributor

XVilka commented Feb 28, 2018

@XVilka
Copy link
Contributor

XVilka commented Feb 28, 2018

@thestr4ng3r
Copy link
Contributor

I will try to do msvc soon.

@Maijin
Copy link
Contributor

Maijin commented May 6, 2018

@thestr4ng3r @XVilka @r00tus3r can you check the boxes in the initial post of the issue so we know what is remaining to do here?

@XVilka
Copy link
Contributor

XVilka commented May 7, 2018

@sivaramaaa I think along with types information loading from PDB and DWARF we can load C++ classes as structures at first. Assigning you to think about how it can be done the fastest/easiest way.

@Maijin done, we need to add more tests into r2r for this.

@XVilka
Copy link
Contributor

XVilka commented Jul 19, 2018

@XVilka
Copy link
Contributor

XVilka commented Jan 15, 2019

See also https://github.com/0xgalz/Virtuailor tool for creating automatic C++ virtual tables in IDA Pro based on the runtime information.

@XVilka
Copy link
Contributor

XVilka commented Feb 1, 2019

@XVilka
Copy link
Contributor

XVilka commented Feb 6, 2019

DeClassifier: Class-Inheritance InferenceEngine for Optimized C++ Binaries
1901.10073.pdf

@XVilka
Copy link
Contributor

XVilka commented Oct 29, 2019

@XVilka XVilka pinned this issue Dec 17, 2019
@ret2libc ret2libc transferred this issue from radareorg/radare2 Jun 23, 2020
@XVilka XVilka transferred this issue from radareorg/ideas Jun 23, 2020
@XVilka XVilka added C++ C++ analysis related issues DWARF DWARF symbols and types debug information PDB PDB and CodeView debug symbols formats from Microsoft types Parsing, propagating and inferring simple and complex types labels Jun 23, 2020
@XVilka XVilka added this to To do in Type Analysis Improvements via automation Jun 23, 2020
@radareorg radareorg deleted a comment from ret2libc Jun 23, 2020
@HoundThe
Copy link
Contributor

I guess I can tick, ASCII inheritance graph with this PR #17362

@XVilka
Copy link
Contributor

XVilka commented Sep 29, 2020

See also these for extracting C++ classes information from kernelcache:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ C++ analysis related issues DWARF DWARF symbols and types debug information PDB PDB and CodeView debug symbols formats from Microsoft types Parsing, propagating and inferring simple and complex types
Projects
Development

No branches or pull requests

9 participants