Skip to content

Commit

Permalink
Renamed images can now be read, key is now hashed before use
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Geitz committed Dec 3, 2015
1 parent e00cb90 commit ea40aa1
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
9 changes: 5 additions & 4 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
36 changes: 28 additions & 8 deletions afs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];
Expand All @@ -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));
Expand Down
4 changes: 3 additions & 1 deletion albumfs.1
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 25 additions & 1 deletion albumfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions include/afspng.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions include/albumfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
#include <fcntl.h>
#include <math.h>
#include <sys/types.h>

#include <openssl/md5.h>

/* Preprocessor Macros */

#define _GNU_SOURCE
#define VERSION "0.1.2"
#define MAX_FILENAME 64
#define MAX_PATH 512
#define MINIMUM_PNG 2
Expand All @@ -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);
Expand Down

0 comments on commit ea40aa1

Please sign in to comment.