我正在为具有非常高安全标准的实用程序组开发一个工具(出于显而易见的原因)。此工具在 ESRI 的 ArcMap 应用程序中运行(使用 ArcMap API - ArcPy)。 ArcFM 是安装在 ArcMap 之上的软件,用于基于实用程序的分析(ArcFM 拥有独立于 ArcMap 的许可)。我正在开发的工具需要 ArcPy (Python) 使用 PyWin32 checkout ArcFM 许可证(参见下面的代码片段)
#ArcFM licensing
import win32com.client
app = win32com.client.Dispatch("Miner.Framework.Dispatch.MMAppInitializeDispatch")
runtime = win32com.client.Dispatch("Miner.Framework.Dispatch.MMRuntimeEnvironmentDispatch")
app.Initialize(0x5)
#end ArcFm licensing
为了在我正在开发的工具中使用某些 ArcFM 功能,必须首先在脚本中 check out ArcFM 许可。
此代码片段检查了 ArcFM 的许可,因此我可以在 GUI 之外访问 ArcFM 功能。 Utility Group 的 IT 主管一直在犹豫是否要在他们的机器上安装 PyWIN,因为他/她担心这会给用户提供过多的访问权限。
据我了解,Win32 不会为用户提供对其计算机的“额外”访问权限(它只允许他们通过 API 访问功能)。例如,如果用户无权访问注册表项,Win32(或 PyWin32)将不会绕过分配给该用户配置文件的任何安全设置。
我的理解正确吗?我错过了什么吗?
请您参考如下方法:
[GitHub]: mhammond/pywin32 - Python for Windows (pywin32) Extensions (强调是我的)指出:
This is the readme for the Python for Win32 (pywin32) extensions, which provides access to many of the Windows APIs from Python.
因此,PyWin32 是 WINAPI 的 Python 包装器(它只允许从Python 以一种友好的方式)。无论它(未)安装在 Python 安装上,WINAPI 仍然存在并且可以从以下位置访问:
- C
Python 也可以(例如使用 [Python 3]: ctypes - A foreign function library for Python ),但是代码会很多:
- 更长(需要各种转换)
- 可读性差(大量“维护”代码 - 与业务逻辑无关)
- 容易出错
你可以查看 [SO]: Get the title of a window of another program using the process name (@CristiFati's answer)两种方法之间的差异(也检查(最后一部分)[SO]: python win32service - Getting triggered startup information for service (@CristiFati's answer))。其他语言
由于 Pywin32 没有官方文档页面,我将引用下一个最好的东西(我发现的):[ActiveState.Docs]: PyWin32 Documentation .
例子:
- 既然您提到了注册表:
- [ActiveState.Docs]: win32api.RegOpenKeyEx包裹 [MS.Docs]: RegOpenKeyExW function
- 但这也许不是最好的例子,因为注册表功能也可以通过 [Python 3]: winreg - Windows registry access 获得。 (它是 Python 标准库的一部分)
- 另一个(与安全有关):
底线
PyWin32 没有授予(默认)额外的特权(权利)。
不过,我正试图找到管理层对安装 PyWin32 的担忧的原因。
一般来说,专家(在 WINAPI 领域)很可能知道:
- C(开发人员数量正在减少)
- Win 内部(这里也不是很多)
- 一般计算机(低级)知识
- 从上面的 3 个中,这些用户会知道调用 WINAPI 的含义(如果不知道,他们会很容易知道在哪里/搜索/调查什么以获得答案)<
从这些用户的 PoV 来看,这没有区别。但是由于可以查询 PyWin32 模块的内容:
>>> import win32security >>> >>> print([name for name in dir(win32security) if callable(getattr(win32security, name))]) ['ACL', 'AcceptSecurityContext', 'AcquireCredentialsHandle', 'AdjustTokenGroups', 'AdjustTokenPrivileges', 'AllocateLocallyUniqueId', 'CheckTokenMembership', 'ConvertSecurityDescriptorToStringSecurityDescriptor', 'ConvertSidToStringSid', 'ConvertStringSecurityDescriptorToSecurityDescriptor', 'ConvertStringSidToSid', 'CreateRestrictedToken', 'CreateWellKnownSid', 'CredHandleType', 'CryptEnumProviders', 'CtxtHandleType', 'DsBind', 'DsCrackNames', 'DsGetDcName', 'DsGetSpn', 'DsListDomainsInSite', 'DsListInfoForServer', 'DsListRoles', 'DsListServersForDomainInSite', 'DsListServersInSite', 'DsListSites', 'DsUnBind', 'DsWriteAccountSpn', 'DuplicateToken', 'DuplicateTokenEx', 'EnumerateSecurityPackages', 'GetBinarySid', 'GetFileSecurity', 'GetKernelObjectSecurity', 'GetNamedSecurityInfo', 'GetPolicyHandle', 'GetSecurityInfo', 'GetTokenInformation', 'GetUserObjectSecurity', 'ImpersonateAnonymousToken', 'ImpersonateLoggedOnUser', 'ImpersonateNamedPipeClient', 'ImpersonateSelf', 'InitializeSecurityContext', 'IsTokenRestricted', 'LogonUser', 'LogonUserEx', 'LookupAccountName', 'LookupAccountSid', 'LookupPrivilegeDisplayName', 'LookupPrivilegeName', 'LookupPrivilegeValue', 'LsaAddAccountRights', 'LsaCallAuthenticationPackage', 'LsaClose', 'LsaConnectUntrusted', 'LsaDeregisterLogonProcess', 'LsaEnumerateAccountRights', 'LsaEnumerateAccountsWithUserRight', 'LsaEnumerateLogonSessions', 'LsaGetLogonSessionData', 'LsaLookupAuthenticationPackage', 'LsaOpenPolicy', 'LsaQueryInformationPolicy', 'LsaRegisterLogonProcess', 'LsaRegisterPolicyChangeNotification', 'LsaRemoveAccountRights', 'LsaRetrievePrivateData', 'LsaSetInformationPolicy', 'LsaStorePrivateData', 'LsaUnregisterPolicyChangeNotification', 'MapGenericMask', 'OpenProcessToken', 'OpenThreadToken', 'PyCredHandleType', 'PyCtxtHandleType', 'PySecBufferDescType', 'PySecBufferType', 'QuerySecurityPackageInfo', 'RevertToSelf', 'SECURITY_ATTRIBUTES', 'SECURITY_DESCRIPTOR', 'SID', 'SecBufferDescType', 'SecBufferType', 'SetFileSecurity', 'SetKernelObjectSecurity', 'SetNamedSecurityInfo', 'SetSecurityInfo', 'SetThreadToken', 'SetTokenInformation', 'SetUserObjectSecurity', 'TranslateName', 'error']
这可能会得到其他类型的用户和想法。
所以(可争论:假)的担忧是,伟大的力量(包括知识的力量)与可能没有的用户共享处理这种权力需要巨大的责任。在某些情况下,这可能会导致(有点戏剧化)灾难(至于是因为错误还是恶意并不十分相关)。
与现实生活场景相提并论:门上有一把虚拟锁(或沙滩上鞋子里的钱包):
- 将阻止 ~90%+ 的小偷(平庸的小偷)
- 对真正的主人没有影响
