2 * rcracki_mt is a multithreaded implementation and fork of the original
\r
5 * Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
\r
6 * Copyright Martin Westergaard Jørgensen <martinwj2005@gmail.com>
\r
7 * Copyright 2009, 2010 Daniël Niggebrugge <niggebrugge@fox-it.com>
\r
8 * Copyright 2009, 2010 James Nobis <frt@quelrod.net>
\r
10 * This file is part of racrcki_mt.
\r
12 * rcracki_mt is free software: you can redistribute it and/or modify
\r
13 * it under the terms of the GNU General Public License as published by
\r
14 * the Free Software Foundation, version 2 of the License.
\r
16 * rcracki_mt is distributed in the hope that it will be useful,
\r
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
19 * GNU General Public License for more details.
\r
21 * You should have received a copy of the GNU General Public License
\r
22 * along with rcracki_mt. If not, see <http://www.gnu.org/licenses/>.
\r
26 #pragma warning(disable : 4786 4267 4018)
\r
32 #include <windows.h>
\r
35 #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
\r
36 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
\r
38 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
\r
43 int tz_minuteswest; /* minutes W of Greenwich */
\r
44 int tz_dsttime; /* type of dst correction */
\r
47 int gettimeofday(struct timeval *tv, struct timezone *tz)
\r
49 // Define a structure to receive the current Windows filetime
\r
52 // Initialize the present time to 0 and the timezone to UTC
\r
53 unsigned __int64 tmpres = 0;
\r
54 static int tzflag = 0;
\r
58 GetSystemTimeAsFileTime(&ft);
\r
60 // The GetSystemTimeAsFileTime returns the number of 100 nanosecond
\r
61 // intervals since Jan 1, 1601 in a structure. Copy the high bits to
\r
62 // the 64 bit tmpres, shift it left by 32 then or in the low 32 bits.
\r
63 tmpres |= ft.dwHighDateTime;
\r
65 tmpres |= ft.dwLowDateTime;
\r
67 // Convert to microseconds by dividing by 10
\r
70 // The Unix epoch starts on Jan 1 1970. Need to subtract the difference
\r
71 // in seconds from Jan 1 1601.
\r
72 tmpres -= DELTA_EPOCH_IN_MICROSECS;
\r
74 // Finally change microseconds to seconds and place in the seconds value.
\r
75 // The modulus picks up the microseconds.
\r
76 tv->tv_sec = (long)(tmpres / 1000000UL);
\r
77 tv->tv_usec = (long)(tmpres % 1000000UL);
\r
88 // Adjust for the timezone west of Greenwich
\r
89 tz->tz_minuteswest = _timezone / 60;
\r
90 tz->tz_dsttime = _daylight;
\r
96 #elif defined(__APPLE__) || \
\r
97 ((defined(__unix__) || defined(unix)) && !defined(USG))
\r
99 #include <sys/param.h>
\r
102 #include <sys/sysctl.h>
\r
103 #elif defined(__linux__)
\r
104 #include <sys/sysinfo.h>
\r
106 #error Unsupported Operating System
\r
110 //////////////////////////////////////////////////////////////////////
\r
112 timeval sub_timeofday( timeval tv2, timeval tv )
\r
116 final.tv_usec = tv2.tv_usec - tv.tv_usec;
\r
117 final.tv_sec = tv2.tv_sec - tv.tv_sec;
\r
119 if ( final.tv_usec < 0 )
\r
121 final.tv_usec += 1000000;
\r
128 unsigned int GetFileLen(FILE* file)
\r
130 long int pos = ftell(file);
\r
131 fseek(file, 0, SEEK_END);
\r
132 long int len = ftell(file);
\r
133 fseek(file, pos, SEEK_SET);
\r
138 string TrimString(string s)
\r
140 while (s.size() > 0)
\r
142 if (s[0] == ' ' || s[0] == '\t')
\r
148 while (s.size() > 0)
\r
150 if (s[s.size() - 1] == ' ' || s[s.size() - 1] == '\t')
\r
151 s = s.substr(0, s.size() - 1);
\r
158 bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset)
\r
160 // Example: hybrid(mixalpha-numeric-all-space#1-6,numeric#1-4)
\r
161 if(sCharset.substr(0, 6) != "hybrid") // Not hybrid charset
\r
164 UINT4 nEnd = (int) sCharset.rfind(')');
\r
165 UINT4 nStart = (int) sCharset.rfind('(');
\r
166 string sChar = sCharset.substr(nStart + 1, nEnd - nStart - 1);
\r
167 vector<string> vParts;
\r
168 SeperateString(sChar, ",", vParts);
\r
169 for(UINT4 i = 0; i < vParts.size(); i++)
\r
171 tCharset stCharset;
\r
172 vector<string> vParts2;
\r
173 SeperateString(vParts[i], "#", vParts2);
\r
174 stCharset.sName = vParts2[0];
\r
175 vector<string> vParts3;
\r
176 SeperateString(vParts2[1], "-", vParts3);
\r
177 stCharset.nPlainLenMin = atoi(vParts3[0].c_str());
\r
178 stCharset.nPlainLenMax = atoi(vParts3[1].c_str());
\r
179 vCharset.push_back(stCharset);
\r
183 bool ReadLinesFromFile(string sPathName, vector<string>& vLine)
\r
187 FILE* file = fopen(sPathName.c_str(), "rb");
\r
190 unsigned int len = GetFileLen(file);
\r
191 char* data = new char[len + 1];
\r
192 fread(data, 1, len, file);
\r
194 string content = data;
\r
199 for (i = 0; i < content.size(); i++)
\r
201 if (content[i] == '\r')
\r
206 while ((n = content.find("\n", 0)) != -1)
\r
208 string line = content.substr(0, n);
\r
209 line = TrimString(line);
\r
211 vLine.push_back(line);
\r
212 content = content.substr(n + 1);
\r
223 bool writeResultLineToFile(string sOutputFile, string sHash, string sPlain, string sBinary)
\r
225 FILE* file = fopen(sOutputFile.c_str(), "a");
\r
228 string buffer = sHash + ":" + sPlain + ":" + sBinary + "\n";
\r
229 fputs (buffer.c_str(), file);
\r
237 bool SeperateString(string s, string sSeperator, vector<string>& vPart)
\r
242 for (i = 0; i < sSeperator.size(); i++)
\r
244 int n = s.find(sSeperator[i]);
\r
247 vPart.push_back(s.substr(0, n));
\r
248 s = s.substr(n + 1);
\r
252 printf("not found: %c\n", sSeperator[i]);
\r
253 printf("s: %s\n", s.c_str());
\r
257 vPart.push_back(s);
\r
262 string uint64tostr(uint64 n)
\r
267 sprintf(str, "%I64u", n);
\r
269 sprintf(str, "%llu", n);
\r
275 string uint64tohexstr(uint64 n)
\r
280 sprintf(str, "%016I64x", n);
\r
282 sprintf(str, "%016llx", n);
\r
288 string HexToStr(const unsigned char* pData, int nLen)
\r
292 for (i = 0; i < nLen; i++)
\r
295 sprintf(szByte, "%02x", pData[i]);
\r
302 uint64 GetAvailPhysMemorySize()
\r
306 GlobalMemoryStatus(&ms);
\r
307 return ms.dwAvailPhys;
\r
309 int mib[2] = { CTL_HW, HW_PHYSMEM };
\r
311 //XXX warning size_t isn't portable
\r
313 len = sizeof(physMem);
\r
314 sysctl(mib, 2, &physMem, &len, NULL, 0);
\r
316 #elif defined(__linux__)
\r
317 struct sysinfo info;
\r
319 return ( info.freeram + info.bufferram ) * (unsigned long) info.mem_unit;
\r
322 #error Unsupported Operating System
\r
326 string GetApplicationPath()
\r
328 char fullPath[FILENAME_MAX];
\r
331 GetModuleFileName(NULL, fullPath, FILENAME_MAX);
\r
334 sprintf(szTmp, "/proc/%d/exe", getpid());
\r
335 int bytes = readlink(szTmp, fullPath, FILENAME_MAX);
\r
337 fullPath[bytes] = '\0';
\r
340 string sApplicationPath = fullPath;
\r
342 int nIndex = sApplicationPath.find_last_of('\\');
\r
344 int nIndex = sApplicationPath.find_last_of('/');
\r
348 sApplicationPath = sApplicationPath.substr(0, nIndex+1);
\r
350 //printf ("\n\nDebug: The application directory is %s\n", sApplicationPath.c_str());
\r
351 return sApplicationPath;
\r
354 void ParseHash(string sHash, unsigned char* pHash, int& nHashLen)
\r
357 for (i = 0; i < sHash.size() / 2; i++)
\r
359 string sSub = sHash.substr(i * 2, 2);
\r
361 sscanf(sSub.c_str(), "%02x", &nValue);
\r
362 pHash[i] = (unsigned char)nValue;
\r
365 nHashLen = (int) sHash.size() / 2;
\r
370 printf("RainbowCrack (improved, multi-threaded) - Making a Faster Cryptanalytic Time-Memory Trade-Off\n");
\r
371 printf("by Martin Westergaard <martinwj2005@gmail.com>\n");
\r
372 printf("multi-threaded and enhanced by neinbrucke (version 0.6.3)\n");
\r
373 printf("http://www.freerainbowtables.com/\n");
\r
374 printf("original code by Zhu Shuanglei <shuanglei@hotmail.com>\n");
\r
375 printf("http://www.antsight.com/zsl/rainbowcrack/\n\n");
\r
378 // XXX nmap is GPL2, will check newer releases regarding license
\r
379 // Code comes from nmap, used for the linux implementation of kbhit()
\r
382 static int tty_fd = 0;
\r
383 struct termios saved_ti;
\r
389 if (tty_fd && tcgetpgrp(tty_fd) == getpid()) {
\r
391 numChars = read(tty_fd, &c, 1);
\r
392 if (numChars > 0) return c;
\r
400 if (!tty_fd) return;
\r
402 tcsetattr(tty_fd, TCSANOW, &saved_ti);
\r
415 if ((tty_fd = open("/dev/tty", O_RDONLY | O_NONBLOCK)) < 0) return;
\r
417 tcgetattr(tty_fd, &ti);
\r
419 ti.c_lflag &= ~(ICANON | ECHO);
\r
421 ti.c_cc[VTIME] = 0;
\r
422 tcsetattr(tty_fd, TCSANOW, &ti);
\r
427 void tty_flush(void)
\r
429 tcflush(tty_fd, TCIFLUSH);
\r