惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
S
Securelist
D
Docker
The Register - Security
The Register - Security
GbyAI
GbyAI
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
罗磊的独立博客
博客园 - 【当耐特】
F
Full Disclosure
WordPress大学
WordPress大学
腾讯CDC
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
I
InfoQ
MyScale Blog
MyScale Blog
量子位
Cyberwarzone
Cyberwarzone
博客园 - 三生石上(FineUI控件)
The Hacker News
The Hacker News
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
博客园_首页
H
Help Net Security
K
Kaspersky official blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Webroot Blog
Webroot Blog
Blog — PlanetScale
Blog — PlanetScale
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
The Cloudflare Blog
P
Proofpoint News Feed
V
Visual Studio Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
爱范儿
爱范儿
P
Privacy International News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog RSS Feed

博客园 - Frodo

北京骗子花样——母婴篇 MSN的弹出页面里面也有病毒,当心 makefile学习笔记 Base-from-Member 惯用法(转) boost.asio库学习笔记—— receive和read的区别: 手动安装boost库 http://www.taobao.com Sample OpenVPN 2.0 config file 配置文件的简单翻译 - Frodo 奥运节目主持人爆笑口误 转——让IRIS嗅探器可以在Win2003 SP1上运行 转 —— http cookie HTTP Cookies 扫盲 进程间数据通讯要注意的问题 不要混合使用运行时库的静态版本和动态版本!!!! Linux下面如何进行C语言编程技术教程 linux command 最简单的办法,不用安装任何软件,就屏蔽ClickEye(点睛广告) 如何关闭 FlashGet 右侧的网页 老陈学 C++ 序列之二: 友元函数
在多个进程间共享内核对象时的安全性
Frodo · 2008-03-26 · via 博客园 - Frodo

   近些天在开发一个项目的时候,需要在2个进程间通讯,当一个进程读好共享数据时告诉另外一个进程,以便进行同步操作。
用的是内核对象semaphone。一个调用::CreateSemaphore(NULL, nInitialCount, nMaxCount, "aNameOfsSemphoneName”), 另外一个调用::OpenSemaphore( SEMAPHORE_MODIFY_STATE, TRUE, "aNameOfsSemphoneName”)。当我在控制台调试程式时,发现一切都很正常。但是当我把第一个调用CreateSemaphore的进程写成服务程式,部署好了,启动服务,然后再次调试那个调用OpenSemaphore的进程的时候,问题就出现了,返回的错误代码是5(决绝访问)。然后我再把那个服务程式以和我登录window的用户名一样的帐号运行,然后再次调试那个调用OpenSemaphore的进程,这时候就可以正常打开了。
   以上情况表明,是window安全性原因,影响了OpenSemaphore的操作。察看msdn,发现如果CreateSemaphore时,第1参数为NULL。

The lpSecurityDescriptor member of the structure specifies a security descriptor for the new semaphore. If lpSemaphoreAttributes is NULL, the semaphore gets a default security descriptor. The ACLs in the default security descriptor for a semaphore come from the primary or impersonation token of the creator.
   By default, the default DACL in the access token of a process allows access only to the user represented by the access token. If other users must access the object, you can either create a security descriptor with the appropriate access, or add ACEs to the DACL that grants access to a group of users. 
   因此,如果将服务部署为以system帐号运行,然后测试程式以administrator运行,结果就是测试程式不能打开OpenSemaphore,错误代码为5,拒绝访问。
    基于此,我建立一个函数,让他返回一个很低安全性的lpSecurityDescriptor ,这样服务程式可以以system帐号,运行,而测试程式则以一般的帐号运行即可。不过这样就是牺牲了要建立的内核对象的安全性。选取与否可以择情参考。
HANDLE get_sa()
{
 static SECURITY_ATTRIBUTES sa;
 static SECURITY_DESCRIPTOR sd;
 static PSECURITY_DESCRIPTOR pSA = NULL;
 if( pSA == NULL )
 {
  pSA = &sa;

  if ( ! InitializeSecurityDescriptor ( &sd, SECURITY_DESCRIPTOR_REVISION) )
  {
   return NULL;
  }
  if ( ! SetSecurityDescriptorDacl ( &sd, TRUE, ( PACL) NULL, FALSE) )
  {
   return NULL;
  }
  memset ( ( VOID *) &sa, 0, sizeof ( SECURITY_ATTRIBUTES) );  
  sa.bInheritHandle = TRUE;
  sa.nLength = sizeof(SECURITY_ATTRIBUTES);
  sa.lpSecurityDescriptor = &sd;
 }
 return pSA;
}

posted on 2008-03-26 14:37  Frodo  阅读(1005)  评论()    收藏  举报