吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 422|回复: 16
收起左侧

[Python 原创] 用python制作的md5碰撞代码[优化版]

[复制链接]
KarlOtto 发表于 2025-3-29 18:28
本帖最后由 KarlOtto 于 2025-3-29 20:24 编辑

import hashlib
import multiprocessing
from itertools import product, islice
from string import printable
from datetime import datetime
import math

# ############################
# 优化版配置函数
# ############################
def get_config():
    """交互式配置爆破参数"""
    print("MD5爆破工具 (超强优化版)")
    print("-"*40)

    # 目标哈希验证
    while True:
        target_hash = input("请输入目标MD5哈希值: ").strip().lower()
        if len(target_hash) == 32 and all(c in '0123456789abcdef' for c in target_hash):
            break
        print("错误:必须输入有效的32位十六进制MD5哈希")

    # 前缀输入(支持空值)
    prefix = input("请输入拼接前缀(直接回车表示无前缀): ").strip()

    # 高级配置
    max_length = int(input("最大尝试长度(推荐≤6): ") or 6)
    chunk_size = int(input("分块大小(推荐内存1GB=625000): ") or 625000)

    return {
        'target_hash': target_hash,
        'prefix': prefix,
        'max_length': max_length,
        'chunk_size': chunk_size,
        'cpu_cores': multiprocessing.cpu_count()
    }

# ############################
# 数学化候选生成器(减少内存占用)
# ############################
def generate_candidates(charset, length, start, end):
    """基于数学计算生成候选字符串"""
    base = len(charset)
    for i in range(start, end):
        candidate = []
        n = i
        for _ in range(length):
            candidate.append(charset[n % base])
            n = n // base
        yield ''.join(reversed(candidate))

# ############################
# 优化版工作函数
# ############################
def hash_worker(args):
    """数学化分块爆破"""
    target_hash, prefix, length, charset, chunk_start, chunk_size = args
    start_time = datetime.now()
    charset = tuple(charset)
    total = len(charset) ** length
    end = min(chunk_start + chunk_size, total)

    # 预计算前缀字节
    prefix_bytes = prefix.encode()
    target = target_hash

    # 分块爆破
    for candidate in generate_candidates(charset, length, chunk_start, end):
        s = prefix + candidate
        if hashlib.md5(s.encode()).hexdigest() == target:
            return (candidate, length, datetime.now() - start_time)

    return (None, length, datetime.now() - start_time)

# ############################
# 智能任务调度器
# ############################
def task_generator(config, primary_charset, full_charset):
    """动态生成任务(优先短长度+主字典)"""
    # 第一阶段:主字典所有长度
    for length in range(1, config['max_length']+1):
        total = len(primary_charset) ** length
        chunk_num = math.ceil(total / config['chunk_size'])
        for chunk in range(chunk_num):
            start = chunk * config['chunk_size']
            yield (
                config['target_hash'],
                config['prefix'],
                length,
                primary_charset,
                start,
                config['chunk_size']
            )

    # 第二阶段:扩展字典所有长度
    for length in range(1, config['max_length']+1):
        total = len(full_charset) ** length
        chunk_num = math.ceil(total / config['chunk_size'])
        for chunk in range(chunk_num):
            start = chunk * config['chunk_size']
            yield (
                config['target_hash'],
                config['prefix'],
                length,
                full_charset,
                start,
                config['chunk_size']
            )

# ############################
# 主程序
# ############################
def main():
    try:
        config = get_config()
        dict_primary = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-_"
        dict_full = printable.strip()
        start_time = datetime.now()  # 修复:添加全局开始时间记录

        print("\n" + "="*60)
        print(f" 目标哈希: {config['target_hash']}")
        print(f" 前缀: '{config['prefix']}'" if config['prefix'] else " 无前缀")
        print(f" CPU核心数: {config['cpu_cores']}")
        print(f" 最大长度: {config['max_length']}")
        print(f" 分块大小: {config['chunk_size']}")
        print("="*60 + "\n")

        with multiprocessing.Pool(config['cpu_cores']) as pool:
            # 生成动态任务流
            tasks = task_generator(config, dict_primary, dict_full)

            # 提交任务并处理结果
            found = False
            for result in pool.imap_unordered(hash_worker, tasks, chunksize=4):
                candidate, length, time_used = result
                status = f"长度{length} 块完成 | 耗时{time_used}"
                print(status.ljust(50), end='\r')

                if candidate:
                    print("\n" + "="*40)
                    print(f"[+] 破解成功!原始输入 = {candidate}")
                    if config['prefix']:
                        print(f"[+] 完整字符串 = {config['prefix']}{candidate}")
                    print(f"[+] 破解长度 = {length}")
                    print(f"[+] 总耗时 = {datetime.now()-start_time}")
                    print("="*40)
                    found = True
                    break

            if not found:
                print("\n[!] 未在指定范围内找到匹配结果")

    except KeyboardInterrupt:
        print("\n[!] 用户终止操作")

if __name__ == "__main__":
    main()

现在5个字符的md5碰撞可以缩短到半分钟内
PixPin_2025-03-29_20-22-59.png

免费评分

参与人数 4吾爱币 +8 热心值 +4 收起 理由
苏紫方璇 + 5 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
flyer_2001 + 1 + 1 谢谢@Thanks!
helian147 + 1 + 1 热心回复!
jasperx + 1 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

poptop 发表于 2025-4-1 13:50
谢谢分享                                         
大白baymax 发表于 2025-3-29 19:28
本帖最后由 大白baymax 于 2025-3-30 10:19 编辑

已经帮助楼主打包成功,福利坛友。
通过网盘分享的文件:md5碰撞优化版.rar
链接: https://pan.baidu.com/s/18hjy7sg0UcpLWzZzgT9PTQ?pwd=84r3 提取码: 84r3

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
一场荒唐半生梦 + 1 + 1 热心回复!

查看全部评分

一场荒唐半生梦 发表于 2025-3-29 18:46
starskyyks 发表于 2025-3-29 18:54
很不错还有么
 楼主| KarlOtto 发表于 2025-3-29 18:55

你可以自己复制下来打包
一场荒唐半生梦 发表于 2025-3-29 19:15
KarlOtto 发表于 2025-3-29 18:55
你可以自己复制下来打包

我不知道python的要哪些打包工具
一场荒唐半生梦 发表于 2025-3-29 19:34
大白baymax 发表于 2025-3-29 19:28
已经帮助楼主打包成功,福利坛友。
通过网盘分享的文件:md5碰撞.rar
链接: https://pan.baidu.com/s/1 ...

好的好的 谢谢你 python是用什么软件打包和测试的??
zwgwww123 发表于 2025-3-29 19:55
大白baymax 发表于 2025-3-29 19:28
已经帮助楼主打包成功,福利坛友。
通过网盘分享的文件:md5碰撞.rar
链接: https://pan.baidu.com/s/1 ...

感谢!!好人一生平安!!
 楼主| KarlOtto 发表于 2025-3-30 10:05
大白baymax 发表于 2025-3-29 19:28
已经帮助楼主打包成功,福利坛友。
通过网盘分享的文件:md5碰撞.rar
链接: https://pan.baidu.com/s/1 ...

做了一个优化,新版速度快了一点
大白baymax 发表于 2025-3-30 10:09
KarlOtto 发表于 2025-3-30 10:05
做了一个优化,新版速度快了一点

好的  我再打包一下
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-4-8 01:01

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表