如何确定进口来源?

2024-04-29 11:32:45 发布

您现在位置:Python中文网/ 问答频道 /正文

请原谅我的无知。我不太懂Python,也根本写不出来。你知道吗

我正在尝试审核CVE-2013-1445的python项目。我相信找到了一个可能需要注意的源文件(以及其他改进的机会)。文件是util.py,它有以下行:

import base64

from Crypto.Hash import HMAC
from Crypto import Random
...

当我看Python crypto docs时,我没有看到提到Random类。只有hashlibhmac

The modules described in this chapter implement various algorithms of a
cryptographic nature. They are available at the discretion of the
installation. On Unix systems, the crypt module may also be available.
Here’s an overview:

    15.1. hashlib — Secure hashes and message digests
    15.2. hmac — Keyed-Hashing for Message Authentication

...

Random究竟从何而来?是本地的还是第三方的?你知道吗

或者我的问题应该是,Crypto从哪里来?如果Crypto是它的第三方,我如何确定第三方库和类是如何/在哪里包含的(相对于本机库和类)?你知道吗

为了完整起见,我试图理解Python的作用域和名称空间,但目前对我来说毫无意义(正如这个问题可能演示的那样)。例如,CryptoRandom没有明显的作用域或命名空间(除了RandomCrypto的一部分之外)。你知道吗

提前谢谢。你知道吗


Tags: ofthe项目fromimport空间randomcrypto
2条回答

Crypto不是任何标准Python发行版的一部分。这就是为什么Python文档没有提到;-)您可以在这里下载源代码:

https://www.dlitz.net/software/pycrypto/

你在问文件存放在哪里吗?模块有一个名为__file__的属性,它列出了模块在磁盘上的路径。你知道吗

>>> from Crypto import Random
>>> Random.__file__
'/home/ubuntu/.env/local/lib/python2.7/site-packages/Crypto/Random/__init__.pyc'

(在我的例子中,PyCrypto安装在myhome dir的virtualenv中)

相关问题 更多 >