Advertisement
waliedassar

Reversed nt!PiControlQueryConflictList

May 2nd, 2021
1,472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.82 KB | None | 0 0
  1. struct _PLUG_PLAY_QUERY_CONFLICT_LIST_USER
  2. {
  3.   int Sig0;
  4.   int field_4;
  5.   int field_8;
  6.   int field_C;
  7.   int Sig1;
  8. };
  9.  
  10.  
  11.  
  12. struct _PLUG_PLAY_QUERY_CONFLICT_LIST
  13. {
  14.   _UNICODE_STRING uniInstancePath;
  15.   __int64 pUserInfo;
  16.   int UserInfoLength;
  17.   char PadX[4];
  18.   __int64 pBackupMemory;
  19.   int BackupMemorySize;
  20.   int PadY;
  21.   int Status;
  22.   int PadZ;
  23. };
  24.  
  25.  
  26. //InfoClass 0x12
  27. //Size 0x38
  28. int PiControlQueryConflictList
  29. (__int64 InfoClass,
  30. _PLUG_PLAY_QUERY_CONFLICT_LIST* pConflictInfo,
  31. __int64 InfoLength,
  32. char PrevMode)
  33. {
  34.     _UNICODE_STRING uniInstancePath = {0};
  35.     void* pKernelBuffer = 0;
  36.     if(pConflictInfo->pBackupMemory == 0)
  37.     {
  38.         return STATUS_BUFFER_TOO_SMALL;
  39.     }
  40.     if(pConflictInfo->BackupMemorySize < 0x20)
  41.     {
  42.         return STATUS_BUFFER_TOO_SMALL;
  43.     }
  44.     void* pUserInfo =   pConflictInfo->pUserInfo;
  45.     if(!pUserInfo)
  46.     {
  47.         return STATUS_INVALID_PARAMETER;
  48.     }
  49.     if(pConflictInfo->UserInfoLength < 0x28)
  50.     {
  51.         return STATUS_INVALID_PARAMETER;
  52.     }
  53.     //Bug here, to be reported
  54.     //no probing at all
  55.     _PLUG_PLAY_QUERY_CONFLICT_LIST_USER* pUserInfoX =
  56.     (_PLUG_PLAY_QUERY_CONFLICT_LIST_USER*)pUserInfo;
  57.    
  58.     if(pUserInfoX->Sig0 != 1)
  59.     {
  60.         return STATUS_INVALID_PARAMETER;
  61.     }
  62.     if(pUserInfoX->Sig1 != 1)
  63.     {
  64.         return STATUS_INVALID_PARAMETER;
  65.     }
  66.    
  67.     ushort var_LenX =
  68.     pConflictInfo->DummyLength;
  69.    
  70.     uniInstancePath.MaxLength = var_LenX;
  71.     uniInstancePath.Length = var_LenX;
  72.    
  73.     if( (var_LenX - 1) > 0x18F)
  74.     {
  75.         return STATUS_INVALID_PARAMETER;
  76.     }
  77.    
  78.     if(var_LenX & 1)
  79.     {
  80.         return STATUS_INVALID_PARAMETER;
  81.     }
  82.    
  83.     void* pCopiedUserInfoInKernel = 0;
  84.     void* pKernelInfo = 0;//r15
  85.    
  86.     uniInstancePath.Buffer = 0;
  87.    
  88.    
  89.    
  90.    
  91.     int ret =
  92.     PiControlMakeUserModeCallersCopy
  93.     (&pCopiedUserInfoInKernel,
  94.     pUserInfoX,
  95.     pConflictInfo->UserInfoLength,
  96.     1 /* Alignment */,
  97.     PrevMode,
  98.     true /* AllocNew */);
  99.    
  100.     if(ret >= 0)
  101.     {
  102.         ret =
  103.         PiControlAllocateBufferForUserModeCaller
  104.         (&pKernelInfo,
  105.         pConflictInfo->BackupMemorySize,
  106.         PrevMode,
  107.         pConflictInfo->pBackupMemory /* Another Bug */);
  108.        
  109.         if(ret >= 0)
  110.         {
  111.             ret =
  112.             PiControlMakeUserModeCallersCopy
  113.             (&uniInstancePath.Buffer,
  114.             pConflictInfo->pDummy,
  115.             pConflictInfo->DummyLength,
  116.             2 /* Alignment */,
  117.             PrevMode,
  118.             1 /* AllocNew */);
  119.            
  120.             if(ret >= 0)
  121.             {
  122.                 ret =
  123.                 STATUS_NO_SUCH_DEVICE;
  124.                
  125.                 PpDevNodeLockTree(true);
  126.                
  127.                 _DEVICE_OBJECT* pDev =
  128.                 PnpDeviceObjectFromDeviceInstanceWithTag
  129.                 (&uniInstancePath,
  130.                 0x43706E50 /* PnpC */);
  131.                
  132.                 if(pDev)
  133.                 {
  134.                     _DEVOBJ_EXTENSION* pDevObjExt =
  135.                     pDev->DeviceObjectExtension;
  136.                    
  137.                     _DEVICE_NODE* pDevNode =
  138.                     pDevObjExt->DeviceNode;
  139.                    
  140.                     if(pDevNode)
  141.                     {
  142.                         if(pDevNode != IopRootDeviceNode)
  143.                         {
  144.                             ulong DevNodeState =
  145.                             pDevNode->State;
  146.                            
  147.                             if(DevNodeState > 0x314)
  148.                             {
  149.                                 ret =
  150.                                 IopQueryConflictList
  151.                                 (pDev,
  152.                                 pCopiedUserInfoInKernel,
  153.                                 ?? /* Reserved */,
  154.                                 pKernelInfo,
  155.                                 pConflictInfo->BackupMemorySize /* double read bug here */);
  156.                                
  157.                                
  158.                                 int retX =
  159.                                 PiControlMakeUserModeCallersCopy
  160.                                 (&pConflictInfo->pBackupMemory,
  161.                                 pKernelInfo,
  162.                                 pConflictInfo->BackupMemorySize /* double read bug */,
  163.                                 1 /* Alignment */,
  164.                                 PrevMode,
  165.                                 0 /* AllocNew */);
  166.                                
  167.                                 if(retX < 0)
  168.                                 {
  169.                                     ret = retX;
  170.                                 }
  171.                             }
  172.                         }
  173.                     }
  174.                 }
  175.                 PpDevNodeUnlockTree(true);
  176.             }
  177.         }
  178.         //r15 pKernelInfo
  179.     }
  180.     //Common_RETREAT
  181.     PiControlFreeUserModeCallersBuffer
  182.     (PrevMode,pCopiedUserInfoInKernel);
  183.    
  184.     PiControlFreeUserModeCallersBuffer
  185.     (PrevMode,pKernelInfo);
  186.    
  187.     PiControlFreeUserModeCallersBuffer
  188.     (PrevMode,uniInstancePath.Buffer);
  189.    
  190.     if(pDev)
  191.     {
  192.         ObfDereferenceObjectWithTag
  193.         (pDev,0x43706E50);
  194.     }
  195.    
  196.     pConflictInfo->Status = ret;
  197.     return ret;
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement