]> git.sesse.net Git - freerainbowtables/blobdiff - Client Applications/rcracki_mt/HashAlgorithm.cpp
merged paths
[freerainbowtables] / Client Applications / rcracki_mt / HashAlgorithm.cpp
index 66513fcdf4884777a4c518c05fb0d3be6a0cfc13..db22aeba8386fbcc48af69287ebb31bf441ec25e 100644 (file)
@@ -1,29 +1,50 @@
 /*
-   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
-
-   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
-
-   Changes: not using OpenSSL routines the slow way anymore, as suggested by jci.
-*/
+ * rcracki_mt is a multithreaded implementation and fork of the original 
+ * RainbowCrack
+ *
+ * Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+ * Copyright Martin Westergaard Jørgensen <martinwj2005@gmail.com>
+ * Copyright 2009, 2010 Daniël Niggebrugge <niggebrugge@fox-it.com>
+ * Copyright 2009, 2010 James Nobis <frt@quelrod.net>
+ *
+ * This file is part of rcracki_mt.
+ *
+ * rcracki_mt is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * rcracki_mt is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with rcracki_mt.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Changes: not using OpenSSL routines the slow way anymore, as suggested by jci.
+ */
 
 #include "HashAlgorithm.h"
 
 #include "Public.h"
 
 #include <openssl/des.h>
-#include <openssl/md2.h>
-#include <openssl/sha.h>
-#include <openssl/ripemd.h>
-#include <openssl/md5.h>
+//#include <openssl/md2.h>
 #include <openssl/md4.h>
-
-//#include "md5.h"
+#include <openssl/sha.h>
+//#include <openssl/ripemd.h>
 #include "fast_md5.h"
 #include "md4.h"
-#include "sha1.h"
-#ifdef _WIN32
+//#include "sha1.h"
+#if defined(_WIN32) && !defined(__GNUC__)
        #pragma comment(lib, "libeay32.lib")
 #endif
+
+#ifdef __NetBSD__
+       #include <des.h>
+#endif
+
 #define MSCACHE_HASH_SIZE 16
 void setup_des_key(unsigned char key_56[], des_key_schedule &ks)
 {
@@ -110,41 +131,40 @@ void HashHALFLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
 
 void HashNTLMCHALL(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
 {
-  unsigned char UnicodePlain[MAX_PLAIN_LEN];
-  static unsigned char spoofed_challange[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; 
-  
-  int len = (nPlainLen < 127) ? nPlainLen : 127;
-  int i;
-  
-  for (i = 0; i < len; i++)
-  {
-    UnicodePlain[i * 2] = pPlain[i];
-    UnicodePlain[i * 2 + 1] = 0x00;
-  }
-
-  des_key_schedule ks;
-  unsigned char lm[21];
-
-  /*MD4_CTX ctx;
-  MD4_Init(&ctx);
-  MD4_Update(&ctx, UnicodePlain, len * 2);
-  MD4_Final(lm, &ctx);  */
-  MD4_NEW(UnicodePlain, len * 2, lm);
-
-  //MD4(UnicodePlain, len * 2, lm);
-  lm[16] = lm[17] = lm[18] = lm[19] = lm[20] = 0;
-
-  setup_des_key(lm, ks);
-  des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)pHash, ks, DES_ENCRYPT);
-
-  setup_des_key(&lm[7], ks);
-  des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[8], ks, DES_ENCRYPT);
-
-  setup_des_key(&lm[14], ks);
-  des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[16], ks, DES_ENCRYPT);
+       unsigned char UnicodePlain[MAX_PLAIN_LEN];
+       static unsigned char spoofed_challange[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; 
+       
+       int len = (nPlainLen < 127) ? nPlainLen : 127;
+       int i;
+       
+       for (i = 0; i < len; i++)
+       {
+       UnicodePlain[i * 2] = pPlain[i];
+       UnicodePlain[i * 2 + 1] = 0x00;
+       }
+       
+       des_key_schedule ks;
+       unsigned char lm[21];
+       
+       /*MD4_CTX ctx;
+       MD4_Init(&ctx);
+       MD4_Update(&ctx, UnicodePlain, len * 2);
+       MD4_Final(lm, &ctx);  */
+       MD4_NEW(UnicodePlain, len * 2, lm);
+       
+       //MD4(UnicodePlain, len * 2, lm);
+       lm[16] = lm[17] = lm[18] = lm[19] = lm[20] = 0;
+       
+       setup_des_key(lm, ks);
+       des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)pHash, ks, DES_ENCRYPT);
+       
+       setup_des_key(&lm[7], ks);
+       des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[8], ks, DES_ENCRYPT);
+       
+       setup_des_key(&lm[14], ks);
+       des_ecb_encrypt((des_cblock*)spoofed_challange, (des_cblock*)&pHash[16], ks, DES_ENCRYPT);
 }
 
-
 void HashORACLE(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
 {
        char ToEncrypt[256];
@@ -155,11 +175,17 @@ void HashORACLE(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
        DES_key_schedule ks1,ks2;
        unsigned char deskey_fixed[]={ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
        int i,j;
-
-       strcpy (username, "SYS");
+#if defined(_WIN32) && !defined(__GNUC__)
+       strcpy_s(username, sizeof(username), "SYS");
+#else
+       strcpy(username, "SYS");
+#endif
        int userlen = 3;
-       
-       strupr ((char*) pPlain);
+#if defined(_WIN32) && !defined(__GNUC__)
+       _strupr((char*) pPlain);
+#else
+       strupr((char*) pPlain);
+#endif
        memset (ToEncrypt,0,sizeof(ToEncrypt));
 
        for (i=1,j=0; j<userlen; i++,j++)
@@ -194,15 +220,10 @@ void HashNTLM(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
                UnicodePlain[i * 2 + 1] = 0x00;
        }
 
-       /*MD4_CTX ctx;
-       MD4_Init(&ctx);
-       MD4_Update(&ctx, UnicodePlain, nPlainLen * 2);
-       MD4_Final(pHash, &ctx);*/
-
-       //MD4(UnicodePlain, nPlainLen * 2, pHash);
        MD4_NEW(UnicodePlain, nPlainLen * 2, pHash);
 }
 
+/*
 void HashMD2(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
 {
        MD2_CTX ctx;
@@ -212,44 +233,34 @@ void HashMD2(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
 
        //MD2(pPlain, nPlainLen, pHash);
 }
+*/
 
 void HashMD4(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
 {
-       /*MD4_CTX ctx;
-       MD4_Init(&ctx);
-       MD4_Update(&ctx, pPlain, nPlainLen);
-       MD4_Final(pHash, &ctx);*/
-
        MD4_NEW(pPlain, nPlainLen, pHash);
-       //MD4(pPlain, nPlainLen, pHash);
 }
 
 void HashMD5(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
 {
-       //MD5_NEW(pPlain, nPlainLen, pHash);
        fast_MD5(pPlain, nPlainLen, pHash);
 }
 void HashDoubleMD5(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
 {
-       //MD5_NEW(pPlain, nPlainLen, pHash);
        fast_MD5(pPlain, nPlainLen, pHash);
        unsigned char hash[16];
        memcpy(hash, pHash, 16);
-       //MD5_NEW(hash, 16, pHash);
        fast_MD5(hash, 16, pHash);
 }
 
 void HashSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
 {
-       /*SHA_CTX ctx;
+       SHA_CTX ctx;
        SHA1_Init(&ctx);
-       SHA1_Update(&ctx, pPlain, nPlainLen);
-       SHA1_Final(pHash, &ctx);*/
-
-       //SHA1(pPlain, nPlainLen, pHash);
-       SHA1_NEW(pPlain, nPlainLen, pHash);
+       SHA1_Update(&ctx, (unsigned char *) pPlain, nPlainLen);
+       SHA1_Final(pHash, &ctx);
 }
 
+/*
 void HashRIPEMD160(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
 {
        RIPEMD160_CTX ctx;
@@ -259,6 +270,7 @@ void HashRIPEMD160(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
 
        //RIPEMD160(pPlain, nPlainLen, pHash);
 }
+*/
 
 void HashMSCACHE(unsigned char *pPlain, int nPlainLen, unsigned char* pHash)
 {
@@ -284,10 +296,12 @@ void HashMSCACHE(unsigned char *pPlain, int nPlainLen, unsigned char* pHash)
                unicode_user[i*2] = username[i];
                unicode_user[i*2+1] = 0x00;
        }
-
+       /*
        MD4_Init(&ctx);
        MD4_Update(&ctx,unicode_pwd,nPlainLen*2);
        MD4_Final(final1,&ctx);
+       */
+       MD4_NEW( (unsigned char*)unicode_pwd, nPlainLen*2, final1 );
 
        MD4_Init(&ctx);
        MD4_Update(&ctx,final1,MD4_DIGEST_LENGTH);
@@ -317,19 +331,19 @@ void HashMSCACHE(unsigned char *pPlain, int nPlainLen, unsigned char* pHash)
 
 inline void mysql_hash_password_323(unsigned long *result, const char *password) 
 {
-  register unsigned long nr=1345345333L, add=7, nr2=0x12345671L;
-  unsigned long tmp;
-  for (; *password ; password++) 
-  {
-    if (*password == ' ' || *password == '\t') continue;
-       tmp= (unsigned long) (unsigned char) *password;
-       nr^= (((nr & 63)+add)*tmp)+ (nr << 8);
-       nr2+=(nr2 << 8) ^ nr;
-       add+=tmp;
-  }
-  result[0]=nr & (((unsigned long) 1L << 31) -1L); /* Don't use sign bit (str2int) */;
-  result[1]=nr2 & (((unsigned long) 1L << 31) -1L);
-  return;
+       register unsigned long nr=1345345333L, add=7, nr2=0x12345671L;
+       unsigned long tmp;
+       for (; *password ; password++) 
+       {
+               if (*password == ' ' || *password == '\t') continue;
+               tmp= (unsigned long) (unsigned char) *password;
+               nr^= (((nr & 63)+add)*tmp)+ (nr << 8);
+               nr2+=(nr2 << 8) ^ nr;
+               add+=tmp;
+       }
+       result[0]=nr & (((unsigned long) 1L << 31) -1L); /* Don't use sign bit (str2int) */;
+       result[1]=nr2 & (((unsigned long) 1L << 31) -1L);
+       return;
 }
 
 void HashMySQL323(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
@@ -364,14 +378,14 @@ void HashMySQLSHA1(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
 // Code for PIX password hashing
 //*********************************************************************************
 static char itoa64[] =          /* 0 ... 63 => ascii - 64 */
-        "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+       "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 
 void _crypt_to64(char *s, unsigned long v, int n)
 {
-        while (--n >= 0) {
-                *s++ = itoa64[v&0x3f];
-                v >>= 6;
-        }
+       while (--n >= 0) {
+               *s++ = itoa64[v&0x3f];
+               v >>= 6;
+       }
 }
 
 void HashPIX(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
@@ -400,13 +414,13 @@ void HashPIX(unsigned char* pPlain, int nPlainLen, unsigned char* pHash)
        free (pass);
 }
 
-#ifndef _WIN32
+#if !defined(_WIN32) || defined(__GNUC__)
 char *strupr(char *s1)
 {
        char *p = s1;
        while(*p)
        {
-               toupper(*p);
+               *p = (char) toupper(*p);
                p++;
        }
        return s1;