Initial commit
[hashcat.git] / src / shared.c
index 6f14c42..3feb053 100644 (file)
@@ -4787,11 +4787,6 @@ int sort_by_tuning_db_entry (const void *v1, const void *v2)
 
   if (res3 != 0) return (res3);
 
-  const int res4 = t1->workload_profile
-                 - t2->workload_profile;
-
-  if (res4 != 0) return (res4);
-
   return 0;
 }
 
@@ -5839,6 +5834,7 @@ char *strhashtype (const uint hash_mode)
     case 12800: return ((char *) HT_12800); break;
     case 12900: return ((char *) HT_12900); break;
     case 13000: return ((char *) HT_13000); break;
+    case 13100: return ((char *) HT_13100); break;
   }
 
   return ((char *) "Unknown");
@@ -5858,6 +5854,7 @@ char *strstatus (const uint devices_status)
     case  STATUS_QUIT:               return ((char *) ST_0007); break;
     case  STATUS_BYPASS:             return ((char *) ST_0008); break;
     case  STATUS_STOP_AT_CHECKPOINT: return ((char *) ST_0009); break;
+    case  STATUS_AUTOTUNE:           return ((char *) ST_0010); break;
   }
 
   return ((char *) "Unknown");
@@ -8282,6 +8279,36 @@ void ascii_digest (char out_buf[4096], uint salt_pos, uint digest_pos)
       byte_swap_32 (digest_buf[1])
     );
   }
+  else if (hash_mode == 13100)
+  {
+    krb5tgs_t *krb5tgss = (krb5tgs_t *) data.esalts_buf;
+
+    krb5tgs_t *krb5tgs = &krb5tgss[salt_pos];
+
+    u8 *ptr_checksum  = (u8 *) krb5tgs->checksum;
+    u8 *ptr_edata2 = (u8 *) krb5tgs->edata2;
+
+    char data[256] = { 0 };
+
+    char *ptr_data = data;
+
+    for (uint i = 0; i < 16; i++, ptr_data += 2)
+      sprintf (ptr_data, "%02x", ptr_checksum[i]);
+
+    /* skip '$' */
+    ptr_data++;
+
+    for (uint i = 0; i < 32; i++, ptr_data += 2)
+      sprintf (ptr_data, "%02x", ptr_edata2[i]);
+
+    *ptr_data = 0;
+
+    snprintf (out_buf, len-1, "%s$%s$%s$%s",
+      SIGNATURE_KRB5TGS,
+      (char *) krb5tgs->account_info,
+      data,
+      data + 33);
+  }
   else
   {
     if (hash_type == HASH_TYPE_MD4)
@@ -9161,7 +9188,7 @@ tuning_db_t *tuning_db_init (const char *tuning_db_file)
 
       tuning_db->alias_cnt++;
     }
-    else if (token_cnt == 7)
+    else if (token_cnt == 6)
     {
       if ((token_ptr[1][0] != '0') &&
           (token_ptr[1][0] != '1') &&
@@ -9175,21 +9202,11 @@ tuning_db_t *tuning_db_init (const char *tuning_db_file)
 
       if ((token_ptr[3][0] != '1') &&
           (token_ptr[3][0] != '2') &&
-          (token_ptr[3][0] != '3') &&
-          (token_ptr[3][0] != '*'))
-      {
-        log_info ("WARNING: Tuning-db: Invalid workload_profile '%c' in Line '%u'", token_ptr[3][0], line_num);
-
-        continue;
-      }
-
-      if ((token_ptr[4][0] != '1') &&
-          (token_ptr[4][0] != '2') &&
-          (token_ptr[4][0] != '4') &&
-          (token_ptr[4][0] != '8') &&
-          (token_ptr[4][0] != 'N'))
+          (token_ptr[3][0] != '4') &&
+          (token_ptr[3][0] != '8') &&
+          (token_ptr[3][0] != 'N'))
       {
-        log_info ("WARNING: Tuning-db: Invalid vector_width '%c' in Line '%u'", token_ptr[4][0], line_num);
+        log_info ("WARNING: Tuning-db: Invalid vector_width '%c' in Line '%u'", token_ptr[3][0], line_num);
 
         continue;
       }
@@ -9198,49 +9215,60 @@ tuning_db_t *tuning_db_init (const char *tuning_db_file)
 
       int attack_mode      = -1;
       int hash_type        = -1;
-      int workload_profile = -1;
       int vector_width     = -1;
       int kernel_accel     = -1;
       int kernel_loops     = -1;
 
       if (token_ptr[1][0] != '*') attack_mode      = atoi (token_ptr[1]);
       if (token_ptr[2][0] != '*') hash_type        = atoi (token_ptr[2]);
-      if (token_ptr[3][0] != '*') workload_profile = atoi (token_ptr[3]);
-      if (token_ptr[4][0] != 'N') vector_width     = atoi (token_ptr[4]);
-
-      kernel_accel = atoi (token_ptr[5]);
+      if (token_ptr[3][0] != 'N') vector_width     = atoi (token_ptr[3]);
 
-      if ((kernel_accel < 1) || (kernel_accel > 1024))
+      if (token_ptr[4][0] != 'A')
       {
-        log_info ("WARNING: Tuning-db: Invalid kernel_accel '%d' in Line '%u'", kernel_accel, line_num);
+        kernel_accel = atoi (token_ptr[4]);
 
-        continue;
-      }
+        if ((kernel_accel < 1) || (kernel_accel > 1024))
+        {
+          log_info ("WARNING: Tuning-db: Invalid kernel_accel '%d' in Line '%u'", kernel_accel, line_num);
 
-      kernel_loops = atoi (token_ptr[6]);
+          continue;
+        }
+      }
+      else
+      {
+        kernel_accel = 0;
+      }
 
-      if ((kernel_loops < 1) || (kernel_loops > 1024))
+      if (token_ptr[5][0] != 'A')
       {
-        log_info ("WARNING: Tuning-db: Invalid kernel_loops '%d' in Line '%u'", kernel_loops, line_num);
+        kernel_loops = atoi (token_ptr[5]);
 
-        continue;
+        if ((kernel_loops < 1) || (kernel_loops > 1024))
+        {
+          log_info ("WARNING: Tuning-db: Invalid kernel_loops '%d' in Line '%u'", kernel_loops, line_num);
+
+          continue;
+        }
+      }
+      else
+      {
+        kernel_loops = 0;
       }
 
       tuning_db_entry_t *entry = &tuning_db->entry_buf[tuning_db->entry_cnt];
 
-      entry->device_name      = mystrdup (device_name);
-      entry->attack_mode      = attack_mode;
-      entry->hash_type        = hash_type;
-      entry->workload_profile = workload_profile;
-      entry->vector_width     = vector_width;
-      entry->kernel_accel     = kernel_accel;
-      entry->kernel_loops     = kernel_loops;
+      entry->device_name  = mystrdup (device_name);
+      entry->attack_mode  = attack_mode;
+      entry->hash_type    = hash_type;
+      entry->vector_width = vector_width;
+      entry->kernel_accel = kernel_accel;
+      entry->kernel_loops = kernel_loops;
 
       tuning_db->entry_cnt++;
     }
     else
     {
-      // todo: some warning message
+      log_info ("WARNING: Tuning-db: Invalid number of token in Line '%u'", line_num);
 
       continue;
     }
@@ -9258,7 +9286,7 @@ tuning_db_t *tuning_db_init (const char *tuning_db_file)
   return tuning_db;
 }
 
-tuning_db_entry_t *tuning_db_search (tuning_db_t *tuning_db, char *device_name, int attack_mode, int hash_type, int workload_profile)
+tuning_db_entry_t *tuning_db_search (tuning_db_t *tuning_db, char *device_name, int attack_mode, int hash_type)
 {
   static tuning_db_entry_t s;
 
@@ -9292,21 +9320,19 @@ tuning_db_entry_t *tuning_db_search (tuning_db_t *tuning_db, char *device_name,
 
   // bsearch is not ideal but fast enough
 
-  s.device_name       = device_name_nospace;
-  s.attack_mode       = attack_mode;
-  s.hash_type         = hash_type;
-  s.workload_profile  = workload_profile;
+  s.device_name = device_name_nospace;
+  s.attack_mode = attack_mode;
+  s.hash_type   = hash_type;
 
   tuning_db_entry_t *entry = NULL;
 
-  // this will produce all 2^4 combinations required
+  // this will produce all 2^3 combinations required
 
-  for (i = 0; i < 16; i++)
+  for (i = 0; i < 8; i++)
   {
-    s.device_name       = (i & 1) ? "*" : device_name_nospace;
-    s.attack_mode       = (i & 2) ?  -1 : attack_mode;
-    s.hash_type         = (i & 4) ?  -1 : hash_type;
-    s.workload_profile  = (i & 8) ?  -1 : workload_profile;
+    s.device_name = (i & 1) ? "*" : device_name_nospace;
+    s.attack_mode = (i & 2) ?  -1 : attack_mode;
+    s.hash_type   = (i & 4) ?  -1 : hash_type;
 
     entry = bsearch (&s, tuning_db->entry_buf, tuning_db->entry_cnt, sizeof (tuning_db_entry_t), sort_by_tuning_db_entry);
 
@@ -9324,17 +9350,6 @@ tuning_db_entry_t *tuning_db_search (tuning_db_t *tuning_db, char *device_name,
     }
   }
 
-  // if still not found use some defaults
-
-  if (entry == NULL)
-  {
-    s.vector_width = TUNING_DB_DEFAULT_VECTOR_WIDTH;
-    s.kernel_accel = TUNING_DB_DEFAULT_KERNEL_ACCEL;
-    s.kernel_loops = TUNING_DB_DEFAULT_KERNEL_LOOPS;
-
-    return &s;
-  }
-
   // free converted device_name
 
   myfree (device_name_nospace);
@@ -18687,6 +18702,102 @@ int rar5_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf)
   return (PARSER_OK);
 }
 
+int krb5tgs_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf)
+{
+  if ((input_len < DISPLAY_LEN_MIN_13100) || (input_len > DISPLAY_LEN_MAX_13100)) return (PARSER_GLOBAL_LENGTH);
+
+  if (memcmp (SIGNATURE_KRB5TGS, input_buf, 11)) return (PARSER_SIGNATURE_UNMATCHED);
+
+  u32 *digest = (u32 *) hash_buf->digest;
+
+  salt_t *salt = hash_buf->salt;
+
+  krb5tgs_t *krb5tgs = (krb5tgs_t *) hash_buf->esalt;
+
+  /**
+   * parse line
+   */
+
+  /* Skip '$' */
+  char *account_pos = input_buf + 11 + 1; 
+  
+  char *data_pos;
+
+  uint data_len;
+
+  if (account_pos[0] == '*')
+  {
+    account_pos++;
+
+    data_pos = strchr (account_pos, '*');
+
+    /* Skip '*' */
+    data_pos++;
+
+    if (data_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED);
+
+    uint account_len = data_pos - account_pos + 1;
+
+    if (account_len >= 512) return (PARSER_SALT_LENGTH);
+
+    /* Skip '$' */
+    data_pos++;
+
+    data_len = input_len - 11 - 1 - account_len - 2;
+
+    memcpy (krb5tgs->account_info, account_pos - 1, account_len);
+  }
+  else
+  {
+    /* assume $krb5tgs$23$checksum$edata2 */
+    data_pos = account_pos;
+
+    memcpy (krb5tgs->account_info, "**", 3);
+
+    data_len = input_len - 11 - 1 - 1;
+  }
+
+  if (data_len < ((16 + 32) * 2)) return (PARSER_SALT_LENGTH);
+
+  char *checksum_ptr = (char *) krb5tgs->checksum;
+
+  for (uint i = 0; i < 16 * 2; i += 2)
+  {
+    const char p0 = data_pos[i + 0];
+    const char p1 = data_pos[i + 1];
+
+    *checksum_ptr++ = hex_convert (p1) << 0
+                     | hex_convert (p0) << 4;
+  }
+
+  char *edata_ptr = (char *) krb5tgs->edata2;
+
+  /* skip '$' */
+  for (uint i = 16 * 2 + 1; i < input_len; i += 2)
+  {
+    const char p0 = data_pos[i + 0];
+    const char p1 = data_pos[i + 1];
+    *edata_ptr++ = hex_convert (p1) << 0
+                    | hex_convert (p0) << 4;
+  }
+  
+  krb5tgs->edata2_len = strlen(edata_ptr - input_len)/(2 * 4);
+
+  salt->salt_buf[0] = krb5tgs->checksum[0];
+  salt->salt_buf[1] = krb5tgs->checksum[1];
+  salt->salt_buf[2] = krb5tgs->checksum[2];
+  salt->salt_buf[3] = krb5tgs->checksum[3];
+  
+  salt->salt_len = 32;
+
+  digest[0] = krb5tgs->checksum[0];
+  digest[1] = krb5tgs->checksum[1];
+  digest[2] = krb5tgs->checksum[2];
+  digest[3] = krb5tgs->checksum[3];
+
+  return (PARSER_OK);
+}
+
 int cf10_parse_hash (char *input_buf, uint input_len, hash_t *hash_buf)
 {
   if ((input_len < DISPLAY_LEN_MIN_12600) || (input_len > DISPLAY_LEN_MAX_12600)) return (PARSER_GLOBAL_LENGTH);