houndsniff

Hash identification tool
git clone git://mcdim.xyz/houndsniff.git
Log | Files | Refs | README | LICENSE

main.c (4206B)


      1 /*
      2  * Houndsniff - version 2.1
      3  *
      4  * by Michael Constantine Dimopoulos et al
      5  * https://mcdim.xyz <mk@mcdim.xyz> GNU GPLv3
      6  *
      7  */
      8 
      9 #include <stdio.h>
     10 #include <stdlib.h>
     11 #include <stdbool.h>
     12 #include <string.h>
     13 #include <ctype.h>
     14 #include <readline/history.h>
     15 #include <readline/readline.h>
     16 #include "select.h"
     17 
     18 #define VERSION "2.1"
     19 
     20 #define BUFFER_SIZE 1024
     21 
     22 #define RED "\x1b[31m"
     23 #define RESET "\x1b[0m"
     24  
     25 static int
     26 hasUpper(char ch[])
     27 {
     28 	int len = strlen(ch);
     29 	int i;
     30 	
     31 	for (i = 0; i < len; i++) {
     32 		if (isupper(ch[i])) return 1;
     33 	} 
     34 
     35 	return 0;
     36 }
     37 
     38 void
     39 banner()
     40 { 
     41 	printf(	"          __			\n"
     42 		"(\\,------'()'--o  Sniff..	\n"
     43 		" \\_ )  _   /-''    Sniff...	\n"
     44 		"  /_)_) /_)_)			\n\n");
     45 	/*https://www.asciiart.eu/animals/dogs*/
     46 	
     47 	printf( "Houndsniff - Hash Identification Program - Version %s\n"
     48 		"By Michael Constantine Dimopoulos et al <mk@mcdim.xyz>\n"
     49 		"\n",VERSION);
     50 }
     51 
     52 static int
     53 starts_with(const char *a, const char *b)
     54 {
     55 	if(strncmp(a, b, strlen(b)) == 0) return 1;
     56 		return 0;
     57 }
     58 
     59 static void
     60 dprint(char *name, int clean_out)
     61 {
     62 	if (!clean_out) {
     63 		printf("[" RED "+" RESET "] Definite identification: "
     64 	       RED "%s" RESET "\n", name);
     65 	} else {
     66 		printf("%s 100.00\n", replace(name));
     67 	}
     68 }
     69 
     70 
     71 /* This is the first test;
     72  * here we identify the hash
     73  * based on *definite* characteristics
     74  */
     75 void
     76 definite(char string[], int length, int co)
     77 {
     78 
     79 	if (starts_with(string, "$P"))
     80 		dprint("Wordpress hash", co);
     81 	else if (starts_with(string, "$1$"))
     82 		dprint("MD5 crypt(3)", co);
     83 	else if (starts_with(string, "$5$"))
     84 		dprint("SHA256 crypt(3)", co);
     85 	else if (starts_with(string, "$6$"))
     86 		dprint("SHA512 crypt(3)", co);
     87 	else if (string[length-1]=='=') 
     88 		dprint("Base64 or Base32", co);
     89 	else if (starts_with(string, "$apr1$"))
     90 		dprint("APR1", co);
     91 	else if (starts_with(string, "$H$"))
     92 		dprint("phpBB", co);
     93 	else if (starts_with(string, "sha1$"))
     94 		dprint("SHA1 Django", co);
     95 	else if (length==65 && string[32]==':')
     96 		dprint("MD5 Joomla (pass:salt)", co);
     97 	else if (starts_with(string, "$2y$"))
     98 		dprint("PHP password_hash", co);
     99 }
    100 
    101 /* this function determines charset*/
    102 const char*
    103 charset(char string[])
    104 {
    105 	if (strchr(string, '$') != NULL)
    106 		return "b";	
    107 	else if (strchr(string, '/') != NULL)
    108 		return "c";
    109 	else if (string[0]=='0' && string[1]=='x' && string[2]=='0')
    110 		return "d";
    111 	else if (hasUpper(string)==1)
    112 		return "e";
    113 	else
    114 		return "a";
    115 }
    116 
    117 static void
    118 help(char *exename)
    119 {
    120 	printf( "If your hash includes a dollar sign ($) or other\n"
    121 		"special symbols, make sure you place it in between\n"
    122 		"quotes.\n\n"
    123 
    124 		"Contributors:\n"
    125 		"Christopher Wellons, Martin K.\n"
    126 		"tuu & fizzie on ##c@freenode\n\n"
    127 
    128 		"  -i   use interactive shell\n"
    129 		"  -s   use scripting mode\n"
    130 		"  -l   list supported hashing algorithms\n"
    131 		"  -h   display this panel and exit\n"
    132 		"  -v   print version and exit\n"
    133 		"\nUsage: Usage: %s [HASH] [-h|-v|-l] [-i] [-s]\n",
    134 		exename);
    135 }
    136 
    137 void
    138 driver(char *hash, int clean_out)
    139 {
    140 	int len = strlen(hash);
    141 	const char* chars = charset(hash);
    142 
    143 	if (!clean_out) {
    144 		printf("Hash: " RED "%s" RESET "\n", hash);
    145 		printf("Length: " RED "%d" RESET "\n",len);
    146 		printf("Charset: " RED "%s" RESET "\n\n", chars);
    147 	}
    148 
    149 	sel(len, chars, clean_out);
    150 	definite(hash, len, clean_out);
    151 
    152 	printf("\n");
    153 }
    154 
    155 void
    156 main(int argc, char* argv[])
    157 {
    158 
    159 	if (argc==1) {
    160 		banner();
    161 		printf("Usage: %s [HASH] [-h|-v|-l] [-i] [-s]\n", argv[0]);
    162 		exit(EXIT_FAILURE);
    163 	}
    164 
    165 	if (strcmp(argv[1],"-h")==0 || strcmp(argv[1],"--help")==0){
    166 		banner();
    167 		help(argv[0]);
    168 	} else if (strcmp(argv[1], "-l")==0) {
    169 		banner();
    170 		list();
    171 	} else if (strcmp(argv[1], "-i")==0) {
    172 		banner();
    173 		using_history();
    174 		while(1) {
    175 			char *hash;
    176 			hash = readline("houndsniff > ");
    177 			rl_bind_key('\t', rl_complete);
    178 			
    179 			if (!hash) break;
    180 			
    181 			add_history(hash);
    182 			driver(hash, 0);
    183 			printf("--------------------------\n");
    184 			free(hash);
    185 		}
    186 	} else if (strcmp(argv[1], "-s")==0) {
    187 		char buffer[BUFFER_SIZE];
    188 		while (fgets(buffer, sizeof(buffer), stdin) != NULL) {
    189 			strtok(buffer, "\n");
    190 			driver(buffer, 1);
    191 		}
    192 
    193 	} else if (strcmp(argv[1], "-v")==0) {
    194 		printf("houndsniff-v%s\n", VERSION);      
    195 	} else {
    196 		banner();
    197 		driver(argv[1], 0);
    198 	}
    199 	exit(EXIT_SUCCESS);
    200 }