저는 C로 작은 암호 해독 프로그램을 작성하여 "resource.bin"이라는 한 파일에서 키를 강제로 강제 실행하고이 프로그램을 사용하여 DES-EDE (여기서는 "rom_dump.bin")를 사용하여 다른 파일의 암호를 해독해야했습니다. 올바른 키에 대한 표시는 해독 된 파일 내용이로 끝나는 10 자리 숫자로 시작한다는 것 \0
입니다. 그 후 복호화 된 콘텐츠를 다른 파일 (여기서는 "decrypted.bin")에 기록하고 파일은 ECDSA (함수 사용 EVP_ecdsa()
) 로 해시해야합니다 . 이 모든 작업은 SUSE Linux에서 수행됩니다. 파일은 여기에서 찾을 수 있습니다.
https://spideroak.com/browse/share/see/stack/StackOverflow/
이제 암호 해독은 잘 작동하지만 해시 값이 올바르지 않습니다.
a493af52c1a000fcace34de8b0a74a9cf9067ffc
그러나 며칠 동안 검색해도 문제를 찾을 수 없습니다. 내가 감독하고있는 것은 아마 잊을 수없는 일이지만 누군가가 나를 도울 수 있다면 매우 기쁠 것입니다. 미리 감사드립니다.
#include <stdio.h>
#include <string.h>
#include <openssl/evp.h>
#include <unistd.h>
#include <fcntl.h>
const unsigned long long bufferSize = 0x10000;
int checkOutput(unsigned char *output) {
int i = 0;
for (i; i < 6; i++) {
if (!isdigit(output[i])) {
return 0;
}
}
return 1;
}
void changeKey(unsigned char *key, unsigned char *fileContent, long keyLength,
long initVectorLength) {
int i = 0;
for (i; i < keyLength + initVectorLength; i++) {
key[i] = fileContent[i];
}
}
void toHashFile(FILE *hashFile, unsigned char *hash, int hashLength) {
int i = 0;
for (i; i < hashLength; i++) {
fprintf(hashFile, "%02x", hash[i]);
}
fprintf(hashFile, "\n");
}
void toOutputFile(FILE *fileName, unsigned char *output,
int outputLength) {
int i = 0;
for (i; i < outputLength; i++) {
fprintf(fileName, "%c", output[i]);
}
fprintf(fileName, "\n");
}
void writeToFile(const unsigned char *fileName, unsigned char *content,
int contentLength,
void (*functionPointer)(FILE *, unsigned char *, int)) {
FILE *file = fopen(fileName, "w");
(*functionPointer)(file, content, contentLength);
fclose(file);
}
void createHash(unsigned char *hash, unsigned char *output, int length,
int *hashLength) {
EVP_MD_CTX hashContext;
EVP_MD_CTX_init(&hashContext);
EVP_DigestInit(&hashContext, EVP_ecdsa());
EVP_DigestUpdate(&hashContext, output, length);
EVP_DigestFinal(&hashContext, hash, hashLength);
}
int main() {
/* output stuff */
unsigned char keyAndInitVector[24] = {0x00};
unsigned char output[bufferSize];
unsigned char outputFinal[bufferSize];
int outputLength;
/* determine key length and init vector */
int initVectorLength = EVP_CIPHER_iv_length(EVP_des_ede_ecb());
int keyLength = EVP_CIPHER_key_length(EVP_des_ede_ecb());
/* read resource files */
unsigned char romFileContent[bufferSize];
unsigned char resFileContent[bufferSize];
int romLength = read(open("rom_dump.bin", O_RDONLY), romFileContent,
bufferSize);
int resLength = read(open("resource.bin", O_RDONLY), resFileContent,
bufferSize);
/* init context */
EVP_CIPHER_CTX cypherContext;
EVP_CIPHER_CTX_init(&cypherContext);
int i = 0, j;
int isDecrypted = 0;
for (i; i < romLength - (keyLength + initVectorLength) &&
!isDecrypted; i++) {
changeKey(keyAndInitVector, romFileContent + i, keyLength,
initVectorLength);
EVP_DecryptInit(&cypherContext, EVP_des_ede_ecb(),
keyAndInitVector, keyAndInitVector + keyLength);
EVP_DecryptUpdate(&cypherContext, output, &outputLength,
resFileContent, resLength);
for (j = 0; j < resLength; j++) {
if (checkOutput(output + j) == 1) {
isDecrypted = 1;
break;
}
}
}
if (isDecrypted) {
int postfixLength;
EVP_DecryptFinal(&cypherContext, outputFinal,
&postfixLength);
writeToFile("decrypted.bin", output,
outputLength + postfixLength, &toOutputFile);
int hashLength = 0;
unsigned char hash[bufferSize];
createHash(hash, output, outputLength + postfixLength,
&hashLength);
writeToFile("hash.txt", hash, hashLength, &toHashFile);
}
EVP_CIPHER_CTX_cleanup(&cypherContext);
return isDecrypted;
}
당신의에서 toOutputFile()
기능, 당신은 추가 \n
파일에 있지만 아래로 main()
그렇지 파일을 해시를 수행하지만 output
.
즉, 파일에 존재하지 않는 decrypted.bin
추가 항목 \n
이 output
있으므로 파일을 해시 할 때 해시가 해당 프로그램으로 만든 것과 다릅니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다