SQLCipher-Password-Cracker-OpenCL使用记录

很麻烦,真的很麻烦

pip 安装

1
pip install pysqlcipher

不过这个方法多半是行不通的

手动安装

原版项目地址:GitHub - EnMicroMsg.db-Password-Cracker
其中 issue: CUDA version completed but won’t release 中出现了一个 OpenCL 显卡加速版项目,地址为:GitHub - whiteblackitty/SQLCipher-Password-Cracker-OpenCL: Password cracker for SQLCipher v2 using OpenCL
以下方法均基于 OpenCL 显卡加速版项目进行

下载项目与安装依赖项

克隆仓库

1
2
3
git clone https://github.com/whiteblackitty/SQLCipher-Password-Cracker-OpenCL.git

git clone

修改项目文件

对于 SQLCipher-Password-Cracker-OpenCL 项目

1
2
3
4
5
6
7
8
9
10
11
12
# /SQLCipher-Password-Cracker-OpenCL/Lib/opencl.py
`np.bool` --> `bool`
# numpy新版本中删除了`np.bool`,推荐使用python内建类型`bool`

# /SQLCipher-Password-Cracker-OpenCL/run.py, line 43
`passphrase+=chr(pword)` --> `passphrase+=chr(int(pword[0]))`
# python3.8及以后版本的python语法变更

# /SQLCipher-Password-Cracker-OpenCL/Lib/pbkdf2-sha1_aes-256-cbc.cl, line 752
``
-->
`if(((uint)(data[5] ^ iv[5])==0x40) && ((uint)(data[6] ^ iv[6])==0x20) && ((uint)(data[7] ^ iv[7])==0x20))`

安装环境

安装 CUDA 与 cuDNN

见网上教程

安装 OpenCL SDK

Intel 官网下载
Intel 官网
不清楚这个是什么
GitHub - KhronosGroup/OpenCL-SDK: OpenCL SDK

编译 SQLCipher

参见:Win64 setup — Compiling SQLCipher · sqlitebrowser/sqlitebrowser Wiki · GitHub,现简单记录如下。

该步骤貌似并不是必须,最后产生的文件可能可以使用 sqlite-amalgamation 中的文件代替。

安装 VS

VS 版本≥VS2013
选择 使用C++的桌面应用开发,需要勾选 Windows 10 SDKMSVCC++ ATL
其中 Windows 10 SDK 安装位置由 \HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows Kits\Installed Roots\ 的字符串 KitsRoot10 指定

安装 ActiveTcl

ActiveTcl

安装 OpenSSL

选择 The OpenSSL binaries (/bin) directory
安装完毕后需手动添加环境变量(用户变量即可)OPENSSL_CONF,地址为 <OPENSSLDIR>\OpenSSL-Win64\bin\openssl.cfg

配置环境变量

由于编译 SQLCipher 通过命令行使用 nmake,头文件和库文件搜索目录全部从环境变量中指定。

向系统变量中添加 LIB,路径为 <WIN10_SDK>\Lib\10.0.20348.0\um\x64;<WIN10_SDK>\Lib\10.0.20348.0\ucrt\x64;<VS_PATH>\VC\Tools\MSVC\14.36.32532\lib\x64;

向系统变量中添加 INCLUDE,路径为 <VS_PATH>\VC\Tools\MSVC\14.36.32532\include;<WIN10_SDK>\Include\10.0.20348.0\shared;<WIN10_SDK>\Include\10.0.20348.0\ucrt;<WIN10_SDK>\Include\10.0.20348.0\um;<WIN10_SDK>\Include\10.0.20348.0\winrt;

编译 SQLCipher

克隆 SQLCipher

1
2
git clone https://github.com/sqlcipher/sqlcipher.git
cd ./sqlcipher

可能还需要将 nmakerc 添加至环境变量 PATH,路径为 <VS_PATH>\VC\Tools\MSVC\14.36.32532\bin\Hostx64\x64;<WIN10_SDK>\bin\10.0.20348.0\x64

进行编译

1
2
nmake /f Makefile.msc clean
nmake /f Makefile.msc

这里多半会报错,但是只要生成了 sqlite3.csqlite3.h 即可

编译 pysqlcipher

克隆 pysqlcipher

1
2
git clone https://github.com/rigglemania/pysqlcipher3.git
cd ./pysqlcipher

编译 amalgamation

新建文件夹 pysqlcipher/amalgamation/,将 sqlite3.csqlite3.h 复制到 pysqlcipher/amalgamation/ 中。

下载 sqlite-amalgamation,解压至 pysqlcipher3/src/python3/sqlcipher 中。

由于 python 版本变化,修改 pysqlcipher3\src\python3 中的源文件,将 MODULE_NAME 替换为 "pysqlcipher3.dbapi2"
否则会产生以下报错

1
2
3
4
5
6
src\python3\cache.c(261): 
error C2017: illegal escape sequence
error C2061: syntax error: identifier 'Node'
error C2001: newline in constant
error C2224: left of '.Cache' must have struct/union type
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2"

之后即可进行编译

1
2
3
cd ./pysqlcipher/
python setup.py clean
python setup.py build_amalgamation

编译 pysqlcipher

1
python setup.py install 

验证

1
2
python
import pysqlcipher3 # 不报错就代表安装成功

SQLCipher-Password-Cracker-OpenCL 使用

项目库中的源码经过修改后即可直接使用了,将数据库放在 /SQLCipher-Password-Cracker-OpenCL/ 下,然后修改 Run.py 中数据库的名称后就可以运行了

1
2
python Run.py # 如果显卡(包含集显)不止一张,需要指定显卡编号
python Run.py 0 # 指定显卡编号

工具版本记录

我没有特意使用资料中的版本,而是选择最新版本,侥幸安装成功
python3.11.3
Win64OpenSSL-3_1_1
ActiveTcl-8.6.13.0000-MSWin32-x64-559160e0.msi
gowxdump-master-934a12de5f8febcb4d1f69d4f4c7fe6217d7df93.zip
pysqlcipher3-1.2.0.tar.gz
sqlcipher-4.5.4.zip
sqlite-amalgamation-3420000.zip

参考文献

python - Install pysqlcipher3 windows - Stack Overflow
GitHub - Monogi/pysqlcipher3_install_win10
win10 Python3安装pysqlcipher3的问题总结_no module named 'pysqlcipher3_orange_xiang的博客-CSDN博客
Win64 setup — Compiling SQLCipher · sqlitebrowser/sqlitebrowser Wiki · GitHub
在微信,如何导出自己和朋友的聊天记录? - 知乎
GitHub - whiteblackitty/SQLCipher-Password-Cracker-OpenCL: Password cracker for SQLCipher v2 using OpenCL
编译Windows 64bit平台pysqlcipher3 for Python3.7 - 作业部落 Cmd Markdown 编辑阅读器
安装pysqlcipher3时出现问题 - 问答 - 腾讯云开发者社区-腾讯云