-
Notifications
You must be signed in to change notification settings - Fork 55
Replace internal CreateThread calls with an internal implementation to avoid monitor detection by NtQueryInformationThread using ThreadQuerySetWin32StartAddress #95
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
base: capemon
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -799,6 +799,47 @@ DWORD tid_from_thread_handle(HANDLE thread_handle) | |||||||||||||||||||||||||||||
return (DWORD)(ULONG_PTR)cid.UniqueThread; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
VOID CALLBACK thread_callback(PVOID context_param, BOOLEAN timeout) | ||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||
THREAD_CONTEXT *context = (THREAD_CONTEXT*)context_param; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if (context->thread_id) | ||||||||||||||||||||||||||||||
*context->thread_id = GetCurrentThreadId(); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
context->start_routine(context->parameter); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
SetEvent(context->event); | ||||||||||||||||||||||||||||||
CloseHandle(context->event); | ||||||||||||||||||||||||||||||
free(context); | ||||||||||||||||||||||||||||||
Comment on lines
+811
to
+813
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding error handling around
Suggested change
|
||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
HANDLE our_createthread(PTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD *lpThreadId) | ||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||
HANDLE timer = NULL; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
THREAD_CONTEXT *context = (THREAD_CONTEXT*)calloc(1, sizeof(THREAD_CONTEXT)); | ||||||||||||||||||||||||||||||
if (!context) | ||||||||||||||||||||||||||||||
return NULL; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
context->start_routine = lpStartAddress; | ||||||||||||||||||||||||||||||
context->parameter = lpParameter; | ||||||||||||||||||||||||||||||
context->thread_id = lpThreadId; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
context->event = CreateEvent(NULL, TRUE, FALSE, NULL); | ||||||||||||||||||||||||||||||
if (!context->event) { | ||||||||||||||||||||||||||||||
free(context); | ||||||||||||||||||||||||||||||
return NULL; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if (!CreateTimerQueueTimer(&timer, NULL, thread_callback, context, 0, 0, WT_EXECUTEDEFAULT)) { | ||||||||||||||||||||||||||||||
CloseHandle(context->event); | ||||||||||||||||||||||||||||||
free(context); | ||||||||||||||||||||||||||||||
return NULL; | ||||||||||||||||||||||||||||||
Comment on lines
+834
to
+837
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
return context->event; | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function returns the event handle, but the actual thread execution is asynchronous via a timer. If the timer creation fails, the event handle is closed and memory is freed. However, if the timer creation succeeds, the caller receives the event handle but has no direct way to manage the timer's lifecycle. This could lead to confusion and potential resource leaks if the caller expects a traditional thread handle. Consider returning the timer handle instead of the event handle, or providing a separate function to manage the timer's lifecycle.
Suggested change
|
||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
DWORD our_getprocessid(HANDLE Process) | ||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||
DWORD ret; | ||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thread ID is retrieved within the
thread_callback
function usingGetCurrentThreadId()
. This ID is then stored in thecontext->thread_id
pointer. However, the thread might terminate before the ID is retrieved, leading to a potential race condition or incorrect thread ID being stored. Consider using a synchronization mechanism to ensure that the thread ID is retrieved before the thread terminates, or use a different approach to retrieve the thread ID.