Skip to content

Commit

Permalink
added md5 attack data
Browse files Browse the repository at this point in the history
  • Loading branch information
bluyam committed Apr 17, 2015
1 parent 2feb83c commit cf42485
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
Binary file added lib/stego-attack-lib/fluffy1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/stego-attack-lib/fluffy2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/stego-attack-lib/fluffy3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/stego-attack-lib/img1.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/stego-attack-lib/img2.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions lib/stego-attack-lib/md5attack.cc
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;
}

0 comments on commit cf42485

Please sign in to comment.