字典破解总结(实战BUUCTF[8.2.3 字典破解])

定义

在CTF中,如果存在对密码的提示,如压缩包密码以"abc"开头且总长度为7,我们就会优先采用字典破解的方式。

这里我们用会用到在Kali中用到的工具crunch

如:

bash 复制代码
crunch 10 10 -t abc%%%%%%% -o abc_7digit.txt
复制代码
crunch 10 10:固定生成 10 位 字符串
-t abc%%%%%%%:模板参数
abc:固定开头

%:代表数字 0-9,写 7 个就是 7 位数字
@:小写字母 a-z
,:大写字母 A-Z	
^:特殊符号
-o abc_7digit.txt:把字典保存到文件里
-z gzip:压缩输出

实战:[第八章][8.2.3 字典破解]字典破解

这道题,《CTF实战:从入门到提升》这本书里没有给一点提示,所以就得把能想到的所有CTF常用字典,Top1000字典搞来,暴力破解一遍。这里我问了Workbuddy,生成了一个字典脚本.py,字典脚本脚本如下:

python 复制代码
import zipfile
import itertools
import string

# ============================================================
# CTF 字典破解 ZIP
# 字典来源:
#   1. CTF 高频密码(比赛中出现最多的)
#   2. 常见数字组合
#   3. 键盘走位
#   4. 常见英文弱密码
#   5. ctf/flag 相关变体
# ============================================================

ZIP_PATH = r'c:\Users\lenovo\WorkBuddy\Claw\字典破解.zip'

# --- CTF & 通用高频密码字典 ---
CTF_WORDLIST = [
    # CTF 专用
    "flag", "ctf", "ctf123", "flag123", "ctfctf", "passwd", "password",
    "p@ssw0rd", "p@ssword", "passw0rd", "admin", "admin123", "administrator",
    "root", "root123", "toor", "test", "test123", "guest", "guest123",
    # 数字序列
    "123456", "1234567", "12345678", "123456789", "1234567890",
    "111111", "222222", "333333", "666666", "888888", "000000",
    "123123", "321321", "112233", "123321", "1q2w3e", "1q2w3e4r",
    "1q2w3e4r5t", "qwerty", "qwerty123", "qwertyuiop",
    # 常见英文弱密码
    "password", "password1", "password123", "iloveyou", "sunshine",
    "princess", "monkey", "dragon", "master", "letmein", "welcome",
    "login", "hello", "hello123", "abc123", "abcd1234", "baseball",
    "football", "shadow", "superman", "batman", "trustno1",
    # 键盘走位
    "qazwsx", "zxcvbnm", "asdfgh", "asdfghjkl", "1234qwer",
    # 年份/日期
    "2020", "2021", "2022", "2023", "2024", "2025",
    "20200101", "20210101", "20221212", "19891231",
    # 中文拼音常见
    "woaini", "woshini", "nihaoma", "zhongguo", "beijing",
    # CTF 平台常见
    "hack", "hacker", "hacking", "exploit", "shell", "pwn", "pwned",
    "reverse", "crypto", "web", "misc", "binary",
    # 空密码
    "",
    # 其他
    "pass", "123", "1234", "12345", "654321", "7654321",
    "a123456", "a12345678", "aa123456",
    "abc", "abcdef", "abcdefg", "abcdefgh",
    "111", "1111", "11111", "000", "0000", "00000",
    "9999", "99999", "8888", "88888", "7777", "6666", "5555",
    "4321", "4444", "3333", "2222", "1111", "3141592",
    "123qwe", "123abc", "a1b2c3", "aaa111",
    "success", "game", "love", "god", "sex", "god123",
    "michael", "jessica", "charlie", "thomas", "robert",
    "pokemon", "starwars", "matrix", "linux", "windows",
]

# --- 生成额外的数字组合 (4-8位纯数字) ---
extra = []
# 4位
for n in range(0, 10000):
    extra.append(f"{n:04d}")
# 6位常见
for n in [100000,110000,111111,112233,121212,123321,123456,
          123654,132456,147258,159357,159753,192168,200000,
          202020,210987,212121,246810,258369,314159,321654,
          456789,519519,520520,521521,654321,666666,696969,
          741852,741963,753951,789456,852456,852963,963852,
          987654,999999]:
    extra.append(str(n))

wordlist = CTF_WORDLIST + extra

print(f"[*] 字典总词条数: {len(wordlist)}")
print(f"[*] 开始破解: {ZIP_PATH}")
print()

found = False
count = 0
try:
    zf = zipfile.ZipFile(ZIP_PATH)
    for pwd in wordlist:
        count += 1
        if count % 500 == 0:
            print(f"  [~] 已尝试 {count}/{len(wordlist)} ... 当前: {repr(pwd)}")
        try:
            zf.extractall(
                path=r'c:\Users\lenovo\WorkBuddy\Claw\cracked_output',
                pwd=pwd.encode('utf-8')
            )
            print(f"\n[+] 破解成功!密码是: {repr(pwd)}")
            found = True
            break
        except (RuntimeError, zipfile.BadZipFile):
            continue
        except Exception:
            # 尝试 latin-1 编码
            try:
                zf.extractall(
                    path=r'c:\Users\lenovo\WorkBuddy\Claw\cracked_output',
                    pwd=pwd.encode('latin-1')
                )
                print(f"\n[+] 破解成功!密码是: {repr(pwd)}")
                found = True
                break
            except Exception:
                continue
except Exception as e:
    print(f"[-] 打开ZIP出错: {e}")

if not found:
    print(f"\n[-] 字典破解失败,已尝试 {count} 个密码,未找到匹配项")
    print("    建议:尝试更大字典(如 rockyou.txt)或暴力破解")
else:
    import os
    out_dir = r'c:\Users\lenovo\WorkBuddy\Claw\cracked_output'
    for f in os.listdir(out_dir):
        fpath = os.path.join(out_dir, f)
        print(f"[*] 解压文件: {fpath}")
        try:
            content = open(fpath, 'rb').read()
            print(f"[*] 内容: {content}")
        except Exception:
            pass

最后拿到密码是:p@ssw0rd

成功破解压缩包。

相关推荐
@insist1231 小时前
信息安全工程师核心考点:物理与环境安全(上篇)
安全·软考·信息安全工程师·软件水平考试
其实防守也摸鱼1 小时前
《SQL注入进阶实验:基于sqli-Labs的报错注入(Error-Based Injection)实战解析》
网络·数据库·sql·安全·网络安全·sql注入·报错注入
jinanwuhuaguo1 小时前
反熵共同体——OpenClaw的宇宙热力学本体论(第十七篇)
大数据·人工智能·安全·架构·kotlin·openclaw
介一安全2 小时前
【Web安全】Blind XSS漏洞:从挖掘到防御
安全·web安全·xss
空中海2 小时前
第四篇:进阶篇 — 缓存、消息队列、安全与常用中间件
安全·缓存·中间件
土豆.exe2 小时前
Cast Attack:Java 中 Ghost Bits(幽灵比特)引发的新型安全威胁——Java 生态里被忽视的底层风险引发一系列绕过
java·python·安全
YaBingSec3 小时前
玄机网络安全靶场:Jackson-databind 反序列化漏洞(CVE-2017-7525)
linux·网络·笔记·安全·web安全
TechWayfarer3 小时前
网络安全溯源实战:78.1%网络攻击来自境外,如何精准定位攻击源
网络·安全·web安全
视觉&物联智能3 小时前
【杂谈】-人工智能于现代网络安全运营的价值持续攀升
人工智能·安全·web安全·ai·chatgpt·agi·deepseek