非管理员用户可以远程连接到服务控制管理器,前提是他们具有“从网络访问此计算机”用户权限。默认情况下,此权限授予所有用户。
对单个服务的访问由每个服务上的 ACL 控制。您必须已经知道服务名称,因为非管理员用户无法远程枚举服务。
服务的默认安全描述符如下:
D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;IU)(A;;CCLCSWLOCRRC;;;SU)S:(AU;FA;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;WD)
您可以使用sc sdshow 命令确定服务的安全描述符。字符串格式在 MSDN 上的Security Descriptor Definition Language 中有描述。
好的,让我们展开那个安全描述符字符串。这有点棘手,因为 SDDL 权限和等效安全管理器权限之间的映射似乎没有在 MSDN 或 SDK 标头中得到很好的记录;幸运的是,Wayne Martin 已经为我们完成了繁重的工作,并将结果发布在博客条目Service Control Manager Security for non-admins。
D: - this part is the DACL, the permissions on the service.
由于所有条目都是允许条目,因此顺序并不重要;为方便起见,我将它们从最低到最高特权列出。
(A;;CCLCSWLOCRRC;;;IU) - allow the interactive user the following rights:
CC - SERVICE_QUERY_CONFIG (the right to query the service configuration)
LC - SERVICE_QUERY_STATUS (the right to query the service status)
SW - SERVICE_ENUMERATE_DEPENDENTS (the right to see service dependencies)
LO - SERVICE_INTERROGATE (the right to send SERVICE_CONTROL_INTERROGATE)
CR - SERVICE_USER_DEFINED_CONTROL (the right to send a user defined control)
RC - READ_CONTROL (the right to see the permissions)
(A;;CCLCSWLOCRRC;;;SU) - allow services the following rights:
same as for the interactive user
(A;;CCLCSWRPWPDTLOCRRC;;;SY) - allow local system the following rights:
same as for the interactive user, plus:
RP - SERVICE_START (the right to start the service)
WP - SERVICE_STOP (the right to stop the service)
DT - SERVICE_PAUSE_CONTINUE (the right to send pause and continue requests)
(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA) - allow the Administrators group:
same as for local system, plus:
DC - SERVICE_CHANGE_CONFIG (the right to reconfigure the service)
SD - DELETE (the right to delete the service)
WD - WRITE_DAC (permission to change the permissions)
WO - WRITE_OWNER (permission to take ownership)
安全描述符字符串 (S:(...)) 的第二部分是 SACL,它控制完成的审计工作。我们目前对此不感兴趣。
您会注意到,没有适用于非管理远程用户的允许权限。要向特定用户授予远程访问权限,请为该用户添加与交互式用户具有相同权限的允许 ACE。
如果这是您自己的服务,您可以在安装服务时使用SetServiceObjectSecurity 函数更改权限。您还可以使用此函数编写程序来更改现有服务的权限。
或者,您可以在命令行中使用sc sdset,根据 SDDL 字符串设置现有服务的权限。您首先需要查找用户的 SID 字符串;在域中,您可以使用 Active Directory 用户和计算机来执行此操作。 SID 字符串可以通过objectSid 属性中的属性编辑器选项卡查看。 (很遗憾,您不能以这种方式复制和粘贴。欢迎提出更方便的查找用户 SID 方法的建议。)
如果 SID 字符串是S-1-5-21-131085535662-8349591032-725385543-5981,例如,命令行是
sc sdset myservice D:(A;;CCLCSWLOCRRC;;;S-1-5-21-131085535662-8349591032-725385543-5981)(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;IU)(A;;CCLCSWLOCRRC;;;SU)
(您无需指定SACL;如果不指定,将保留现有的SACL。)