PyWin32 可以让用户 "too-much" 访问 Win32 API 吗?

Can PyWin32 give users "too-much" access to the Win32 API?

我正在为具有非常高安全标准的实用程序组开发一个工具(出于显而易见的原因)。此工具在 ESRI 的 ArcMap 应用程序中运行(使用 ArcMap API - ArcPy)。 ArcFM 是安装在 ArcMap 之上的软件,用于基于实用程序的分析(ArcFM 拥有独立于 ArcMap 的许可)。我正在开发的工具需要 ArcPy (Python) 使用 PyWin32 签出 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 功能,必须先在脚本中检出 ArcFM 许可。

此代码片段检查了 ArcFM 的许可,因此我可以在 GUI 之外访问 ArcFM 功能。 Utility Group 的 IT 主管一直在犹豫是否要在他们的机器上安装 PyWIN,因为 he/she 担心它会给用户提供太多访问自己计算机的权限。

据我了解,Win32 不会授予用户 "extra" 访问其计算机的权限(它只允许他们通过 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.

所以,PyWin32PythonWINAPI[= 的包装106=]s(它只是允许以友好的方式从 Python 调用它们)。不管它(不是)安装在 Python 安装上,WINAPIs 仍然存在并且可以从以下位置访问:

  • C
  • Python 以及(例如使用 [Python 3]: ctypes - A foreign function library for Python), 代码会很多:

    1. 更长(需要各种转换)
    2. 可读性较差(大量 "maintenance" 代码 - 与业务逻辑无关)
    3. 容易出错


    你可以检查 for difference between the 2 approaches (also check (the last part of) ).

  • 其他语言

由于 Pywin32 没有官方文档页面,我将引用下一个最好的(我发现的):[ActiveState.Docs]: PyWin32 Documentation.

示例:


底线

PyWin32.

没有授予(默认)额外的特权(权利)

不过,我正试图找到管理层对安装 PyWin32 的担忧的原因。

一般来说,专家(在 WINAPI 领域)最有可能知道:

  1. C(开发者数量正在减少)
  2. Win 内部(这里也不是很多)
  3. 一般计算机(低级)知识
  4. 从上面的 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%+的盗贼(一般的)
  • 对真正的高手无效