From ea40aa1b901a382d13e1826b7a650188ac76f948 Mon Sep 17 00:00:00 2001 From: Michael Geitz Date: Thu, 3 Dec 2015 00:50:18 -0500 Subject: [PATCH] Renamed images can now be read, key is now hashed before use --- Makefile | 2 +- README | 9 +++++---- afs.c | 36 ++++++++++++++++++++++++++++-------- albumfs.1 | 4 +++- albumfs.c | 26 +++++++++++++++++++++++++- include/afspng.h | 1 + include/albumfs.h | 4 ++-- 7 files changed, 65 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 85ebafb..d6578ba 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ MAN=albumfs.1 CFLAGS=-Wall -D_FILE_OFFSET_BITS=8 PKG=`pkg-config fuse --cflags --libs` -LIBS=-lpng -lm +LIBS=-lpng -lm -lssl -lcrypto all: objects $(NAME) rm ${OBJECTS} diff --git a/README b/README index b44c0ea..14b39e8 100644 --- a/README +++ b/README @@ -8,24 +8,25 @@ key encrypted LSB steganography PNG album filesystem in userspace Create, access, and modify a key encrypted LSB steganography filesystem in userspace using a directory of PNG images. Filesystem state is only preserved after safely closing the filesystem via unmount or Ctrl+C. A filesystem may only use images with the same dimensions as the root image provided. + A filesystem requires a name, key, root image, and storage images. To access a filesystem the correct key, filesystem name, and root image must be given. All data is XOR'd with the key as it is read and written from the images. The root image stores the filesystem name, consumed and total space, image and file count, image filenames, and file meta data. All images added to the filesystem while formatting or expanding are found in the same directory as the root image. + Formatting a filesystem wipes each avialable least signifigant bit in the images provided, similarly removing a file wipes its data and shifts the filesystem if there is a hole. All files in the filesystem have permissions of 644 and cannot be edited, but can be read, renamed, deleted, and copied. DEPENDENCIES: - libfuse-dev - - pkg-config - libpng12-dev + - libssl-dev + - pkg-config COMPILE: - make all - sudo make install - - make clean KNOWN BUGS: - - Filesystem cannot survive image renames - Filesystem does not support directories @@ -53,6 +54,6 @@ EXAMPLES: TODO: - - Replace use of name for image tracking with sum + - Use different way to write to root image so offset can be unsigned - Support directories - Add option for live updating diff --git a/afs.c b/afs.c index cb3803f..62763ad 100644 --- a/afs.c +++ b/afs.c @@ -518,8 +518,9 @@ void writeRoot() { // Write png_data for each valid image for (y = 0; y < afs->img_count; y++) { - writeBytes((void *) afs->images[y]->filename, MAX_FILENAME, offset); - offset = offset - MAX_FILENAME; + getMD5(afs->images[y]->filename, afs->images[y]->md5); + writeBytes((void *) afs->images[y]->md5, sizeof(afs->images[y]->md5), offset); + offset = offset -sizeof(afs->images[y]->md5); } // Write file_meta for each file @@ -533,6 +534,8 @@ void writeRoot() { /* Read filesystem_meta and png_data from root img */ void readRoot() { + DIR *FD; + struct dirent *dir; int y; int offset = -1; char name[64]; @@ -555,18 +558,35 @@ void readRoot() { printf("Found filesystem %s [%0.2f/%0.2f] %d files in %d images\n", name, afs->consumed, afs->capacity, afs->file_count, afs->img_count); png_data **dir_images = malloc((sizeof(png_data*) * afs->img_count)); + FD = opendir(afs->img_dir); + if (!FD) { + fprintf(stderr, "Cannot open directory %s", afs->img_dir); + free(afs); + exit(1); + } // Read png_data for each valid image for (y = 0; y < afs->img_count; y++) { png_data *new_img = malloc(sizeof(png_data)); - readBytes((void *) new_img->filename, MAX_FILENAME, offset); - offset = offset - MAX_FILENAME; - dir_images[y] = new_img; - if (!read_png(new_img, afs->img_dir)) { - fprintf(stderr, "Filesystem is missing image %s!", new_img->filename); - exit(1); + char tmp[strlen(new_img->md5)]; + readBytes((void *) new_img->md5, sizeof(new_img->md5), offset); + offset = offset - sizeof(new_img->md5); + while ((dir = readdir(FD)) != NULL) { + memset(tmp, 0, sizeof(new_img->md5)); + getMD5(dir->d_name, tmp);; + if (strncmp(tmp, new_img->md5, sizeof(new_img->md5)) == 0) { + strcpy(new_img->filename, dir->d_name); + if (!read_png(new_img, afs->img_dir)) { + fprintf(stderr, "Filesystem is missing image %s!", new_img->filename); + exit(1); + } + dir_images[y] = new_img; + break; + } } + seekdir(FD, 0); } + closedir(FD); afs->images = dir_images; afs_file **files = malloc((sizeof(afs_file*) * afs->file_count)); diff --git a/albumfs.1 b/albumfs.1 index 928b97e..024845d 100644 --- a/albumfs.1 +++ b/albumfs.1 @@ -1,12 +1,14 @@ .\" Manpage for albumfs. -.TH ALBUMFS 1 "Dec 2015" "0.1.2" "User Commands" +.TH ALBUMFS 1 "Dec 2015" "0.1.3" "User Commands" .SH NAME albumfs \- key encrypted LSB steganography PNG album filesystem in userspace .SH SYNOPSIS albumfs [OPTIONS]... [PATH/TO/ROOTIMAGE.PNG] .SH DESCRIPTION Create, access, and modify a LSB steganography filesystem in userspace using a directory of PNG images. Filesystem state is only preserved after safely closing the filesystem via unmount or Ctrl+C. A filesystem may only use images with the same dimensions as the root image provided. +.PP A filesystem requires a name, key, root image, and storage images. To access a filesystem the correct key, filesystem name, and root image must be given. All data is XOR'd with the key as it is read and written from the images. The root image stores the filesystem name, consumed and total space, image and file count, image filenames, and file meta data. All images added to the filesystem while formatting or expanding are found in the same directory as the root image. +.PP Formatting a filesystem wipes each avialable least signifigant bit in the images provided, similarly removing a file wipes its imprint and shifts the filesystem if there is a hole. All files in the filesystem have permissions of 644 and cannot be edited, but can be read, renamed, deleted, and copied. .TP .B -format diff --git a/albumfs.c b/albumfs.c index 6fc0613..71fa2d8 100644 --- a/albumfs.c +++ b/albumfs.c @@ -63,7 +63,11 @@ int main(int argc, char *argv[]) { strcat(afs->name, ".afs"); printf("Enter encryption key for %s:\n", afs->name); fgets(afs->key, sizeof(afs->key), stdin); - afs->key[strlen(afs->key) - 1] = '\0'; + //afs->key[strlen(afs->key) - 1] = '\0'; + MD5_CTX mdContext; + MD5_Init (&mdContext); + MD5_Update (&mdContext, afs->key, sizeof(afs->key)); + MD5_Final ((unsigned char *)afs->key, &mdContext); printf("\e[1;1H\e[2J"); // Check mount @@ -108,3 +112,23 @@ int parseArgv(int argc, char *argv[], char *option) { } return 0; } + + +/* Calculate MD5 of a file */ +int getMD5(char *filename, char *md5_sum) { + char path[MAX_PATH]; + strcpy(path, afs->img_dir); + strcat(path, filename); + FILE *f = fopen(path, "rb"); + char data[sizeof(md5_sum)]; + + if (f == NULL) { return 0; } + MD5_CTX mdContext; + MD5_Init (&mdContext); + while (fread (data, 1, sizeof(md5_sum), f) != 0) { + MD5_Update (&mdContext, data, sizeof(md5_sum)); + } + MD5_Final ((unsigned char *)md5_sum, &mdContext); + pclose(f); + return 1; +} diff --git a/include/afspng.h b/include/afspng.h index 85a767a..f680c81 100644 --- a/include/afspng.h +++ b/include/afspng.h @@ -16,6 +16,7 @@ typedef enum {modified, not_modified} image_state; struct PNG_image_data { char filename [MAX_FILENAME]; + char md5[64]; int32_t width, height, channels; unsigned char png_sig[8]; png_byte color_type; diff --git a/include/albumfs.h b/include/albumfs.h index 311a490..cab136d 100644 --- a/include/albumfs.h +++ b/include/albumfs.h @@ -20,12 +20,11 @@ #include #include #include - +#include /* Preprocessor Macros */ #define _GNU_SOURCE -#define VERSION "0.1.2" #define MAX_FILENAME 64 #define MAX_PATH 512 #define MINIMUM_PNG 2 @@ -45,6 +44,7 @@ int8_t afs_dbg; //albumfs.c void afs_usage(); int parseArgv(int argc, char *argv[], char *option); +int getMD5(char *filename, char *mds_sum); //afs.c int wipeFile(char *path); int findFile(char *path);