1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-12-26 08:28:20 +00:00

Added hash-modes 18200 (Kerberos 5 AS-REP etype 23)

This commit is contained in:
Arseniy Sharoglazov 2018-10-30 19:05:44 +03:00
parent b8eb7105dd
commit ee873da300
15 changed files with 4279 additions and 3 deletions

View File

@ -1294,6 +1294,15 @@ typedef struct krb5tgs
} krb5tgs_t;
typedef struct krb5asrep
{
u32 account_info[512];
u32 checksum[4];
u32 edata2[5120];
u32 edata2_len;
} krb5asrep_t;
typedef struct tc
{
u32 salt_buf[32];

View File

@ -0,0 +1,760 @@
/**
* Author......: see docs/credits.txt
* License.....: MIT
*/
//too much register pressure
//#define NEW_SIMD_CODE
#include "inc_vendor.cl"
#include "inc_hash_constants.h"
#include "inc_hash_functions.cl"
#include "inc_types.cl"
#include "inc_common.cl"
#include "inc_rp_optimized.h"
#include "inc_rp_optimized.cl"
#include "inc_simd.cl"
#include "inc_hash_md4.cl"
#include "inc_hash_md5.cl"
typedef struct
{
u8 S[256];
u32 wtf_its_faster;
} RC4_KEY;
DECLSPEC void swap (__local RC4_KEY *rc4_key, const u8 i, const u8 j)
{
u8 tmp;
tmp = rc4_key->S[i];
rc4_key->S[i] = rc4_key->S[j];
rc4_key->S[j] = tmp;
}
DECLSPEC void rc4_init_16 (__local RC4_KEY *rc4_key, const u32 *data)
{
u32 v = 0x03020100;
u32 a = 0x04040404;
__local u32 *ptr = (__local u32 *) rc4_key->S;
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < 64; i++)
{
*ptr++ = v; v += a;
}
u32 j = 0;
for (u32 i = 0; i < 16; i++)
{
u32 idx = i * 16;
u32 v;
v = data[0];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
v = data[1];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
v = data[2];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
v = data[3];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
}
}
DECLSPEC u8 rc4_next_16 (__local RC4_KEY *rc4_key, u8 i, u8 j, const __global u32 *in, u32 *out)
{
#ifdef _unroll
#pragma unroll
#endif
for (u32 k = 0; k < 4; k++)
{
u32 xor4 = 0;
u8 idx;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 0;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 8;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 16;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 24;
out[k] = in[k] ^ xor4;
}
return j;
}
DECLSPEC void hmac_md5_pad (u32 *w0, u32 *w1, u32 *w2, u32 *w3, u32 *ipad, u32 *opad)
{
w0[0] = w0[0] ^ 0x36363636;
w0[1] = w0[1] ^ 0x36363636;
w0[2] = w0[2] ^ 0x36363636;
w0[3] = w0[3] ^ 0x36363636;
w1[0] = w1[0] ^ 0x36363636;
w1[1] = w1[1] ^ 0x36363636;
w1[2] = w1[2] ^ 0x36363636;
w1[3] = w1[3] ^ 0x36363636;
w2[0] = w2[0] ^ 0x36363636;
w2[1] = w2[1] ^ 0x36363636;
w2[2] = w2[2] ^ 0x36363636;
w2[3] = w2[3] ^ 0x36363636;
w3[0] = w3[0] ^ 0x36363636;
w3[1] = w3[1] ^ 0x36363636;
w3[2] = w3[2] ^ 0x36363636;
w3[3] = w3[3] ^ 0x36363636;
ipad[0] = MD5M_A;
ipad[1] = MD5M_B;
ipad[2] = MD5M_C;
ipad[3] = MD5M_D;
md5_transform (w0, w1, w2, w3, ipad);
w0[0] = w0[0] ^ 0x6a6a6a6a;
w0[1] = w0[1] ^ 0x6a6a6a6a;
w0[2] = w0[2] ^ 0x6a6a6a6a;
w0[3] = w0[3] ^ 0x6a6a6a6a;
w1[0] = w1[0] ^ 0x6a6a6a6a;
w1[1] = w1[1] ^ 0x6a6a6a6a;
w1[2] = w1[2] ^ 0x6a6a6a6a;
w1[3] = w1[3] ^ 0x6a6a6a6a;
w2[0] = w2[0] ^ 0x6a6a6a6a;
w2[1] = w2[1] ^ 0x6a6a6a6a;
w2[2] = w2[2] ^ 0x6a6a6a6a;
w2[3] = w2[3] ^ 0x6a6a6a6a;
w3[0] = w3[0] ^ 0x6a6a6a6a;
w3[1] = w3[1] ^ 0x6a6a6a6a;
w3[2] = w3[2] ^ 0x6a6a6a6a;
w3[3] = w3[3] ^ 0x6a6a6a6a;
opad[0] = MD5M_A;
opad[1] = MD5M_B;
opad[2] = MD5M_C;
opad[3] = MD5M_D;
md5_transform (w0, w1, w2, w3, opad);
}
DECLSPEC void hmac_md5_run (u32 *w0, u32 *w1, u32 *w2, u32 *w3, u32 *ipad, u32 *opad, u32 *digest)
{
digest[0] = ipad[0];
digest[1] = ipad[1];
digest[2] = ipad[2];
digest[3] = ipad[3];
md5_transform (w0, w1, w2, w3, digest);
w0[0] = digest[0];
w0[1] = digest[1];
w0[2] = digest[2];
w0[3] = digest[3];
w1[0] = 0x80;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = (64 + 16) * 8;
w3[3] = 0;
digest[0] = opad[0];
digest[1] = opad[1];
digest[2] = opad[2];
digest[3] = opad[3];
md5_transform (w0, w1, w2, w3, digest);
}
DECLSPEC int decrypt_and_check (__local RC4_KEY *rc4_key, u32 *data, __global const u32 *edata2, const u32 edata2_len, const u32 *K2, const u32 *checksum)
{
rc4_init_16 (rc4_key, data);
u32 out0[4];
/*
8 first bytes are nonce, then ASN1 structs (DER encoding: TLV)
The first byte is always 0x79 (01 1 11001, where 01 = "class=APPLICATION", 1 = "form=constructed", 11001 is application type 25)
The next byte is the length:
if length < 128 bytes:
length is on 1 byte, and the next byte is 0x30 (class=SEQUENCE)
else if length <= 256:
length is on 2 bytes, the first byte is 0x81, and the third byte is 0x30 (class=SEQUENCE)
else if length > 256:
length is on 3 bytes, the first byte is 0x82, and the fourth byte is 0x30 (class=SEQUENCE)
*/
rc4_next_16 (rc4_key, 0, 0, edata2 + 0, out0);
if (((out0[2] & 0x00ff80ff) != 0x00300079) &&
((out0[2] & 0xFF00FFFF) != 0x30008179) &&
((out0[2] & 0x0000FFFF) != 0x00008279 || (out0[3] & 0x000000FF) != 0x00000030))
return 0;
rc4_init_16 (rc4_key, data);
u8 i = 0;
u8 j = 0;
// init hmac
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
w0[0] = K2[0];
w0[1] = K2[1];
w0[2] = K2[2];
w0[3] = K2[3];
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
u32 ipad[4];
u32 opad[4];
hmac_md5_pad (w0, w1, w2, w3, ipad, opad);
int edata2_left;
for (edata2_left = edata2_len; edata2_left >= 64; edata2_left -= 64)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w2); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w3); i += 16; edata2 += 4;
md5_transform (w0, w1, w2, w3, ipad);
}
w0[0] = 0;
w0[1] = 0;
w0[2] = 0;
w0[3] = 0;
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
if (edata2_left < 16)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w0, edata2_left & 0xf);
append_0x80_1x4 (w0, edata2_left & 0xf);
w3[2] = (64 + edata2_len) * 8;
w3[3] = 0;
md5_transform (w0, w1, w2, w3, ipad);
}
else if (edata2_left < 32)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w1, edata2_left & 0xf);
append_0x80_1x4 (w1, edata2_left & 0xf);
w3[2] = (64 + edata2_len) * 8;
w3[3] = 0;
md5_transform (w0, w1, w2, w3, ipad);
}
else if (edata2_left < 48)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w2); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w2, edata2_left & 0xf);
append_0x80_1x4 (w2, edata2_left & 0xf);
w3[2] = (64 + edata2_len) * 8;
w3[3] = 0;
md5_transform (w0, w1, w2, w3, ipad);
}
else
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w2); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w3); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w3, edata2_left & 0xf);
append_0x80_1x4 (w3, edata2_left & 0xf);
if (edata2_left < 56)
{
w3[2] = (64 + edata2_len) * 8;
w3[3] = 0;
md5_transform (w0, w1, w2, w3, ipad);
}
else
{
md5_transform (w0, w1, w2, w3, ipad);
w0[0] = 0;
w0[1] = 0;
w0[2] = 0;
w0[3] = 0;
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = (64 + edata2_len) * 8;
w3[3] = 0;
md5_transform (w0, w1, w2, w3, ipad);
}
}
w0[0] = ipad[0];
w0[1] = ipad[1];
w0[2] = ipad[2];
w0[3] = ipad[3];
w1[0] = 0x80;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = (64 + 16) * 8;
w3[3] = 0;
md5_transform (w0, w1, w2, w3, opad);
if (checksum[0] != opad[0]) return 0;
if (checksum[1] != opad[1]) return 0;
if (checksum[2] != opad[2]) return 0;
if (checksum[3] != opad[3]) return 0;
return 1;
}
DECLSPEC void kerb_prepare (const u32 *w0, const u32 *w1, const u32 pw_len, const u32 *checksum, u32 *digest, u32 *K2)
{
/**
* pads
*/
u32 w0_t[4];
u32 w1_t[4];
u32 w2_t[4];
u32 w3_t[4];
w0_t[0] = w0[0];
w0_t[1] = w0[1];
w0_t[2] = w0[2];
w0_t[3] = w0[3];
w1_t[0] = w1[0];
w1_t[1] = w1[1];
w1_t[2] = w1[2];
w1_t[3] = w1[3];
w2_t[0] = 0;
w2_t[1] = 0;
w2_t[2] = 0;
w2_t[3] = 0;
w3_t[0] = 0;
w3_t[1] = 0;
w3_t[2] = 0;
w3_t[3] = 0;
// K=MD4(Little_indian(UNICODE(pwd))
append_0x80_2x4 (w0_t, w1_t, pw_len);
make_utf16le (w1_t, w2_t, w3_t);
make_utf16le (w0_t, w0_t, w1_t);
w3_t[2] = pw_len * 8 * 2;
w3_t[3] = 0;
digest[0] = MD4M_A;
digest[1] = MD4M_B;
digest[2] = MD4M_C;
digest[3] = MD4M_D;
md4_transform (w0_t, w1_t, w2_t, w3_t, digest);
// K1=MD5_HMAC(K,1); with 2 encoded as little indian on 4 bytes (02000000 in hexa);
w0_t[0] = digest[0];
w0_t[1] = digest[1];
w0_t[2] = digest[2];
w0_t[3] = digest[3];
w1_t[0] = 0;
w1_t[1] = 0;
w1_t[2] = 0;
w1_t[3] = 0;
w2_t[0] = 0;
w2_t[1] = 0;
w2_t[2] = 0;
w2_t[3] = 0;
w3_t[0] = 0;
w3_t[1] = 0;
w3_t[2] = 0;
w3_t[3] = 0;
u32 ipad[4];
u32 opad[4];
hmac_md5_pad (w0_t, w1_t, w2_t, w3_t, ipad, opad);
w0_t[0] = 8;
w0_t[1] = 0x80;
w0_t[2] = 0;
w0_t[3] = 0;
w1_t[0] = 0;
w1_t[1] = 0;
w1_t[2] = 0;
w1_t[3] = 0;
w2_t[0] = 0;
w2_t[1] = 0;
w2_t[2] = 0;
w2_t[3] = 0;
w3_t[0] = 0;
w3_t[1] = 0;
w3_t[2] = (64 + 4) * 8;
w3_t[3] = 0;
hmac_md5_run (w0_t, w1_t, w2_t, w3_t, ipad, opad, digest);
// K2 = K1;
K2[0] = digest[0];
K2[1] = digest[1];
K2[2] = digest[2];
K2[3] = digest[3];
// K3=MD5_HMAC(K1,checksum);
w0_t[0] = digest[0];
w0_t[1] = digest[1];
w0_t[2] = digest[2];
w0_t[3] = digest[3];
w1_t[0] = 0;
w1_t[1] = 0;
w1_t[2] = 0;
w1_t[3] = 0;
w2_t[0] = 0;
w2_t[1] = 0;
w2_t[2] = 0;
w2_t[3] = 0;
w3_t[0] = 0;
w3_t[1] = 0;
w3_t[2] = 0;
w3_t[3] = 0;
hmac_md5_pad (w0_t, w1_t, w2_t, w3_t, ipad, opad);
w0_t[0] = checksum[0];
w0_t[1] = checksum[1];
w0_t[2] = checksum[2];
w0_t[3] = checksum[3];
w1_t[0] = 0x80;
w1_t[1] = 0;
w1_t[2] = 0;
w1_t[3] = 0;
w2_t[0] = 0;
w2_t[1] = 0;
w2_t[2] = 0;
w2_t[3] = 0;
w3_t[0] = 0;
w3_t[1] = 0;
w3_t[2] = (64 + 16) * 8;
w3_t[3] = 0;
hmac_md5_run (w0_t, w1_t, w2_t, w3_t, ipad, opad, digest);
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_m04 (__global pw_t *pws, __constant const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
/**
* modifier
*/
const u64 lid = get_local_id (0);
const u64 gid = get_global_id (0);
if (gid >= gid_max) return;
/**
* base
*/
u32 pw_buf0[4];
pw_buf0[0] = pws[gid].i[ 0];
pw_buf0[1] = pws[gid].i[ 1];
pw_buf0[2] = pws[gid].i[ 2];
pw_buf0[3] = pws[gid].i[ 3];
u32 pw_buf1[4];
pw_buf1[0] = pws[gid].i[ 4];
pw_buf1[1] = pws[gid].i[ 5];
pw_buf1[2] = pws[gid].i[ 6];
pw_buf1[3] = pws[gid].i[ 7];
const u32 pw_len = pws[gid].pw_len;
/**
* shared
*/
__local RC4_KEY rc4_keys[64];
__local RC4_KEY *rc4_key = &rc4_keys[lid];
/**
* salt
*/
u32 checksum[4];
checksum[0] = krb5asrep_bufs[digests_offset].checksum[0];
checksum[1] = krb5asrep_bufs[digests_offset].checksum[1];
checksum[2] = krb5asrep_bufs[digests_offset].checksum[2];
checksum[3] = krb5asrep_bufs[digests_offset].checksum[3];
/**
* loop
*/
for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
{
u32x w0[4] = { 0 };
u32x w1[4] = { 0 };
u32x w2[4] = { 0 };
u32x w3[4] = { 0 };
const u32x out_len = apply_rules_vect (pw_buf0, pw_buf1, pw_len, rules_buf, il_pos, w0, w1);
/**
* kerberos
*/
u32 digest[4];
u32 K2[4];
kerb_prepare (w0, w1, out_len, checksum, digest, K2);
u32 tmp[4];
tmp[0] = digest[0];
tmp[1] = digest[1];
tmp[2] = digest[2];
tmp[3] = digest[3];
if (decrypt_and_check (rc4_key, tmp, krb5asrep_bufs[digests_offset].edata2, krb5asrep_bufs[digests_offset].edata2_len, K2, checksum) == 1)
{
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
{
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos);
}
}
}
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_m08 (__global pw_t *pws, __constant const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_m16 (__global pw_t *pws, __constant const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_s04 (__global pw_t *pws, __constant const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
/**
* modifier
*/
const u64 lid = get_local_id (0);
const u64 gid = get_global_id (0);
if (gid >= gid_max) return;
/**
* base
*/
u32 pw_buf0[4];
pw_buf0[0] = pws[gid].i[ 0];
pw_buf0[1] = pws[gid].i[ 1];
pw_buf0[2] = pws[gid].i[ 2];
pw_buf0[3] = pws[gid].i[ 3];
u32 pw_buf1[4];
pw_buf1[0] = pws[gid].i[ 4];
pw_buf1[1] = pws[gid].i[ 5];
pw_buf1[2] = pws[gid].i[ 6];
pw_buf1[3] = pws[gid].i[ 7];
const u32 pw_len = pws[gid].pw_len;
/**
* shared
*/
__local RC4_KEY rc4_keys[64];
__local RC4_KEY *rc4_key = &rc4_keys[lid];
/**
* salt
*/
u32 checksum[4];
checksum[0] = krb5asrep_bufs[digests_offset].checksum[0];
checksum[1] = krb5asrep_bufs[digests_offset].checksum[1];
checksum[2] = krb5asrep_bufs[digests_offset].checksum[2];
checksum[3] = krb5asrep_bufs[digests_offset].checksum[3];
/**
* loop
*/
for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
{
u32x w0[4] = { 0 };
u32x w1[4] = { 0 };
u32x w2[4] = { 0 };
u32x w3[4] = { 0 };
const u32x out_len = apply_rules_vect (pw_buf0, pw_buf1, pw_len, rules_buf, il_pos, w0, w1);
/**
* kerberos
*/
u32 digest[4];
u32 K2[4];
kerb_prepare (w0, w1, out_len, checksum, digest, K2);
u32 tmp[4];
tmp[0] = digest[0];
tmp[1] = digest[1];
tmp[2] = digest[2];
tmp[3] = digest[3];
if (decrypt_and_check (rc4_key, tmp, krb5asrep_bufs[digests_offset].edata2, krb5asrep_bufs[digests_offset].edata2_len, K2, checksum) == 1)
{
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
{
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos);
}
}
}
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_s08 (__global pw_t *pws, __constant const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_s16 (__global pw_t *pws, __constant const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
}

500
OpenCL/m18200_a0-pure.cl Normal file
View File

@ -0,0 +1,500 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
//shared mem too small
//#define NEW_SIMD_CODE
#include "inc_vendor.cl"
#include "inc_hash_constants.h"
#include "inc_hash_functions.cl"
#include "inc_types.cl"
#include "inc_common.cl"
#include "inc_rp.h"
#include "inc_rp.cl"
#include "inc_hash_md4.cl"
#include "inc_hash_md5.cl"
typedef struct
{
u8 S[256];
u32 wtf_its_faster;
} RC4_KEY;
DECLSPEC void swap (__local RC4_KEY *rc4_key, const u8 i, const u8 j)
{
u8 tmp;
tmp = rc4_key->S[i];
rc4_key->S[i] = rc4_key->S[j];
rc4_key->S[j] = tmp;
}
DECLSPEC void rc4_init_16 (__local RC4_KEY *rc4_key, const u32 *data)
{
u32 v = 0x03020100;
u32 a = 0x04040404;
__local u32 *ptr = (__local u32 *) rc4_key->S;
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < 64; i++)
{
*ptr++ = v; v += a;
}
u32 j = 0;
for (u32 i = 0; i < 16; i++)
{
u32 idx = i * 16;
u32 v;
v = data[0];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
v = data[1];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
v = data[2];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
v = data[3];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
}
}
DECLSPEC u8 rc4_next_16 (__local RC4_KEY *rc4_key, u8 i, u8 j, const __global u32 *in, u32 *out)
{
#ifdef _unroll
#pragma unroll
#endif
for (u32 k = 0; k < 4; k++)
{
u32 xor4 = 0;
u8 idx;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 0;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 8;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 16;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 24;
out[k] = in[k] ^ xor4;
}
return j;
}
DECLSPEC int decrypt_and_check (__local RC4_KEY *rc4_key, u32 *data, __global const u32 *edata2, const u32 edata2_len, const u32 *K2, const u32 *checksum)
{
rc4_init_16 (rc4_key, data);
u32 out0[4];
/*
8 first bytes are nonce, then ASN1 structs (DER encoding: TLV)
The first byte is always 0x79 (01 1 11001, where 01 = "class=APPLICATION", 1 = "form=constructed", 11001 is application type 25)
The next byte is the length:
if length < 128 bytes:
length is on 1 byte, and the next byte is 0x30 (class=SEQUENCE)
else if length <= 256:
length is on 2 bytes, the first byte is 0x81, and the third byte is 0x30 (class=SEQUENCE)
else if length > 256:
length is on 3 bytes, the first byte is 0x82, and the fourth byte is 0x30 (class=SEQUENCE)
*/
rc4_next_16 (rc4_key, 0, 0, edata2 + 0, out0);
if (((out0[2] & 0x00ff80ff) != 0x00300079) &&
((out0[2] & 0xFF00FFFF) != 0x30008179) &&
((out0[2] & 0x0000FFFF) != 0x00008279 || (out0[3] & 0x000000FF) != 0x00000030))
return 0;
rc4_init_16 (rc4_key, data);
u8 i = 0;
u8 j = 0;
// init hmac
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
w0[0] = K2[0];
w0[1] = K2[1];
w0[2] = K2[2];
w0[3] = K2[3];
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
md5_hmac_ctx_t ctx;
md5_hmac_init_64 (&ctx, w0, w1, w2, w3);
int edata2_left;
for (edata2_left = edata2_len; edata2_left >= 64; edata2_left -= 64)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w2); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w3); i += 16; edata2 += 4;
md5_hmac_update_64 (&ctx, w0, w1, w2, w3, 64);
}
w0[0] = 0;
w0[1] = 0;
w0[2] = 0;
w0[3] = 0;
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
if (edata2_left < 16)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w0, edata2_left & 0xf);
}
else if (edata2_left < 32)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w1, edata2_left & 0xf);
}
else if (edata2_left < 48)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w2); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w2, edata2_left & 0xf);
}
else
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w2); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w3); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w3, edata2_left & 0xf);
}
md5_hmac_update_64 (&ctx, w0, w1, w2, w3, edata2_left);
md5_hmac_final (&ctx);
if (checksum[0] != ctx.opad.h[0]) return 0;
if (checksum[1] != ctx.opad.h[1]) return 0;
if (checksum[2] != ctx.opad.h[2]) return 0;
if (checksum[3] != ctx.opad.h[3]) return 0;
return 1;
}
DECLSPEC void kerb_prepare (const u32 *K, const u32 *checksum, u32 *digest, u32 *K2)
{
// K1=MD5_HMAC(K,1); with 1 encoded as little indian on 4 bytes (01000000 in hexa);
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
w0[0] = K[0];
w0[1] = K[1];
w0[2] = K[2];
w0[3] = K[3];
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
md5_hmac_ctx_t ctx1;
md5_hmac_init_64 (&ctx1, w0, w1, w2, w3);
w0[0] = 8;
w0[1] = 0;
w0[2] = 0;
w0[3] = 0;
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
md5_hmac_update_64 (&ctx1, w0, w1, w2, w3, 4);
md5_hmac_final (&ctx1);
w0[0] = ctx1.opad.h[0];
w0[1] = ctx1.opad.h[1];
w0[2] = ctx1.opad.h[2];
w0[3] = ctx1.opad.h[3];
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
md5_hmac_ctx_t ctx;
md5_hmac_init_64 (&ctx, w0, w1, w2, w3);
w0[0] = checksum[0];
w0[1] = checksum[1];
w0[2] = checksum[2];
w0[3] = checksum[3];
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
md5_hmac_update_64 (&ctx, w0, w1, w2, w3, 16);
md5_hmac_final (&ctx);
digest[0] = ctx.opad.h[0];
digest[1] = ctx.opad.h[1];
digest[2] = ctx.opad.h[2];
digest[3] = ctx.opad.h[3];
K2[0] = ctx1.opad.h[0];
K2[1] = ctx1.opad.h[1];
K2[2] = ctx1.opad.h[2];
K2[3] = ctx1.opad.h[3];
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_mxx (__global pw_t *pws, __constant const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global const krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
/**
* modifier
*/
const u64 lid = get_local_id (0);
const u64 gid = get_global_id (0);
if (gid >= gid_max) return;
/**
* base
*/
COPY_PW (pws[gid]);
__local RC4_KEY rc4_keys[64];
__local RC4_KEY *rc4_key = &rc4_keys[lid];
u32 checksum[4];
checksum[0] = krb5asrep_bufs[digests_offset].checksum[0];
checksum[1] = krb5asrep_bufs[digests_offset].checksum[1];
checksum[2] = krb5asrep_bufs[digests_offset].checksum[2];
checksum[3] = krb5asrep_bufs[digests_offset].checksum[3];
/**
* loop
*/
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
{
pw_t tmp = PASTE_PW;
tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len);
md4_ctx_t ctx;
md4_init (&ctx);
md4_update_utf16le (&ctx, tmp.i, tmp.pw_len);
md4_final (&ctx);
u32 digest[4];
u32 K2[4];
kerb_prepare (ctx.h, checksum, digest, K2);
if (decrypt_and_check (rc4_key, digest, krb5asrep_bufs[digests_offset].edata2, krb5asrep_bufs[digests_offset].edata2_len, K2, checksum) == 1)
{
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
{
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos);
}
}
}
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_sxx (__global pw_t *pws, __constant const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global const krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
/**
* modifier
*/
const u64 lid = get_local_id (0);
const u64 gid = get_global_id (0);
if (gid >= gid_max) return;
/**
* base
*/
COPY_PW (pws[gid]);
__local RC4_KEY rc4_keys[64];
__local RC4_KEY *rc4_key = &rc4_keys[lid];
u32 checksum[4];
checksum[0] = krb5asrep_bufs[digests_offset].checksum[0];
checksum[1] = krb5asrep_bufs[digests_offset].checksum[1];
checksum[2] = krb5asrep_bufs[digests_offset].checksum[2];
checksum[3] = krb5asrep_bufs[digests_offset].checksum[3];
/**
* loop
*/
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
{
pw_t tmp = PASTE_PW;
tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len);
md4_ctx_t ctx;
md4_init (&ctx);
md4_update_utf16le (&ctx, tmp.i, tmp.pw_len);
md4_final (&ctx);
u32 digest[4];
u32 K2[4];
kerb_prepare (ctx.h, checksum, digest, K2);
if (decrypt_and_check (rc4_key, digest, krb5asrep_bufs[digests_offset].edata2, krb5asrep_bufs[digests_offset].edata2_len, K2, checksum) == 1)
{
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
{
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos);
}
}
}
}

View File

@ -0,0 +1,856 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
//too much register pressure
//#define NEW_SIMD_CODE
#include "inc_vendor.cl"
#include "inc_hash_constants.h"
#include "inc_hash_functions.cl"
#include "inc_types.cl"
#include "inc_common.cl"
#include "inc_simd.cl"
#include "inc_hash_md4.cl"
#include "inc_hash_md5.cl"
typedef struct
{
u8 S[256];
u32 wtf_its_faster;
} RC4_KEY;
DECLSPEC void swap (__local RC4_KEY *rc4_key, const u8 i, const u8 j)
{
u8 tmp;
tmp = rc4_key->S[i];
rc4_key->S[i] = rc4_key->S[j];
rc4_key->S[j] = tmp;
}
DECLSPEC void rc4_init_16 (__local RC4_KEY *rc4_key, const u32 *data)
{
u32 v = 0x03020100;
u32 a = 0x04040404;
__local u32 *ptr = (__local u32 *) rc4_key->S;
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < 64; i++)
{
*ptr++ = v; v += a;
}
u32 j = 0;
for (u32 i = 0; i < 16; i++)
{
u32 idx = i * 16;
u32 v;
v = data[0];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
v = data[1];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
v = data[2];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
v = data[3];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
}
}
DECLSPEC u8 rc4_next_16 (__local RC4_KEY *rc4_key, u8 i, u8 j, const __global u32 *in, u32 *out)
{
#ifdef _unroll
#pragma unroll
#endif
for (u32 k = 0; k < 4; k++)
{
u32 xor4 = 0;
u8 idx;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 0;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 8;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 16;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 24;
out[k] = in[k] ^ xor4;
}
return j;
}
DECLSPEC void hmac_md5_pad (u32 *w0, u32 *w1, u32 *w2, u32 *w3, u32 *ipad, u32 *opad)
{
w0[0] = w0[0] ^ 0x36363636;
w0[1] = w0[1] ^ 0x36363636;
w0[2] = w0[2] ^ 0x36363636;
w0[3] = w0[3] ^ 0x36363636;
w1[0] = w1[0] ^ 0x36363636;
w1[1] = w1[1] ^ 0x36363636;
w1[2] = w1[2] ^ 0x36363636;
w1[3] = w1[3] ^ 0x36363636;
w2[0] = w2[0] ^ 0x36363636;
w2[1] = w2[1] ^ 0x36363636;
w2[2] = w2[2] ^ 0x36363636;
w2[3] = w2[3] ^ 0x36363636;
w3[0] = w3[0] ^ 0x36363636;
w3[1] = w3[1] ^ 0x36363636;
w3[2] = w3[2] ^ 0x36363636;
w3[3] = w3[3] ^ 0x36363636;
ipad[0] = MD5M_A;
ipad[1] = MD5M_B;
ipad[2] = MD5M_C;
ipad[3] = MD5M_D;
md5_transform (w0, w1, w2, w3, ipad);
w0[0] = w0[0] ^ 0x6a6a6a6a;
w0[1] = w0[1] ^ 0x6a6a6a6a;
w0[2] = w0[2] ^ 0x6a6a6a6a;
w0[3] = w0[3] ^ 0x6a6a6a6a;
w1[0] = w1[0] ^ 0x6a6a6a6a;
w1[1] = w1[1] ^ 0x6a6a6a6a;
w1[2] = w1[2] ^ 0x6a6a6a6a;
w1[3] = w1[3] ^ 0x6a6a6a6a;
w2[0] = w2[0] ^ 0x6a6a6a6a;
w2[1] = w2[1] ^ 0x6a6a6a6a;
w2[2] = w2[2] ^ 0x6a6a6a6a;
w2[3] = w2[3] ^ 0x6a6a6a6a;
w3[0] = w3[0] ^ 0x6a6a6a6a;
w3[1] = w3[1] ^ 0x6a6a6a6a;
w3[2] = w3[2] ^ 0x6a6a6a6a;
w3[3] = w3[3] ^ 0x6a6a6a6a;
opad[0] = MD5M_A;
opad[1] = MD5M_B;
opad[2] = MD5M_C;
opad[3] = MD5M_D;
md5_transform (w0, w1, w2, w3, opad);
}
DECLSPEC void hmac_md5_run (u32 *w0, u32 *w1, u32 *w2, u32 *w3, u32 *ipad, u32 *opad, u32 *digest)
{
digest[0] = ipad[0];
digest[1] = ipad[1];
digest[2] = ipad[2];
digest[3] = ipad[3];
md5_transform (w0, w1, w2, w3, digest);
w0[0] = digest[0];
w0[1] = digest[1];
w0[2] = digest[2];
w0[3] = digest[3];
w1[0] = 0x80;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = (64 + 16) * 8;
w3[3] = 0;
digest[0] = opad[0];
digest[1] = opad[1];
digest[2] = opad[2];
digest[3] = opad[3];
md5_transform (w0, w1, w2, w3, digest);
}
DECLSPEC int decrypt_and_check (__local RC4_KEY *rc4_key, u32 *data, __global const u32 *edata2, const u32 edata2_len, const u32 *K2, const u32 *checksum)
{
rc4_init_16 (rc4_key, data);
u32 out0[4];
/*
8 first bytes are nonce, then ASN1 structs (DER encoding: TLV)
The first byte is always 0x79 (01 1 11001, where 01 = "class=APPLICATION", 1 = "form=constructed", 11001 is application type 25)
The next byte is the length:
if length < 128 bytes:
length is on 1 byte, and the next byte is 0x30 (class=SEQUENCE)
else if length <= 256:
length is on 2 bytes, the first byte is 0x81, and the third byte is 0x30 (class=SEQUENCE)
else if length > 256:
length is on 3 bytes, the first byte is 0x82, and the fourth byte is 0x30 (class=SEQUENCE)
*/
rc4_next_16 (rc4_key, 0, 0, edata2 + 0, out0);
if (((out0[2] & 0x00ff80ff) != 0x00300079) &&
((out0[2] & 0xFF00FFFF) != 0x30008179) &&
((out0[2] & 0x0000FFFF) != 0x00008279 || (out0[3] & 0x000000FF) != 0x00000030))
return 0;
rc4_init_16 (rc4_key, data);
u8 i = 0;
u8 j = 0;
// init hmac
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
w0[0] = K2[0];
w0[1] = K2[1];
w0[2] = K2[2];
w0[3] = K2[3];
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
u32 ipad[4];
u32 opad[4];
hmac_md5_pad (w0, w1, w2, w3, ipad, opad);
int edata2_left;
for (edata2_left = edata2_len; edata2_left >= 64; edata2_left -= 64)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w2); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w3); i += 16; edata2 += 4;
md5_transform (w0, w1, w2, w3, ipad);
}
w0[0] = 0;
w0[1] = 0;
w0[2] = 0;
w0[3] = 0;
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
if (edata2_left < 16)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w0, edata2_left & 0xf);
append_0x80_1x4 (w0, edata2_left & 0xf);
w3[2] = (64 + edata2_len) * 8;
w3[3] = 0;
md5_transform (w0, w1, w2, w3, ipad);
}
else if (edata2_left < 32)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w1, edata2_left & 0xf);
append_0x80_1x4 (w1, edata2_left & 0xf);
w3[2] = (64 + edata2_len) * 8;
w3[3] = 0;
md5_transform (w0, w1, w2, w3, ipad);
}
else if (edata2_left < 48)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w2); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w2, edata2_left & 0xf);
append_0x80_1x4 (w2, edata2_left & 0xf);
w3[2] = (64 + edata2_len) * 8;
w3[3] = 0;
md5_transform (w0, w1, w2, w3, ipad);
}
else
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w2); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w3); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w3, edata2_left & 0xf);
append_0x80_1x4 (w3, edata2_left & 0xf);
if (edata2_left < 56)
{
w3[2] = (64 + edata2_len) * 8;
w3[3] = 0;
md5_transform (w0, w1, w2, w3, ipad);
}
else
{
md5_transform (w0, w1, w2, w3, ipad);
w0[0] = 0;
w0[1] = 0;
w0[2] = 0;
w0[3] = 0;
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = (64 + edata2_len) * 8;
w3[3] = 0;
md5_transform (w0, w1, w2, w3, ipad);
}
}
w0[0] = ipad[0];
w0[1] = ipad[1];
w0[2] = ipad[2];
w0[3] = ipad[3];
w1[0] = 0x80;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = (64 + 16) * 8;
w3[3] = 0;
md5_transform (w0, w1, w2, w3, opad);
if (checksum[0] != opad[0]) return 0;
if (checksum[1] != opad[1]) return 0;
if (checksum[2] != opad[2]) return 0;
if (checksum[3] != opad[3]) return 0;
return 1;
}
DECLSPEC void kerb_prepare (const u32 *w0, const u32 *w1, const u32 pw_len, const u32 *checksum, u32 *digest, u32 *K2)
{
/**
* pads
*/
u32 w0_t[4];
u32 w1_t[4];
u32 w2_t[4];
u32 w3_t[4];
w0_t[0] = w0[0];
w0_t[1] = w0[1];
w0_t[2] = w0[2];
w0_t[3] = w0[3];
w1_t[0] = w1[0];
w1_t[1] = w1[1];
w1_t[2] = w1[2];
w1_t[3] = w1[3];
w2_t[0] = 0;
w2_t[1] = 0;
w2_t[2] = 0;
w2_t[3] = 0;
w3_t[0] = 0;
w3_t[1] = 0;
w3_t[2] = 0;
w3_t[3] = 0;
// K=MD4(Little_indian(UNICODE(pwd))
append_0x80_2x4 (w0_t, w1_t, pw_len);
make_utf16le (w1_t, w2_t, w3_t);
make_utf16le (w0_t, w0_t, w1_t);
w3_t[2] = pw_len * 8 * 2;
w3_t[3] = 0;
digest[0] = MD4M_A;
digest[1] = MD4M_B;
digest[2] = MD4M_C;
digest[3] = MD4M_D;
md4_transform (w0_t, w1_t, w2_t, w3_t, digest);
// K1=MD5_HMAC(K,1); with 2 encoded as little indian on 4 bytes (02000000 in hexa);
w0_t[0] = digest[0];
w0_t[1] = digest[1];
w0_t[2] = digest[2];
w0_t[3] = digest[3];
w1_t[0] = 0;
w1_t[1] = 0;
w1_t[2] = 0;
w1_t[3] = 0;
w2_t[0] = 0;
w2_t[1] = 0;
w2_t[2] = 0;
w2_t[3] = 0;
w3_t[0] = 0;
w3_t[1] = 0;
w3_t[2] = 0;
w3_t[3] = 0;
u32 ipad[4];
u32 opad[4];
hmac_md5_pad (w0_t, w1_t, w2_t, w3_t, ipad, opad);
w0_t[0] = 8;
w0_t[1] = 0x80;
w0_t[2] = 0;
w0_t[3] = 0;
w1_t[0] = 0;
w1_t[1] = 0;
w1_t[2] = 0;
w1_t[3] = 0;
w2_t[0] = 0;
w2_t[1] = 0;
w2_t[2] = 0;
w2_t[3] = 0;
w3_t[0] = 0;
w3_t[1] = 0;
w3_t[2] = (64 + 4) * 8;
w3_t[3] = 0;
hmac_md5_run (w0_t, w1_t, w2_t, w3_t, ipad, opad, digest);
// K2 = K1;
K2[0] = digest[0];
K2[1] = digest[1];
K2[2] = digest[2];
K2[3] = digest[3];
// K3=MD5_HMAC(K1,checksum);
w0_t[0] = digest[0];
w0_t[1] = digest[1];
w0_t[2] = digest[2];
w0_t[3] = digest[3];
w1_t[0] = 0;
w1_t[1] = 0;
w1_t[2] = 0;
w1_t[3] = 0;
w2_t[0] = 0;
w2_t[1] = 0;
w2_t[2] = 0;
w2_t[3] = 0;
w3_t[0] = 0;
w3_t[1] = 0;
w3_t[2] = 0;
w3_t[3] = 0;
hmac_md5_pad (w0_t, w1_t, w2_t, w3_t, ipad, opad);
w0_t[0] = checksum[0];
w0_t[1] = checksum[1];
w0_t[2] = checksum[2];
w0_t[3] = checksum[3];
w1_t[0] = 0x80;
w1_t[1] = 0;
w1_t[2] = 0;
w1_t[3] = 0;
w2_t[0] = 0;
w2_t[1] = 0;
w2_t[2] = 0;
w2_t[3] = 0;
w3_t[0] = 0;
w3_t[1] = 0;
w3_t[2] = (64 + 16) * 8;
w3_t[3] = 0;
hmac_md5_run (w0_t, w1_t, w2_t, w3_t, ipad, opad, digest);
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_m04 (__global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
/**
* modifier
*/
const u64 lid = get_local_id (0);
/**
* base
*/
const u64 gid = get_global_id (0);
if (gid >= gid_max) return;
u32 pw_buf0[4];
u32 pw_buf1[4];
pw_buf0[0] = pws[gid].i[0];
pw_buf0[1] = pws[gid].i[1];
pw_buf0[2] = pws[gid].i[2];
pw_buf0[3] = pws[gid].i[3];
pw_buf1[0] = pws[gid].i[4];
pw_buf1[1] = pws[gid].i[5];
pw_buf1[2] = pws[gid].i[6];
pw_buf1[3] = pws[gid].i[7];
const u32 pw_l_len = pws[gid].pw_len;
/**
* shared
*/
__local RC4_KEY rc4_keys[64];
__local RC4_KEY *rc4_key = &rc4_keys[lid];
/**
* salt
*/
u32 checksum[4];
checksum[0] = krb5asrep_bufs[digests_offset].checksum[0];
checksum[1] = krb5asrep_bufs[digests_offset].checksum[1];
checksum[2] = krb5asrep_bufs[digests_offset].checksum[2];
checksum[3] = krb5asrep_bufs[digests_offset].checksum[3];
/**
* loop
*/
for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
{
const u32x pw_r_len = pwlenx_create_combt (combs_buf, il_pos);
const u32x pw_len = pw_l_len + pw_r_len;
/**
* concat password candidate
*/
u32x wordl0[4] = { 0 };
u32x wordl1[4] = { 0 };
u32x wordl2[4] = { 0 };
u32x wordl3[4] = { 0 };
wordl0[0] = pw_buf0[0];
wordl0[1] = pw_buf0[1];
wordl0[2] = pw_buf0[2];
wordl0[3] = pw_buf0[3];
wordl1[0] = pw_buf1[0];
wordl1[1] = pw_buf1[1];
wordl1[2] = pw_buf1[2];
wordl1[3] = pw_buf1[3];
u32x wordr0[4] = { 0 };
u32x wordr1[4] = { 0 };
u32x wordr2[4] = { 0 };
u32x wordr3[4] = { 0 };
wordr0[0] = ix_create_combt (combs_buf, il_pos, 0);
wordr0[1] = ix_create_combt (combs_buf, il_pos, 1);
wordr0[2] = ix_create_combt (combs_buf, il_pos, 2);
wordr0[3] = ix_create_combt (combs_buf, il_pos, 3);
wordr1[0] = ix_create_combt (combs_buf, il_pos, 4);
wordr1[1] = ix_create_combt (combs_buf, il_pos, 5);
wordr1[2] = ix_create_combt (combs_buf, il_pos, 6);
wordr1[3] = ix_create_combt (combs_buf, il_pos, 7);
if (combs_mode == COMBINATOR_MODE_BASE_LEFT)
{
switch_buffer_by_offset_le_VV (wordr0, wordr1, wordr2, wordr3, pw_l_len);
}
else
{
switch_buffer_by_offset_le_VV (wordl0, wordl1, wordl2, wordl3, pw_r_len);
}
u32x w0[4];
u32x w1[4];
w0[0] = wordl0[0] | wordr0[0];
w0[1] = wordl0[1] | wordr0[1];
w0[2] = wordl0[2] | wordr0[2];
w0[3] = wordl0[3] | wordr0[3];
w1[0] = wordl1[0] | wordr1[0];
w1[1] = wordl1[1] | wordr1[1];
w1[2] = wordl1[2] | wordr1[2];
w1[3] = wordl1[3] | wordr1[3];
/**
* kerberos
*/
u32 digest[4];
u32 K2[4];
kerb_prepare (w0, w1, pw_len, checksum, digest, K2);
u32 tmp[4];
tmp[0] = digest[0];
tmp[1] = digest[1];
tmp[2] = digest[2];
tmp[3] = digest[3];
if (decrypt_and_check (rc4_key, tmp, krb5asrep_bufs[digests_offset].edata2, krb5asrep_bufs[digests_offset].edata2_len, K2, checksum) == 1)
{
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
{
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos);
}
}
}
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_m08 (__global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_m16 (__global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_s04 (__global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
/**
* modifier
*/
const u64 lid = get_local_id (0);
/**
* base
*/
const u64 gid = get_global_id (0);
if (gid >= gid_max) return;
u32 pw_buf0[4];
u32 pw_buf1[4];
pw_buf0[0] = pws[gid].i[0];
pw_buf0[1] = pws[gid].i[1];
pw_buf0[2] = pws[gid].i[2];
pw_buf0[3] = pws[gid].i[3];
pw_buf1[0] = pws[gid].i[4];
pw_buf1[1] = pws[gid].i[5];
pw_buf1[2] = pws[gid].i[6];
pw_buf1[3] = pws[gid].i[7];
const u32 pw_l_len = pws[gid].pw_len;
/**
* shared
*/
__local RC4_KEY rc4_keys[64];
__local RC4_KEY *rc4_key = &rc4_keys[lid];
/**
* salt
*/
u32 checksum[4];
checksum[0] = krb5asrep_bufs[digests_offset].checksum[0];
checksum[1] = krb5asrep_bufs[digests_offset].checksum[1];
checksum[2] = krb5asrep_bufs[digests_offset].checksum[2];
checksum[3] = krb5asrep_bufs[digests_offset].checksum[3];
/**
* loop
*/
for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
{
const u32x pw_r_len = pwlenx_create_combt (combs_buf, il_pos);
const u32x pw_len = pw_l_len + pw_r_len;
/**
* concat password candidate
*/
u32x wordl0[4] = { 0 };
u32x wordl1[4] = { 0 };
u32x wordl2[4] = { 0 };
u32x wordl3[4] = { 0 };
wordl0[0] = pw_buf0[0];
wordl0[1] = pw_buf0[1];
wordl0[2] = pw_buf0[2];
wordl0[3] = pw_buf0[3];
wordl1[0] = pw_buf1[0];
wordl1[1] = pw_buf1[1];
wordl1[2] = pw_buf1[2];
wordl1[3] = pw_buf1[3];
u32x wordr0[4] = { 0 };
u32x wordr1[4] = { 0 };
u32x wordr2[4] = { 0 };
u32x wordr3[4] = { 0 };
wordr0[0] = ix_create_combt (combs_buf, il_pos, 0);
wordr0[1] = ix_create_combt (combs_buf, il_pos, 1);
wordr0[2] = ix_create_combt (combs_buf, il_pos, 2);
wordr0[3] = ix_create_combt (combs_buf, il_pos, 3);
wordr1[0] = ix_create_combt (combs_buf, il_pos, 4);
wordr1[1] = ix_create_combt (combs_buf, il_pos, 5);
wordr1[2] = ix_create_combt (combs_buf, il_pos, 6);
wordr1[3] = ix_create_combt (combs_buf, il_pos, 7);
if (combs_mode == COMBINATOR_MODE_BASE_LEFT)
{
switch_buffer_by_offset_le_VV (wordr0, wordr1, wordr2, wordr3, pw_l_len);
}
else
{
switch_buffer_by_offset_le_VV (wordl0, wordl1, wordl2, wordl3, pw_r_len);
}
u32x w0[4];
u32x w1[4];
w0[0] = wordl0[0] | wordr0[0];
w0[1] = wordl0[1] | wordr0[1];
w0[2] = wordl0[2] | wordr0[2];
w0[3] = wordl0[3] | wordr0[3];
w1[0] = wordl1[0] | wordr1[0];
w1[1] = wordl1[1] | wordr1[1];
w1[2] = wordl1[2] | wordr1[2];
w1[3] = wordl1[3] | wordr1[3];
/**
* kerberos
*/
u32 digest[4];
u32 K2[4];
kerb_prepare (w0, w1, pw_len, checksum, digest, K2);
u32 tmp[4];
tmp[0] = digest[0];
tmp[1] = digest[1];
tmp[2] = digest[2];
tmp[3] = digest[3];
if (decrypt_and_check (rc4_key, tmp, krb5asrep_bufs[digests_offset].edata2, krb5asrep_bufs[digests_offset].edata2_len, K2, checksum) == 1)
{
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
{
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos);
}
}
}
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_s08 (__global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_s16 (__global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
}

494
OpenCL/m18200_a1-pure.cl Normal file
View File

@ -0,0 +1,494 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
//shared mem too small
//#define NEW_SIMD_CODE
#include "inc_vendor.cl"
#include "inc_hash_constants.h"
#include "inc_hash_functions.cl"
#include "inc_types.cl"
#include "inc_common.cl"
#include "inc_hash_md4.cl"
#include "inc_hash_md5.cl"
typedef struct
{
u8 S[256];
u32 wtf_its_faster;
} RC4_KEY;
DECLSPEC void swap (__local RC4_KEY *rc4_key, const u8 i, const u8 j)
{
u8 tmp;
tmp = rc4_key->S[i];
rc4_key->S[i] = rc4_key->S[j];
rc4_key->S[j] = tmp;
}
DECLSPEC void rc4_init_16 (__local RC4_KEY *rc4_key, const u32 *data)
{
u32 v = 0x03020100;
u32 a = 0x04040404;
__local u32 *ptr = (__local u32 *) rc4_key->S;
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < 64; i++)
{
*ptr++ = v; v += a;
}
u32 j = 0;
for (u32 i = 0; i < 16; i++)
{
u32 idx = i * 16;
u32 v;
v = data[0];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
v = data[1];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
v = data[2];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
v = data[3];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
}
}
DECLSPEC u8 rc4_next_16 (__local RC4_KEY *rc4_key, u8 i, u8 j, const __global u32 *in, u32 *out)
{
#ifdef _unroll
#pragma unroll
#endif
for (u32 k = 0; k < 4; k++)
{
u32 xor4 = 0;
u8 idx;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 0;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 8;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 16;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 24;
out[k] = in[k] ^ xor4;
}
return j;
}
DECLSPEC int decrypt_and_check (__local RC4_KEY *rc4_key, u32 *data, __global const u32 *edata2, const u32 edata2_len, const u32 *K2, const u32 *checksum)
{
rc4_init_16 (rc4_key, data);
u32 out0[4];
/*
8 first bytes are nonce, then ASN1 structs (DER encoding: TLV)
The first byte is always 0x79 (01 1 11001, where 01 = "class=APPLICATION", 1 = "form=constructed", 11001 is application type 25)
The next byte is the length:
if length < 128 bytes:
length is on 1 byte, and the next byte is 0x30 (class=SEQUENCE)
else if length <= 256:
length is on 2 bytes, the first byte is 0x81, and the third byte is 0x30 (class=SEQUENCE)
else if length > 256:
length is on 3 bytes, the first byte is 0x82, and the fourth byte is 0x30 (class=SEQUENCE)
*/
rc4_next_16 (rc4_key, 0, 0, edata2 + 0, out0);
if (((out0[2] & 0x00ff80ff) != 0x00300079) &&
((out0[2] & 0xFF00FFFF) != 0x30008179) &&
((out0[2] & 0x0000FFFF) != 0x00008279 || (out0[3] & 0x000000FF) != 0x00000030))
return 0;
rc4_init_16 (rc4_key, data);
u8 i = 0;
u8 j = 0;
// init hmac
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
w0[0] = K2[0];
w0[1] = K2[1];
w0[2] = K2[2];
w0[3] = K2[3];
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
md5_hmac_ctx_t ctx;
md5_hmac_init_64 (&ctx, w0, w1, w2, w3);
int edata2_left;
for (edata2_left = edata2_len; edata2_left >= 64; edata2_left -= 64)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w2); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w3); i += 16; edata2 += 4;
md5_hmac_update_64 (&ctx, w0, w1, w2, w3, 64);
}
w0[0] = 0;
w0[1] = 0;
w0[2] = 0;
w0[3] = 0;
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
if (edata2_left < 16)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w0, edata2_left & 0xf);
}
else if (edata2_left < 32)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w1, edata2_left & 0xf);
}
else if (edata2_left < 48)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w2); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w2, edata2_left & 0xf);
}
else
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w2); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w3); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w3, edata2_left & 0xf);
}
md5_hmac_update_64 (&ctx, w0, w1, w2, w3, edata2_left);
md5_hmac_final (&ctx);
if (checksum[0] != ctx.opad.h[0]) return 0;
if (checksum[1] != ctx.opad.h[1]) return 0;
if (checksum[2] != ctx.opad.h[2]) return 0;
if (checksum[3] != ctx.opad.h[3]) return 0;
return 1;
}
DECLSPEC void kerb_prepare (const u32 *K, const u32 *checksum, u32 *digest, u32 *K2)
{
// K1=MD5_HMAC(K,1); with 1 encoded as little indian on 4 bytes (01000000 in hexa);
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
w0[0] = K[0];
w0[1] = K[1];
w0[2] = K[2];
w0[3] = K[3];
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
md5_hmac_ctx_t ctx1;
md5_hmac_init_64 (&ctx1, w0, w1, w2, w3);
w0[0] = 8;
w0[1] = 0;
w0[2] = 0;
w0[3] = 0;
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
md5_hmac_update_64 (&ctx1, w0, w1, w2, w3, 4);
md5_hmac_final (&ctx1);
w0[0] = ctx1.opad.h[0];
w0[1] = ctx1.opad.h[1];
w0[2] = ctx1.opad.h[2];
w0[3] = ctx1.opad.h[3];
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
md5_hmac_ctx_t ctx;
md5_hmac_init_64 (&ctx, w0, w1, w2, w3);
w0[0] = checksum[0];
w0[1] = checksum[1];
w0[2] = checksum[2];
w0[3] = checksum[3];
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
md5_hmac_update_64 (&ctx, w0, w1, w2, w3, 16);
md5_hmac_final (&ctx);
digest[0] = ctx.opad.h[0];
digest[1] = ctx.opad.h[1];
digest[2] = ctx.opad.h[2];
digest[3] = ctx.opad.h[3];
K2[0] = ctx1.opad.h[0];
K2[1] = ctx1.opad.h[1];
K2[2] = ctx1.opad.h[2];
K2[3] = ctx1.opad.h[3];
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_mxx (__global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global const krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
/**
* modifier
*/
const u64 lid = get_local_id (0);
const u64 gid = get_global_id (0);
if (gid >= gid_max) return;
/**
* base
*/
__local RC4_KEY rc4_keys[64];
__local RC4_KEY *rc4_key = &rc4_keys[lid];
u32 checksum[4];
checksum[0] = krb5asrep_bufs[digests_offset].checksum[0];
checksum[1] = krb5asrep_bufs[digests_offset].checksum[1];
checksum[2] = krb5asrep_bufs[digests_offset].checksum[2];
checksum[3] = krb5asrep_bufs[digests_offset].checksum[3];
md4_ctx_t ctx0;
md4_init (&ctx0);
md4_update_global_utf16le (&ctx0, pws[gid].i, pws[gid].pw_len);
/**
* loop
*/
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
{
md4_ctx_t ctx = ctx0;
md4_update_global_utf16le (&ctx, combs_buf[il_pos].i, combs_buf[il_pos].pw_len);
md4_final (&ctx);
u32 digest[4];
u32 K2[4];
kerb_prepare (ctx.h, checksum, digest, K2);
if (decrypt_and_check (rc4_key, digest, krb5asrep_bufs[digests_offset].edata2, krb5asrep_bufs[digests_offset].edata2_len, K2, checksum) == 1)
{
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
{
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos);
}
}
}
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_sxx (__global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global const krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
/**
* modifier
*/
const u64 lid = get_local_id (0);
const u64 gid = get_global_id (0);
if (gid >= gid_max) return;
/**
* base
*/
__local RC4_KEY rc4_keys[64];
__local RC4_KEY *rc4_key = &rc4_keys[lid];
u32 checksum[4];
checksum[0] = krb5asrep_bufs[digests_offset].checksum[0];
checksum[1] = krb5asrep_bufs[digests_offset].checksum[1];
checksum[2] = krb5asrep_bufs[digests_offset].checksum[2];
checksum[3] = krb5asrep_bufs[digests_offset].checksum[3];
md4_ctx_t ctx0;
md4_init (&ctx0);
md4_update_global_utf16le (&ctx0, pws[gid].i, pws[gid].pw_len);
/**
* loop
*/
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
{
md4_ctx_t ctx = ctx0;
md4_update_global_utf16le (&ctx, combs_buf[il_pos].i, combs_buf[il_pos].pw_len);
md4_final (&ctx);
u32 digest[4];
u32 K2[4];
kerb_prepare (ctx.h, checksum, digest, K2);
if (decrypt_and_check (rc4_key, digest, krb5asrep_bufs[digests_offset].edata2, krb5asrep_bufs[digests_offset].edata2_len, K2, checksum) == 1)
{
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
{
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos);
}
}
}
}

View File

@ -0,0 +1,837 @@
/**
* Author......: see docs/credits.txt
* License.....: MIT
*/
//too much register pressure
//#define NEW_SIMD_CODE
#include "inc_vendor.cl"
#include "inc_hash_constants.h"
#include "inc_hash_functions.cl"
#include "inc_types.cl"
#include "inc_common.cl"
#include "inc_simd.cl"
#include "inc_hash_md4.cl"
#include "inc_hash_md5.cl"
typedef struct
{
u8 S[256];
u32 wtf_its_faster;
} RC4_KEY;
DECLSPEC void swap (__local RC4_KEY *rc4_key, const u8 i, const u8 j)
{
u8 tmp;
tmp = rc4_key->S[i];
rc4_key->S[i] = rc4_key->S[j];
rc4_key->S[j] = tmp;
}
DECLSPEC void rc4_init_16 (__local RC4_KEY *rc4_key, const u32 *data)
{
u32 v = 0x03020100;
u32 a = 0x04040404;
__local u32 *ptr = (__local u32 *) rc4_key->S;
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < 64; i++)
{
*ptr++ = v; v += a;
}
u32 j = 0;
for (u32 i = 0; i < 16; i++)
{
u32 idx = i * 16;
u32 v;
v = data[0];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
v = data[1];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
v = data[2];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
v = data[3];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
}
}
DECLSPEC u8 rc4_next_16 (__local RC4_KEY *rc4_key, u8 i, u8 j, const __global u32 *in, u32 *out)
{
#ifdef _unroll
#pragma unroll
#endif
for (u32 k = 0; k < 4; k++)
{
u32 xor4 = 0;
u8 idx;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 0;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 8;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 16;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 24;
out[k] = in[k] ^ xor4;
}
return j;
}
DECLSPEC void hmac_md5_pad (u32 *w0, u32 *w1, u32 *w2, u32 *w3, u32 *ipad, u32 *opad)
{
w0[0] = w0[0] ^ 0x36363636;
w0[1] = w0[1] ^ 0x36363636;
w0[2] = w0[2] ^ 0x36363636;
w0[3] = w0[3] ^ 0x36363636;
w1[0] = w1[0] ^ 0x36363636;
w1[1] = w1[1] ^ 0x36363636;
w1[2] = w1[2] ^ 0x36363636;
w1[3] = w1[3] ^ 0x36363636;
w2[0] = w2[0] ^ 0x36363636;
w2[1] = w2[1] ^ 0x36363636;
w2[2] = w2[2] ^ 0x36363636;
w2[3] = w2[3] ^ 0x36363636;
w3[0] = w3[0] ^ 0x36363636;
w3[1] = w3[1] ^ 0x36363636;
w3[2] = w3[2] ^ 0x36363636;
w3[3] = w3[3] ^ 0x36363636;
ipad[0] = MD5M_A;
ipad[1] = MD5M_B;
ipad[2] = MD5M_C;
ipad[3] = MD5M_D;
md5_transform (w0, w1, w2, w3, ipad);
w0[0] = w0[0] ^ 0x6a6a6a6a;
w0[1] = w0[1] ^ 0x6a6a6a6a;
w0[2] = w0[2] ^ 0x6a6a6a6a;
w0[3] = w0[3] ^ 0x6a6a6a6a;
w1[0] = w1[0] ^ 0x6a6a6a6a;
w1[1] = w1[1] ^ 0x6a6a6a6a;
w1[2] = w1[2] ^ 0x6a6a6a6a;
w1[3] = w1[3] ^ 0x6a6a6a6a;
w2[0] = w2[0] ^ 0x6a6a6a6a;
w2[1] = w2[1] ^ 0x6a6a6a6a;
w2[2] = w2[2] ^ 0x6a6a6a6a;
w2[3] = w2[3] ^ 0x6a6a6a6a;
w3[0] = w3[0] ^ 0x6a6a6a6a;
w3[1] = w3[1] ^ 0x6a6a6a6a;
w3[2] = w3[2] ^ 0x6a6a6a6a;
w3[3] = w3[3] ^ 0x6a6a6a6a;
opad[0] = MD5M_A;
opad[1] = MD5M_B;
opad[2] = MD5M_C;
opad[3] = MD5M_D;
md5_transform (w0, w1, w2, w3, opad);
}
DECLSPEC void hmac_md5_run (u32 *w0, u32 *w1, u32 *w2, u32 *w3, u32 *ipad, u32 *opad, u32 *digest)
{
digest[0] = ipad[0];
digest[1] = ipad[1];
digest[2] = ipad[2];
digest[3] = ipad[3];
md5_transform (w0, w1, w2, w3, digest);
w0[0] = digest[0];
w0[1] = digest[1];
w0[2] = digest[2];
w0[3] = digest[3];
w1[0] = 0x80;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = (64 + 16) * 8;
w3[3] = 0;
digest[0] = opad[0];
digest[1] = opad[1];
digest[2] = opad[2];
digest[3] = opad[3];
md5_transform (w0, w1, w2, w3, digest);
}
DECLSPEC int decrypt_and_check (__local RC4_KEY *rc4_key, u32 *data, __global const u32 *edata2, const u32 edata2_len, const u32 *K2, const u32 *checksum)
{
rc4_init_16 (rc4_key, data);
u32 out0[4];
/*
8 first bytes are nonce, then ASN1 structs (DER encoding: TLV)
The first byte is always 0x79 (01 1 11001, where 01 = "class=APPLICATION", 1 = "form=constructed", 11001 is application type 25)
The next byte is the length:
if length < 128 bytes:
length is on 1 byte, and the next byte is 0x30 (class=SEQUENCE)
else if length <= 256:
length is on 2 bytes, the first byte is 0x81, and the third byte is 0x30 (class=SEQUENCE)
else if length > 256:
length is on 3 bytes, the first byte is 0x82, and the fourth byte is 0x30 (class=SEQUENCE)
*/
rc4_next_16 (rc4_key, 0, 0, edata2 + 0, out0);
if (((out0[2] & 0x00ff80ff) != 0x00300079) &&
((out0[2] & 0xFF00FFFF) != 0x30008179) &&
((out0[2] & 0x0000FFFF) != 0x00008279 || (out0[3] & 0x000000FF) != 0x00000030))
return 0;
rc4_init_16 (rc4_key, data);
u8 i = 0;
u8 j = 0;
// init hmac
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
w0[0] = K2[0];
w0[1] = K2[1];
w0[2] = K2[2];
w0[3] = K2[3];
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
u32 ipad[4];
u32 opad[4];
hmac_md5_pad (w0, w1, w2, w3, ipad, opad);
int edata2_left;
for (edata2_left = edata2_len; edata2_left >= 64; edata2_left -= 64)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w2); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w3); i += 16; edata2 += 4;
md5_transform (w0, w1, w2, w3, ipad);
}
w0[0] = 0;
w0[1] = 0;
w0[2] = 0;
w0[3] = 0;
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
if (edata2_left < 16)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w0, edata2_left & 0xf);
append_0x80_1x4 (w0, edata2_left & 0xf);
w3[2] = (64 + edata2_len) * 8;
w3[3] = 0;
md5_transform (w0, w1, w2, w3, ipad);
}
else if (edata2_left < 32)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w1, edata2_left & 0xf);
append_0x80_1x4 (w1, edata2_left & 0xf);
w3[2] = (64 + edata2_len) * 8;
w3[3] = 0;
md5_transform (w0, w1, w2, w3, ipad);
}
else if (edata2_left < 48)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w2); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w2, edata2_left & 0xf);
append_0x80_1x4 (w2, edata2_left & 0xf);
w3[2] = (64 + edata2_len) * 8;
w3[3] = 0;
md5_transform (w0, w1, w2, w3, ipad);
}
else
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w2); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w3); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w3, edata2_left & 0xf);
append_0x80_1x4 (w3, edata2_left & 0xf);
if (edata2_left < 56)
{
w3[2] = (64 + edata2_len) * 8;
w3[3] = 0;
md5_transform (w0, w1, w2, w3, ipad);
}
else
{
md5_transform (w0, w1, w2, w3, ipad);
w0[0] = 0;
w0[1] = 0;
w0[2] = 0;
w0[3] = 0;
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = (64 + edata2_len) * 8;
w3[3] = 0;
md5_transform (w0, w1, w2, w3, ipad);
}
}
w0[0] = ipad[0];
w0[1] = ipad[1];
w0[2] = ipad[2];
w0[3] = ipad[3];
w1[0] = 0x80;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = (64 + 16) * 8;
w3[3] = 0;
md5_transform (w0, w1, w2, w3, opad);
if (checksum[0] != opad[0]) return 0;
if (checksum[1] != opad[1]) return 0;
if (checksum[2] != opad[2]) return 0;
if (checksum[3] != opad[3]) return 0;
return 1;
}
DECLSPEC void kerb_prepare (const u32 *w0, const u32 *w1, const u32 pw_len, const u32 *checksum, u32 *digest, u32 *K2)
{
/**
* pads
*/
u32 w0_t[4];
u32 w1_t[4];
u32 w2_t[4];
u32 w3_t[4];
w0_t[0] = w0[0];
w0_t[1] = w0[1];
w0_t[2] = w0[2];
w0_t[3] = w0[3];
w1_t[0] = w1[0];
w1_t[1] = w1[1];
w1_t[2] = w1[2];
w1_t[3] = w1[3];
w2_t[0] = 0;
w2_t[1] = 0;
w2_t[2] = 0;
w2_t[3] = 0;
w3_t[0] = 0;
w3_t[1] = 0;
w3_t[2] = 0;
w3_t[3] = 0;
// K=MD4(Little_indian(UNICODE(pwd))
append_0x80_2x4 (w0_t, w1_t, pw_len);
make_utf16le (w1_t, w2_t, w3_t);
make_utf16le (w0_t, w0_t, w1_t);
w3_t[2] = pw_len * 8 * 2;
w3_t[3] = 0;
digest[0] = MD4M_A;
digest[1] = MD4M_B;
digest[2] = MD4M_C;
digest[3] = MD4M_D;
md4_transform (w0_t, w1_t, w2_t, w3_t, digest);
// K1=MD5_HMAC(K,1); with 2 encoded as little indian on 4 bytes (02000000 in hexa);
w0_t[0] = digest[0];
w0_t[1] = digest[1];
w0_t[2] = digest[2];
w0_t[3] = digest[3];
w1_t[0] = 0;
w1_t[1] = 0;
w1_t[2] = 0;
w1_t[3] = 0;
w2_t[0] = 0;
w2_t[1] = 0;
w2_t[2] = 0;
w2_t[3] = 0;
w3_t[0] = 0;
w3_t[1] = 0;
w3_t[2] = 0;
w3_t[3] = 0;
u32 ipad[4];
u32 opad[4];
hmac_md5_pad (w0_t, w1_t, w2_t, w3_t, ipad, opad);
w0_t[0] = 8;
w0_t[1] = 0x80;
w0_t[2] = 0;
w0_t[3] = 0;
w1_t[0] = 0;
w1_t[1] = 0;
w1_t[2] = 0;
w1_t[3] = 0;
w2_t[0] = 0;
w2_t[1] = 0;
w2_t[2] = 0;
w2_t[3] = 0;
w3_t[0] = 0;
w3_t[1] = 0;
w3_t[2] = (64 + 4) * 8;
w3_t[3] = 0;
hmac_md5_run (w0_t, w1_t, w2_t, w3_t, ipad, opad, digest);
// K2 = K1;
K2[0] = digest[0];
K2[1] = digest[1];
K2[2] = digest[2];
K2[3] = digest[3];
// K3=MD5_HMAC(K1,checksum);
w0_t[0] = digest[0];
w0_t[1] = digest[1];
w0_t[2] = digest[2];
w0_t[3] = digest[3];
w1_t[0] = 0;
w1_t[1] = 0;
w1_t[2] = 0;
w1_t[3] = 0;
w2_t[0] = 0;
w2_t[1] = 0;
w2_t[2] = 0;
w2_t[3] = 0;
w3_t[0] = 0;
w3_t[1] = 0;
w3_t[2] = 0;
w3_t[3] = 0;
hmac_md5_pad (w0_t, w1_t, w2_t, w3_t, ipad, opad);
w0_t[0] = checksum[0];
w0_t[1] = checksum[1];
w0_t[2] = checksum[2];
w0_t[3] = checksum[3];
w1_t[0] = 0x80;
w1_t[1] = 0;
w1_t[2] = 0;
w1_t[3] = 0;
w2_t[0] = 0;
w2_t[1] = 0;
w2_t[2] = 0;
w2_t[3] = 0;
w3_t[0] = 0;
w3_t[1] = 0;
w3_t[2] = (64 + 16) * 8;
w3_t[3] = 0;
hmac_md5_run (w0_t, w1_t, w2_t, w3_t, ipad, opad, digest);
}
DECLSPEC void m18200 (__local RC4_KEY *rc4_key, u32 *w0, u32 *w1, u32 *w2, u32 *w3, const u32 pw_len, __global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset)
{
/**
* modifier
*/
const u64 gid = get_global_id (0);
const u64 lid = get_local_id (0);
/**
* salt
*/
u32 checksum[4];
checksum[0] = krb5asrep_bufs[digests_offset].checksum[0];
checksum[1] = krb5asrep_bufs[digests_offset].checksum[1];
checksum[2] = krb5asrep_bufs[digests_offset].checksum[2];
checksum[3] = krb5asrep_bufs[digests_offset].checksum[3];
/**
* loop
*/
u32 w0l = w0[0];
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
{
const u32 w0r = bfs_buf[il_pos].i;
w0[0] = w0l | w0r;
/**
* kerberos
*/
u32 digest[4];
u32 K2[4];
kerb_prepare (w0, w1, pw_len, checksum, digest, K2);
u32 tmp[4];
tmp[0] = digest[0];
tmp[1] = digest[1];
tmp[2] = digest[2];
tmp[3] = digest[3];
if (decrypt_and_check (rc4_key, tmp, krb5asrep_bufs[digests_offset].edata2, krb5asrep_bufs[digests_offset].edata2_len, K2, checksum) == 1)
{
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
{
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos);
}
}
}
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_m04 (__global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
/**
* base
*/
const u64 gid = get_global_id (0);
const u64 lid = get_local_id (0);
if (gid >= gid_max) return;
u32 w0[4];
w0[0] = pws[gid].i[ 0];
w0[1] = pws[gid].i[ 1];
w0[2] = pws[gid].i[ 2];
w0[3] = pws[gid].i[ 3];
u32 w1[4];
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
u32 w2[4];
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
u32 w3[4];
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
const u32 pw_len = pws[gid].pw_len;
/**
* main
*/
__local RC4_KEY rc4_keys[64];
__local RC4_KEY *rc4_key = &rc4_keys[lid];
m18200 (rc4_key, w0, w1, w2, w3, pw_len, pws, rules_buf, combs_buf, bfs_buf, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, krb5asrep_bufs, d_return_buf, d_scryptV0_buf, d_scryptV1_buf, d_scryptV2_buf, d_scryptV3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset);
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_m08 (__global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
/**
* base
*/
const u64 gid = get_global_id (0);
const u64 lid = get_local_id (0);
if (gid >= gid_max) return;
u32 w0[4];
w0[0] = pws[gid].i[ 0];
w0[1] = pws[gid].i[ 1];
w0[2] = pws[gid].i[ 2];
w0[3] = pws[gid].i[ 3];
u32 w1[4];
w1[0] = pws[gid].i[ 4];
w1[1] = pws[gid].i[ 5];
w1[2] = pws[gid].i[ 6];
w1[3] = pws[gid].i[ 7];
u32 w2[4];
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
u32 w3[4];
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
const u32 pw_len = pws[gid].pw_len;
/**
* main
*/
__local RC4_KEY rc4_keys[64];
__local RC4_KEY *rc4_key = &rc4_keys[lid];
m18200 (rc4_key, w0, w1, w2, w3, pw_len, pws, rules_buf, combs_buf, bfs_buf, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, krb5asrep_bufs, d_return_buf, d_scryptV0_buf, d_scryptV1_buf, d_scryptV2_buf, d_scryptV3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset);
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_m16 (__global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_s04 (__global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
/**
* base
*/
const u64 gid = get_global_id (0);
const u64 lid = get_local_id (0);
if (gid >= gid_max) return;
u32 w0[4];
w0[0] = pws[gid].i[ 0];
w0[1] = pws[gid].i[ 1];
w0[2] = pws[gid].i[ 2];
w0[3] = pws[gid].i[ 3];
u32 w1[4];
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
u32 w2[4];
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
u32 w3[4];
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
const u32 pw_len = pws[gid].pw_len;
/**
* main
*/
__local RC4_KEY rc4_keys[64];
__local RC4_KEY *rc4_key = &rc4_keys[lid];
m18200 (rc4_key, w0, w1, w2, w3, pw_len, pws, rules_buf, combs_buf, bfs_buf, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, krb5asrep_bufs, d_return_buf, d_scryptV0_buf, d_scryptV1_buf, d_scryptV2_buf, d_scryptV3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset);
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_s08 (__global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
/**
* base
*/
const u64 gid = get_global_id (0);
const u64 lid = get_local_id (0);
if (gid >= gid_max) return;
u32 w0[4];
w0[0] = pws[gid].i[ 0];
w0[1] = pws[gid].i[ 1];
w0[2] = pws[gid].i[ 2];
w0[3] = pws[gid].i[ 3];
u32 w1[4];
w1[0] = pws[gid].i[ 4];
w1[1] = pws[gid].i[ 5];
w1[2] = pws[gid].i[ 6];
w1[3] = pws[gid].i[ 7];
u32 w2[4];
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
u32 w3[4];
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
const u32 pw_len = pws[gid].pw_len;
/**
* main
*/
__local RC4_KEY rc4_keys[64];
__local RC4_KEY *rc4_key = &rc4_keys[lid];
m18200 (rc4_key, w0, w1, w2, w3, pw_len, pws, rules_buf, combs_buf, bfs_buf, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, krb5asrep_bufs, d_return_buf, d_scryptV0_buf, d_scryptV1_buf, d_scryptV2_buf, d_scryptV3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset);
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_s16 (__global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __global const bf_t *bfs_buf, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
}

520
OpenCL/m18200_a3-pure.cl Normal file
View File

@ -0,0 +1,520 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
//shared mem too small
//#define NEW_SIMD_CODE
#include "inc_vendor.cl"
#include "inc_hash_constants.h"
#include "inc_hash_functions.cl"
#include "inc_types.cl"
#include "inc_common.cl"
#include "inc_hash_md4.cl"
#include "inc_hash_md5.cl"
typedef struct
{
u8 S[256];
u32 wtf_its_faster;
} RC4_KEY;
DECLSPEC void swap (__local RC4_KEY *rc4_key, const u8 i, const u8 j)
{
u8 tmp;
tmp = rc4_key->S[i];
rc4_key->S[i] = rc4_key->S[j];
rc4_key->S[j] = tmp;
}
DECLSPEC void rc4_init_16 (__local RC4_KEY *rc4_key, const u32 *data)
{
u32 v = 0x03020100;
u32 a = 0x04040404;
__local u32 *ptr = (__local u32 *) rc4_key->S;
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < 64; i++)
{
*ptr++ = v; v += a;
}
u32 j = 0;
for (u32 i = 0; i < 16; i++)
{
u32 idx = i * 16;
u32 v;
v = data[0];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
v = data[1];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
v = data[2];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
v = data[3];
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
}
}
DECLSPEC u8 rc4_next_16 (__local RC4_KEY *rc4_key, u8 i, u8 j, const __global u32 *in, u32 *out)
{
#ifdef _unroll
#pragma unroll
#endif
for (u32 k = 0; k < 4; k++)
{
u32 xor4 = 0;
u8 idx;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 0;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 8;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 16;
i += 1;
j += rc4_key->S[i];
swap (rc4_key, i, j);
idx = rc4_key->S[i] + rc4_key->S[j];
xor4 |= rc4_key->S[idx] << 24;
out[k] = in[k] ^ xor4;
}
return j;
}
DECLSPEC int decrypt_and_check (__local RC4_KEY *rc4_key, u32 *data, __global const u32 *edata2, const u32 edata2_len, const u32 *K2, const u32 *checksum)
{
rc4_init_16 (rc4_key, data);
u32 out0[4];
/*
8 first bytes are nonce, then ASN1 structs (DER encoding: TLV)
The first byte is always 0x79 (01 1 11001, where 01 = "class=APPLICATION", 1 = "form=constructed", 11001 is application type 25)
The next byte is the length:
if length < 128 bytes:
length is on 1 byte, and the next byte is 0x30 (class=SEQUENCE)
else if length <= 256:
length is on 2 bytes, the first byte is 0x81, and the third byte is 0x30 (class=SEQUENCE)
else if length > 256:
length is on 3 bytes, the first byte is 0x82, and the fourth byte is 0x30 (class=SEQUENCE)
*/
rc4_next_16 (rc4_key, 0, 0, edata2 + 0, out0);
if (((out0[2] & 0x00ff80ff) != 0x00300079) &&
((out0[2] & 0xFF00FFFF) != 0x30008179) &&
((out0[2] & 0x0000FFFF) != 0x00008279 || (out0[3] & 0x000000FF) != 0x00000030))
return 0;
rc4_init_16 (rc4_key, data);
u8 i = 0;
u8 j = 0;
// init hmac
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
w0[0] = K2[0];
w0[1] = K2[1];
w0[2] = K2[2];
w0[3] = K2[3];
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
md5_hmac_ctx_t ctx;
md5_hmac_init_64 (&ctx, w0, w1, w2, w3);
int edata2_left;
for (edata2_left = edata2_len; edata2_left >= 64; edata2_left -= 64)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w2); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w3); i += 16; edata2 += 4;
md5_hmac_update_64 (&ctx, w0, w1, w2, w3, 64);
}
w0[0] = 0;
w0[1] = 0;
w0[2] = 0;
w0[3] = 0;
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
if (edata2_left < 16)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w0, edata2_left & 0xf);
}
else if (edata2_left < 32)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w1, edata2_left & 0xf);
}
else if (edata2_left < 48)
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w2); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w2, edata2_left & 0xf);
}
else
{
j = rc4_next_16 (rc4_key, i, j, edata2, w0); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w1); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w2); i += 16; edata2 += 4;
j = rc4_next_16 (rc4_key, i, j, edata2, w3); i += 16; edata2 += 4;
truncate_block_4x4_le_S (w3, edata2_left & 0xf);
}
md5_hmac_update_64 (&ctx, w0, w1, w2, w3, edata2_left);
md5_hmac_final (&ctx);
if (checksum[0] != ctx.opad.h[0]) return 0;
if (checksum[1] != ctx.opad.h[1]) return 0;
if (checksum[2] != ctx.opad.h[2]) return 0;
if (checksum[3] != ctx.opad.h[3]) return 0;
return 1;
}
DECLSPEC void kerb_prepare (const u32 *K, const u32 *checksum, u32 *digest, u32 *K2)
{
// K1=MD5_HMAC(K,1); with 1 encoded as little indian on 4 bytes (01000000 in hexa);
u32 w0[4];
u32 w1[4];
u32 w2[4];
u32 w3[4];
w0[0] = K[0];
w0[1] = K[1];
w0[2] = K[2];
w0[3] = K[3];
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
md5_hmac_ctx_t ctx1;
md5_hmac_init_64 (&ctx1, w0, w1, w2, w3);
w0[0] = 8;
w0[1] = 0;
w0[2] = 0;
w0[3] = 0;
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
md5_hmac_update_64 (&ctx1, w0, w1, w2, w3, 4);
md5_hmac_final (&ctx1);
w0[0] = ctx1.opad.h[0];
w0[1] = ctx1.opad.h[1];
w0[2] = ctx1.opad.h[2];
w0[3] = ctx1.opad.h[3];
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
md5_hmac_ctx_t ctx;
md5_hmac_init_64 (&ctx, w0, w1, w2, w3);
w0[0] = checksum[0];
w0[1] = checksum[1];
w0[2] = checksum[2];
w0[3] = checksum[3];
w1[0] = 0;
w1[1] = 0;
w1[2] = 0;
w1[3] = 0;
w2[0] = 0;
w2[1] = 0;
w2[2] = 0;
w2[3] = 0;
w3[0] = 0;
w3[1] = 0;
w3[2] = 0;
w3[3] = 0;
md5_hmac_update_64 (&ctx, w0, w1, w2, w3, 16);
md5_hmac_final (&ctx);
digest[0] = ctx.opad.h[0];
digest[1] = ctx.opad.h[1];
digest[2] = ctx.opad.h[2];
digest[3] = ctx.opad.h[3];
K2[0] = ctx1.opad.h[0];
K2[1] = ctx1.opad.h[1];
K2[2] = ctx1.opad.h[2];
K2[3] = ctx1.opad.h[3];
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_mxx (__global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __constant const u32x *words_buf_r, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global const krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
/**
* modifier
*/
const u64 lid = get_local_id (0);
const u64 gid = get_global_id (0);
if (gid >= gid_max) return;
/**
* base
*/
const u32 pw_len = pws[gid].pw_len;
u32x w[64] = { 0 };
for (int i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
{
w[idx] = pws[gid].i[idx];
}
__local RC4_KEY rc4_keys[64];
__local RC4_KEY *rc4_key = &rc4_keys[lid];
u32 checksum[4];
checksum[0] = krb5asrep_bufs[digests_offset].checksum[0];
checksum[1] = krb5asrep_bufs[digests_offset].checksum[1];
checksum[2] = krb5asrep_bufs[digests_offset].checksum[2];
checksum[3] = krb5asrep_bufs[digests_offset].checksum[3];
/**
* loop
*/
u32x w0l = w[0];
for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
{
const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
const u32x w0 = w0l | w0r;
w[0] = w0;
md4_ctx_t ctx;
md4_init (&ctx);
md4_update_utf16le (&ctx, w, pw_len);
md4_final (&ctx);
u32 digest[4];
u32 K2[4];
kerb_prepare (ctx.h, checksum, digest, K2);
if (decrypt_and_check (rc4_key, digest, krb5asrep_bufs[digests_offset].edata2, krb5asrep_bufs[digests_offset].edata2_len, K2, checksum) == 1)
{
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
{
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos);
}
}
}
}
__kernel void __attribute__((reqd_work_group_size(64, 1, 1))) m18200_sxx (__global pw_t *pws, __global const kernel_rule_t *rules_buf, __global const pw_t *combs_buf, __constant const u32x *words_buf_r, __global void *tmps, __global void *hooks, __global const u32 *bitmaps_buf_s1_a, __global const u32 *bitmaps_buf_s1_b, __global const u32 *bitmaps_buf_s1_c, __global const u32 *bitmaps_buf_s1_d, __global const u32 *bitmaps_buf_s2_a, __global const u32 *bitmaps_buf_s2_b, __global const u32 *bitmaps_buf_s2_c, __global const u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global const digest_t *digests_buf, __global u32 *hashes_shown, __global const salt_t *salt_bufs, __global const krb5asrep_t *krb5asrep_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u64 gid_max)
{
/**
* modifier
*/
const u64 lid = get_local_id (0);
const u64 gid = get_global_id (0);
if (gid >= gid_max) return;
/**
* base
*/
const u32 pw_len = pws[gid].pw_len;
u32x w[64] = { 0 };
for (int i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
{
w[idx] = pws[gid].i[idx];
}
__local RC4_KEY rc4_keys[64];
__local RC4_KEY *rc4_key = &rc4_keys[lid];
u32 checksum[4];
checksum[0] = krb5asrep_bufs[digests_offset].checksum[0];
checksum[1] = krb5asrep_bufs[digests_offset].checksum[1];
checksum[2] = krb5asrep_bufs[digests_offset].checksum[2];
checksum[3] = krb5asrep_bufs[digests_offset].checksum[3];
/**
* loop
*/
u32x w0l = w[0];
for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
{
const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
const u32x w0 = w0l | w0r;
w[0] = w0;
md4_ctx_t ctx;
md4_init (&ctx);
md4_update_utf16le (&ctx, w, pw_len);
md4_final (&ctx);
u32 digest[4];
u32 K2[4];
kerb_prepare (ctx.h, checksum, digest, K2);
if (decrypt_and_check (rc4_key, digest, krb5asrep_bufs[digests_offset].edata2, krb5asrep_bufs[digests_offset].edata2_len, K2, checksum) == 1)
{
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
{
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos);
}
}
}
}

View File

@ -11,6 +11,7 @@
- Added pure kernels for hash-mode 11700 (Streebog-256)
- Added pure kernels for hash-mode 11800 (Streebog-512)
- Added hash-modes 18200 (Kerberos 5 AS-REP etype 23)
##
## Improvements

View File

@ -258,6 +258,7 @@ NVIDIA GPUs require "NVIDIA Driver" (367.x or later)
- Ethereum Wallet, SCRYPT
- Ethereum Pre-Sale Wallet, PBKDF2-HMAC-SHA256
- Ansible Vault
- Kerberos 5 AS-REP etype 23
- Plaintext
##

View File

@ -176,7 +176,7 @@ _hashcat ()
{
local VERSION=5.0.0
local HASH_MODES="0 10 11 12 20 21 22 23 30 40 50 60 100 101 110 111 112 120 121 122 124 130 131 132 133 140 141 150 160 200 300 400 500 501 600 900 1000 1100 1400 1410 1411 1420 1421 1430 1440 1441 1450 1460 1500 1600 1700 1710 1711 1720 1722 1730 1731 1740 1750 1760 1800 2100 2400 2410 2500 2501 2600 2611 2612 2711 2811 3000 3100 3200 3710 3711 3800 3910 4010 4110 4300 4400 4500 4520 4521 4522 4700 4800 4900 5100 5200 5300 5400 5500 5600 5700 5800 6000 6100 6211 6212 6213 6221 6222 6223 6231 6232 6233 6241 6242 6243 6300 6400 6500 6600 6700 6800 6900 7000 7100 7200 7300 7400 7500 7700 7800 7900 8000 8100 8200 8300 8400 8500 8600 8700 8800 8900 9000 9100 9200 9300 9400 9500 9600 9700 9710 9720 9800 9810 9820 9900 10000 10100 10200 10300 10400 10410 10420 10500 10600 10700 10800 10900 11000 11100 11200 11300 11400 11500 11600 11700 11800 11900 12000 12001 12100 12200 12300 12400 12500 12600 12700 12800 12900 13000 13100 13200 13300 13400 13500 13600 13800 13900 14000 14100 14700 14800 14900 15000 15100 15200 15300 15400 15500 15600 15700 15900 16000 16100 16200 16300 16400 16500 16600 16700 16800 16801 16900 17300 17400 17500 17600 17700 17800 17900 18000 18100"
local HASH_MODES="0 10 11 12 20 21 22 23 30 40 50 60 100 101 110 111 112 120 121 122 124 130 131 132 133 140 141 150 160 200 300 400 500 501 600 900 1000 1100 1400 1410 1411 1420 1421 1430 1440 1441 1450 1460 1500 1600 1700 1710 1711 1720 1722 1730 1731 1740 1750 1760 1800 2100 2400 2410 2500 2501 2600 2611 2612 2711 2811 3000 3100 3200 3710 3711 3800 3910 4010 4110 4300 4400 4500 4520 4521 4522 4700 4800 4900 5100 5200 5300 5400 5500 5600 5700 5800 6000 6100 6211 6212 6213 6221 6222 6223 6231 6232 6233 6241 6242 6243 6300 6400 6500 6600 6700 6800 6900 7000 7100 7200 7300 7400 7500 7700 7800 7900 8000 8100 8200 8300 8400 8500 8600 8700 8800 8900 9000 9100 9200 9300 9400 9500 9600 9700 9710 9720 9800 9810 9820 9900 10000 10100 10200 10300 10400 10410 10420 10500 10600 10700 10800 10900 11000 11100 11200 11300 11400 11500 11600 11700 11800 11900 12000 12001 12100 12200 12300 12400 12500 12600 12700 12800 12900 13000 13100 13200 13300 13400 13500 13600 13800 13900 14000 14100 14700 14800 14900 15000 15100 15200 15300 15400 15500 15600 15700 15900 16000 16100 16200 16300 16400 16500 16600 16700 16800 16801 16900 17300 17400 17500 17600 17700 17800 17900 18000 18100 18200"
local ATTACK_MODES="0 1 3 6 7"
local HCCAPX_MESSAGE_PAIRS="0 1 2 3 4 5"
local OUTFILE_FORMATS="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"

View File

@ -284,6 +284,15 @@ typedef struct krb5tgs
} krb5tgs_t;
typedef struct krb5asrep
{
u32 account_info[512];
u32 checksum[4];
u32 edata2[5120];
u32 edata2_len;
} krb5asrep_t;
typedef struct keepass
{
u32 version;
@ -1113,6 +1122,7 @@ typedef enum hash_type
HASH_TYPE_WPA_PMKID_PBKDF2 = 68,
HASH_TYPE_WPA_PMKID_PMK = 69,
HASH_TYPE_ANSIBLE_VAULT = 70,
HASH_TYPE_KRB5ASREP = 71,
} hash_type_t;
@ -1331,6 +1341,7 @@ typedef enum kern_type
KERN_TYPE_KECCAK_384 = 17900,
KERN_TYPE_KECCAK_512 = 18000,
KERN_TYPE_TOTP_HMACSHA1 = 18100,
KERN_TYPE_KRB5ASREP = 18200,
KERN_TYPE_PLAINTEXT = 99999,
} kern_type_t;
@ -1490,6 +1501,7 @@ int sha512grub_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_bu
int sha512b64s_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED hashconfig_t *hashconfig);
int krb5pa_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED hashconfig_t *hashconfig);
int krb5tgs_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED hashconfig_t *hashconfig);
int krb5asrep_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED hashconfig_t *hashconfig);
int sapb_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED hashconfig_t *hashconfig);
int sapg_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED hashconfig_t *hashconfig);
int drupal7_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED hashconfig_t *hashconfig);

View File

@ -290,6 +290,7 @@ static const char *ST_HASH_17800 = "203f88777f18bb4ee1226627b547808f38d90d3e1062
static const char *ST_HASH_17900 = "5804b7ada5806ba79540100e9a7ef493654ff2a21d94d4f2ce4bf69abda5d94bf03701fe9525a15dfdc625bfbd769701";
static const char *ST_HASH_18000 = "2fbf5c9080f0a704de2e915ba8fdae6ab00bbc026b2c1c8fa07da1239381c6b7f4dfd399bf9652500da723694a4c719587dd0219cb30eabe61210a8ae4dc0b03";
static const char *ST_HASH_18100 = "597056:3600";
static const char *ST_HASH_18200 = "$krb5asrep$23$user@domain.com:3e156ada591263b8aab0965f5aebd837$007497cb51b6c8116d6407a782ea0e1c5402b17db7afa6b05a6d30ed164a9933c754d720e279c6c573679bd27128fe77e5fea1f72334c1193c8ff0b370fadc6368bf2d49bbfdba4c5dccab95e8c8ebfdc75f438a0797dbfb2f8a1a5f4c423f9bfc1fea483342a11bd56a216f4d5158ccc4b224b52894fadfba3957dfe4b6b8f5f9f9fe422811a314768673e0c924340b8ccb84775ce9defaa3baa0910b676ad0036d13032b0dd94e3b13903cc738a7b6d00b0b3c210d1f972a6c7cae9bd3c959acf7565be528fc179118f28c679f6deeee1456f0781eb8154e18e49cb27b64bf74cd7112a0ebae2102ac";
static const char *ST_HASH_99999 = "hashcat";
static const char *OPTI_STR_OPTIMIZED_KERNEL = "Optimized-Kernel";
@ -546,6 +547,7 @@ static const char *HT_17800 = "Keccak-256";
static const char *HT_17900 = "Keccak-384";
static const char *HT_18000 = "Keccak-512";
static const char *HT_18100 = "TOTP (HMAC-SHA1)";
static const char *HT_18200 = "Kerberos 5 AS-REP etype 23";
static const char *HT_99999 = "Plaintext";
static const char *HT_00011 = "Joomla < 2.5.18";
@ -631,6 +633,7 @@ static const char *SIGNATURE_EPISERVER = "$episerver$";
static const char *SIGNATURE_KEEPASS = "$keepass$";
static const char *SIGNATURE_KRB5PA = "$krb5pa$23$";
static const char *SIGNATURE_KRB5TGS = "$krb5tgs$23$";
static const char *SIGNATURE_KRB5ASREP = "$krb5asrep$23$";
static const char *SIGNATURE_MD5AIX = "{smd5}";
static const char *SIGNATURE_MD5APR1 = "$apr1$";
static const char *SIGNATURE_MD5CRYPT = "$1$";
@ -14216,6 +14219,107 @@ int krb5tgs_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UN
return (PARSER_OK);
}
int krb5asrep_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED hashconfig_t *hashconfig)
{
u32 *digest = (u32 *) hash_buf->digest;
salt_t *salt = hash_buf->salt;
krb5asrep_t *krb5asrep = (krb5asrep_t *) hash_buf->esalt;
token_t token;
token.signatures_cnt = 1;
token.signatures_buf[0] = SIGNATURE_KRB5ASREP;
token.len[0] = strlen(SIGNATURE_KRB5ASREP);
token.attr[0] = TOKEN_ATTR_FIXED_LENGTH
| TOKEN_ATTR_VERIFY_SIGNATURE;
/**
* $krb5asrep$23$user_principal_name:checksum$edata2
*/
if (input_len < 16) return (PARSER_SALT_LENGTH);
char *upn_info_start = (char *) input_buf + strlen(SIGNATURE_KRB5ASREP);
char *upn_info_stop = strchr ((const char *) upn_info_start, ':');
if (upn_info_stop == NULL) return (PARSER_SEPARATOR_UNMATCHED);
upn_info_stop++; // we want the : char included
const int upn_info_len = upn_info_stop - upn_info_start;
token.token_cnt = 4;
token.len[1] = upn_info_len;
token.attr[1] = TOKEN_ATTR_FIXED_LENGTH;
token.sep[2] = '$';
token.len_min[2] = 32;
token.len_max[2] = 32;
token.attr[2] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
token.sep[3] = '$';
token.len_min[3] = 64;
token.len_max[3] = 40960;
token.attr[3] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
const int rc_tokenizer = input_tokenizer (input_buf, input_len, &token);
if (rc_tokenizer != PARSER_OK) return (rc_tokenizer);
u8 *checksum_pos;
u8 *data_pos;
int data_len;
checksum_pos = token.buf[2];
data_pos = token.buf[3];
data_len = token.len[3];
memcpy (krb5asrep->account_info, token.buf[1], token.len[1]);
krb5asrep->checksum[0] = hex_to_u32 (checksum_pos + 0);
krb5asrep->checksum[1] = hex_to_u32 (checksum_pos + 8);
krb5asrep->checksum[2] = hex_to_u32 (checksum_pos + 16);
krb5asrep->checksum[3] = hex_to_u32 (checksum_pos + 24);
u8 *edata_ptr = (u8 *) krb5asrep->edata2;
for (int i = 0; i < data_len; i += 2)
{
const u8 p0 = data_pos[i + 0];
const u8 p1 = data_pos[i + 1];
*edata_ptr++ = hex_convert (p1) << 0
| hex_convert (p0) << 4;
}
krb5asrep->edata2_len = data_len / 2;
/* this is needed for hmac_md5 */
*edata_ptr++ = 0x80;
salt->salt_buf[0] = krb5asrep->checksum[0];
salt->salt_buf[1] = krb5asrep->checksum[1];
salt->salt_buf[2] = krb5asrep->checksum[2];
salt->salt_buf[3] = krb5asrep->checksum[3];
salt->salt_len = 16;
digest[0] = krb5asrep->checksum[0];
digest[1] = krb5asrep->checksum[1];
digest[2] = krb5asrep->checksum[2];
digest[3] = krb5asrep->checksum[3];
return (PARSER_OK);
}
int axcrypt_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED hashconfig_t *hashconfig)
{
u32 *digest = (u32 *) hash_buf->digest;
@ -18579,6 +18683,7 @@ const char *strhashtype (const u32 hash_mode)
case 17900: return HT_17900;
case 18000: return HT_18000;
case 18100: return HT_18100;
case 18200: return HT_18200;
case 99999: return HT_99999;
}
@ -22384,6 +22489,30 @@ int ascii_digest (hashcat_ctx_t *hashcat_ctx, char *out_buf, const size_t out_le
snprintf (out_buf, out_len - 1, "%06d:%" PRIu64, digest_buf[0], tmp_salt_buf);
}
else if (hash_mode == 18200)
{
krb5asrep_t *krb5asreps = (krb5asrep_t *) esalts_buf;
krb5asrep_t *krb5asrep = &krb5asreps[digest_cur];
char data[5120 * 4 * 2] = { 0 };
for (u32 i = 0, j = 0; i < krb5asrep->edata2_len; i += 1, j += 2)
{
u8 *ptr_edata2 = (u8 *) krb5asrep->edata2;
sprintf (data + j, "%02x", ptr_edata2[i]);
}
snprintf (out_buf, out_len - 1, "%s%s%08x%08x%08x%08x$%s",
SIGNATURE_KRB5ASREP,
(char *) krb5asrep->account_info,
byte_swap_32 (krb5asrep->checksum[0]),
byte_swap_32 (krb5asrep->checksum[1]),
byte_swap_32 (krb5asrep->checksum[2]),
byte_swap_32 (krb5asrep->checksum[3]),
data);
}
else if (hash_mode == 99999)
{
char *ptr = (char *) digest_buf;
@ -27692,6 +27821,23 @@ int hashconfig_init (hashcat_ctx_t *hashcat_ctx)
hashconfig->st_pass = ST_PASS_HASHCAT_PLAIN;
break;
case 18200: hashconfig->hash_type = HASH_TYPE_KRB5ASREP;
hashconfig->salt_type = SALT_TYPE_EMBEDDED;
hashconfig->attack_exec = ATTACK_EXEC_INSIDE_KERNEL;
hashconfig->opts_type = OPTS_TYPE_PT_GENERATE_LE;
hashconfig->kern_type = KERN_TYPE_KRB5ASREP;
hashconfig->dgst_size = DGST_SIZE_4_4;
hashconfig->parse_func = krb5asrep_parse_hash;
hashconfig->opti_type = OPTI_TYPE_ZERO_BYTE
| OPTI_TYPE_NOT_ITERATED;
hashconfig->dgst_pos0 = 0;
hashconfig->dgst_pos1 = 1;
hashconfig->dgst_pos2 = 2;
hashconfig->dgst_pos3 = 3;
hashconfig->st_hash = ST_HASH_18200;
hashconfig->st_pass = ST_PASS_HASHCAT_PLAIN;
break;
case 99999: hashconfig->hash_type = HASH_TYPE_PLAINTEXT;
hashconfig->salt_type = SALT_TYPE_NONE;
hashconfig->attack_exec = ATTACK_EXEC_INSIDE_KERNEL;
@ -27917,6 +28063,7 @@ int hashconfig_init (hashcat_ctx_t *hashcat_ctx)
case 16800: hashconfig->esalt_size = sizeof (wpa_pmkid_t); break;
case 16801: hashconfig->esalt_size = sizeof (wpa_pmkid_t); break;
case 16900: hashconfig->esalt_size = sizeof (ansible_vault_t); break;
case 18200: hashconfig->esalt_size = sizeof (krb5asrep_t); break;
}
// hook_salt_size
@ -28087,6 +28234,7 @@ u32 hashconfig_forced_kernel_threads (hashcat_ctx_t *hashcat_ctx)
if (hashconfig->hash_mode == 10500) kernel_threads = 64; // RC4
if (hashconfig->hash_mode == 13100) kernel_threads = 64; // RC4
if (hashconfig->hash_mode == 15700) kernel_threads = 1; // SCRYPT
if (hashconfig->hash_mode == 18200) kernel_threads = 64; // RC4
return kernel_threads;
}

View File

@ -222,6 +222,7 @@ static const char *const USAGE_BIG[] =
" 13100 | Kerberos 5 TGS-REP etype 23 | Network Protocols",
" 16100 | TACACS+ | Network Protocols",
" 16500 | JWT (JSON Web Token) | Network Protocols",
" 18200 | Kerberos 5 AS-REP etype 23 | Network Protocols",
" 121 | SMF (Simple Machines Forum) > v1.1 | Forums, CMS, E-Commerce, Frameworks",
" 400 | phpBB3 (MD5) | Forums, CMS, E-Commerce, Frameworks",
" 2611 | vBulletin < v3.8.5 | Forums, CMS, E-Commerce, Frameworks",

View File

@ -61,7 +61,7 @@ my $hashcat = "./hashcat";
my $MAX_LEN = 55;
my @modes = (0, 10, 11, 12, 20, 21, 22, 23, 30, 40, 50, 60, 100, 101, 110, 111, 112, 120, 121, 122, 125, 130, 131, 132, 133, 140, 141, 150, 160, 200, 300, 400, 500, 600, 900, 1000, 1100, 1300, 1400, 1410, 1411, 1420, 1430, 1440, 1441, 1450, 1460, 1500, 1600, 1700, 1710, 1711, 1720, 1730, 1740, 1722, 1731, 1750, 1760, 1800, 2100, 2400, 2410, 2500, 2600, 2611, 2612, 2711, 2811, 3000, 3100, 3200, 3710, 3711, 3300, 3500, 3610, 3720, 3800, 3910, 4010, 4110, 4210, 4300, 4400, 4500, 4520, 4521, 4522, 4600, 4700, 4800, 4900, 5100, 5300, 5400, 5500, 5600, 5700, 5800, 6000, 6100, 6300, 6400, 6500, 6600, 6700, 6800, 6900, 7000, 7100, 7200, 7300, 7400, 7500, 7700, 7701, 7800, 7801, 7900, 8000, 8100, 8200, 8300, 8400, 8500, 8600, 8700, 8900, 9100, 9200, 9300, 9400, 9500, 9600, 9700, 9800, 9900, 10000, 10100, 10200, 10300, 10400, 10500, 10600, 10700, 10800, 10900, 11000, 11100, 11200, 11300, 11400, 11500, 11600, 11700, 11800, 11900, 12000, 12001, 12100, 12200, 12300, 12400, 12600, 12700, 12800, 12900, 13000, 13100, 13200, 13300, 13400, 13500, 13600, 13800, 13900, 14000, 14100, 14400, 14700, 14800, 14900, 15000, 15100, 15200, 15300, 15400, 15500, 15600, 15700, 15900, 16000, 16100, 16200, 16300, 16400, 16500, 16600, 16700, 16800, 16900, 17300, 17400, 17500, 17600, 17700, 17800, 17900, 18000, 18100, 99999);
my @modes = (0, 10, 11, 12, 20, 21, 22, 23, 30, 40, 50, 60, 100, 101, 110, 111, 112, 120, 121, 122, 125, 130, 131, 132, 133, 140, 141, 150, 160, 200, 300, 400, 500, 600, 900, 1000, 1100, 1300, 1400, 1410, 1411, 1420, 1430, 1440, 1441, 1450, 1460, 1500, 1600, 1700, 1710, 1711, 1720, 1730, 1740, 1722, 1731, 1750, 1760, 1800, 2100, 2400, 2410, 2500, 2600, 2611, 2612, 2711, 2811, 3000, 3100, 3200, 3710, 3711, 3300, 3500, 3610, 3720, 3800, 3910, 4010, 4110, 4210, 4300, 4400, 4500, 4520, 4521, 4522, 4600, 4700, 4800, 4900, 5100, 5300, 5400, 5500, 5600, 5700, 5800, 6000, 6100, 6300, 6400, 6500, 6600, 6700, 6800, 6900, 7000, 7100, 7200, 7300, 7400, 7500, 7700, 7701, 7800, 7801, 7900, 8000, 8100, 8200, 8300, 8400, 8500, 8600, 8700, 8900, 9100, 9200, 9300, 9400, 9500, 9600, 9700, 9800, 9900, 10000, 10100, 10200, 10300, 10400, 10500, 10600, 10700, 10800, 10900, 11000, 11100, 11200, 11300, 11400, 11500, 11600, 11700, 11800, 11900, 12000, 12001, 12100, 12200, 12300, 12400, 12600, 12700, 12800, 12900, 13000, 13100, 13200, 13300, 13400, 13500, 13600, 13800, 13900, 14000, 14100, 14400, 14700, 14800, 14900, 15000, 15100, 15200, 15300, 15400, 15500, 15600, 15700, 15900, 16000, 16100, 16200, 16300, 16400, 16500, 16600, 16700, 16800, 16900, 17300, 17400, 17500, 17600, 17700, 17800, 17900, 18000, 18100, 18200, 99999);
my %is_utf16le = map { $_ => 1 } qw (30 40 130 131 132 133 140 141 1000 1100 1430 1440 1441 1730 1740 1731 5500 5600 8000 9400 9500 9600 9700 9800 11600 13500 13800);
my %less_fifteen = map { $_ => 1 } qw (500 1600 1800 3200 6300 7400 10500 10700);
@ -3000,6 +3000,36 @@ sub verify
next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
}
elsif ($mode == 18200)
{
($hash_in, $word) = split ":", $line;
next unless defined $hash_in;
next unless defined $word;
my @data = split ('\$', $hash_in);
next unless scalar @data == 8;
shift @data;
my $signature = shift @data;
my $algorithm = shift @data;
my $user_principal_name = shift @data;
my $checksum = shift @data;
my $edata2 = shift @data;
next unless ($signature eq "krb5asrep");
next unless (length ($checksum) == 32);
next unless (length ($edata2) >= 64);
$salt = $user_principal_name;
$param = $checksum;
$param2 = $edata2;
next unless (exists ($db->{$hash_in}) and (! defined ($db->{$hash_in})));
}
else
{
print "ERROR: hash mode is not supported\n";
@ -3471,6 +3501,14 @@ sub verify
return unless (substr ($line, 0, $len) eq $hash_out);
}
elsif ($mode == 18200)
{
$hash_out = gen_hash ($mode, $word, $salt, $iter, $param, $param2);
$len = length $hash_out;
return unless (substr ($line, 0, $len) eq $hash_out);
}
else
{
$hash_out = gen_hash ($mode, $word, $salt, $iter);
@ -4056,6 +4094,12 @@ sub passthrough
{
$tmp_hash = gen_hash ($mode, $word_buf, substr ($salt_buf, 0, 64));
}
elsif ($mode == 18200)
{
$salt_buf = get_random_kerberos5_as_rep_salt ();
$tmp_hash = gen_hash ($mode, $word_buf, $salt_buf);
}
else
{
print "ERROR: Unsupported hash type\n";
@ -5188,6 +5232,20 @@ sub single
}
}
}
elsif ($mode == 18200)
{
for (my $i = 1; $i < 27; $i++)
{
if ($len != 0)
{
rnd ($mode, $len, 16);
}
else
{
rnd ($mode, $i, 16);
}
}
}
}
}
@ -10019,6 +10077,71 @@ END_CODE
## token must be leading zero padded, and salt leading zero stripped
$tmp_hash = sprintf ("%06d:%d", $token, int ($salt_buf));
}
elsif ($mode == 18200)
{
my @salt_arr = split (':', $salt_buf);
my $user_principal_name = $salt_arr[0];
my $k = md4 (encode ("UTF-16LE", $word_buf));
my $k1 = hmac_md5 ("\x08\x00\x00\x00", $k);
my $cleartext_ticket = '7981df3081dca01b3019a003020117a112041071e026814da2' .
'3f129f0e67a01b73f79aa11c301a3018a003020100a111180f32303138313033303039353' .
'831365aa206020460fdc6caa311180f32303337303931343032343830355aa40703050050' .
'c10000a511180f32303138313033303039353831365aa611180f323031383130333030393' .
'53831365aa711180f32303138313033303139353831365aa811180f323031383130333131' .
'30303433385aa90d1b0b545952454c4c2e434f5250aa20301ea003020101a11730151b066' .
'b72627467741b0b545952454c4c2e434f5250';
my $checksum = "";
if (defined $additional_param)
{
$checksum = pack ("H*", $additional_param);
}
else
{
my $nonce = $salt_arr[1];
$cleartext_ticket = $nonce . $cleartext_ticket;
$checksum = hmac_md5 (pack ("H*", $cleartext_ticket), $k1);
}
my $k3 = hmac_md5 ($checksum, $k1);
my $edata2 = "";
if (defined $additional_param2)
{
$edata2 = $additional_param2;
my $cipher_decrypt = Crypt::RC4->new ($k3);
my $ticket_decrypt = unpack ("H*", $cipher_decrypt->RC4 (pack ("H*", $edata2)));
my $check_correct = ((substr ($ticket_decrypt, 16, 4) eq "7981" && substr ($ticket_decrypt, 22, 2) eq "30")) ||
((substr ($ticket_decrypt, 16, 2) eq "79") && (substr ($ticket_decrypt, 20, 2) eq "30")) ||
((substr ($ticket_decrypt, 16, 4) eq "7982") && (substr ($ticket_decrypt, 24, 2) eq "30"));
if ($check_correct == 1)
{
$cleartext_ticket = $ticket_decrypt;
}
else # validation failed
{
# fake/wrong ticket (otherwise if we just decrypt/encrypt we end up with false positives all the time)
$cleartext_ticket = "0" x (length ($cleartext_ticket) + 16);
}
}
my $cipher = Crypt::RC4->new ($k3);
$edata2 = $cipher->RC4 (pack ("H*", $cleartext_ticket));
$tmp_hash = sprintf ('$krb5asrep$23$%s:%s$%s', $user_principal_name, unpack ("H*", $checksum), unpack ("H*", $edata2));
}
elsif ($mode == 99999)
{
$tmp_hash = sprintf ("%s", $word_buf);
@ -10169,6 +10292,10 @@ sub rnd
{
$salt_buf = get_random_jwt_salt ();
}
elsif ($mode == 18200)
{
$salt_buf = get_random_kerberos5_as_rep_salt ();
}
else
{
my @salt_arr;
@ -11454,6 +11581,16 @@ sub get_random_kerberos5_tgs_salt
return $salt_buf;
}
sub get_random_kerberos5_as_rep_salt
{
my $nonce = randbytes (8);
my $user_principal_name = "user\@domain.com";
my $salt_buf = $user_principal_name . ":" . unpack ("H*", $nonce);
return $salt_buf;
}
sub get_random_axcrypt_salt
{
my $mysalt = randbytes (16);

View File

@ -9,7 +9,7 @@ TDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# missing hash types: 5200,6251,6261,6271,6281
HASH_TYPES="0 10 11 12 20 21 22 23 30 40 50 60 100 101 110 111 112 120 121 122 125 130 131 132 133 140 141 150 160 200 300 400 500 600 900 1000 1100 1300 1400 1410 1411 1420 1430 1440 1441 1450 1460 1500 1600 1700 1710 1711 1720 1722 1730 1731 1740 1750 1760 1800 2100 2400 2410 2500 2600 2611 2612 2711 2811 3000 3100 3200 3710 3711 3800 3910 4010 4110 4300 4400 4500 4520 4521 4522 4700 4800 4900 5100 5300 5400 5500 5600 5700 5800 6000 6100 6211 6212 6213 6221 6222 6223 6231 6232 6233 6241 6242 6243 6300 6400 6500 6600 6700 6800 6900 7000 7100 7200 7300 7400 7500 7700 7701 7800 7801 7900 8000 8100 8200 8300 8400 8500 8600 8700 8900 9100 9200 9300 9400 9500 9600 9700 9800 9900 10000 10100 10200 10300 10400 10500 10600 10700 10800 10900 11000 11100 11200 11300 11400 11500 11600 11700 11800 11900 12000 12001 12100 12200 12300 12400 12600 12700 12800 12900 13000 13100 13200 13300 13400 13500 13600 13800 13900 14000 14100 14400 14600 14700 14800 14900 15000 15100 15200 15300 15400 15500 15600 15700 15900 16000 16100 16200 16300 16400 16500 16600 16700 16800 16900 17300 17400 17500 17600 17700 17800 17900 18000 18100 99999"
HASH_TYPES="0 10 11 12 20 21 22 23 30 40 50 60 100 101 110 111 112 120 121 122 125 130 131 132 133 140 141 150 160 200 300 400 500 600 900 1000 1100 1300 1400 1410 1411 1420 1430 1440 1441 1450 1460 1500 1600 1700 1710 1711 1720 1722 1730 1731 1740 1750 1760 1800 2100 2400 2410 2500 2600 2611 2612 2711 2811 3000 3100 3200 3710 3711 3800 3910 4010 4110 4300 4400 4500 4520 4521 4522 4700 4800 4900 5100 5300 5400 5500 5600 5700 5800 6000 6100 6211 6212 6213 6221 6222 6223 6231 6232 6233 6241 6242 6243 6300 6400 6500 6600 6700 6800 6900 7000 7100 7200 7300 7400 7500 7700 7701 7800 7801 7900 8000 8100 8200 8300 8400 8500 8600 8700 8900 9100 9200 9300 9400 9500 9600 9700 9800 9900 10000 10100 10200 10300 10400 10500 10600 10700 10800 10900 11000 11100 11200 11300 11400 11500 11600 11700 11800 11900 12000 12001 12100 12200 12300 12400 12600 12700 12800 12900 13000 13100 13200 13300 13400 13500 13600 13800 13900 14000 14100 14400 14600 14700 14800 14900 15000 15100 15200 15300 15400 15500 15600 15700 15900 16000 16100 16200 16300 16400 16500 16600 16700 16800 16900 17300 17400 17500 17600 17700 17800 17900 18000 18100 18200 99999"
#ATTACK_MODES="0 1 3 6 7"
ATTACK_MODES="0 1 3 7"