利用base64库暴力破解base加密

本文介绍了一个Base加密题目的解密过程。通过分析不同Base加密方式的特点,并利用Python的base64库进行暴力破解,最终成功解密了一段密文。

做个base加密题python语法出了一堆错误。。。。。

附上py中关于base加密/解码的知识:http://www.open-open.com/lib/view/open1433990719973.html

题目:

 

enc1.txt中是: R1lZVElOWlVHWTNFQ05SUkdNWlRLTVJXSU0zREdNWlRHVVlUR01CVUlRMkRJTkpSR05DQT09PT0=

 

首先学了下python下base的知识 一般用base64库下的 base64.b64/32/16decode()/encode()就够用了

看到这个题,第一感觉是base中解密有没有明显特征,查了一圈又实验了几个发现base64和32加密后结果应该不能分辨,但长度都是4的整数倍,结尾有时会用补=,16可能可辨,数字偏多而且结尾不出现=。

所以直接识别是不行了,那就只能暴力破解了:

  用py过程中出了些问题 例如缩进问题,空格和Tab不能混用,一直以为只要相等就没事,其实不行;文件名不能用python预留的关键词,例如base64这个词就不行。

 代码如下

import base64

text='R1lZVElOWlVHWTNFQ05SUkdNWlRLTVJXSU0zREdNWlRHVVlUR01CVUlRMkRJTkpSR05DQT09PT0='

for i in range(3):
    try:
        if i==0:
            text=base64.b16decode(text)
        if i==1:
            text=base64.b32decode(text)
        if i==2:
            text=base64.b64decode(text) 
    except:
        continue
    for j in range(3):
        try:
            if j==0:
                text=base64.b16decode(text)
            if j==1:
                text=base64.b32decode(text)
            if j==2:
                text=base64.b64decode(text) 
        except:
            continue
        for k in range(3):
            try:
                if k==0:
                    text=base64.b16decode(text)
                if k==1:
                    text=base64.b32decode(text)
                if k==2:
                    text=base64.b64decode(text) 
            except:
     continue print text

  复制过来的代码缩进可能有些问题

思路就是三层for循环3种base全都试一遍

开始没有用try/except 结果提示如果不是base16加密,使用base16解密就会出错,于是用try+continue即可解决

 

结果如下:

 

转载于:https://www.cnblogs.com/Aiden-/p/6915781.html

暴力破解NTLM加密算法需要对于每个可能的密码进行哈希计算,并将其与目标哈希进行比较。C++可以使用Windows API中的Cryptographic Service Provider (CSP)来实现NTLM哈希计算。以下是一个使用CSP进行NTLM哈希计算的示例代码: ```c++ #include <windows.h> #include <wincrypt.h> #include <iostream> #include <string> bool CrackNTLMHash(const std::string& hash, const std::string& charset, int length, std::string& password) { // Open a handle to the Microsoft Base Cryptographic Provider HCRYPTPROV hProv; if (!CryptAcquireContext(&hProv, nullptr, MS_DEF_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { std::cerr << "Failed to acquire cryptographic context\n"; return false; } // Convert the hex-encoded hash to binary std::string hashBytes; for (size_t i = 0; i < hash.length(); i += 2) { hashBytes += static_cast<char>(std::stoi(hash.substr(i, 2), nullptr, 16)); } // Allocate a buffer for the hash object HCRYPTHASH hHash; if (!CryptCreateHash(hProv, CALG_MD4, 0, 0, &hHash)) { std::cerr << "Failed to create hash object\n"; CryptReleaseContext(hProv, 0); return false; } // Iterate over all possible passwords std::string passwordHash; for (int i = 0; i < length; ++i) { std::string password(length, charset[0]); do { // Hash the password if (!CryptHashData(hHash, reinterpret_cast<const BYTE*>(password.data()), length, 0)) { std::cerr << "Failed to hash data\n"; CryptDestroyHash(hHash); CryptReleaseContext(hProv, 0); return false; } // Get the hash value DWORD hashLength = 16; BYTE hashValue[16]; if (!CryptGetHashParam(hHash, HP_HASHVAL, hashValue, &hashLength, 0)) { std::cerr << "Failed to get hash value\n"; CryptDestroyHash(hHash); CryptReleaseContext(hProv, 0); return false; } // Compare the hash value to the target hash passwordHash.assign(reinterpret_cast<const char*>(hashValue), hashLength); if (passwordHash == hashBytes) { password = password.substr(0, i) + password[i] + password.substr(i + 1); break; } // Reset the hash object if (!CryptDestroyHash(hHash) || !CryptCreateHash(hProv, CALG_MD4, 0, 0, &hHash)) { std::cerr << "Failed to reset hash object\n"; CryptReleaseContext(hProv, 0); return false; } } while (std::next_permutation(password.begin(), password.end(), [&charset](char a, char b) { return charset.find(a) < charset.find(b); })); } // Release resources CryptDestroyHash(hHash); CryptReleaseContext(hProv, 0); // Check if the password was found if (passwordHash == hashBytes) { password = password.substr(0, length); return true; } else { return false; } } ``` 该代码将目标哈希作为十六进制字符串传递,因此您需要将其从NTLM哈希格式转换为十六进制字符串。此外,您需要为字符集和密码长度指定值。代码将在字符集中迭代所有可能的密码,并使用Cryptographic Service Provider计算NTLM哈希。如果找到密码,则将其保存在传递的字符串参数中并返回true,否则返回false。注意,这是一种非常低效的方法,因为它需要尝试所有可能的密码。在现实世界中,密码长度和复杂度通常足以使暴力破解成为不切实际的选择。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值