⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ntlm_check.c

📁 samba最新软件
💻 C
📖 第 1 页 / 共 2 页
字号:
		DEBUG(3,("ntlm_password_check: NO NT password stored for user %s.\n", 			 username));	}	*lm_sess_key = data_blob(NULL, 0);	*user_sess_key = data_blob(NULL, 0);	/* Check for cleartext netlogon. Used by Exchange 5.5. */	if ((logon_parameters & MSV1_0_CLEARTEXT_PASSWORD_ALLOWED)	    && challenge->length == sizeof(zeros) 	    && (memcmp(challenge->data, zeros, challenge->length) == 0 )) {		struct samr_Password client_nt;		struct samr_Password client_lm;		char *unix_pw = NULL;		bool lm_ok;		DEBUG(4,("ntlm_password_check: checking plaintext passwords for user %s\n",			 username));		mdfour(client_nt.hash, nt_response->data, nt_response->length);				if (lm_response->length && 		    (convert_string_talloc(mem_ctx, lp_iconv_convenience(lp_ctx), CH_DOS, CH_UNIX, 					  lm_response->data, lm_response->length, 					   (void **)&unix_pw) != -1)) {			if (E_deshash(unix_pw, client_lm.hash)) {				lm_ok = true;			} else {				lm_ok = false;			}		} else {			lm_ok = false;		}		return hash_password_check(mem_ctx, 					   lp_ctx,					   lm_ok ? &client_lm : NULL, 					   nt_response->length ? &client_nt : NULL, 					   username,  					   stored_lanman, stored_nt);	}	if (nt_response->length != 0 && nt_response->length < 24) {		DEBUG(2,("ntlm_password_check: invalid NT password length (%lu) for user %s\n", 			 (unsigned long)nt_response->length, username));			}		if (nt_response->length > 24 && stored_nt) {		/* We have the NT MD4 hash challenge available - see if we can		   use it 		*/		DEBUG(4,("ntlm_password_check: Checking NTLMv2 password with domain [%s]\n", client_domain));		if (smb_pwd_check_ntlmv2(mem_ctx,					 nt_response, 					 stored_nt->hash, challenge, 					 client_username, 					 client_domain,					 false,					 user_sess_key)) {			*lm_sess_key = *user_sess_key;			if (user_sess_key->length) {				lm_sess_key->length = 8;			}			return NT_STATUS_OK;		}				DEBUG(4,("ntlm_password_check: Checking NTLMv2 password with uppercased version of domain [%s]\n", client_domain));		if (smb_pwd_check_ntlmv2(mem_ctx,					 nt_response, 					 stored_nt->hash, challenge, 					 client_username, 					 client_domain,					 true,					 user_sess_key)) {			*lm_sess_key = *user_sess_key;			if (user_sess_key->length) {				lm_sess_key->length = 8;			}			return NT_STATUS_OK;		}				DEBUG(4,("ntlm_password_check: Checking NTLMv2 password without a domain\n"));		if (smb_pwd_check_ntlmv2(mem_ctx,					 nt_response, 					 stored_nt->hash, challenge, 					 client_username, 					 "",					 false,					 user_sess_key)) {			*lm_sess_key = *user_sess_key;			if (user_sess_key->length) {				lm_sess_key->length = 8;			}			return NT_STATUS_OK;		} else {			DEBUG(3,("ntlm_password_check: NTLMv2 password check failed\n"));		}	} else if (nt_response->length == 24 && stored_nt) {		if (lp_ntlm_auth(lp_ctx)) {					/* We have the NT MD4 hash challenge available - see if we can			   use it (ie. does it exist in the smbpasswd file).			*/			DEBUG(4,("ntlm_password_check: Checking NT MD4 password\n"));			if (smb_pwd_check_ntlmv1(mem_ctx, 						 nt_response, 						 stored_nt->hash, challenge,						 user_sess_key)) {				/* The LM session key for this response is not very secure, 				   so use it only if we otherwise allow LM authentication */								if (lp_lanman_auth(lp_ctx) && stored_lanman) {					*lm_sess_key = data_blob_talloc(mem_ctx, stored_lanman->hash, 8);				}				return NT_STATUS_OK;			} else {				DEBUG(3,("ntlm_password_check: NT MD4 password check failed for user %s\n",					 username));				return NT_STATUS_WRONG_PASSWORD;			}		} else {			DEBUG(2,("ntlm_password_check: NTLMv1 passwords NOT PERMITTED for user %s\n",				 username));						/* no return, becouse we might pick up LMv2 in the LM field */		}	}		if (lm_response->length == 0) {		DEBUG(3,("ntlm_password_check: NEITHER LanMan nor NT password supplied for user %s\n",			 username));		return NT_STATUS_WRONG_PASSWORD;	}		if (lm_response->length < 24) {		DEBUG(2,("ntlm_password_check: invalid LanMan password length (%lu) for user %s\n", 			 (unsigned long)nt_response->length, username));				return NT_STATUS_WRONG_PASSWORD;	}			if (!lp_lanman_auth(lp_ctx)) {		DEBUG(3,("ntlm_password_check: Lanman passwords NOT PERMITTED for user %s\n",			 username));	} else if (!stored_lanman) {		DEBUG(3,("ntlm_password_check: NO LanMan password set for user %s (and no NT password supplied)\n",			 username));	} else if (strchr_m(username, '@')) {		DEBUG(3,("ntlm_password_check: NO LanMan password allowed for username@realm logins (user: %s)\n",			 username));	} else {		DEBUG(4,("ntlm_password_check: Checking LM password\n"));		if (smb_pwd_check_ntlmv1(mem_ctx,					 lm_response, 					 stored_lanman->hash, challenge,					 NULL)) {			/* The session key for this response is still very odd.  			   It not very secure, so use it only if we otherwise 			   allow LM authentication */			if (lp_lanman_auth(lp_ctx) && stored_lanman) {				uint8_t first_8_lm_hash[16];				memcpy(first_8_lm_hash, stored_lanman->hash, 8);				memset(first_8_lm_hash + 8, '\0', 8);				*user_sess_key = data_blob_talloc(mem_ctx, first_8_lm_hash, 16);				*lm_sess_key = data_blob_talloc(mem_ctx, stored_lanman->hash, 8);			}			return NT_STATUS_OK;		}	}		if (!stored_nt) {		DEBUG(4,("ntlm_password_check: LM password check failed for user, no NT password %s\n",username));		return NT_STATUS_WRONG_PASSWORD;	}		/* This is for 'LMv2' authentication.  almost NTLMv2 but limited to 24 bytes.	   - related to Win9X, legacy NAS pass-though authentication	*/	DEBUG(4,("ntlm_password_check: Checking LMv2 password with domain %s\n", client_domain));	if (smb_pwd_check_ntlmv2(mem_ctx,				 lm_response, 				 stored_nt->hash, challenge, 				 client_username,				 client_domain,				 false,				 &tmp_sess_key)) {		if (nt_response->length > 24) {			/* If NTLMv2 authentication has preceeded us			 * (even if it failed), then use the session			 * key from that.  See the RPC-SAMLOGON			 * torture test */			smb_sess_key_ntlmv2(mem_ctx,					    nt_response, 					    stored_nt->hash, challenge, 					    client_username,					    client_domain,					    false,					    user_sess_key);		} else {			/* Otherwise, use the LMv2 session key */			*user_sess_key = tmp_sess_key;		}		*lm_sess_key = *user_sess_key;		if (user_sess_key->length) {			lm_sess_key->length = 8;		}		return NT_STATUS_OK;	}		DEBUG(4,("ntlm_password_check: Checking LMv2 password with upper-cased version of domain %s\n", client_domain));	if (smb_pwd_check_ntlmv2(mem_ctx,				 lm_response, 				 stored_nt->hash, challenge, 				 client_username,				 client_domain,				 true,				 &tmp_sess_key)) {		if (nt_response->length > 24) {			/* If NTLMv2 authentication has preceeded us			 * (even if it failed), then use the session			 * key from that.  See the RPC-SAMLOGON			 * torture test */			smb_sess_key_ntlmv2(mem_ctx,					    nt_response, 					    stored_nt->hash, challenge, 					    client_username,					    client_domain,					    true,					    user_sess_key);		} else {			/* Otherwise, use the LMv2 session key */			*user_sess_key = tmp_sess_key;		}		*lm_sess_key = *user_sess_key;		if (user_sess_key->length) {			lm_sess_key->length = 8;		}		return NT_STATUS_OK;	}		DEBUG(4,("ntlm_password_check: Checking LMv2 password without a domain\n"));	if (smb_pwd_check_ntlmv2(mem_ctx,				 lm_response, 				 stored_nt->hash, challenge, 				 client_username,				 "",				 false,				 &tmp_sess_key)) {		if (nt_response->length > 24) {			/* If NTLMv2 authentication has preceeded us			 * (even if it failed), then use the session			 * key from that.  See the RPC-SAMLOGON			 * torture test */			smb_sess_key_ntlmv2(mem_ctx,					    nt_response, 					    stored_nt->hash, challenge, 					    client_username,					    "",					    false,					    user_sess_key);		} else {			/* Otherwise, use the LMv2 session key */			*user_sess_key = tmp_sess_key;		}		*lm_sess_key = *user_sess_key;		if (user_sess_key->length) {			lm_sess_key->length = 8;		}		return NT_STATUS_OK;	}	/* Apparently NT accepts NT responses in the LM field	   - I think this is related to Win9X pass-though authentication	*/	DEBUG(4,("ntlm_password_check: Checking NT MD4 password in LM field\n"));	if (lp_ntlm_auth(lp_ctx)) {		if (smb_pwd_check_ntlmv1(mem_ctx, 					 lm_response, 					 stored_nt->hash, challenge,					 NULL)) {			/* The session key for this response is still very odd.  			   It not very secure, so use it only if we otherwise 			   allow LM authentication */			if (lp_lanman_auth(lp_ctx) && stored_lanman) {				uint8_t first_8_lm_hash[16];				memcpy(first_8_lm_hash, stored_lanman->hash, 8);				memset(first_8_lm_hash + 8, '\0', 8);				*user_sess_key = data_blob_talloc(mem_ctx, first_8_lm_hash, 16);				*lm_sess_key = data_blob_talloc(mem_ctx, stored_lanman->hash, 8);			}			return NT_STATUS_OK;		}		DEBUG(3,("ntlm_password_check: LM password, NT MD4 password in LM field and LMv2 failed for user %s\n",username));	} else {		DEBUG(3,("ntlm_password_check: LM password and LMv2 failed for user %s, and NT MD4 password in LM field not permitted\n",username));	}	/* Try and match error codes */	if (strchr_m(username, '@')) {		return NT_STATUS_NOT_FOUND;	}	return NT_STATUS_WRONG_PASSWORD;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -