对于NTLM Response,也就是我们常说的NTLMv1的方式,可以表述如下:
服务器发送一个8字节的随机数作为challenge。
客户端返回48字节的response。下面描述NTLMv1的步骤:
步骤一:获取挑战值
K1 | K2 | K3 = LM-Hash | 5-bytes-0
R1 = DES(K1,C) | DES(K2,C) | DES(K3,C)
K1 | K2 | K3 = NT-Hash | 5-bytes-0
R2 = DES(K1,C) | DES(K2,C) | DES(K3,C)
步骤四:获取NTLMv1 response
我们在DES的算法中,key的输入是64比特,将这8个字节分别去掉CRC校验位(第8位),生成56比特的key。现在我们直接输入为56字节比 特,可以通过LM-Hash中介绍的使用str_to_key函数,将这56比特的key变为64比特的key作为DES算法的输入,或者我们直接在 DES算法中增加一个函数用于处理直接56比特key的输入。如下:
下面,我们给出NTLM v1 reponse的程序:static int ip_56key_seq[] ={
50,43,36,29,22,15,8,
1, 51,44,37,30,23,16,
9, 2, 52,45,38,31,24,
17,10,3, 53,46,39,32,
56,49,42,35,28,21,14,
7, 55,48,41,34,27,20,
13, 6,54,47,40,33,26,
19,12,5, 25,18,11,4};
void algorithm_des_56key(IN unsigned char * src, IN unsigned char * secrect,
OUT unsigned char * dst){
unsigned char s[64],key[64],L[32],R[32],K[48],E[48];
int i = 0;
storebit(src,8,s);
storebit(secrect,8,key);
//step1: initial permutation src and key
initail_permutation(s,ip_data_seq,64,s);
initail_permutation(key,ip_56key_seq,56,key);
//step2:16次计算
//获取原始的L0和R0
memcpy(L,s,32);
memcpy(R,s+32,32);
//进行16次计算
for(i = 0; i < 16 ; i++){
//获取K
getkey(key,key_offset[i]);
initail_permutation(key,ip_key,48,K);
//F计算
initail_permutation(R,ip_e,48,E);
xorbit(E,K,48,E);
s_box_function(E,s1,E);
s_box_function(E + 6,s2,E + 4);
s_box_function(E + 12,s3,E + 8);
s_box_function(E + 18,s4,E + 12);
s_box_function(E + 24,s5,E + 16);
s_box_function(E + 30,s6,E + 20);
s_box_function(E + 36,s7,E + 24);
s_box_function(E + 42,s8,E + 28);
initail_permutation(E,ip_p,32,E);
xorbit(E,L,32,E);
memcpy(L,R,32);
memcpy(R,E,32);
}
memcpy(s,R,32);
memcpy(s+32,L,32);
initail_permutation(s,inverse_ip_p,64,s);
parsebit(s,dst,8);
}
void ntlmv1_response(IN char * passwd, IN int passwd_len,IN unsigned char * chanllenge,
OUT unsigned char * dst, OUT int * dst_len){
unsigned char hash[21];
//K1 | K2 | K3 = LM-Hash | 5-bytes-0
//R1 = DES(K1,C) | DES(K2,C) | DES(K3,C)
lm_hash(passwd, hash,NULL);
memset(hash + 16,0,5);
algorithm_des_56key(chanllenge, hash,dst);
algorithm_des_56key(chanllenge, hash+7,dst+8);
algorithm_des_56key(chanllenge, hash+14,dst+16);
//K1 | K2 | K3 = NT-Hash | 5-bytes-0
//R2 = DES(K1,C) | DES(K2,C) | DES(K3,C)
nt_hash(passwd, 0,hash,NULL);
memset(hash + 16,0,5);
algorithm_des_56key(chanllenge,hash,dst+24);
algorithm_des_56key(chanllenge,hash+7,dst+32);
algorithm_des_56key(chanllenge,hash+14,dst+40);
if(dst_len != NULL)
* dst_len = 48;
}