您当前的位置: 首页 > 

顺其自然~

暂无认证

  • 1浏览

    0关注

    1317博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

给window内核对象赋予任何人都可以访问的权限

顺其自然~ 发布时间:2021-07-28 14:30:02 ,浏览量:1

SECURITY_DESCRIPTOR sdEventSecurityDesc;
SECURITY_ATTRIBUTES saEventSecurityAttr;
if(InitializeSecurityDescriptor(&sdEventSecurityDesc, SECURITY_DESCRIPTOR_REVISION)) //Revision level
{
  if(SetSecurityDescriptorDacl(&sdEventSecurityDesc,
   TRUE, // DACL presence
   NULL, // DACL (NULL DACL means all access granted)
   FALSE)) // default DACL
  {
   saEventSecurityAttr.nLength = sizeof(SECURITY_DESCRIPTOR);
   saEventSecurityAttr.lpSecurityDescriptor = (LPVOID)&sdEventSecurityDesc;
   saEventSecurityAttr.bInheritHandle = TRUE;

   // now you can fill param LPSECURITY_ATTRIBUTES while &saEventSecurityAttr
  }
}

在vista及以上windows版本,如果要上低优先级的程序访问高优先级创建的对象,还必须通过下面代码来设置

#include 
#include 
#include 
//LABEL_SECURITY_INFORMATION  SDDL  SACL被设为低完整性级别
LPCWSTR LOW_INTEGRITY_SDDL_SACL_W = L"S:(ML;;NW;;;LW)";

bool SetObjectToLowIntegrity(HANDLE hObject, SE_OBJECT_TYPE type)
{
 bool bRet = false;
 DWORD dwErr = ERROR_SUCCESS;
 PSECURITY_DESCRIPTOR pSD = NULL;
 PACL pSacl = NULL;
 BOOL fSaclPresent = FALSE;
 BOOL fSaclDefaulted = FALSE;

 if (ConvertStringSecurityDescriptorToSecurityDescriptorW(
  LOW_INTEGRITY_SDDL_SACL_W, SDDL_REVISION_1, &pSD, NULL))
 {
  if (GetSecurityDescriptorSacl(pSD, &fSaclPresent, &pSacl, &fSaclDefaulted))
  {
   dwErr = SetSecurityInfo (
    hObject, type, LABEL_SECURITY_INFORMATION,
    NULL, NULL, NULL, pSacl );

   bRet = (ERROR_SUCCESS == dwErr);
  }
  LocalFree ( pSD );
 }
 return bRet;
}

关注
打赏
1662339380
查看更多评论
立即登录/注册

微信扫码登录

0.0428s