我尝试了多次,无法编译成功。应该是cryptopp没有安装好,但我的水平实在有限。
该项目是根据Local State秘钥来解密Login Data中的密码。
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <windows.h>
#include <wincrypt.h>
#include <sqlite3.h>
#include <cryptopp/aes.h>
#include <cryptopp/filters.h>
#include <cryptopp/modes.h>
#include <cryptopp/base64.h>
#pragma comment(lib, "cryptlib.lib")
#pragma comment(lib, "crypt32.lib")
#pragma comment(lib, "sqlite3.lib")
std::string GetString(const std::string& localStateFile) {
std::ifstream file(localStateFile);
std::string line;
std::string encryptedKey;
while (std::getline(file, line)) {
if (line.find("\"encrypted_key\":") != std::string::npos) {
encryptedKey = line.substr(line.find(":") + 2);
break;
}
}
file.close();
return encryptedKey;
}
std::vector<unsigned char> PullTheKey(const std::string& base64EncryptedKey) {
std::vector<unsigned char> encryptedKey, decryptedKey;
CryptoPP::StringSource ss(base64EncryptedKey, true,
new CryptoPP::Base64Decoder(
new CryptoPP::VectorSink(encryptedKey)
)
);
if (encryptedKey.size() > 5) {
encryptedKey.erase(encryptedKey.begin(), encryptedKey.begin() + 5);
}
DATA_BLOB inputBlob, outputBlob;
inputBlob.cbData = static_cast<DWORD>(encryptedKey.size());
inputBlob.pbData = reinterpret_cast<BYTE*>(encryptedKey.data());
if (CryptUnprotectData(&inputBlob, nullptr, nullptr, nullptr, nullptr, 0, &outputBlob)) {
decryptedKey.resize(outputBlob.cbData);
memcpy(decryptedKey.data(), outputBlob.pbData, outputBlob.cbData);
LocalFree(outputBlob.pbData);
}
return decryptedKey;
}
std::string DecryptString(const std::vector<unsigned char>& key, const std::vector<unsigned char>& data) {
std::vector<unsigned char> decryptedData;
const unsigned char* nonce = data.data() + 3;
const unsigned char* cipherBytes = data.data() + 15;
CryptoPP::GCM<CryptoPP::AES>::Decryption gcmDecryption;
gcmDecryption.SetKeyWithIV(key.data(), key.size(), nonce, 12);
CryptoPP::StringSource ss(cipherBytes, data.size() - 15, true,
new CryptoPP::AuthenticatedDecryptionFilter(
gcmDecryption,
new CryptoPP::VectorSink(decryptedData)
)
);
std::string plaintext(decryptedData.begin(), decryptedData.end());
return plaintext;
}
int main() {
std::string localStateFile = "D:\\1\\Local State";
std::vector<unsigned char> key;
std::string base64EncryptedKey = GetString(localStateFile);
if (!base64EncryptedKey.empty()) {
key = PullTheKey(base64EncryptedKey);
} else {
std::cout << "Failed to retrieve the encrypted key from the Local State file." << std::endl;
return 1;
}
std::string loginDataFile = "D:\\1\\Login Data";
sqlite3* db;
if (sqlite3_open_v2(loginDataFile.c_str(), &db, SQLITE_OPEN_READONLY, nullptr) == SQLITE_OK) {
sqlite3_stmt* stmt;
std::string query = "SELECT origin_url, username_value, password_value FROM logins";
if (sqlite3_prepare_v2(db, query.c_str(), -1, &stmt, nullptr) == SQLITE_OK) {
while (sqlite3_step(stmt) == SQLITE_ROW) {
const unsigned char* url = sqlite3_column_text(stmt, 0);
const unsigned char* username = sqlite3_column_text(stmt, 1);
const unsigned char* encryptedPassword = sqlite3_column_text(stmt, 2);
std::vector<unsigned char> encryptedData;
CryptoPP::StringSource ss(reinterpret_cast<const char*>(encryptedPassword), -1, true,
new CryptoPP::Base64Decoder(
new CryptoPP::VectorSink(encryptedData)
)
);
std::string decryptedPassword = DecryptString(key, encryptedData);
std::cout << "URL: " << url << std::endl;
std::cout << "Username: " << username << std::endl;
std::cout << "Decrypted Password: " << decryptedPassword << std::endl;
std::cout << std::endl;
}
sqlite3_finalize(stmt);
}
sqlite3_close(db);
} else {
std::cout << "Failed to open the Login Data database." << std::endl;
return 1;
}
return 0;
}
这个cryptopp依赖都下载后,配置好包含和库,编译就可以,有问题把错误贴出来可以帮忙解决。
朋友你好,看了下,代码没看出有明显问题,可能确实式没安装好库,你先按照下面来检查一遍:
1.头文件引用问题:
确保已正确安装和链接Crypto++和SQLite3库。
检查头文件引用是否正确,例如#include <cryptopp/aes.h>和#include <sqlite3.h>。
2.编译链接问题:
确保已正确链接Crypto++库和SQLite3库。
在代码开头添加#pragma comment(lib, "cryptlib.lib")、#pragma comment(lib, "crypt32.lib")和#pragma comment(lib, "sqlite3.lib")来指定链接的库文件。
3.文件路径问题:
检查localStateFile和loginDataFile变量中的文件路径是否正确。
确保程序有权限访问这些文件。
4.数据库操作问题:
确保SQLite3数据库文件Login Data存在于指定的路径,并且有读取权限。
5.数组越界问题:
检查encryptedKey和encryptedData向量的大小,确保没有越界访问。
6.编码问题:
确保源文件以UTF-8编码保存,以避免中文乱码问题。
希望可以帮到你,帮忙点个采纳吧。谢谢啦!
没装好 别人编译成功,你那一样不是编译不成功
这是我编译中的出现的问题
已编译完成,包括源码工程,和编译完的exe文件:
链接: https://pan.baidu.com/s/13_YxIGhyJj_eIdRllD8wJw
提取码私信发你