initial commit

master
leonnicolas 5 years ago
commit d34dcbf4ea

@ -0,0 +1,7 @@
all: compile
compile:
gcc -std=c11 -o brutef main.c crypwrapper.c `libgcrypt-config --cflags --libs`
rainbow:
gcc -std=c11 -o rainb createRainbow.c crypwrapper.c `libgcrypt-config --cflags --libs`

@ -0,0 +1,5 @@
type make rainbow to compile rainbow table generator
./rainb file.txt will create hash values from password file file.txt and safe them in file.txt.sha256
make will compile only the brute force application
./brutef file.txt.sha256 somepassword will decrypt some summy data with somepassword's hash value and then try to decript it using hashes in file.txt.sha256

@ -0,0 +1,58 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "rainbowvalue.h"
#include "cryptwrapper.h"
int main(int argc, char const *argv[]) {
if (argc != 2){
printf("one argument expected ,argc =%i\n",argc);
return 1;
}
FILE *fptr;
fptr = fopen(argv[1],"r");
if(fptr == NULL)
{
printf("Could not open file %s\n", argv[1]);
return 1;
}
FILE *tfptr;
char str[strlen(argv[1])+7];
strcpy(str,argv[1]);
strcat(str,".sha256");
tfptr = fopen(str,"wb");
if(tfptr == NULL)
{
printf("Could not create file %s\n", str);
return 1;
}
mycryptwrapper_init();
char line[256];
gcry_error_t err;
size_t mens = gcry_md_get_algo_dlen(algo);
void * digest=malloc(mens);
//printdata(buf,5);
//printf("\n");
struct s_rainbowvalue256 r;
while (fgets(line, sizeof(line), fptr)) {
gcry_md_hash_buffer(algo,digest,line,strlen(line)-1);// -1 so trailing \n is not used for calculation
//mycryptwrapper_print(digest, strlen(digest));
//printf("%s", line);
strcpy(r.pw , line);
strcpy(r.hash,digest);
fwrite(&r, sizeof(struct s_rainbowvalue256),1,tfptr);
}
fclose(tfptr);
fclose(fptr);
return 0;
}

@ -0,0 +1,26 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gcrypt.h"
#include <inttypes.h>
#ifndef mycryptwrapper_
#define mycryptwrapper_
#define NEED_LIBGCRYPT_VERSION "1.6.5" //should be 1.8.5 but my libgcrypt as mismatched versions :(
#define algo GCRY_MD_SHA256
#define cipher GCRY_CIPHER_DES
void mycryptwrapper_init();
void mycryptwrapper_print();
#endif

@ -0,0 +1,31 @@
#include "cryptwrapper.h"
void mycryptwrapper_init(){
/* Version check should be the very first call because it
makes sure that important subsystems are initialized.
#define NEED_LIBGCRYPT_VERSION to the minimum required version. */
if (!gcry_check_version (NEED_LIBGCRYPT_VERSION))
{
fprintf (stderr, "libgcrypt is too old (need %s, have %s)\n",
NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL));
exit (2);
}
/* Disable secure memory. */
gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
/* ... If required, other initialization goes here. */
/* Tell Libgcrypt that initialization has completed. */
gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
}
void mycryptwrapper_print(const void * buf, size_t len){
for (size_t i = 0; i< len; i++){
printf("%02x ", ((uint8_t*)buf)[i]);
}
printf("\n");
}

119
main.c

@ -0,0 +1,119 @@
#include <stdio.h>
#include "gcrypt.h"
#include<stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <strings.h>
#include <inttypes.h>
#include "cryptwrapper.h"
#include "rainbowvalue.h"
#define NEED_LIBGCRYPT_VERSION "1.6.5" //should be 1.8.5 but my libgcrypt as mismatched versions :(
#define algo GCRY_MD_SHA256
#define cipher GCRY_CIPHER_DES
void printdata(const void * buf, size_t len){
for (size_t i = 0; i< len; i++){
printf("%x ", ((uint8_t*)buf)[i]);
}
}
int main(int argc, char const *argv[]) {
if (argc < 2){
printf("please select rainbow table\n");
return 1;
}
FILE * fptr = fopen(argv[1],"rb");
if (fptr==NULL){
printf("could not open file %s\n",argv[1]);
return 1;
}
char* pw_clear = malloc(256);
memset(pw_clear,0,256);
if (argc==3){
strcpy(pw_clear,argv[2]);
}
else{
strcpy(pw_clear,"ELEONORY");
}
const char * dummydata = "0123456789";
mycryptwrapper_init();
gcry_cipher_hd_t hd;
gcry_error_t err= gcry_cipher_open(&hd,cipher,GCRY_CIPHER_MODE_CFB,0);
size_t mens = gcry_md_get_algo_dlen(algo);
void * digest=malloc(mens);
gcry_md_hash_buffer(algo,digest,pw_clear,strlen(pw_clear));
printf("hash Key:");
mycryptwrapper_print(digest,mens);
//printf("\n");
if(gcry_cipher_setkey(hd,digest,8)){
printf("could not set key for encryption");
}
size_t len = 8;
void * iv = malloc(len);
err = gcry_cipher_setiv(hd, iv , len);
if (err){
printf("could not init init vector");
}
unsigned char * encrypted_secret = malloc(32);
err = gcry_cipher_encrypt(hd,encrypted_secret,32,dummydata,10);
if (err){
printf("could not encrypt");
}
printf("encypted data:");
mycryptwrapper_print(encrypted_secret,32);
//printf("\n");
void * out = malloc(256);//allocate mem for decrypted buffer
struct s_rainbowvalue256 r;
while (fread(&r, sizeof(struct s_rainbowvalue256), 1,fptr)) {//reading hash values from rainbowtable
gcry_cipher_hd_t dhd;
gcry_error_t err= gcry_cipher_open(&dhd,cipher,GCRY_CIPHER_MODE_CFB,0);
if (err){
printf("could not open handle\n");
}
//printf("hash key: ");
//mycryptwrapper_print(r.hash,32);
err = gcry_cipher_setkey(dhd,r.hash,8);
if (err) {
printf("could not set key \n");
}
memset(iv,0,len);
err = gcry_cipher_setiv(dhd, iv , len);
if (err){
printf("could not init init vector");
}
memset(out,0,256);
err = gcry_cipher_decrypt(dhd,out,256,encrypted_secret,strlen(encrypted_secret));
if (err){
printf("could not decrypt\n");
}
//printf("encrpyted secret:");
//mycryptwrapper_print(encrypted_secret,strlen(encrypted_secret));
//printf("\ndecrypted");
//mycryptwrapper_print(out,256);
if (strcmp(out,dummydata)==0){
printf("pw: %sfor data: %s\npwhash: ", r.pw, (char*)out);
mycryptwrapper_print(r.hash, strlen(r.hash));
return 0;
}
gcry_cipher_close(dhd);//close cipher
}
printf("\nnothing found\n");
//printdata(digest,mens);
return 0;
}

@ -0,0 +1,9 @@
#ifndef rainbowvalue
#define rainbowvalue
struct s_rainbowvalue256 {
char pw[256];
char hash[256];
};
#endif
Loading…
Cancel
Save