简体   繁体   English

Python和密码术:md5

[英]Python and Cryptography: md5

I am very interested in python and cryptography and I would like to know what would be the most simple method in python to crack a hash. 我对python和密码学非常感兴趣,我想知道python中破解哈希最简单的方法是什么。

I would like to build a small python script that can crack this hash:21232f297a57a5a743894a0e4a801fc3 which is simply 'admin'. 我想构建一个可以破解此哈希值的小型python脚本:21232f297a57a5a743894a0e4a801fc3,即“ admin”。

What process would I need to go through to guess what this hash represents? 我需要经过什么过程才能猜测此哈希表示什么?

I have read up about md5 and at this point in time I have only just started learning the methods behind cryptography, but they also go into deep computer science which is something I don't understand as of yet. 我已经阅读了有关md5的知识,并且在这一点上,我才刚刚开始学习密码学背后的方法,但是它们也进入了深度计算机科学领域,这是我目前还不了解的东西。

I did some research here: http://nsfsecurity.pr.erau.edu/crypto/md5.html 我在这里做了一些研究: http : //nsfsecurity.pr.erau.edu/crypto/md5.html

You can output a hex md5 like so: 您可以像这样输出十六进制的md5:

>>> from hashlib import md5
>>> md5('admin').hexdigest()
'21232f297a57a5a743894a0e4a801fc3'

If you have a list of words, you could try them one by one and output if their md5 matches your desired one. 如果您有单词列表,则可以一一尝试,如果它们的md5与您想要的单词匹配,则输出。 (This is known as a dictionary attack) (这被称为字典攻击)

>>> words = 'test', 'alex', 'steve', 'admin'
>>> for word in words:
...     if md5(word).hexdigest() == '21232f297a57a5a743894a0e4a801fc3':
...         print word
...         break
... 
admin

If you were serious about cracking an MD5 you'd have much better results on the GPU - try a tool like OCLHashCat 如果您真的想破解MD5,则在GPU上会有更好的结果-尝试使用OCLHashCat之类的工具

http://www.google.com/search?q=md5+lookup http://www.google.com/search?q=md5+lookup

>>> import requests
>>> import lxml.html
>>> 
>>> def reverse_md5(digest):
...     r = requests.get('http://www.md5-lookup.com/index.php?q={}'.format(digest))
...     root = lxml.html.fromstring(r.content)
...     for x in root.cssselect('#LSResult table tr')[4:-3]:
...         return x.find('td').text_content() 
...     # fallback to brute force.
...     # ...
... 
>>> reverse_md5('21232f297a57a5a743894a0e4a801fc3')
'admin'
>>> reverse_md5('21232f297a57a5a743894a0e4a801fc4') # lookup fail
>>>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM