Repository navigation
Expand file tree
/
Copy pathentry.cpp
More file actions
198 lines (165 loc) · 4.39 KB
/
Copy pathentry.cpp
File metadata and controls
198 lines (165 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include "core.hpp"
KAPC_STATE Apc;
KAPC_STATE Apc2;
PVOID currentWin32Thread = 0;
PEPROCESS currentProcess = 0;
PETHREAD currentThread = 0;
CLIENT_ID currentCid = { 0 };
bool isWin32Thread = false;
PETHREAD GetValidWin32Thread( PVOID* win32Thread )
{
int currentThreadId = 1;
NTSTATUS status = STATUS_SUCCESS;
do
{
PETHREAD currentEthread = 0;
status = PsLookupThreadByThreadId( ( HANDLE ) currentThreadId, ¤tEthread );
if ( !NT_SUCCESS( status ) || !currentEthread )
{
currentThreadId++;
continue;
}
if ( PsIsThreadTerminating( currentEthread ) )
{
currentThreadId++;
continue;
}
PVOID Win32Thread = PsGetThreadWin32Thread( currentEthread );
//memcpy(&Win32Thread, (PVOID)((UINT64)currentEthread + win32ThreadOffset), sizeof(PVOID));
if ( Win32Thread )
{
PEPROCESS threadOwner = PsGetThreadProcess( currentEthread );
char procName[ 15 ];
memcpy( &procName, PsGetProcessImageFileName( threadOwner ), sizeof( procName ) );
if ( !strcmp( procName, "explorer.exe" ) )
{
*win32Thread = Win32Thread;
return currentEthread;
}
}
currentThreadId++;
} while ( 0x3000 > currentThreadId );
return 0;
}
inline void SpoofWin32Thread( PVOID newWin32Value, PEPROCESS newProcess, CLIENT_ID newClientId )
{
PKTHREAD currentThread = KeGetCurrentThread( );
PsSetThreadWin32Thread( currentThread, newWin32Value, PsGetThreadWin32Thread( currentThread ) );
PVOID processPtr = ( PVOID ) ( ( char* ) currentThread + processOffset );
memcpy( processPtr, &newProcess, sizeof( PEPROCESS ) );
PVOID clientIdPtr = ( PVOID ) ( ( char* ) currentThread + cidOffset );
memcpy( clientIdPtr, &newClientId, sizeof( CLIENT_ID ) );
}
bool SpoofWin32Thread( )
{
if ( isWin32Thread )
{
_DbgPrint( "already win32\n" );
return true;
}
PVOID targetWin32Thread = 0;
PETHREAD targetThread = GetValidWin32Thread( &targetWin32Thread );
if ( !targetWin32Thread || !targetThread )
{
_DbgPrint( "failed to find win32thread" );
return false;
}
PEPROCESS targetProcess = PsGetThreadProcess( targetThread );
CLIENT_ID targetCid = { 0 };
memcpy( &targetCid, ( PVOID ) ( ( char* ) targetThread + cidOffset ), sizeof( CLIENT_ID ) );
KeStackAttachProcess( targetProcess, &Apc );
SpoofWin32Thread( targetWin32Thread, targetProcess, targetCid );
isWin32Thread = true;
}
void UnspoofWin32Thread( )
{
if ( !isWin32Thread )
return;
SpoofWin32Thread( currentWin32Thread, currentProcess, currentCid );
KeUnstackDetachProcess( &Apc );
isWin32Thread = false;
}
VOID
ThreadEntry
(
PVOID Ctx
)
{
currentProcess = IoGetCurrentProcess( );
currentThread = KeGetCurrentThread( ); // __readgsqword(0x188u)
//_ETHREAD->_CLIENT_ID Cid;
memcpy( ¤tCid, ( PVOID ) ( ( char* ) currentThread + cidOffset ), sizeof( CLIENT_ID ) );
KeStackAttachProcess(
(PRKPROCESS)_Client,
&Apc2
);
PHYSICAL_ADDRESS PhysShared = MmGetPhysicalAddress(
reinterpret_cast< PVOID >( _SharedMemAddr )
);
if ( PhysShared.QuadPart )
{
SharedMem = reinterpret_cast< c_SharedMem* >(
MmMapIoSpace(
PhysShared,
sizeof( SharedMem ),
MmNonCached
)
);
}
KeUnstackDetachProcess(
&Apc2
);
if ( SharedMem )
{
while ( TRUE )
{
if ( !SpoofWin32Thread( ) && !isWin32Thread )
{
_DbgPrint( "Spoof thread failed\n" );
continue;
}
if ( !pCore::SendSharedMemTick( ) )
{
_DbgPrint( "Sent tick failed\n" );
continue;
}
UnspoofWin32Thread( );
YieldProcessor( );
}
}
ObDereferenceObject( _Client );
}
NTSTATUS
ReroutedEntry(
std::uint64_t SharedMemAddr,
std::uint32_t ClientPID
)
{
_SharedMemAddr = SharedMemAddr;
_ClientPID = ClientPID;
_DbgPrint( "wowbigweaponssir -> Shared mem ptr -> 0x%llp\n", _SharedMemAddr );
_DbgPrint( "wowbigweaponssir -> Client proc ID-> 0x%llp\n", _ClientPID );
if ( !NT_SUCCESS( // [amap] driver entry returned [0xC0000001L]
PsLookupProcessByProcessId(
HANDLE( ClientPID ),
&_Client
)
)
)
{
return STATUS_UNSUCCESSFUL; // [amap] driver entry returned [0xC0000001L]
}
HANDLE SystemThreadHdl;
PsCreateSystemThread(
&SystemThreadHdl,
THREAD_ALL_ACCESS,
NULL,
NULL,
NULL,
ThreadEntry,
NULL
);
return ZwClose(
SystemThreadHdl // [amap] driver entry returned [0x00000000L]
);
}