Ignore:
Timestamp:
Jun 9, 2016, 2:23:12 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: apply latest security patches to trunk

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/libsmb/ntlmssp.c

    r918 r920  
    163163}
    164164
     165bool ntlmssp_have_feature(struct ntlmssp_state *ntlmssp_state,
     166                          uint32_t feature)
     167{
     168        if (feature & NTLMSSP_FEATURE_SIGN) {
     169                if (ntlmssp_state->session_key.length == 0) {
     170                        return false;
     171                }
     172                if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_SIGN) {
     173                        return true;
     174                }
     175        }
     176
     177        if (feature & NTLMSSP_FEATURE_SEAL) {
     178                if (ntlmssp_state->session_key.length == 0) {
     179                        return false;
     180                }
     181                if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_SEAL) {
     182                        return true;
     183                }
     184        }
     185
     186        if (feature & NTLMSSP_FEATURE_SESSION_KEY) {
     187                if (ntlmssp_state->session_key.length > 0) {
     188                        return true;
     189                }
     190        }
     191
     192        return false;
     193}
     194
    165195/**
    166196 * Request features for the NTLMSSP negotiation
     
    177207         */
    178208        if (in_list("NTLMSSP_FEATURE_SESSION_KEY", feature_list, True)) {
    179                 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SIGN;
     209                ntlmssp_state->required_flags |= NTLMSSP_NEGOTIATE_SIGN;
    180210        }
    181211        if (in_list("NTLMSSP_FEATURE_SIGN", feature_list, True)) {
    182                 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SIGN;
     212                ntlmssp_state->required_flags |= NTLMSSP_NEGOTIATE_SIGN;
    183213        }
    184214        if(in_list("NTLMSSP_FEATURE_SEAL", feature_list, True)) {
    185                 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SEAL;
     215                ntlmssp_state->required_flags |= NTLMSSP_NEGOTIATE_SEAL;
    186216        }
    187217        if (in_list("NTLMSSP_FEATURE_CCACHE", feature_list, true)) {
    188218                ntlmssp_state->use_ccache = true;
    189219        }
     220
     221        ntlmssp_state->neg_flags |= ntlmssp_state->required_flags;
    190222}
    191223
     
    200232        /* As per JRA's comment above */
    201233        if (feature & NTLMSSP_FEATURE_SESSION_KEY) {
    202                 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SIGN;
     234                ntlmssp_state->required_flags |= NTLMSSP_NEGOTIATE_SIGN;
    203235        }
    204236        if (feature & NTLMSSP_FEATURE_SIGN) {
    205                 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SIGN;
     237                ntlmssp_state->required_flags |= NTLMSSP_NEGOTIATE_SIGN;
    206238        }
    207239        if (feature & NTLMSSP_FEATURE_SEAL) {
    208                 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SEAL;
     240                ntlmssp_state->required_flags |= NTLMSSP_NEGOTIATE_SIGN;
     241                ntlmssp_state->required_flags |= NTLMSSP_NEGOTIATE_SEAL;
    209242        }
    210243        if (feature & NTLMSSP_FEATURE_CCACHE) {
    211244                ntlmssp_state->use_ccache = true;
    212245        }
     246
     247        ntlmssp_state->neg_flags |= ntlmssp_state->required_flags;
    213248}
    214249
     
    388423
    389424        if (ntlmssp_state->use_ntlmv2) {
    390                 ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_NTLM2;
     425                ntlmssp_state->required_flags |= NTLMSSP_NEGOTIATE_NTLM2;
     426                ntlmssp_state->allow_lm_key = false;
     427        }
     428
     429        if (ntlmssp_state->allow_lm_key) {
     430                ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_LM_KEY;
    391431        }
    392432
     
    421461
    422462        return NT_STATUS_MORE_PROCESSING_REQUIRED;
     463}
     464
     465static NTSTATUS ntlmssp3_handle_neg_flags(struct ntlmssp_state *ntlmssp_state,
     466                                          uint32_t flags)
     467{
     468        uint32_t missing_flags = ntlmssp_state->required_flags;
     469
     470        if (flags & NTLMSSP_NEGOTIATE_UNICODE) {
     471                ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_UNICODE;
     472                ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_OEM;
     473                ntlmssp_state->unicode = true;
     474        } else {
     475                ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_UNICODE;
     476                ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_OEM;
     477                ntlmssp_state->unicode = false;
     478        }
     479
     480        /*
     481         * NTLMSSP_NEGOTIATE_NTLM2 (NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY)
     482         * has priority over NTLMSSP_NEGOTIATE_LM_KEY
     483         */
     484        if (!(flags & NTLMSSP_NEGOTIATE_NTLM2)) {
     485                ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_NTLM2;
     486        }
     487
     488        if (ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_NTLM2) {
     489                ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
     490        }
     491
     492        if (!(flags & NTLMSSP_NEGOTIATE_LM_KEY)) {
     493                ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
     494        }
     495
     496        if (!(flags & NTLMSSP_NEGOTIATE_ALWAYS_SIGN)) {
     497                ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_ALWAYS_SIGN;
     498        }
     499
     500        if (!(flags & NTLMSSP_NEGOTIATE_128)) {
     501                ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_128;
     502        }
     503
     504        if (!(flags & NTLMSSP_NEGOTIATE_56)) {
     505                ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_56;
     506        }
     507
     508        if (!(flags & NTLMSSP_NEGOTIATE_KEY_EXCH)) {
     509                ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_KEY_EXCH;
     510        }
     511
     512        if (!(flags & NTLMSSP_NEGOTIATE_SIGN)) {
     513                ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_SIGN;
     514        }
     515
     516        if (!(flags & NTLMSSP_NEGOTIATE_SEAL)) {
     517                ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_SEAL;
     518        }
     519
     520        if ((flags & NTLMSSP_REQUEST_TARGET)) {
     521                ntlmssp_state->neg_flags |= NTLMSSP_REQUEST_TARGET;
     522        }
     523
     524        missing_flags &= ~ntlmssp_state->neg_flags;
     525        if (missing_flags != 0) {
     526                NTSTATUS status = NT_STATUS_RPC_SEC_PKG_ERROR;
     527                DEBUG(1, ("%s: Got challenge flags[0x%08x] "
     528                          "- possible downgrade detected! "
     529                          "missing_flags[0x%08x] - %s\n",
     530                          __func__,
     531                          (unsigned)flags,
     532                          (unsigned)missing_flags,
     533                          nt_errstr(status)));
     534                debug_ntlmssp_flags(missing_flags);
     535                DEBUGADD(4, ("neg_flags[0x%08x]\n",
     536                             (unsigned)ntlmssp_state->neg_flags));
     537                debug_ntlmssp_flags(ntlmssp_state->neg_flags);
     538
     539                return status;
     540        }
     541
     542        return NT_STATUS_OK;
    423543}
    424544
     
    449569        NTSTATUS nt_status = NT_STATUS_OK;
    450570
     571        if (!msrpc_parse(ntlmssp_state, &reply, "CdBd",
     572                         "NTLMSSP",
     573                         &ntlmssp_command,
     574                         &server_domain_blob,
     575                         &chal_flags)) {
     576                DEBUG(1, ("Failed to parse the NTLMSSP Challenge: (#1)\n"));
     577                dump_data(2, reply.data, reply.length);
     578
     579                return NT_STATUS_INVALID_PARAMETER;
     580        }
     581        data_blob_free(&server_domain_blob);
     582
     583        DEBUG(3, ("Got challenge flags:\n"));
     584        debug_ntlmssp_flags(chal_flags);
     585
     586        nt_status = ntlmssp3_handle_neg_flags(ntlmssp_state, chal_flags);
     587        if (!NT_STATUS_IS_OK(nt_status)) {
     588                return nt_status;
     589        }
     590
    451591        if (ntlmssp_state->use_ccache) {
    452592                struct wbcCredentialCacheParams params;
     
    498638
    499639noccache:
    500 
    501         if (!msrpc_parse(ntlmssp_state, &reply, "CdBd",
    502                          "NTLMSSP",
    503                          &ntlmssp_command,
    504                          &server_domain_blob,
    505                          &chal_flags)) {
    506                 DEBUG(1, ("Failed to parse the NTLMSSP Challenge: (#1)\n"));
    507                 dump_data(2, reply.data, reply.length);
    508 
    509                 return NT_STATUS_INVALID_PARAMETER;
    510         }
    511640
    512641        if (DEBUGLEVEL >= 10) {
     
    525654                }
    526655        }
    527 
    528         data_blob_free(&server_domain_blob);
    529 
    530         DEBUG(3, ("Got challenge flags:\n"));
    531         debug_ntlmssp_flags(chal_flags);
    532 
    533         ntlmssp_handle_neg_flags(ntlmssp_state, chal_flags, lp_client_lanman_auth());
    534656
    535657        if (ntlmssp_state->unicode) {
     
    770892
    771893        ntlmssp_state->use_ntlmv2 = use_ntlmv2;
     894        ntlmssp_state->allow_lm_key = lp_client_lanman_auth();
    772895
    773896        ntlmssp_state->expected_state = NTLMSSP_INITIAL;
     
    781904                NTLMSSP_REQUEST_TARGET;
    782905
     906        if (ntlmssp_state->use_ntlmv2) {
     907                ntlmssp_state->allow_lm_key = false;
     908        }
     909
    783910        ntlmssp_state->client.netbios_name = talloc_strdup(ntlmssp_state, netbios_name);
    784911        if (!ntlmssp_state->client.netbios_name) {
Note: See TracChangeset for help on using the changeset viewer.