Skip to content

MSVC and MinGW meterpreter and extensions cannot be mixed #758

@dledda-r7

Description

@dledda-r7

I have spent some time triaging the segment fault I was having while working on the split of the standard API.
Turns out neither MSVC nor MinGW builds are broken, they are just incopatible between each other.

Root Cause

During my testing I was working with a MSVC compiled metsrv (the default embedded in the gem) and a mingw compiled stdapi. today after obtaining a debuggable mingw stdapi build I have triaged the segment fault occur in a free call performed inside the fs_getwd function.
Little background: When we perform load stdapi, by default, we will do a sysinfo and get the current working directory that's why we are calling that function after performing a load.

The fs_getwd function, inside the fs_win.c get a WCHAR that need to be converted to UTF8 before being embedded inside the TLV package, However, in order to do that, we use a function helper wchar_to_utf8 declared inside the metsrv unicode.c file and passed to the extension using the metapi structure. the output string is allocated with calloc INSIDE THE METSRV DLL and then is FREED INSIDE THE STDAPI DLL. Here is the catch, the calloc() and free() looks to be different across MSVC and MinGW, meaning we will not be able to free a chunk of memory allocated with one compiler using the free of the other.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions