CTF之 MD5 爆破两个例子

有两个例子,一个是知道组成的字符为数字,然后知道加盐后的MD5,求组成的字符
第二个是知道字符长度为0-6,然后给出字符集,用暴力的办法解出该MD5字符
下面就是两个例子了,下次遇着类似的继续备之
import hashlib

import string


def crackMd5(dst):
    dst = dst.lower()

    for a in range(0,10):

        for b in range(0,10):

            for c in range(0,10):

                for d in range(0,10):

                    word = str(a) + str(b) + str(c) + str(d) + "_heetian"

                    tmp = hashlib.md5(word).hexdigest()

                    if dst == tmp:
                        return word

    return None


if __name__ == "__main__":
    raw_input(crackMd5("158e64cfc9991940700acc5dc0f310e3"))


例子2:不确定长度

# -*- coding:utf-8 -*-
__author__ = 'Administrator'
#from ultrapower.fd
import itertools as its
import md5

#暴力破解
def uncipher(maxlenth,salt,ciphertext_s,str_letter):
  ciphertext_s=ciphertext_s
  salt = salt
  maxlenth=int(maxlenth)
  str_letter=str_letter
  ciphertext=''
  for i in range(1, maxlenth+1):
    # 迭代生成明文(例如abc,repeat=2  结果为(a,a)(a,b)(a,c)(b,b)(b,a)(b,c)(c,c)(c,a)(c,b)
    r = its.product(str_letter, repeat=i)
    for j in r:
      plaintext = "".join(j) #连接成字符串
      plaintext = "%s%s" % (plaintext, salt)  #把盐加到明文的后面 每次生成的最终明文
      #print plaintext   #打印明文
      # 开始解密,方法是,每个明文进来,加密成密文,然后密文与密文做对比
      md501 = md5.new()
      md501.update(plaintext)
      ciphertext = md501.hexdigest()
      # 对比密文确认明文
      if ciphertext == ciphertext_s:  #如果密文一致 退出2层循环
        break
    if ciphertext == ciphertext_s:    #如果密文一致,退出1层循环,打印结果
      print "task finished(plain,cipher)"
      print "%s:%s" % (plaintext, ciphertext) #打印结果
      break

#开始执行主函数
#str_letter="abcdefghijklmnopqrstuvwxyz0123456789"
#str_letter="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
#str_letter="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
str_letter="abcdefghijklmnopqrstuvwxyz"   #明文的字符范围
maxlenth=6   #明文的最大长度,一般不会超过6位,否则短时间很难暴力破解
salt='5948'  #加盐 #如果不加盐,为空就是正常的md5解密
ciphertext_s='81bdf501ef206ae7d3b92070196f7e98'     #密文
uncipher(maxlenth,salt,ciphertext_s,str_letter)     #开始解密
  • 4
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值