Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Joseph Kogut

By: a guest on Jan 30th, 2010  |  syntax: C++  |  size: 2.50 KB  |  views: 87  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //Part of Laverna's Brute
  2.  
  3. #include "CPUPath.h"
  4.  
  5. CPUPath::CPUPath(int id)
  6. : id(id)
  7. {
  8.         // Assign a unique portion of the keyspace to the thread (Based on id)
  9.         keyspaceSize = (masterThread::pow(charsetLength, maxChars) / numWorkers);
  10.  
  11.         keyspaceBegin = (keyspaceSize * id);
  12.         keyspaceEnd = (keyspaceBegin + keyspaceSize);
  13.  
  14.         // Set the key location
  15.         keyLocation = keyspaceBegin;
  16.  
  17.         currentKey.reserve(maxChars);
  18.  
  19.         Director::manageWorker(this);
  20. }
  21.  
  22. CPUPath::~CPUPath()
  23. {
  24. }
  25.  
  26. void CPUPath::operator()()
  27. {
  28.         searchKeyspace();
  29. }
  30.  
  31. void CPUPath::searchKeyspace()
  32. {
  33.         masterThread::setRemainingTargets(getNumTargets());
  34.         keyGenerator keygen(keyspaceBegin, masterThread::getCharset());
  35.  
  36.         bool multiHash = false;
  37.  
  38.         if(getNumTargets() > 1)
  39.         {
  40.                 multiHash = true;
  41.         }
  42.         else
  43.         {
  44.                 targetIterator = targets.begin();
  45.         }
  46.  
  47.         while((keyLocation < keyspaceEnd) && !targets.empty())
  48.         {
  49.                 // Get the next key
  50.                 currentKey = keygen++;
  51.  
  52.                 // If attacking multiple targets, use the hash map. Otherwise, disable it.
  53.                 if(multiHash)
  54.                 {
  55.                         // Look through the targets for our hash
  56.                         targetIterator = targets.find(ntlm.getWeakHash(currentKey));
  57.  
  58.                         if(targetIterator != targets.end()) // Match was found
  59.                         {
  60.                                 masterThread::printResult(targetIterator->second, currentKey);
  61.  
  62.                                 removeTarget(targetIterator);
  63.                                 masterThread::setRemainingTargets(getNumTargets());
  64.                         }
  65.                 }
  66.                 else
  67.                 {
  68.                         if(ntlm.getWeakHash(currentKey) == targetIterator->first)
  69.                         {
  70.                                 masterThread::printResult(targetIterator->second, currentKey);
  71.  
  72.                                 removeTarget(targetIterator);
  73.                                 masterThread::setRemainingTargets(getNumTargets());
  74.                         }
  75.                 }
  76.         }
  77.  
  78.         // If all targets have been cracked, rejoice and signal the master thread that we're done.
  79.         if(targets.empty())
  80.         {
  81.                 masterThread::setSuccess();
  82.         }
  83.         // If not, ask the director if we can have more work. If the director finds work for us, we restart the search.
  84.         else if(Director::reassignKeyspace(this))
  85.         {
  86.                 searchKeyspace();
  87.         }
  88. }
  89.  
  90. int CPUPath::getThreadID()
  91. {
  92.         return id;
  93. }
  94.  
  95. unsigned long long CPUPath::getKeyspaceEnd()
  96. {
  97.         return keyspaceEnd;
  98. }
  99.  
  100. unsigned long long CPUPath::getKeyspaceBegin()
  101. {
  102.         return keyspaceBegin;
  103. }
  104.  
  105. unsigned long long CPUPath::getKeyLocation()
  106. {
  107.         return keyLocation;
  108. }
  109.  
  110. void CPUPath::moveKeyspaceEnd(unsigned long long input)
  111. {
  112.         keyspaceEnd = input;
  113. }
  114.  
  115. void CPUPath::moveKeyspaceBegin(unsigned long long input)
  116. {
  117.         keyspaceBegin = input;
  118. }
  119.  
  120. void CPUPath::moveKeylocation(unsigned long long input)
  121. {
  122.         keyLocation = input;
  123. }