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"
2010-05-25 14:19:22 +04:00
# include "../libcli/auth/ntlmssp.h"
2009-03-17 12:08:31 +03:00
# include "../libcli/auth/libcli_auth.h"
2010-05-18 02:16:40 +04:00
# include "../lib/crypto/md5.h"
# include "../lib/crypto/hmacmd5.h"
# include "../lib/crypto/crc32.h"
2010-05-25 14:58:52 +04:00
# include "../libcli/auth/ntlmssp_private.h"
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 ,
2008-09-24 21:20:33 +04:00
struct arcfour_state * state )
{
dump_data_pw ( description , state - > sbox , sizeof ( state - > sbox ) ) ;
}
2009-12-29 19:25:20 +03:00
static void calc_ntlmv2_key ( uint8_t subkey [ 16 ] ,
DATA_BLOB session_key ,
const char * constant )
2003-03-10 05:14:35 +03:00
{
struct MD5Context ctx3 ;
MD5Init ( & ctx3 ) ;
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
MD5Update ( & ctx3 , session_key . data , session_key . length ) ;
2009-12-29 19:25:20 +03:00
MD5Update ( & ctx3 , ( const uint8_t * ) constant , strlen ( constant ) + 1 ) ;
2005-09-30 21:13:37 +04:00
MD5Final ( subkey , & ctx3 ) ;
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
{
if ( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_NTLM2 ) {
HMACMD5Context ctx ;
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 + + ;
hmac_md5_init_limK_to_64 ( ntlmssp_state - > crypt - > ntlm2 . sending . sign_key , 16 , & ctx ) ;
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 + + ;
hmac_md5_init_limK_to_64 ( ntlmssp_state - > crypt - > ntlm2 . receiving . sign_key , 16 , & ctx ) ;
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 ) ;
2009-12-29 19:25:47 +03:00
hmac_md5_update ( seq_num , sizeof ( seq_num ) , & ctx ) ;
2005-09-30 21:13:37 +04:00
hmac_md5_update ( whole_pdu , pdu_length , & ctx ) ;
hmac_md5_final ( digest , & ctx ) ;
if ( encrypt_sig & & ( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_KEY_EXCH ) ) {
2004-01-05 03:11:35 +03:00
switch ( direction ) {
case NTLMSSP_SEND :
2010-01-09 16:38:35 +03:00
arcfour_crypt_sbox ( & ntlmssp_state - > crypt - > ntlm2 . sending . seal_state ,
2010-01-09 16:06:27 +03:00
digest , 8 ) ;
2004-01-05 03:11:35 +03:00
break ;
case NTLMSSP_RECEIVE :
2010-01-09 16:38:35 +03:00
arcfour_crypt_sbox ( & ntlmssp_state - > crypt - > ntlm2 . receiving . seal_state ,
2010-01-09 16:06:27 +03:00
digest , 8 ) ;
2004-01-05 03:11:35 +03:00
break ;
}
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 ) ;
memcpy ( sig - > data + 12 , seq_num , 4 ) ;
dump_data_pw ( " ntlmssp v2 sig " , sig - > data , sig - > length ) ;
2003-03-10 05:14:35 +03:00
} else {
2010-01-07 12:43:23 +03:00
bool ok ;
2009-12-29 19:25:47 +03:00
uint32_t crc ;
2010-01-09 16:06:27 +03:00
2008-09-24 18:46:02 +04:00
crc = crc32_calc_buffer ( data , length ) ;
2010-01-07 12:43:23 +03:00
2010-05-25 14:55:40 +04:00
ok = 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 ) ;
2010-01-07 12:43:23 +03:00
if ( ! ok ) {
2003-03-10 05:14:35 +03:00
return NT_STATUS_NO_MEMORY ;
}
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 ) ;
arcfour_crypt_sbox ( & ntlmssp_state - > crypt - > ntlm . seal_state ,
2010-01-09 16:06:27 +03:00
sig - > data + 4 , sig - > length - 4 ) ;
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 | |
2010-01-09 16:06:27 +03:00
memcmp ( local_sig . data , sig - > data , sig - > length ) ! = 0 ) {
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 | |
2010-01-09 16:06:27 +03:00
memcmp ( local_sig . data + 8 , sig - > data + 8 , sig - > length - 8 ) ! = 0 ) {
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
{
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 ;
}
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
* send_seal_hash is not constant , but is is rather
* 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 ;
}
2010-01-09 16:38:35 +03:00
arcfour_crypt_sbox ( & ntlmssp_state - > crypt - > ntlm2 . sending . seal_state ,
2010-01-09 16:06:27 +03:00
data , length ) ;
2005-09-30 21:13:37 +04:00
if ( ntlmssp_state - > neg_flags & NTLMSSP_NEGOTIATE_KEY_EXCH ) {
2010-01-09 16:38:35 +03:00
arcfour_crypt_sbox ( & ntlmssp_state - > crypt - > ntlm2 . sending . seal_state ,
2010-01-09 16:06:27 +03:00
sig - > data + 4 , 8 ) ;
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 {
2010-01-07 12:43:23 +03:00
bool ok ;
2009-12-29 19:25:47 +03:00
uint32_t crc ;
2010-01-09 16:06:27 +03:00
2008-09-24 18:46:02 +04:00
crc = crc32_calc_buffer ( data , length ) ;
2010-01-07 12:43:23 +03:00
2010-05-25 14:55:40 +04:00
ok = 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 ) ;
2010-01-07 12:43:23 +03:00
if ( ! ok ) {
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_NO_MEMORY ;
}
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
* is not constant , but is is rather updated with
* 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 ) ;
arcfour_crypt_sbox ( & ntlmssp_state - > crypt - > ntlm . seal_state ,
2010-01-09 16:06:27 +03:00
data , length ) ;
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
2010-01-09 16:38:35 +03:00
arcfour_crypt_sbox ( & ntlmssp_state - > crypt - > ntlm . seal_state ,
2010-01-09 16:06:27 +03:00
sig - > data + 4 , sig - > length - 4 ) ;
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 ;
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. */
2010-01-09 16:38:35 +03:00
arcfour_crypt_sbox ( & ntlmssp_state - > crypt - > ntlm2 . receiving . seal_state ,
2010-01-09 16:06:27 +03:00
data , length ) ;
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 {
2010-01-09 16:38:35 +03:00
arcfour_crypt_sbox ( & ntlmssp_state - > crypt - > ntlm . seal_state ,
2010-01-09 16:06:27 +03:00
data , length ) ;
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
}
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
}
/**
Initialise the state for NTLMSSP signing .
*/
2009-12-22 10:50:55 +03:00
NTSTATUS ntlmssp_sign_init ( struct ntlmssp_state * ntlmssp_state )
2003-03-10 05:14:35 +03: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
DEBUG ( 3 , ( " NTLMSSP Sign/Seal - Initialising with flags: \n " ) ) ;
debug_ntlmssp_flags ( ntlmssp_state - > neg_flags ) ;
2003-03-10 05:14:35 +03:00
2006-02-12 19:44:30 +03:00
if ( ntlmssp_state - > session_key . length < 8 ) {
2004-01-05 03:11:35 +03:00
DEBUG ( 3 , ( " NO session key, cannot intialise signing \n " ) ) ;
return NT_STATUS_NO_USER_SESSION_KEY ;
}
2010-01-09 16:38:35 +03:00
ntlmssp_state - > crypt = talloc_zero ( ntlmssp_state ,
union ntlmssp_crypt_state ) ;
if ( ntlmssp_state - > crypt = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
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 ;
2010-01-06 17:22:24 +03:00
uint8_t send_seal_key [ 16 ] ;
DATA_BLOB send_seal_blob = data_blob_const ( send_seal_key ,
sizeof ( send_seal_key ) ) ;
uint8_t recv_seal_key [ 16 ] ;
DATA_BLOB recv_seal_blob = data_blob_const ( recv_seal_key ,
sizeof ( recv_seal_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
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 */
2010-01-09 16:38:35 +03:00
calc_ntlmv2_key ( ntlmssp_state - > crypt - > ntlm2 . sending . sign_key ,
2005-09-30 21:13:37 +04:00
ntlmssp_state - > session_key , send_sign_const ) ;
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 */
2010-01-06 17:22:24 +03:00
calc_ntlmv2_key ( send_seal_key ,
2005-09-30 21:13:37 +04:00
weak_session_key , send_seal_const ) ;
2010-01-06 17:22:24 +03:00
dump_data_pw ( " NTLMSSP send seal key: \n " , send_seal_key , 16 ) ;
2005-09-30 21:13:37 +04:00
2010-01-09 16:38:35 +03:00
arcfour_init ( & ntlmssp_state - > crypt - > ntlm2 . sending . seal_state ,
2010-01-06 17:22:24 +03:00
& send_seal_blob ) ;
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 */
2010-01-09 16:38:35 +03:00
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 */
2010-01-09 16:38:35 +03:00
calc_ntlmv2_key ( ntlmssp_state - > crypt - > ntlm2 . receiving . sign_key ,
2005-09-30 21:13:37 +04:00
ntlmssp_state - > session_key , recv_sign_const ) ;
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 */
2010-01-06 17:22:24 +03:00
calc_ntlmv2_key ( recv_seal_key ,
2005-09-30 21:13:37 +04:00
weak_session_key , recv_seal_const ) ;
2010-01-06 17:22:24 +03:00
dump_data_pw ( " NTLMSSP recv seal key: \n " , recv_seal_key , 16 ) ;
2009-08-14 02:36:21 +04:00
2010-01-09 16:38:35 +03:00
arcfour_init ( & ntlmssp_state - > crypt - > ntlm2 . receiving . seal_state ,
2010-01-06 17:22:24 +03:00
& recv_seal_blob ) ;
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 */
2010-01-09 16:38:35 +03:00
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 {
2010-01-06 17:45:38 +03:00
uint8_t weak_session_key [ 8 ] ;
DATA_BLOB seal_session_key = ntlmssp_state - > session_key ;
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
* and does not occour for NTLM1 . Therefore we only need
* 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 . . .
*/
if ( seal_session_key . length < 16 ) {
/* 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 ) {
memcpy ( weak_session_key , seal_session_key . data , 8 ) ;
seal_session_key = data_blob_const ( weak_session_key , 8 ) ;
/*
* 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
2010-01-09 16:38:35 +03:00
arcfour_init ( & ntlmssp_state - > crypt - > ntlm . seal_state ,
2010-01-06 17:45:38 +03:00
& seal_session_key ) ;
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
2010-01-09 16:38:35 +03:00
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 ;
}