-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Kyle Wilson | ||
// Test Driven Scrumbags | ||
// Compile: gcc -w -o md5attack md5attack.cpp -lcrypt | ||
// Run: ./md5attack <original image file> <new image file> | ||
|
||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <sys/mman.h> | ||
#include <fcntl.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <openssl/md5.h> | ||
|
||
unsigned char result1[MD5_DIGEST_LENGTH]; | ||
unsigned char result2[MD5_DIGEST_LENGTH]; | ||
|
||
// Compare results; cannot use strcmp() because it requires signed char* | ||
int compareHashVals(unsigned char* string1, unsigned char* string2) { | ||
int i; | ||
for(i=0; i<MD5_DIGEST_LENGTH; i++) | ||
if (string1[i]!=string2[i]) return 1; | ||
return 0; | ||
} | ||
|
||
// Print the MD5 sum as hex-digits. | ||
void printMD5Sum(unsigned char* md) { | ||
int i; | ||
for(i=0; i <MD5_DIGEST_LENGTH; i++) { | ||
printf("%02x",md[i]); | ||
} | ||
} | ||
|
||
// Get the size of the file by its file descriptor | ||
unsigned long getSizeByFD(int fd) { | ||
struct stat statbuf; | ||
if(fstat(fd, &statbuf) < 0) exit(-1); | ||
return statbuf.st_size; | ||
} | ||
|
||
// Gets a single file's hash and stores it in the parameter result | ||
void getMD5Hash(char* filename, unsigned char* result) { | ||
int fileDesc; | ||
unsigned long fileSize; | ||
char* fileBuffer; | ||
|
||
fileDesc = open(filename, O_RDONLY); | ||
if(fileDesc < 0) exit(-1); | ||
|
||
fileSize = getSizeByFD(fileDesc); | ||
|
||
fileBuffer = (char*) mmap(0, fileSize, PROT_READ, MAP_SHARED, fileDesc, 0); | ||
MD5((unsigned char*) fileBuffer, fileSize, result); | ||
munmap(fileBuffer, fileSize); | ||
|
||
printMD5Sum(result); | ||
printf(" %s\n", filename); | ||
|
||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
|
||
if(argc != 3) { | ||
printf("Must specify the files\n"); | ||
exit(-1); | ||
} | ||
getMD5Hash(argv[1], result1); | ||
getMD5Hash(argv[2], result2); | ||
|
||
if (compareHashVals(result1, result2)) { | ||
printf("Hashes do not match: There is a message embedded!\n"); | ||
} | ||
else printf("Hashes match: There is no embedded message.\n"); | ||
|
||
return 0; | ||
} |