有没有办法找出两个文件的哈希值?

2024-09-19 14:18:00 发布

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

我有生成两个文件的散列值的python代码。第一个文件位于c:\windows\system32中\wscript.exe以及另一个文件,它是位于d中的第一个文件的克隆:\克隆.exe. 你知道吗

python代码

import os
strcommand ='certutil -hashfile c:\windows\system32\wscript.exe md2'
p=os.popen(strcommand ).read()
print(str(p).split('\n')[1])

strcommand1='certutil -hashfile d:\clone.exe md2'
p=os.popen(strcommand1 ).read()
print(str(p).split('\n')[1])

输出为

D:\pythonprogram>python clonefinder.py
4cef03889db08179b57035e4463a84d5
db1cefe474ce12678ea4d6c61dc42291

但是当我在命令提示符中使用python中使用的命令时,两个文件的哈希值是相同的

命令提示

D:\pythonprogram>certutil -hashfile c:\windows\system32\wscript.exe md2
MD2 hash of c:\windows\system32\wscript.exe:
db1cefe474ce12678ea4d6c61dc42291
CertUtil: -hashfile command completed successfully.

D:\pythonprogram>certutil -hashfile d:\clone.exe md2
MD2 hash of d:\clone.exe:
db1cefe474ce12678ea4d6c61dc42291
CertUtil: -hashfile command completed successfully.

如果我正在执行python程序,我希望哈希值是相同的

有什么帮助吗?你知道吗


Tags: 文件代码cloneoswindowsexepopenhashfile
1条回答
网友
1楼 · 发布于 2024-09-19 14:18:00

Windows可以是一个相当有趣的操作系统,由于它的年龄,一些魔术已被添加到允许旧的Windows代码仍然与Windows7/8/10在某些情况下,你可以看到不同版本的文件目录,如C:\Windows。取决于您的权限/取决于您是否启动32位/64位应用程序。我不知道所有这些机械的心,但已经有一些坏的惊喜。你知道吗

100%确定的是,您没有在两个不同的环境中执行certutil命令。我提议如下。你知道吗

  1. 打开一个命令行窗口
  2. 从该窗口键入certutil命令
  3. 现在用C:\Path_to_your_python\python.exe name_of_your_python_script.py从同一窗口调用python脚本 使用在regexp字符串前面加上r(r“regex”)的python脚本版本

如果仍然有不同的结果,请检查是否安装了32位版本或64位版本的python。 C:\Path_to_your_python\python.exe -V

如果您有一个32位版本,那么我建议安装一个64位版本的python来再次测试。你知道吗

相关问题 更多 >