2009-08-14 02:36:21 +04:00
/*
2003-03-10 05:14:35 +03:00
* Unix SMB / CIFS implementation .
* Version 3.0
* NTLMSSP Signing routines
2005-09-30 21:13:37 +04:00
* Copyright ( C ) Andrew Bartlett 2003 - 2005
2009-08-14 02:36:21 +04:00
*
2003-03-10 05:14:35 +03:00
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2007-07-09 23:25:36 +04:00
* the Free Software Foundation ; either version 3 of the License , or
2003-03-10 05:14:35 +03:00
* ( at your option ) any later version .
2009-08-14 02:36:21 +04:00
*
2003-03-10 05:14:35 +03:00
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
2009-08-14 02:36:21 +04:00
*
2003-03-10 05:14:35 +03:00
* You should have received a copy of the GNU General Public License
2007-07-10 07:42:26 +04:00
* along with this program ; if not , see < http : //www.gnu.org/licenses/>.
2003-03-10 05:14:35 +03:00
*/
# include "includes.h"
2011-07-25 10:04:38 +04:00
# include "../auth/ntlmssp/ntlmssp.h"
2009-03-17 12:08:31 +03:00
# include "../libcli/auth/libcli_auth.h"
2018-10-09 12:39:39 +03:00
# include "zlib.h"
2011-07-25 10:04:38 +04:00
# include "../auth/ntlmssp/ntlmssp_private.h"
2003-03-10 05:14:35 +03:00
2019-06-26 07:41:05 +03:00
# include "lib/crypto/gnutls_helpers.h"
2018-10-30 18:43:03 +03:00
# include <gnutls/gnutls.h>
# include <gnutls/crypto.h>
2017-12-19 12:49:10 +03:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_AUTH
2003-03-10 05:14:35 +03:00
# define CLI_SIGN "session key to client-to-server signing key magic constant"
# define CLI_SEAL "session key to client-to-server sealing key magic constant"
# define SRV_SIGN "session key to server-to-client signing key magic constant"
# define SRV_SEAL "session key to server-to-client sealing key magic constant"
2005-09-30 21:13:37 +04:00
/**
2010-01-09 16:06:27 +03:00
* Some notes on the NTLM2 code :
2005-09-30 21:13:37 +04:00
*
* NTLM2 is a AEAD system . This means that the data encrypted is not
* all the data that is signed . In DCE - RPC case , the headers of the
* DCE - RPC packets are also signed . This prevents some of the
* fun - and - games one might have by changing them .
*
*/
2003-03-10 05:14:35 +03:00
2009-08-14 02:36:21 +04:00
static void dump_arc4_state ( const char * description ,
2018-12-06 20:11:14 +03:00
gnutls_cipher_hd_t * state )
2008-09-24 21:20:33 +04:00
{
2018-12-06 20:11:14 +03:00
DBG_DEBUG ( " %s \n " , description ) ;
2008-09-24 21:20:33 +04:00
}
2018-10-30 18:43:03 +03:00
static NTSTATUS calc_ntlmv2_key ( uint8_t subkey [ 16 ] ,
DATA_BLOB session_key ,
const char * constant )
2003-03-10 05:14:35 +03:00
{
2018-10-30 18:43:03 +03:00
gnutls_hash_hd_t hash_hnd = NULL ;
int rc ;
rc = gnutls_hash_init ( & hash_hnd , GNUTLS_DIG_MD5 ) ;
if ( rc < 0 ) {
2019-06-11 16:21:03 +03:00
return gnutls_error_to_ntstatus ( rc , NT_STATUS_NTLM_BLOCKED ) ;
2018-10-30 18:43:03 +03:00
}
rc = gnutls_hash ( hash_hnd , session_key . data , session_key . length ) ;
if ( rc < 0 ) {
gnutls_hash_deinit ( hash_hnd , NULL ) ;
2019-06-11 16:21:03 +03:00
return gnutls_error_to_ntstatus ( rc , NT_STATUS_NTLM_BLOCKED ) ;
2018-10-30 18:43:03 +03:00
}
rc = gnutls_hash ( hash_hnd , constant , strlen ( constant ) + 1 ) ;
if ( rc < 0 ) {
gnutls_hash_deinit ( hash_hnd , NULL ) ;
2019-06-11 16:21:03 +03:00
return gnutls_error_to_ntstatus ( rc , NT_STATUS_NTLM_BLOCKED ) ;
2018-10-30 18:43:03 +03:00
}
gnutls_hash_deinit ( hash_hnd , subkey ) ;
return NT_STATUS_OK ;
2003-03-10 05:14:35 +03:00
}
2003-04-21 17:00:39 +04:00
enum ntlmssp_direction {
NTLMSSP_SEND ,
NTLMSSP_RECEIVE
} ;
2009-12-22 10:50:55 +03:00
static NTSTATUS ntlmssp_make_packet_signature ( struct ntlmssp_state * ntlmssp_state ,
2010-05-25 14:55:40 +04:00
TALLOC_CTX * sig_mem_ctx ,
2009-12-29 19:25:47 +03:00
const uint8_t * data , size_t length ,
const uint8_t * whole_pdu , size_t pdu_length ,
enum ntlmssp_direction direction ,
DATA_BLOB * sig , bool encrypt_sig )
2003-03-10 05:14:35 +03:00
{
2018-12-06 20:11:14 +03:00
NTSTATUS status = NT_STATUS_UNSUCCESSFUL ;
int rc ;
2018-10-30 18:43:03 +03:00
2003-03-10 05:14:35 +03:00
if ( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_NTLM2 ) {
2018-10-30 18:43:03 +03:00
gnutls_hmac_hd_t hmac_hnd = NULL ;
2009-12-29 19:25:47 +03:00
uint8_t digest [ 16 ] ;
uint8_t seq_num [ 4 ] ;
2003-03-10 05:14:35 +03:00
2010-05-25 14:55:40 +04:00
* sig = data_blob_talloc ( sig_mem_ctx , NULL , NTLMSSP_SIG_SIZE ) ;
2005-09-30 21:13:37 +04:00
if ( ! sig - > data ) {
2003-03-10 05:14:35 +03:00
return NT_STATUS_NO_MEMORY ;
}
2004-01-05 03:11:35 +03:00
2005-09-30 21:13:37 +04:00
switch ( direction ) {
2009-12-25 00:30:42 +03:00
case NTLMSSP_SEND :
DEBUG ( 100 , ( " ntlmssp_make_packet_signature: SEND seq = %u, len = %u, pdu_len = %u \n " ,
2010-01-09 16:38:35 +03:00
ntlmssp_state - > crypt - > ntlm2 . sending . seq_num ,
2009-12-25 00:30:42 +03:00
( unsigned int ) length ,
( unsigned int ) pdu_length ) ) ;
2005-09-30 21:13:37 +04:00
2010-01-09 16:38:35 +03:00
SIVAL ( seq_num , 0 , ntlmssp_state - > crypt - > ntlm2 . sending . seq_num ) ;
ntlmssp_state - > crypt - > ntlm2 . sending . seq_num + + ;
2018-10-30 18:43:03 +03:00
rc = gnutls_hmac_init ( & hmac_hnd ,
GNUTLS_MAC_MD5 ,
ntlmssp_state - > crypt - > ntlm2 . sending . sign_key ,
16 ) ;
if ( rc < 0 ) {
2019-06-11 16:21:03 +03:00
return gnutls_error_to_ntstatus ( rc , NT_STATUS_NTLM_BLOCKED ) ;
2018-10-30 18:43:03 +03:00
}
2009-12-25 00:30:42 +03:00
break ;
case NTLMSSP_RECEIVE :
2005-09-30 21:13:37 +04:00
2009-12-25 00:30:42 +03:00
DEBUG ( 100 , ( " ntlmssp_make_packet_signature: RECV seq = %u, len = %u, pdu_len = %u \n " ,
2010-01-09 16:38:35 +03:00
ntlmssp_state - > crypt - > ntlm2 . receiving . seq_num ,
2009-12-25 00:30:42 +03:00
( unsigned int ) length ,
( unsigned int ) pdu_length ) ) ;
2005-09-30 21:13:37 +04:00
2010-01-09 16:38:35 +03:00
SIVAL ( seq_num , 0 , ntlmssp_state - > crypt - > ntlm2 . receiving . seq_num ) ;
ntlmssp_state - > crypt - > ntlm2 . receiving . seq_num + + ;
2018-10-30 18:43:03 +03:00
rc = gnutls_hmac_init ( & hmac_hnd ,
GNUTLS_MAC_MD5 ,
ntlmssp_state - > crypt - > ntlm2 . receiving . sign_key ,
16 ) ;
if ( rc < 0 ) {
2019-06-11 16:21:03 +03:00
return gnutls_error_to_ntstatus ( rc , NT_STATUS_NTLM_BLOCKED ) ;
2018-10-30 18:43:03 +03:00
}
2009-12-25 00:30:42 +03:00
break ;
2010-01-09 16:06:27 +03:00
}
2005-09-30 21:13:37 +04:00
dump_data_pw ( " pdu data " , whole_pdu , pdu_length ) ;
2018-10-30 18:43:03 +03:00
rc = gnutls_hmac ( hmac_hnd , seq_num , sizeof ( seq_num ) ) ;
if ( rc < 0 ) {
gnutls_hmac_deinit ( hmac_hnd , NULL ) ;
2019-06-11 16:21:03 +03:00
return gnutls_error_to_ntstatus ( rc , NT_STATUS_NTLM_BLOCKED ) ;
2018-10-30 18:43:03 +03:00
}
rc = gnutls_hmac ( hmac_hnd , whole_pdu , pdu_length ) ;
if ( rc < 0 ) {
gnutls_hmac_deinit ( hmac_hnd , NULL ) ;
2019-06-11 16:21:03 +03:00
return gnutls_error_to_ntstatus ( rc , NT_STATUS_NTLM_BLOCKED ) ;
2018-10-30 18:43:03 +03:00
}
gnutls_hmac_deinit ( hmac_hnd , digest ) ;
2005-09-30 21:13:37 +04:00
if ( encrypt_sig & & ( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_KEY_EXCH ) ) {
2004-01-05 03:11:35 +03:00
switch ( direction ) {
case NTLMSSP_SEND :
2018-12-06 20:11:14 +03:00
rc = gnutls_cipher_encrypt ( ntlmssp_state - > crypt - > ntlm2 . sending . seal_state ,
digest ,
8 ) ;
2004-01-05 03:11:35 +03:00
break ;
case NTLMSSP_RECEIVE :
2018-12-06 20:11:14 +03:00
rc = gnutls_cipher_encrypt ( ntlmssp_state - > crypt - > ntlm2 . receiving . seal_state ,
digest ,
8 ) ;
2004-01-05 03:11:35 +03:00
break ;
}
2018-12-06 20:11:14 +03:00
if ( rc < 0 ) {
DBG_ERR ( " gnutls_cipher_encrypt for NTLMv2 EXCH "
" %s packet signature failed: %s \n " ,
direction = = NTLMSSP_SEND ?
" send " : " receive " ,
gnutls_strerror ( rc ) ) ;
return gnutls_error_to_ntstatus ( rc , NT_STATUS_NTLM_BLOCKED ) ;
}
2003-04-21 17:00:39 +04:00
}
2005-09-30 21:13:37 +04:00
SIVAL ( sig - > data , 0 , NTLMSSP_SIGN_VERSION ) ;
memcpy ( sig - > data + 4 , digest , 8 ) ;
2018-10-30 18:43:03 +03:00
ZERO_ARRAY ( digest ) ;
2005-09-30 21:13:37 +04:00
memcpy ( sig - > data + 12 , seq_num , 4 ) ;
2018-10-30 18:43:03 +03:00
ZERO_ARRAY ( seq_num ) ;
2005-09-30 21:13:37 +04:00
dump_data_pw ( " ntlmssp v2 sig " , sig - > data , sig - > length ) ;
2003-03-10 05:14:35 +03:00
} else {
2009-12-29 19:25:47 +03:00
uint32_t crc ;
2010-01-09 16:06:27 +03:00
2018-10-09 12:39:39 +03:00
crc = crc32 ( 0 , Z_NULL , 0 ) ;
crc = crc32 ( crc , data , length ) ;
2010-01-07 12:43:23 +03:00
2011-03-29 00:26:27 +04:00
status = msrpc_gen ( sig_mem_ctx ,
2010-01-07 12:43:23 +03:00
sig , " dddd " ,
NTLMSSP_SIGN_VERSION , 0 , crc ,
2010-01-09 16:38:35 +03:00
ntlmssp_state - > crypt - > ntlm . seq_num ) ;
2011-03-29 00:26:27 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2003-03-10 05:14:35 +03:00
}
2009-08-14 02:36:21 +04:00
2010-01-09 16:38:35 +03:00
ntlmssp_state - > crypt - > ntlm . seq_num + + ;
2005-09-30 21:13:37 +04:00
2010-01-09 16:06:27 +03:00
dump_arc4_state ( " ntlmssp hash: \n " ,
2010-01-09 16:38:35 +03:00
& ntlmssp_state - > crypt - > ntlm . seal_state ) ;
2018-12-06 20:11:14 +03:00
rc = gnutls_cipher_encrypt ( ntlmssp_state - > crypt - > ntlm . seal_state ,
sig - > data + 4 ,
sig - > length - 4 ) ;
if ( rc < 0 ) {
DBG_ERR ( " gnutls_cipher_encrypt for NTLM packet "
" signature failed: %s \n " ,
gnutls_strerror ( rc ) ) ;
return gnutls_error_to_ntstatus ( rc , NT_STATUS_NTLM_BLOCKED ) ;
}
2003-03-10 05:14:35 +03:00
}
2018-10-30 18:43:03 +03:00
2003-03-10 05:14:35 +03:00
return NT_STATUS_OK ;
}
2009-12-22 10:50:55 +03:00
NTSTATUS ntlmssp_sign_packet ( struct ntlmssp_state * ntlmssp_state ,
2010-05-25 14:55:40 +04:00
TALLOC_CTX * sig_mem_ctx ,
2010-01-09 16:06:27 +03:00
const uint8_t * data , size_t length ,
const uint8_t * whole_pdu , size_t pdu_length ,
DATA_BLOB * sig )
2003-03-10 05:14:35 +03:00
{
2004-01-05 03:11:35 +03:00
NTSTATUS nt_status ;
2005-09-30 21:13:37 +04:00
2006-01-18 23:45:44 +03:00
if ( ! ( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_SIGN ) ) {
2005-09-30 21:13:37 +04:00
DEBUG ( 3 , ( " NTLMSSP Signing not negotiated - cannot sign packet! \n " ) ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
2004-01-05 03:11:35 +03:00
if ( ! ntlmssp_state - > session_key . length ) {
DEBUG ( 3 , ( " NO session key, cannot check sign packet \n " ) ) ;
return NT_STATUS_NO_USER_SESSION_KEY ;
}
2005-09-30 21:13:37 +04:00
nt_status = ntlmssp_make_packet_signature ( ntlmssp_state ,
2010-05-25 14:55:40 +04:00
sig_mem_ctx ,
2010-01-09 16:06:27 +03:00
data , length ,
whole_pdu , pdu_length ,
NTLMSSP_SEND , sig , true ) ;
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
return nt_status ;
2003-03-10 05:14:35 +03:00
}
/**
2009-08-14 02:36:21 +04:00
* Check the signature of an incoming packet
* @ note caller * must * check that the signature is the size it expects
2003-03-10 05:14:35 +03:00
*
*/
2009-12-22 10:50:55 +03:00
NTSTATUS ntlmssp_check_packet ( struct ntlmssp_state * ntlmssp_state ,
2010-01-09 16:06:27 +03:00
const uint8_t * data , size_t length ,
const uint8_t * whole_pdu , size_t pdu_length ,
const DATA_BLOB * sig )
2003-03-10 05:14:35 +03:00
{
DATA_BLOB local_sig ;
NTSTATUS nt_status ;
2010-05-25 14:55:40 +04:00
TALLOC_CTX * tmp_ctx ;
2003-03-10 05:14:35 +03:00
2004-01-05 03:11:35 +03:00
if ( ! ntlmssp_state - > session_key . length ) {
DEBUG ( 3 , ( " NO session key, cannot check packet signature \n " ) ) ;
return NT_STATUS_NO_USER_SESSION_KEY ;
}
2003-03-10 05:14:35 +03:00
if ( sig - > length < 8 ) {
2009-08-14 02:36:21 +04:00
DEBUG ( 0 , ( " NTLMSSP packet check failed due to short signature (%lu bytes)! \n " ,
2003-11-03 17:34:25 +03:00
( unsigned long ) sig - > length ) ) ;
2003-03-10 05:14:35 +03:00
}
2010-05-25 14:55:40 +04:00
tmp_ctx = talloc_new ( ntlmssp_state ) ;
if ( ! tmp_ctx ) {
return NT_STATUS_NO_MEMORY ;
}
2005-09-30 21:13:37 +04:00
nt_status = ntlmssp_make_packet_signature ( ntlmssp_state ,
2010-05-25 14:55:40 +04:00
tmp_ctx ,
2010-01-09 16:06:27 +03:00
data , length ,
whole_pdu , pdu_length ,
NTLMSSP_RECEIVE ,
& local_sig , true ) ;
2009-08-14 02:36:21 +04:00
2003-03-10 05:14:35 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
2010-01-09 16:06:27 +03:00
DEBUG ( 0 , ( " NTLMSSP packet sig creation failed with %s \n " ,
nt_errstr ( nt_status ) ) ) ;
2010-05-25 14:55:40 +04:00
talloc_free ( tmp_ctx ) ;
2003-03-10 05:14:35 +03:00
return nt_status ;
}
2009-08-14 02:36:21 +04:00
2005-09-30 21:13:37 +04:00
if ( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_NTLM2 ) {
if ( local_sig . length ! = sig - > length | |
2022-05-11 03:07:43 +03:00
! mem_equal_const_time ( local_sig . data , sig - > data , sig - > length ) ) {
2005-09-30 21:13:37 +04:00
DEBUG ( 5 , ( " BAD SIG NTLM2: wanted signature of \n " ) ) ;
2007-03-28 17:34:59 +04:00
dump_data ( 5 , local_sig . data , local_sig . length ) ;
2003-04-21 17:00:39 +04:00
2005-09-30 21:13:37 +04:00
DEBUG ( 5 , ( " BAD SIG: got signature of \n " ) ) ;
2007-03-28 17:34:59 +04:00
dump_data ( 5 , sig - > data , sig - > length ) ;
2005-09-30 21:13:37 +04:00
DEBUG ( 0 , ( " NTLMSSP NTLM2 packet check failed due to invalid signature! \n " ) ) ;
2010-05-25 14:55:40 +04:00
talloc_free ( tmp_ctx ) ;
2005-09-30 21:13:37 +04:00
return NT_STATUS_ACCESS_DENIED ;
}
} else {
if ( local_sig . length ! = sig - > length | |
2022-05-11 03:07:43 +03:00
! mem_equal_const_time ( local_sig . data + 8 , sig - > data + 8 , sig - > length - 8 ) ) {
2005-09-30 21:13:37 +04:00
DEBUG ( 5 , ( " BAD SIG NTLM1: wanted signature of \n " ) ) ;
2007-03-28 17:34:59 +04:00
dump_data ( 5 , local_sig . data , local_sig . length ) ;
2005-09-30 21:13:37 +04:00
DEBUG ( 5 , ( " BAD SIG: got signature of \n " ) ) ;
2007-03-28 17:34:59 +04:00
dump_data ( 5 , sig - > data , sig - > length ) ;
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
2005-09-30 21:13:37 +04:00
DEBUG ( 0 , ( " NTLMSSP NTLM1 packet check failed due to invalid signature! \n " ) ) ;
2010-05-25 14:55:40 +04:00
talloc_free ( tmp_ctx ) ;
2005-09-30 21:13:37 +04:00
return NT_STATUS_ACCESS_DENIED ;
}
}
dump_data_pw ( " checked ntlmssp signature \n " , sig - > data , sig - > length ) ;
DEBUG ( 10 , ( " ntlmssp_check_packet: NTLMSSP signature OK ! \n " ) ) ;
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
2010-05-25 14:55:40 +04:00
talloc_free ( tmp_ctx ) ;
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
return NT_STATUS_OK ;
}
/**
* Seal data with the NTLMSSP algorithm
*
*/
2009-12-22 10:50:55 +03:00
NTSTATUS ntlmssp_seal_packet ( struct ntlmssp_state * ntlmssp_state ,
2010-05-25 14:55:40 +04:00
TALLOC_CTX * sig_mem_ctx ,
2009-12-29 19:25:47 +03:00
uint8_t * data , size_t length ,
2010-01-06 19:14:25 +03:00
const uint8_t * whole_pdu , size_t pdu_length ,
Changes all over the shop, but all towards:
- NTLM2 support in the server
- KEY_EXCH support in the server
- variable length session keys.
In detail:
- NTLM2 is an extension of NTLMv1, that is compatible with existing
domain controllers (unlike NTLMv2, which requires a DC upgrade).
* This is known as 'NTLMv2 session security' *
(This is not yet implemented on the RPC pipes however, so there may
well still be issues for PDC setups, particuarly around password
changes. We do not fully understand the sign/seal implications of
NTLM2 on RPC pipes.)
This requires modifications to our authentication subsystem, as we
must handle the 'challege' input into the challenge-response algorithm
being changed. This also needs to be turned off for
'security=server', which does not support this.
- KEY_EXCH is another 'security' mechanism, whereby the session key
actually used by the server is sent by the client, rather than being
the shared-secret directly or indirectly.
- As both these methods change the session key, the auth subsystem
needed to be changed, to 'override' session keys provided by the
backend.
- There has also been a major overhaul of the NTLMSSP subsystem, to merge the 'client' and 'server' functions, so they both operate on a single structure. This should help the SPNEGO implementation.
- The 'names blob' in NTLMSSP is always in unicode - never in ascii.
Don't make an ascii version ever.
- The other big change is to allow variable length session keys. We
have always assumed that session keys are 16 bytes long - and padded
to this length if shorter. However, Kerberos session keys are 8 bytes
long, when the krb5 login uses DES.
* This fix allows SMB signging on machines not yet running MIT KRB5 1.3.1. *
- Add better DEBUG() messages to ntlm_auth, warning administrators of
misconfigurations that prevent access to the privileged pipe. This
should help reduce some of the 'it just doesn't work' issues.
- Fix data_blob_talloc() to behave the same way data_blob() does when
passed a NULL data pointer. (just allocate)
REMEMBER to make clean after this commit - I have changed plenty of data structures...
(This used to be commit f3bbc87b0dac63426cda6fac7a295d3aad810ecc)
2003-11-22 16:19:38 +03:00
DATA_BLOB * sig )
2009-08-14 02:36:21 +04:00
{
2018-12-06 20:11:14 +03:00
int rc ;
2006-01-18 23:45:44 +03:00
if ( ! ( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_SEAL ) ) {
2005-09-30 21:13:37 +04:00
DEBUG ( 3 , ( " NTLMSSP Sealing not negotiated - cannot seal packet! \n " ) ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
2011-10-15 07:56:11 +04:00
if ( ! ( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_SIGN ) ) {
DEBUG ( 3 , ( " NTLMSSP Sealing not negotiated - cannot seal packet! \n " ) ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
2004-01-05 03:11:35 +03:00
if ( ! ntlmssp_state - > session_key . length ) {
DEBUG ( 3 , ( " NO session key, cannot seal packet \n " ) ) ;
return NT_STATUS_NO_USER_SESSION_KEY ;
}
Changes all over the shop, but all towards:
- NTLM2 support in the server
- KEY_EXCH support in the server
- variable length session keys.
In detail:
- NTLM2 is an extension of NTLMv1, that is compatible with existing
domain controllers (unlike NTLMv2, which requires a DC upgrade).
* This is known as 'NTLMv2 session security' *
(This is not yet implemented on the RPC pipes however, so there may
well still be issues for PDC setups, particuarly around password
changes. We do not fully understand the sign/seal implications of
NTLM2 on RPC pipes.)
This requires modifications to our authentication subsystem, as we
must handle the 'challege' input into the challenge-response algorithm
being changed. This also needs to be turned off for
'security=server', which does not support this.
- KEY_EXCH is another 'security' mechanism, whereby the session key
actually used by the server is sent by the client, rather than being
the shared-secret directly or indirectly.
- As both these methods change the session key, the auth subsystem
needed to be changed, to 'override' session keys provided by the
backend.
- There has also been a major overhaul of the NTLMSSP subsystem, to merge the 'client' and 'server' functions, so they both operate on a single structure. This should help the SPNEGO implementation.
- The 'names blob' in NTLMSSP is always in unicode - never in ascii.
Don't make an ascii version ever.
- The other big change is to allow variable length session keys. We
have always assumed that session keys are 16 bytes long - and padded
to this length if shorter. However, Kerberos session keys are 8 bytes
long, when the krb5 login uses DES.
* This fix allows SMB signging on machines not yet running MIT KRB5 1.3.1. *
- Add better DEBUG() messages to ntlm_auth, warning administrators of
misconfigurations that prevent access to the privileged pipe. This
should help reduce some of the 'it just doesn't work' issues.
- Fix data_blob_talloc() to behave the same way data_blob() does when
passed a NULL data pointer. (just allocate)
REMEMBER to make clean after this commit - I have changed plenty of data structures...
(This used to be commit f3bbc87b0dac63426cda6fac7a295d3aad810ecc)
2003-11-22 16:19:38 +03:00
DEBUG ( 10 , ( " ntlmssp_seal_data: seal \n " ) ) ;
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
dump_data_pw ( " ntlmssp clear data \n " , data , length ) ;
if ( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_NTLM2 ) {
2010-01-09 16:06:27 +03:00
NTSTATUS nt_status ;
/*
* The order of these two operations matters - we
* must first seal the packet , then seal the
* sequence number - this is because the
2023-09-05 07:02:59 +03:00
* send_seal_hash is not constant , but is rather
2010-01-09 16:06:27 +03:00
* updated with each iteration
*/
nt_status = ntlmssp_make_packet_signature ( ntlmssp_state ,
2010-05-25 14:55:40 +04:00
sig_mem_ctx ,
2010-01-09 16:06:27 +03:00
data , length ,
whole_pdu , pdu_length ,
NTLMSSP_SEND ,
sig , false ) ;
2006-02-13 16:25:36 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
return nt_status ;
}
2018-12-06 20:11:14 +03:00
rc = gnutls_cipher_encrypt ( ntlmssp_state - > crypt - > ntlm2 . sending . seal_state ,
data ,
length ) ;
if ( rc < 0 ) {
DBG_ERR ( " gnutls_cipher_encrypt ntlmv2 sealing the data "
" failed: %s \n " ,
gnutls_strerror ( rc ) ) ;
return gnutls_error_to_ntstatus ( rc , NT_STATUS_NTLM_BLOCKED ) ;
}
2005-09-30 21:13:37 +04:00
if ( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_KEY_EXCH ) {
2018-12-06 20:11:14 +03:00
rc = gnutls_cipher_encrypt ( ntlmssp_state - > crypt - > ntlm2 . sending . seal_state ,
sig - > data + 4 ,
8 ) ;
if ( rc < 0 ) {
DBG_ERR ( " gnutls_cipher_encrypt ntlmv2 sealing "
" the EXCH signature data failed: %s \n " ,
gnutls_strerror ( rc ) ) ;
return gnutls_error_to_ntstatus ( rc , NT_STATUS_NTLM_BLOCKED ) ;
}
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
}
} else {
2011-03-29 00:26:27 +04:00
NTSTATUS status ;
2009-12-29 19:25:47 +03:00
uint32_t crc ;
2010-01-09 16:06:27 +03:00
2018-10-09 12:39:39 +03:00
crc = crc32 ( 0 , Z_NULL , 0 ) ;
crc = crc32 ( crc , data , length ) ;
2010-01-07 12:43:23 +03:00
2011-03-29 00:26:27 +04:00
status = msrpc_gen ( sig_mem_ctx ,
2010-01-07 12:43:23 +03:00
sig , " dddd " ,
NTLMSSP_SIGN_VERSION , 0 , crc ,
2010-01-09 16:38:35 +03:00
ntlmssp_state - > crypt - > ntlm . seq_num ) ;
2011-03-29 00:26:27 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
}
2010-01-09 16:06:27 +03:00
/*
* The order of these two operations matters - we
* must first seal the packet , then seal the
* sequence number - this is because the ntlmv1_arc4_state
2023-09-05 07:02:59 +03:00
* is not constant , but is rather updated with
2010-01-09 16:06:27 +03:00
* each iteration
*/
2009-08-14 02:36:21 +04:00
dump_arc4_state ( " ntlmv1 arc4 state: \n " ,
2010-01-09 16:38:35 +03:00
& ntlmssp_state - > crypt - > ntlm . seal_state ) ;
2018-12-06 20:11:14 +03:00
rc = gnutls_cipher_encrypt ( ntlmssp_state - > crypt - > ntlm . seal_state ,
data ,
length ) ;
if ( rc < 0 ) {
DBG_ERR ( " gnutls_cipher_encrypt ntlmv1 sealing data "
" failed: %s \n " ,
gnutls_strerror ( rc ) ) ;
return gnutls_error_to_ntstatus ( rc , NT_STATUS_NTLM_BLOCKED ) ;
}
2005-09-30 21:13:37 +04:00
2009-08-14 02:36:21 +04:00
dump_arc4_state ( " ntlmv1 arc4 state: \n " ,
2010-01-09 16:38:35 +03:00
& ntlmssp_state - > crypt - > ntlm . seal_state ) ;
2005-09-30 21:13:37 +04:00
2018-12-06 20:11:14 +03:00
rc = gnutls_cipher_encrypt ( ntlmssp_state - > crypt - > ntlm . seal_state ,
sig - > data + 4 ,
sig - > length - 4 ) ;
if ( rc < 0 ) {
DBG_ERR ( " gnutls_cipher_encrypt ntlmv1 sealing signing "
" data failed: %s \n " ,
gnutls_strerror ( rc ) ) ;
return gnutls_error_to_ntstatus ( rc , NT_STATUS_NTLM_BLOCKED ) ;
}
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
2010-01-09 16:38:35 +03:00
ntlmssp_state - > crypt - > ntlm . seq_num + + ;
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
}
2005-09-30 21:13:37 +04:00
dump_data_pw ( " ntlmssp signature \n " , sig - > data , sig - > length ) ;
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
dump_data_pw ( " ntlmssp sealed data \n " , data , length ) ;
return NT_STATUS_OK ;
}
/**
* Unseal data with the NTLMSSP algorithm
*
*/
2009-12-22 10:50:55 +03:00
NTSTATUS ntlmssp_unseal_packet ( struct ntlmssp_state * ntlmssp_state ,
2010-01-09 16:06:27 +03:00
uint8_t * data , size_t length ,
2010-01-06 19:14:25 +03:00
const uint8_t * whole_pdu , size_t pdu_length ,
2010-01-09 13:30:39 +03:00
const DATA_BLOB * sig )
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
{
2010-05-25 14:55:40 +04:00
NTSTATUS status ;
2018-12-06 20:11:14 +03:00
int rc ;
2004-01-05 03:11:35 +03:00
if ( ! ntlmssp_state - > session_key . length ) {
DEBUG ( 3 , ( " NO session key, cannot unseal packet \n " ) ) ;
return NT_STATUS_NO_USER_SESSION_KEY ;
}
2006-09-01 00:37:16 +04:00
DEBUG ( 10 , ( " ntlmssp_unseal_packet: seal \n " ) ) ;
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
dump_data_pw ( " ntlmssp sealed data \n " , data , length ) ;
2005-09-30 21:13:37 +04:00
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
if ( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_NTLM2 ) {
2005-09-30 21:13:37 +04:00
/* First unseal the data. */
2018-12-06 20:11:14 +03:00
rc = gnutls_cipher_decrypt ( ntlmssp_state - > crypt - > ntlm2 . receiving . seal_state ,
data ,
length ) ;
if ( rc < 0 ) {
DBG_ERR ( " gnutls_cipher_decrypt ntlmv2 unsealing the "
" data failed: %s \n " ,
gnutls_strerror ( rc ) ) ;
return gnutls_error_to_ntstatus ( rc , NT_STATUS_NTLM_BLOCKED ) ;
}
2005-09-30 21:13:37 +04:00
dump_data_pw ( " ntlmv2 clear data \n " , data , length ) ;
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
} else {
2018-12-06 20:11:14 +03:00
rc = gnutls_cipher_decrypt ( ntlmssp_state - > crypt - > ntlm . seal_state ,
data ,
length ) ;
if ( rc < 0 ) {
DBG_ERR ( " gnutls_cipher_decrypt ntlmv1 unsealing the "
" data failed: %s \n " ,
gnutls_strerror ( rc ) ) ;
return gnutls_error_to_ntstatus ( rc , NT_STATUS_NTLM_BLOCKED ) ;
}
2005-09-30 21:13:37 +04:00
dump_data_pw ( " ntlmv1 clear data \n " , data , length ) ;
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
}
2018-12-06 20:11:14 +03:00
2010-05-25 14:55:40 +04:00
status = ntlmssp_check_packet ( ntlmssp_state ,
data , length ,
whole_pdu , pdu_length ,
sig ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 1 , ( " NTLMSSP packet check for unseal failed due to invalid signature on %llu bytes of input: \n " ,
( unsigned long long ) length ) ) ;
}
return status ;
2003-03-10 05:14:35 +03:00
}
2011-01-20 08:37:04 +03:00
NTSTATUS ntlmssp_wrap ( struct ntlmssp_state * ntlmssp_state ,
TALLOC_CTX * out_mem_ctx ,
const DATA_BLOB * in ,
DATA_BLOB * out )
{
NTSTATUS nt_status ;
DATA_BLOB sig ;
if ( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_SEAL ) {
2011-10-22 04:48:30 +04:00
if ( in - > length + NTLMSSP_SIG_SIZE < in - > length ) {
return NT_STATUS_INVALID_PARAMETER ;
}
2011-01-20 08:37:04 +03:00
* out = data_blob_talloc ( out_mem_ctx , NULL , in - > length + NTLMSSP_SIG_SIZE ) ;
if ( ! out - > data ) {
return NT_STATUS_NO_MEMORY ;
}
memcpy ( out - > data + NTLMSSP_SIG_SIZE , in - > data , in - > length ) ;
nt_status = ntlmssp_seal_packet ( ntlmssp_state , out_mem_ctx ,
out - > data + NTLMSSP_SIG_SIZE ,
out - > length - NTLMSSP_SIG_SIZE ,
out - > data + NTLMSSP_SIG_SIZE ,
out - > length - NTLMSSP_SIG_SIZE ,
& sig ) ;
if ( NT_STATUS_IS_OK ( nt_status ) ) {
memcpy ( out - > data , sig . data , NTLMSSP_SIG_SIZE ) ;
talloc_free ( sig . data ) ;
}
return nt_status ;
} else if ( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_SIGN ) {
2011-10-22 04:48:30 +04:00
if ( in - > length + NTLMSSP_SIG_SIZE < in - > length ) {
return NT_STATUS_INVALID_PARAMETER ;
}
2011-01-20 08:37:04 +03:00
* out = data_blob_talloc ( out_mem_ctx , NULL , in - > length + NTLMSSP_SIG_SIZE ) ;
if ( ! out - > data ) {
return NT_STATUS_NO_MEMORY ;
}
memcpy ( out - > data + NTLMSSP_SIG_SIZE , in - > data , in - > length ) ;
nt_status = ntlmssp_sign_packet ( ntlmssp_state , out_mem_ctx ,
out - > data + NTLMSSP_SIG_SIZE ,
out - > length - NTLMSSP_SIG_SIZE ,
out - > data + NTLMSSP_SIG_SIZE ,
out - > length - NTLMSSP_SIG_SIZE ,
& sig ) ;
if ( NT_STATUS_IS_OK ( nt_status ) ) {
memcpy ( out - > data , sig . data , NTLMSSP_SIG_SIZE ) ;
talloc_free ( sig . data ) ;
}
return nt_status ;
} else {
* out = data_blob_talloc ( out_mem_ctx , in - > data , in - > length ) ;
if ( ! out - > data ) {
return NT_STATUS_NO_MEMORY ;
}
return NT_STATUS_OK ;
}
}
NTSTATUS ntlmssp_unwrap ( struct ntlmssp_state * ntlmssp_state ,
TALLOC_CTX * out_mem_ctx ,
const DATA_BLOB * in ,
DATA_BLOB * out )
{
DATA_BLOB sig ;
if ( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_SEAL ) {
if ( in - > length < NTLMSSP_SIG_SIZE ) {
return NT_STATUS_INVALID_PARAMETER ;
}
sig . data = in - > data ;
sig . length = NTLMSSP_SIG_SIZE ;
* out = data_blob_talloc ( out_mem_ctx , in - > data + NTLMSSP_SIG_SIZE , in - > length - NTLMSSP_SIG_SIZE ) ;
return ntlmssp_unseal_packet ( ntlmssp_state ,
out - > data , out - > length ,
out - > data , out - > length ,
& sig ) ;
} else if ( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_SIGN ) {
if ( in - > length < NTLMSSP_SIG_SIZE ) {
return NT_STATUS_INVALID_PARAMETER ;
}
sig . data = in - > data ;
sig . length = NTLMSSP_SIG_SIZE ;
2016-03-08 14:58:51 +03:00
* out = data_blob_talloc ( out_mem_ctx , in - > data + NTLMSSP_SIG_SIZE , in - > length - NTLMSSP_SIG_SIZE ) ;
2011-01-20 08:37:04 +03:00
2016-03-08 14:58:51 +03:00
return ntlmssp_check_packet ( ntlmssp_state ,
out - > data , out - > length ,
out - > data , out - > length ,
& sig ) ;
2011-01-20 08:37:04 +03:00
} else {
* out = data_blob_talloc ( out_mem_ctx , in - > data , in - > length ) ;
if ( ! out - > data ) {
return NT_STATUS_NO_MEMORY ;
}
return NT_STATUS_OK ;
}
}
2003-03-10 05:14:35 +03:00
/**
Initialise the state for NTLMSSP signing .
*/
2013-12-17 14:49:31 +04:00
NTSTATUS ntlmssp_sign_reset ( struct ntlmssp_state * ntlmssp_state ,
bool reset_seqnums )
2003-03-10 05:14:35 +03:00
{
2018-12-06 20:11:14 +03:00
int rc ;
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
DEBUG ( 3 , ( " NTLMSSP Sign/Seal - Initialising with flags: \n " ) ) ;
debug_ntlmssp_flags ( ntlmssp_state - > neg_flags ) ;
2003-03-10 05:14:35 +03:00
2010-01-09 16:38:35 +03:00
if ( ntlmssp_state - > crypt = = NULL ) {
2013-12-17 14:49:31 +04:00
return NT_STATUS_INVALID_PARAMETER_MIX ;
2010-01-09 16:38:35 +03:00
}
2015-12-09 16:48:14 +03:00
if ( ntlmssp_state - > force_wrap_seal & &
( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_SIGN ) )
{
/*
* We need to handle NTLMSSP_NEGOTIATE_SIGN as
* NTLMSSP_NEGOTIATE_SEAL if GENSEC_FEATURE_LDAP_STYLE
* is requested .
*
* The negotiation of flags ( and authentication )
* is completed when ntlmssp_sign_init ( ) is called
* so we can safely pretent NTLMSSP_NEGOTIATE_SEAL
* was negotiated .
*/
ntlmssp_state - > neg_flags | = NTLMSSP_NEGOTIATE_SEAL ;
}
2006-02-12 19:44:30 +03:00
if ( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_NTLM2 ) {
2005-09-30 21:13:37 +04:00
DATA_BLOB weak_session_key = ntlmssp_state - > session_key ;
Changes all over the shop, but all towards:
- NTLM2 support in the server
- KEY_EXCH support in the server
- variable length session keys.
In detail:
- NTLM2 is an extension of NTLMv1, that is compatible with existing
domain controllers (unlike NTLMv2, which requires a DC upgrade).
* This is known as 'NTLMv2 session security' *
(This is not yet implemented on the RPC pipes however, so there may
well still be issues for PDC setups, particuarly around password
changes. We do not fully understand the sign/seal implications of
NTLM2 on RPC pipes.)
This requires modifications to our authentication subsystem, as we
must handle the 'challege' input into the challenge-response algorithm
being changed. This also needs to be turned off for
'security=server', which does not support this.
- KEY_EXCH is another 'security' mechanism, whereby the session key
actually used by the server is sent by the client, rather than being
the shared-secret directly or indirectly.
- As both these methods change the session key, the auth subsystem
needed to be changed, to 'override' session keys provided by the
backend.
- There has also been a major overhaul of the NTLMSSP subsystem, to merge the 'client' and 'server' functions, so they both operate on a single structure. This should help the SPNEGO implementation.
- The 'names blob' in NTLMSSP is always in unicode - never in ascii.
Don't make an ascii version ever.
- The other big change is to allow variable length session keys. We
have always assumed that session keys are 16 bytes long - and padded
to this length if shorter. However, Kerberos session keys are 8 bytes
long, when the krb5 login uses DES.
* This fix allows SMB signging on machines not yet running MIT KRB5 1.3.1. *
- Add better DEBUG() messages to ntlm_auth, warning administrators of
misconfigurations that prevent access to the privileged pipe. This
should help reduce some of the 'it just doesn't work' issues.
- Fix data_blob_talloc() to behave the same way data_blob() does when
passed a NULL data pointer. (just allocate)
REMEMBER to make clean after this commit - I have changed plenty of data structures...
(This used to be commit f3bbc87b0dac63426cda6fac7a295d3aad810ecc)
2003-11-22 16:19:38 +03:00
const char * send_sign_const ;
const char * send_seal_const ;
const char * recv_sign_const ;
const char * recv_seal_const ;
2018-12-06 20:11:14 +03:00
uint8_t send_seal_key [ 16 ] = { 0 } ;
gnutls_datum_t send_seal_blob = {
. data = send_seal_key ,
. size = sizeof ( send_seal_key ) ,
} ;
uint8_t recv_seal_key [ 16 ] = { 0 } ;
gnutls_datum_t recv_seal_blob = {
. data = recv_seal_key ,
. size = sizeof ( recv_seal_key ) ,
} ;
2018-10-30 18:43:03 +03:00
NTSTATUS status ;
Changes all over the shop, but all towards:
- NTLM2 support in the server
- KEY_EXCH support in the server
- variable length session keys.
In detail:
- NTLM2 is an extension of NTLMv1, that is compatible with existing
domain controllers (unlike NTLMv2, which requires a DC upgrade).
* This is known as 'NTLMv2 session security' *
(This is not yet implemented on the RPC pipes however, so there may
well still be issues for PDC setups, particuarly around password
changes. We do not fully understand the sign/seal implications of
NTLM2 on RPC pipes.)
This requires modifications to our authentication subsystem, as we
must handle the 'challege' input into the challenge-response algorithm
being changed. This also needs to be turned off for
'security=server', which does not support this.
- KEY_EXCH is another 'security' mechanism, whereby the session key
actually used by the server is sent by the client, rather than being
the shared-secret directly or indirectly.
- As both these methods change the session key, the auth subsystem
needed to be changed, to 'override' session keys provided by the
backend.
- There has also been a major overhaul of the NTLMSSP subsystem, to merge the 'client' and 'server' functions, so they both operate on a single structure. This should help the SPNEGO implementation.
- The 'names blob' in NTLMSSP is always in unicode - never in ascii.
Don't make an ascii version ever.
- The other big change is to allow variable length session keys. We
have always assumed that session keys are 16 bytes long - and padded
to this length if shorter. However, Kerberos session keys are 8 bytes
long, when the krb5 login uses DES.
* This fix allows SMB signging on machines not yet running MIT KRB5 1.3.1. *
- Add better DEBUG() messages to ntlm_auth, warning administrators of
misconfigurations that prevent access to the privileged pipe. This
should help reduce some of the 'it just doesn't work' issues.
- Fix data_blob_talloc() to behave the same way data_blob() does when
passed a NULL data pointer. (just allocate)
REMEMBER to make clean after this commit - I have changed plenty of data structures...
(This used to be commit f3bbc87b0dac63426cda6fac7a295d3aad810ecc)
2003-11-22 16:19:38 +03:00
switch ( ntlmssp_state - > role ) {
case NTLMSSP_CLIENT :
send_sign_const = CLI_SIGN ;
send_seal_const = CLI_SEAL ;
recv_sign_const = SRV_SIGN ;
recv_seal_const = SRV_SEAL ;
break ;
case NTLMSSP_SERVER :
send_sign_const = SRV_SIGN ;
send_seal_const = SRV_SEAL ;
recv_sign_const = CLI_SIGN ;
recv_seal_const = CLI_SEAL ;
break ;
2004-11-20 23:10:43 +03:00
default :
2006-02-12 19:44:30 +03:00
return NT_STATUS_INTERNAL_ERROR ;
Changes all over the shop, but all towards:
- NTLM2 support in the server
- KEY_EXCH support in the server
- variable length session keys.
In detail:
- NTLM2 is an extension of NTLMv1, that is compatible with existing
domain controllers (unlike NTLMv2, which requires a DC upgrade).
* This is known as 'NTLMv2 session security' *
(This is not yet implemented on the RPC pipes however, so there may
well still be issues for PDC setups, particuarly around password
changes. We do not fully understand the sign/seal implications of
NTLM2 on RPC pipes.)
This requires modifications to our authentication subsystem, as we
must handle the 'challege' input into the challenge-response algorithm
being changed. This also needs to be turned off for
'security=server', which does not support this.
- KEY_EXCH is another 'security' mechanism, whereby the session key
actually used by the server is sent by the client, rather than being
the shared-secret directly or indirectly.
- As both these methods change the session key, the auth subsystem
needed to be changed, to 'override' session keys provided by the
backend.
- There has also been a major overhaul of the NTLMSSP subsystem, to merge the 'client' and 'server' functions, so they both operate on a single structure. This should help the SPNEGO implementation.
- The 'names blob' in NTLMSSP is always in unicode - never in ascii.
Don't make an ascii version ever.
- The other big change is to allow variable length session keys. We
have always assumed that session keys are 16 bytes long - and padded
to this length if shorter. However, Kerberos session keys are 8 bytes
long, when the krb5 login uses DES.
* This fix allows SMB signging on machines not yet running MIT KRB5 1.3.1. *
- Add better DEBUG() messages to ntlm_auth, warning administrators of
misconfigurations that prevent access to the privileged pipe. This
should help reduce some of the 'it just doesn't work' issues.
- Fix data_blob_talloc() to behave the same way data_blob() does when
passed a NULL data pointer. (just allocate)
REMEMBER to make clean after this commit - I have changed plenty of data structures...
(This used to be commit f3bbc87b0dac63426cda6fac7a295d3aad810ecc)
2003-11-22 16:19:38 +03:00
}
2010-01-09 16:06:27 +03:00
/*
* Weaken NTLMSSP keys to cope with down - level
* clients , servers and export restrictions .
*
* We probably should have some parameters to
* control this , once we get NTLM2 working .
*
* Key weakening was not performed on the master key
* for NTLM2 , but must be done on the encryption subkeys only .
*/
2005-09-30 21:13:37 +04:00
if ( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_128 ) {
2010-01-09 16:06:27 +03:00
/* nothing to do */
2005-09-30 21:13:37 +04:00
} else if ( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_56 ) {
2006-02-12 19:44:30 +03:00
weak_session_key . length = 7 ;
2005-09-30 21:13:37 +04:00
} else { /* forty bits */
weak_session_key . length = 5 ;
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
}
2005-09-30 21:13:37 +04:00
dump_data_pw ( " NTLMSSP weakend master key: \n " ,
2010-01-09 16:06:27 +03:00
weak_session_key . data ,
weak_session_key . length ) ;
2005-09-30 21:13:37 +04:00
2006-02-12 19:44:30 +03:00
/* SEND: sign key */
2018-10-30 18:43:03 +03:00
status = calc_ntlmv2_key ( ntlmssp_state - > crypt - > ntlm2 . sending . sign_key ,
ntlmssp_state - > session_key , send_sign_const ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2005-09-30 21:13:37 +04:00
dump_data_pw ( " NTLMSSP send sign key: \n " ,
2010-01-09 16:38:35 +03:00
ntlmssp_state - > crypt - > ntlm2 . sending . sign_key , 16 ) ;
2005-09-30 21:13:37 +04:00
2006-02-12 19:44:30 +03:00
/* SEND: seal ARCFOUR pad */
2018-10-30 18:43:03 +03:00
status = calc_ntlmv2_key ( send_seal_key ,
weak_session_key ,
send_seal_const ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2018-12-06 20:11:14 +03:00
dump_data_pw ( " NTLMSSP send seal key: \n " ,
send_seal_key ,
sizeof ( send_seal_key ) ) ;
2005-09-30 21:13:37 +04:00
2018-12-06 20:11:14 +03:00
if ( ntlmssp_state - > crypt - > ntlm2 . sending . seal_state ! = NULL ) {
gnutls_cipher_deinit ( ntlmssp_state - > crypt - > ntlm2 . sending . seal_state ) ;
}
rc = gnutls_cipher_init ( & ntlmssp_state - > crypt - > ntlm2 . sending . seal_state ,
GNUTLS_CIPHER_ARCFOUR_128 ,
& send_seal_blob ,
NULL ) ;
if ( rc < 0 ) {
DBG_ERR ( " gnutls_cipher_init failed: %s \n " ,
gnutls_strerror ( rc ) ) ;
return gnutls_error_to_ntstatus ( rc , NT_STATUS_NTLM_BLOCKED ) ;
}
2005-09-30 21:13:37 +04:00
2009-08-14 02:36:21 +04:00
dump_arc4_state ( " NTLMSSP send seal arc4 state: \n " ,
2010-01-09 16:38:35 +03:00
& ntlmssp_state - > crypt - > ntlm2 . sending . seal_state ) ;
2010-01-09 16:06:27 +03:00
/* SEND: seq num */
2013-12-17 14:49:31 +04:00
if ( reset_seqnums ) {
ntlmssp_state - > crypt - > ntlm2 . sending . seq_num = 0 ;
}
2005-09-30 21:13:37 +04:00
2006-02-12 19:44:30 +03:00
/* RECV: sign key */
2018-10-30 18:43:03 +03:00
status = calc_ntlmv2_key ( ntlmssp_state - > crypt - > ntlm2 . receiving . sign_key ,
ntlmssp_state - > session_key , recv_sign_const ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2010-01-09 16:06:27 +03:00
dump_data_pw ( " NTLMSSP recv sign key: \n " ,
2010-01-09 16:38:35 +03:00
ntlmssp_state - > crypt - > ntlm2 . receiving . sign_key , 16 ) ;
2005-09-30 21:13:37 +04:00
2006-02-12 19:44:30 +03:00
/* RECV: seal ARCFOUR pad */
2018-10-30 18:43:03 +03:00
status = calc_ntlmv2_key ( recv_seal_key ,
weak_session_key ,
recv_seal_const ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2018-12-06 20:11:14 +03:00
dump_data_pw ( " NTLMSSP recv seal key: \n " ,
recv_seal_key ,
sizeof ( recv_seal_key ) ) ;
2009-08-14 02:36:21 +04:00
2018-12-06 20:11:14 +03:00
if ( ntlmssp_state - > crypt - > ntlm2 . receiving . seal_state ! = NULL ) {
gnutls_cipher_deinit ( ntlmssp_state - > crypt - > ntlm2 . receiving . seal_state ) ;
}
rc = gnutls_cipher_init ( & ntlmssp_state - > crypt - > ntlm2 . receiving . seal_state ,
GNUTLS_CIPHER_ARCFOUR_128 ,
& recv_seal_blob ,
NULL ) ;
if ( rc < 0 ) {
DBG_ERR ( " gnutls_cipher_init failed: %s \n " ,
gnutls_strerror ( rc ) ) ;
return gnutls_error_to_ntstatus ( rc , NT_STATUS_NTLM_BLOCKED ) ;
}
2005-09-30 21:13:37 +04:00
2009-08-14 02:36:21 +04:00
dump_arc4_state ( " NTLMSSP recv seal arc4 state: \n " ,
2010-01-09 16:38:35 +03:00
& ntlmssp_state - > crypt - > ntlm2 . receiving . seal_state ) ;
2005-09-30 21:13:37 +04:00
2010-01-09 16:06:27 +03:00
/* RECV: seq num */
2013-12-17 14:49:31 +04:00
if ( reset_seqnums ) {
ntlmssp_state - > crypt - > ntlm2 . receiving . seq_num = 0 ;
}
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
} else {
2018-12-06 20:11:14 +03:00
gnutls_datum_t seal_session_key = {
. data = ntlmssp_state - > session_key . data ,
. size = ntlmssp_state - > session_key . length ,
} ;
2010-01-06 17:45:38 +03:00
bool do_weak = false ;
2005-09-30 21:13:37 +04:00
2010-01-06 17:45:38 +03:00
DEBUG ( 5 , ( " NTLMSSP Sign/Seal - using NTLM1 \n " ) ) ;
2005-09-30 21:13:37 +04:00
2010-01-06 17:45:38 +03:00
/*
* Key weakening not performed on the master key for NTLM2
2023-03-14 10:50:34 +03:00
* and does not occur for NTLM1 . Therefore we only need
2010-01-06 17:45:38 +03:00
* to do this for the LM_KEY .
*/
if ( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_LM_KEY ) {
do_weak = true ;
Jeremy requested that I get my NTLMSSP patch into CVS. He didn't request
the schannel code, but I've included that anyway. :-)
This patch revives the client-side NTLMSSP support for RPC named pipes
in Samba, and cleans up the client and server schannel code. The use of the
new code is enabled by the 'sign', 'seal' and 'schannel' commands in
rpcclient.
The aim was to prove that our separate NTLMSSP client library actually
implements NTLMSSP signing and sealing as per Microsoft's NTLMv1 implementation,
in the hope that knowing this will assist us in correctly implementing
NTLMSSP signing for SMB packets. (Still not yet functional)
This patch replaces the NTLMSSP implementation in rpc_client/cli_pipe.c with
calls to libsmb/ntlmssp.c. In the process, we have gained the ability to
use the more secure NT password, and the ability to sign-only, instead of
having to seal the pipe connection. (Previously we were limited to sealing,
and could only use the LM-password derived key).
Our new client-side NTLMSSP code also needed alteration to cope with our
comparatively simple server-side implementation. A future step is to replace
it with calls to the same NTLMSSP library.
Also included in this patch is the schannel 'sign only' patch I submitted to
the team earlier. While not enabled (and not functional, at this stage) the
work in this patch makes the code paths *much* easier to follow. I have also
included similar hooks in rpccleint to allow the use of schannel on *any* pipe.
rpcclient now defaults to not using schannel (or any other extra per-pipe
authenticiation) for any connection. The 'schannel' command enables schannel
for all pipes until disabled.
This code is also much more secure than the previous code, as changes to our
cli_pipe routines ensure that the authentication footer cannot be removed
by an attacker, and more error states are correctly handled.
(The same needs to be done to our server)
Andrew Bartlett
(This used to be commit 5472ddc9eaf4e79c5b2e1c8ee8c7f190dc285f19)
2003-07-14 12:46:32 +04:00
}
2010-01-06 17:45:38 +03:00
/*
* Nothing to weaken .
* We certainly don ' t want to ' extend ' the length . . .
*/
2018-12-06 20:11:14 +03:00
if ( ntlmssp_state - > session_key . length < 16 ) {
2010-01-06 17:45:38 +03:00
/* TODO: is this really correct? */
do_weak = false ;
}
2006-02-12 19:44:30 +03:00
2010-01-06 17:45:38 +03:00
if ( do_weak ) {
2018-12-06 20:11:14 +03:00
uint8_t weak_session_key [ 8 ] ;
2010-01-06 17:45:38 +03:00
memcpy ( weak_session_key , seal_session_key . data , 8 ) ;
2018-12-06 20:11:14 +03:00
seal_session_key = ( gnutls_datum_t ) {
. data = weak_session_key ,
. size = sizeof ( weak_session_key ) ,
} ;
2010-01-06 17:45:38 +03:00
/*
* LM key doesn ' t support 128 bit crypto , so this is
* the best we can do . If you negotiate 128 bit , but
* not 56 , you end up with 40 bit . . .
*/
if ( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_56 ) {
weak_session_key [ 7 ] = 0xa0 ;
} else { /* forty bits */
weak_session_key [ 5 ] = 0xe5 ;
weak_session_key [ 6 ] = 0x38 ;
weak_session_key [ 7 ] = 0xb0 ;
}
}
2005-09-30 21:13:37 +04:00
2018-12-06 20:11:14 +03:00
if ( ntlmssp_state - > crypt - > ntlm . seal_state ! = NULL ) {
gnutls_cipher_deinit ( ntlmssp_state - > crypt - > ntlm . seal_state ) ;
}
rc = gnutls_cipher_init ( & ntlmssp_state - > crypt - > ntlm . seal_state ,
GNUTLS_CIPHER_ARCFOUR_128 ,
& seal_session_key ,
NULL ) ;
if ( rc < 0 ) {
DBG_ERR ( " gnutls_cipher_init failed: %s \n " ,
gnutls_strerror ( rc ) ) ;
return gnutls_error_to_ntstatus ( rc , NT_STATUS_NTLM_BLOCKED ) ;
}
2003-03-10 05:14:35 +03:00
2010-01-09 16:06:27 +03:00
dump_arc4_state ( " NTLMv1 arc4 state: \n " ,
2010-01-09 16:38:35 +03:00
& ntlmssp_state - > crypt - > ntlm . seal_state ) ;
2005-09-30 21:13:37 +04:00
2013-12-17 14:49:31 +04:00
if ( reset_seqnums ) {
ntlmssp_state - > crypt - > ntlm . seq_num = 0 ;
}
2005-09-30 21:13:37 +04:00
}
2003-03-10 05:14:35 +03:00
return NT_STATUS_OK ;
}
2013-12-17 14:49:31 +04:00
2018-12-06 20:11:14 +03:00
static int ntlmssp_crypt_free_gnutls_cipher_state ( union ntlmssp_crypt_state * c )
{
if ( c - > ntlm2 . sending . seal_state ! = NULL ) {
gnutls_cipher_deinit ( c - > ntlm2 . sending . seal_state ) ;
c - > ntlm2 . sending . seal_state = NULL ;
}
if ( c - > ntlm2 . receiving . seal_state ! = NULL ) {
gnutls_cipher_deinit ( c - > ntlm2 . receiving . seal_state ) ;
c - > ntlm2 . receiving . seal_state = NULL ;
}
if ( c - > ntlm . seal_state ! = NULL ) {
gnutls_cipher_deinit ( c - > ntlm . seal_state ) ;
c - > ntlm . seal_state = NULL ;
}
return 0 ;
}
2013-12-17 14:49:31 +04:00
NTSTATUS ntlmssp_sign_init ( struct ntlmssp_state * ntlmssp_state )
{
if ( ntlmssp_state - > session_key . length < 8 ) {
2017-02-17 22:59:59 +03:00
DEBUG ( 3 , ( " NO session key, cannot initialise signing \n " ) ) ;
2013-12-17 14:49:31 +04:00
return NT_STATUS_NO_USER_SESSION_KEY ;
}
ntlmssp_state - > crypt = talloc_zero ( ntlmssp_state ,
union ntlmssp_crypt_state ) ;
if ( ntlmssp_state - > crypt = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
2018-12-06 20:11:14 +03:00
talloc_set_destructor ( ntlmssp_state - > crypt ,
ntlmssp_crypt_free_gnutls_cipher_state ) ;
2013-12-17 14:49:31 +04:00
return ntlmssp_sign_reset ( ntlmssp_state , true ) ;
}