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

推荐订阅源

Forbes - Security
Forbes - Security
GbyAI
GbyAI
WordPress大学
WordPress大学
小众软件
小众软件
Y
Y Combinator Blog
The GitHub Blog
The GitHub Blog
S
SegmentFault 最新的问题
A
About on SuperTechFans
月光博客
月光博客
F
Fortinet All Blogs
宝玉的分享
宝玉的分享
Microsoft Security Blog
Microsoft Security Blog
大猫的无限游戏
大猫的无限游戏
Hugging Face - Blog
Hugging Face - Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
V2EX
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
N
Netflix TechBlog - Medium
Jina AI
Jina AI
博客园 - 聂微东
Schneier on Security
Schneier on Security
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
N
News | PayPal Newsroom
PCI Perspectives
PCI Perspectives
Last Week in AI
Last Week in AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Proofpoint News Feed
Hacker News: Ask HN
Hacker News: Ask HN
B
Blog
aimingoo的专栏
aimingoo的专栏
P
Privacy International News Feed
Martin Fowler
Martin Fowler
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
NISL@THU
NISL@THU
Know Your Adversary
Know Your Adversary
C
Cybersecurity and Infrastructure Security Agency CISA
博客园 - 叶小钗
N
News and Events Feed by Topic
T
The Exploit Database - CXSecurity.com
Stack Overflow Blog
Stack Overflow Blog
S
Security @ Cisco Blogs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
V
Vulnerabilities – Threatpost
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threatpost
IT之家
IT之家
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)  评论()    收藏  举报