-
Notifications
You must be signed in to change notification settings - Fork 0
/
mac.cc
346 lines (242 loc) · 11 KB
/
mac.cc
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
// mac.cc
#include <windef.h>
#include <winbase.h>
#include <tlhelp32.h>
#include <ws2def.h>
#include <ws2ipdef.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <shellapi.h>
//############################################################################# DEBUG
//#include <ws2tcpip.h>
//#include <winuser.h>
HANDLE gCallbackComplete;
/*
netsh interface ipv4 set address "Ethernet" source=static address=192.168.0.13
MibParameterNotification = 0
MibAddInstance = 1
MibDeleteInstance = 2
MibInitialNotification = 3
IpPrefixOriginOther 0
IpPrefixOriginManual 1
IpPrefixOriginWellKnown 2
IpPrefixOriginDhcp 3
IpPrefixOriginRouterAdvertisement 4
IpPrefixOriginUnchanged 16
IpDadStateInvalid 0
IpDadStateTentative 1
IpDadStateDuplicate 2
IpDadStateDeprecated 3
IpDadStatePreferred 4
https://docs.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-notifyunicastipaddresschange
https://docs.microsoft.com/en-gb/windows/win32/api/netioapi/ns-netioapi-mib_unicastipaddress_row
https://docs.microsoft.com/en-us/windows/win32/api/ws2ipdef/ns-ws2ipdef-sockaddr_inet
https://docs.microsoft.com/en-gb/windows/win32/api/netioapi/nf-netioapi-getunicastipaddressentry
NET_LUID_LH
https://docs.microsoft.com/en-us/windows/win32/api/ifdef/ns-ifdef-net_luid_lh
https://docs.microsoft.com/en-us/windows-hardware/drivers/network/net-luid-value
MibAddInstance
192.168.100.10
MibParameterNotification
192.168.100.10
MibParameterNotification
192.168.100.10
MibDeleteInstance
192.168.100.10
MibAddInstance
5.147.10.61
MibParameterNotification
5.147.10.61
//-------------------------------------------------------------------------
https://docs.microsoft.com/en-us/windows/win32/api/netioapi/ns-netioapi-mib_unicastipaddress_row
https://docs.microsoft.com/en-us/powershell/module/nettcpip/get-netipaddress?view=win10-ps
get-netipaddress -Addressfamily ipv6 -InterfaceAlias "Ethernet 2"
IPAddress : 2a02:908:1869:10e0:436:ad9e:8810:21b9
InterfaceIndex : 4
InterfaceAlias : Ethernet 2
AddressFamily : IPv6
Type : Unicast
PrefixLength : 64
PrefixOrigin : RouterAdvertisement
SuffixOrigin : Link
AddressState : Preferred
ValidLifetime : 01:59:45
PreferredLifetime : 00:00:15
SkipAsSource : False
PolicyStore : ActiveStore
netsh interface ipv6 show addresses "Ethernet 2"
Adresse 2a02:908:1869:10e0:436:ad9e:8810:21b9 Parameter
---------------------------------------------------------
Schnittstellen-LUID : Ethernet 2
Bereichskennung : 0.0
Gültigkeitsdauer : 1h59m49s
Bevorzugte Gültigkeitsdauer : 19s
DAD-Status : Bevorzugt
Adresstyp : Öffentlich
Als Quelle überspringen : false
Verworfen
MibParameterNotification 0
IpDadStateDeprecated 3
MibAddInstance
IpPrefixOriginRouterAdvertisement 4 (link-local: IpPrefixOriginWellKnown 2)
IpSuffixOriginLinkLayerAddress 4 (link-local too !!!)
when ip changes from "deprecated" to "preferred" -> MibParameterNotification 0 (DadState change)
*/
void CALLBACK CallCompleted(PVOID callerContext, PMIB_UNICASTIPADDRESS_ROW row, MIB_NOTIFICATION_TYPE notificationType)
{
DWORD i;
DWORD err = 0;
char ipv6Address[40] = {0};
char myString[255] = {0};
//inet_ntop(AF_INET6, &row->Address.Ipv6.sin6_addr, ipv6Address, sizeof(ipv6Address));
//printf(ipv6Address);
//printf("\n");
//printf("Type: %d", notificationType);
//printf("\n");
//sprintf(myString, "%d", notificationType);
//MessageBox(NULL, myString, "", MB_OK);
if (notificationType == MibAddInstance || notificationType == MibParameterNotification)
//if (0)
//if (1)
{
HMODULE iphlpapi = GetModuleHandle("iphlpapi");
//-----------------------------------------------------------------
typedef NETIOAPI_API WINAPI GetUnicastIpAddressEntry2(_Inout_ PMIB_UNICASTIPADDRESS_ROW Row);
GetUnicastIpAddressEntry2* GetUnicastIpAddressEntry = NULL;
GetUnicastIpAddressEntry = (GetUnicastIpAddressEntry2*) GetProcAddress(iphlpapi, "GetUnicastIpAddressEntry");
//-----------------------------------------------------------------
err = GetUnicastIpAddressEntry(row);
//printf("Prefix: %d", row->PrefixOrigin);
//printf("\n");
if (row->PrefixOrigin == IpPrefixOriginRouterAdvertisement && row->DadState == IpDadStatePreferred)
{
PMIB_UNICASTIPADDRESS_TABLE UnicastTable = NULL;
//-----------------------------------------------------------------
typedef NETIOAPI_API WINAPI DeleteUnicastIpAddressEntry2(_In_ CONST MIB_UNICASTIPADDRESS_ROW *Row);
DeleteUnicastIpAddressEntry2* DeleteUnicastIpAddressEntry = NULL;
DeleteUnicastIpAddressEntry = (DeleteUnicastIpAddressEntry2*) GetProcAddress(iphlpapi, "DeleteUnicastIpAddressEntry");
//-----------------------------------------------------------------
typedef NETIOAPI_API WINAPI GetUnicastIpAddressTable2(_In_ ADDRESS_FAMILY Family, _Outptr_ PMIB_UNICASTIPADDRESS_TABLE *Table);
GetUnicastIpAddressTable2* GetUnicastIpAddressTable = NULL;
GetUnicastIpAddressTable = (GetUnicastIpAddressTable2*) GetProcAddress(iphlpapi, "GetUnicastIpAddressTable");
//-----------------------------------------------------------------
err = GetUnicastIpAddressTable(AF_INET6, &UnicastTable);
//inet_ntop(AF_INET6, &row->Address.Ipv6.sin6_addr, ipv6Address, sizeof(ipv6Address));
//printf("NEW: %s", ipv6Address);
//printf("\n");
for (i = 0; i < UnicastTable -> NumEntries; i++)
{
//if (UnicastTable -> Table[i].DadState == IpDadStateDeprecated)
if (UnicastTable -> Table[i].PrefixOrigin == IpPrefixOriginRouterAdvertisement && memcmp(row -> Address.Ipv6.sin6_addr.u.Byte, UnicastTable -> Table[i].Address.Ipv6.sin6_addr.u.Byte, sizeof(row -> Address.Ipv6.sin6_addr.u.Byte)))
{
//inet_ntop(AF_INET6, &UnicastTable -> Table[i].Address.Ipv6.sin6_addr, ipv6Address, sizeof(ipv6Address));
//printf("DELETE: %s -> %d", ipv6Address, UnicastTable -> Table[i].DadState);
//printf("\n");
DeleteUnicastIpAddressEntry(&UnicastTable -> Table[i]);
}
}
SetEvent(gCallbackComplete);
}
}
}
/*
https://technitium.com/tmac/index.html
x2-xx-xx-xx-xx-xx
x6-xx-xx-xx-xx-xx
xA-xx-xx-xx-xx-xx
xE-xx-xx-xx-xx-xx
MAC spoofing only works with windows 7 if the new MAC's second hex digit is one of the following: 2,6,A,E
HKLM\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}
DriverDesc -> Realtek PCIe GBE Family Controller
https://www.codeproject.com/Tips/1022207/Make-Buzzer-Internal-Speaker-Sound-in-Windows-bit
rundll32 user32.dll,MessageBeep -1
*/
void exec()
{
DWORD i;
DWORD err;
PROCESSENTRY32 pe32;
HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
pe32.dwSize = sizeof(PROCESSENTRY32);
do
{
if (!strcmp("mac.exe", pe32.szExeFile) && pe32.th32ProcessID != GetCurrentProcessId())
{
/*
printf(pe32.szExeFile);
printf("\n");
printf("%d", pe32.th32ProcessID);
printf("\n");
printf("%d", GetCurrentProcessId());
printf("\n");
*/
return;
}
} while (Process32Next(hProcessSnap, &pe32));
//#########################################################################
int nArgs;
wchar_t sSnapshot[20] = {0};
LPWSTR *szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
wcscpy(sSnapshot, L"prefix");
if (nArgs > 1)
{
//printf("SET");
//printf("\n");
wcscpy(sSnapshot, szArglist[1]);
}
//printf("%ws", sSnapshot);
//printf("\n");
//return;
//#########################################################################
//STARTUPINFO startupInfo;
STARTUPINFOW startupInfo;
PROCESS_INFORMATION processInfo;
//wchar_t sParameters[] = {0};
memset(&startupInfo, 0, sizeof(startupInfo));
memset(&processInfo, 0, sizeof(processInfo));
startupInfo.cb = sizeof(startupInfo);
//err = CreateProcess(NULL, "c:\\program files\\vmware\\vmware workstation\\vmrun -T ws reverttosnapshot \"d:\\linux\\linux.vmx\" \"prefix\"", NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &startupInfo, &processInfo);
wchar_t sParameters[] = L"c:\\program files\\vmware\\vmware workstation\\vmrun -T ws reverttosnapshot \"d:\\linux\\linux.vmx\" \"";
wcscat(sParameters, sSnapshot);
wcscat(sParameters, L"\"");
err = CreateProcessW(NULL, sParameters, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &startupInfo, &processInfo);
WaitForSingleObject(processInfo.hProcess, INFINITE);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
//-------------------------------------------------------------------------
//err = CreateProcess(NULL, "c:\\program files\\vmware\\vmware workstation\\vmrun -T ws start \"d:\\linux\\linux.vmx\" nogui", NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &startupInfo, &processInfo);
wcscpy(sParameters, L"c:\\program files\\vmware\\vmware workstation\\vmrun -T ws start \"d:\\linux\\linux.vmx\" nogui");
err = CreateProcessW(NULL, sParameters, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &startupInfo, &processInfo);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
//#########################################################################
HANDLE gNotifyEvent;
char sString[3] = {0};
GetEnvironmentVariable("systemdrive", sString, sizeof(sString));
HMODULE iphlpapi = LoadLibrary(strcat(sString, "\\windows\\System32\\iphlpapi.dll"));
gCallbackComplete = CreateEvent(NULL, FALSE, FALSE, NULL);
//-----------------------------------------------------------------
typedef NETIOAPI_API WINAPI NotifyUnicastIpAddressChange2(_In_ ADDRESS_FAMILY Family, _In_ PUNICAST_IPADDRESS_CHANGE_CALLBACK Callback, _In_opt_ PVOID CallerContext, _In_ BOOLEAN InitialNotification, _Inout_ HANDLE *NotificationHandle);
NotifyUnicastIpAddressChange2* NotifyUnicastIpAddressChange = NULL;
NotifyUnicastIpAddressChange = (NotifyUnicastIpAddressChange2*) GetProcAddress(iphlpapi, "NotifyUnicastIpAddressChange");
//-----------------------------------------------------------------
NotifyUnicastIpAddressChange(AF_INET6, &CallCompleted, "", false, &gNotifyEvent);
//MessageBox(NULL, "aa", "", MB_OK);
WaitForSingleObject(gCallbackComplete, 40000);
//-----------------------------------------------------------------
typedef NETIOAPI_API WINAPI CancelMibChangeNotify3(_In_ HANDLE NotificationHandle);
CancelMibChangeNotify3* CancelMibChangeNotify2 = NULL;
CancelMibChangeNotify2 = (CancelMibChangeNotify3*) GetProcAddress(iphlpapi, "CancelMibChangeNotify2");
//-----------------------------------------------------------------
CancelMibChangeNotify2(gNotifyEvent);
Beep(750, 350);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
//Sleep(5000); return 0;
exec();
}
int main(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
exec();
}