[SCM] Samba Shared Repository - branch v4-12-stable updated

Karolin Seeger kseeger at samba.org
Fri Sep 18 11:52:09 UTC 2020


The branch, v4-12-stable has been updated
       via  356c036ef15 VERSION: Disable GIT_SNAPSHOT for 4.12.7 release.
       via  527a5df295d WHATSNEW: Add release notes for Samba 4.12.7.
       via  04d316f3d51 CVE-2020-1472(ZeroLogon): s4 torture rpc: repeated bytes in client challenge
       via  3eeb5671b80 CVE-2020-1472(ZeroLogon): s4 torture rpc: Test empty machine acct pwd
       via  512060e37ee CVE-2020-1472(ZeroLogon): docs-xml: document 'server require schannel:COMPUTERACCOUNT'
       via  a26ee2bf94a CVE-2020-1472(ZeroLogon): s3:rpc_server/netlogon: log warnings about unsecure configurations
       via  f3f792b8eab CVE-2020-1472(ZeroLogon): s3:rpc_server/netlogon: support "server require schannel:WORKSTATION$ = no"
       via  2462fa5f30e CVE-2020-1472(ZeroLogon): s3:rpc_server/netlogon: refactor dcesrv_netr_creds_server_step_check()
       via  8c5940223e1 CVE-2020-1472(ZeroLogon): s4:rpc_server/netlogon: log warnings about unsecure configurations
       via  e4e0094fdbd CVE-2020-1472(ZeroLogon): s4:rpc_server/netlogon: support "server require schannel:WORKSTATION$ = no"
       via  1a03f011914 CVE-2020-1472(ZeroLogon): s4:rpc_server/netlogon: refactor dcesrv_netr_creds_server_step_check()
       via  e75cfccb1c5 CVE-2020-1472(ZeroLogon): s3:rpc_server/netlogon: protect netr_ServerPasswordSet2 against unencrypted passwords
       via  dac81bdde6a CVE-2020-1472(ZeroLogon): s3:rpc_server/netlogon: Fix mem leak onto p->mem_ctx in error path of _netr_ServerPasswordSet2().
       via  0f4d98c1a2e CVE-2020-1472(ZeroLogon): s4:rpc_server/netlogon: protect netr_ServerPasswordSet2 against unencrypted passwords
       via  e0e2d5911f5 CVE-2020-1472(ZeroLogon): libcli/auth: reject weak client challenges in netlogon_creds_server_init()
       via  ef49b5d0911 CVE-2020-1472(ZeroLogon): libcli/auth: add netlogon_creds_is_random_challenge() to avoid weak values
       via  0371ca12772 CVE-2020-1472(ZeroLogon): s4:rpc_server:netlogon: make use of netlogon_creds_random_challenge()
       via  88d4e02c6b1 CVE-2020-1472(ZeroLogon): s3:rpc_server:netlogon: make use of netlogon_creds_random_challenge()
       via  daeb1bebcea CVE-2020-1472(ZeroLogon): libcli/auth: make use of netlogon_creds_random_challenge() in netlogon_creds_cli.c
       via  d92c031f69a CVE-2020-1472(ZeroLogon): s4:torture/rpc: make use of netlogon_creds_random_challenge()
       via  e862b4ce567 CVE-2020-1472(ZeroLogon): libcli/auth: add netlogon_creds_random_challenge()
       via  6b8d52984e5 VERSION: Bump version up to 4.12.7...
      from  8d9dd75abca VERSION: Disable GIT_SNAPSHOT for the 4.12.6 release.

https://git.samba.org/?p=samba.git;a=shortlog;h=v4-12-stable


- Log -----------------------------------------------------------------
commit 356c036ef15b9790570e151cd1180910b4d35c18
Author: Karolin Seeger <kseeger at samba.org>
Date:   Fri Sep 18 12:43:06 2020 +0200

    VERSION: Disable GIT_SNAPSHOT for 4.12.7 release.
    
    Signed-off-by: Karolin Seeger <kseeger at samba.org>

commit 527a5df295d45ca72f0da002db0bb70332059672
Author: Karolin Seeger <kseeger at samba.org>
Date:   Fri Sep 18 12:17:36 2020 +0200

    WHATSNEW: Add release notes for Samba 4.12.7.
    
    CVE-2020-1472: Samba impact of "ZeroLogon".
    
    Signed-off-by: Karolin Seeger <kseeger at samba.org>

commit 04d316f3d510152c6ff052f62fa7eddd451a1b6b
Author: Gary Lockyer <gary at catalyst.net.nz>
Date:   Fri Sep 18 15:57:34 2020 +1200

    CVE-2020-1472(ZeroLogon): s4 torture rpc: repeated bytes in client challenge
    
    Ensure that client challenges with the first 5 bytes identical are
    rejected.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497
    
    Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>
    
    [abartlet at samba.org: backported from master as test order was flipped]

commit 3eeb5671b8076b22a67c34153d2f0899a02e7a88
Author: Gary Lockyer <gary at catalyst.net.nz>
Date:   Fri Sep 18 12:39:54 2020 +1200

    CVE-2020-1472(ZeroLogon): s4 torture rpc: Test empty machine acct pwd
    
    Ensure that an empty machine account password can't be set by
    netr_ServerPasswordSet2
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497
    
    Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>

commit 512060e37ee996fc5a32dc374d7d47957c5081ef
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Sep 17 17:27:54 2020 +0200

    CVE-2020-1472(ZeroLogon): docs-xml: document 'server require schannel:COMPUTERACCOUNT'
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit a26ee2bf94a2d13a7fd31edd6a8e5d33e55fb0e2
Author: Günther Deschner <gd at samba.org>
Date:   Thu Sep 17 14:42:52 2020 +0200

    CVE-2020-1472(ZeroLogon): s3:rpc_server/netlogon: log warnings about unsecure configurations
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497
    
    Pair-Programmed-With: Stefan Metzmacher <metze at samba.org>
    
    Signed-off-by: Günther Deschner <gd at samba.org>
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit f3f792b8eabe4fc833363d1e8159ffd754279f1f
Author: Günther Deschner <gd at samba.org>
Date:   Thu Sep 17 14:23:16 2020 +0200

    CVE-2020-1472(ZeroLogon): s3:rpc_server/netlogon: support "server require schannel:WORKSTATION$ = no"
    
    This allows to add expections for individual workstations, when using "server schannel = yes".
    "server schannel = auto" is very insecure and will be removed soon.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497
    
    Pair-Programmed-With: Stefan Metzmacher <metze at samba.org>
    
    Signed-off-by: Günther Deschner <gd at samba.org>
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit 2462fa5f30e002e69bc3b6f75aafe0c720151769
Author: Günther Deschner <gd at samba.org>
Date:   Thu Sep 17 14:57:22 2020 +0200

    CVE-2020-1472(ZeroLogon): s3:rpc_server/netlogon: refactor dcesrv_netr_creds_server_step_check()
    
    We should debug more details about the failing request.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497
    
    Pair-Programmed-With: Stefan Metzmacher <metze at samba.org>
    
    Signed-off-by: Günther Deschner <gd at samba.org>
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit 8c5940223e11eb926553f1a9642a4f7805686618
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Sep 17 13:37:26 2020 +0200

    CVE-2020-1472(ZeroLogon): s4:rpc_server/netlogon: log warnings about unsecure configurations
    
    This should give admins wawrnings until they have a secure
    configuration.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Günther Deschner <gd at samba.org>

commit e4e0094fdbdf7b85da1cd10b78568801d0557b26
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Sep 16 10:56:53 2020 +0200

    CVE-2020-1472(ZeroLogon): s4:rpc_server/netlogon: support "server require schannel:WORKSTATION$ = no"
    
    This allows to add expections for individual workstations, when using "server schannel = yes".
    "server schannel = auto" is very insecure and will be removed soon.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit 1a03f0119144c8af8e89cdb7d0c3563be20c7a66
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Sep 16 10:18:45 2020 +0200

    CVE-2020-1472(ZeroLogon): s4:rpc_server/netlogon: refactor dcesrv_netr_creds_server_step_check()
    
    We should debug more details about the failing request.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit e75cfccb1c5d91be12123f7e901a5111f1256352
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Sep 16 12:53:50 2020 -0700

    CVE-2020-1472(ZeroLogon): s3:rpc_server/netlogon: protect netr_ServerPasswordSet2 against unencrypted passwords
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497
    
    Pair-Programmed-With: Stefan Metzmacher <metze at samba.org>
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit dac81bdde6a881b09d6cb3191c119c87381a7c4a
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Sep 16 12:48:21 2020 -0700

    CVE-2020-1472(ZeroLogon): s3:rpc_server/netlogon: Fix mem leak onto p->mem_ctx in error path of _netr_ServerPasswordSet2().
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit 0f4d98c1a2eb157677e16cf925e5095d481da8b1
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Sep 16 19:20:25 2020 +0200

    CVE-2020-1472(ZeroLogon): s4:rpc_server/netlogon: protect netr_ServerPasswordSet2 against unencrypted passwords
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit e0e2d5911f554b4abe508283096fbd1b1e9698e4
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Sep 16 16:17:29 2020 +0200

    CVE-2020-1472(ZeroLogon): libcli/auth: reject weak client challenges in netlogon_creds_server_init()
    
    This implements the note from MS-NRPC 3.1.4.1 Session-Key Negotiation:
    
     7. If none of the first 5 bytes of the client challenge is unique, the
        server MUST fail session-key negotiation without further processing of
        the following steps.
    
    It lets ./zerologon_tester.py from
    https://github.com/SecuraBV/CVE-2020-1472.git
    report: "Attack failed. Target is probably patched."
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit ef49b5d0911aae59cb4dad8bdcbd966d4167522b
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Sep 16 16:15:26 2020 +0200

    CVE-2020-1472(ZeroLogon): libcli/auth: add netlogon_creds_is_random_challenge() to avoid weak values
    
    This is the check Windows is using, so we won't generate challenges,
    which are rejected by Windows DCs (and future Samba DCs).
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit 0371ca12772e0ec8bd62810cf040cfd8e841116b
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Sep 16 16:10:53 2020 +0200

    CVE-2020-1472(ZeroLogon): s4:rpc_server:netlogon: make use of netlogon_creds_random_challenge()
    
    This is not strictly needed, but makes things more clear.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit 88d4e02c6b14c93b5b3fc0712416057989f63a11
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Sep 16 16:10:53 2020 +0200

    CVE-2020-1472(ZeroLogon): s3:rpc_server:netlogon: make use of netlogon_creds_random_challenge()
    
    This is not strictly needed, but makes things more clear.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit daeb1bebcea08d2ce3467743fd092f1826c3fb6e
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Sep 16 16:08:38 2020 +0200

    CVE-2020-1472(ZeroLogon): libcli/auth: make use of netlogon_creds_random_challenge() in netlogon_creds_cli.c
    
    This will avoid getting rejected by the server if we generate
    a weak challenge.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit d92c031f69afaaeef9a1f69d644301086d5cd964
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Sep 16 16:07:30 2020 +0200

    CVE-2020-1472(ZeroLogon): s4:torture/rpc: make use of netlogon_creds_random_challenge()
    
    This will avoid getting flakey tests once our server starts to
    reject weak challenges.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit e862b4ce5678ce19d7d529fd76cfc4e67195ed10
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Sep 16 16:04:57 2020 +0200

    CVE-2020-1472(ZeroLogon): libcli/auth: add netlogon_creds_random_challenge()
    
    It's good to have just a single isolated function that will generate
    random challenges, in future we can add some logic in order to
    avoid weak values, which are likely to be rejected by a server.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 VERSION                                         |   2 +-
 WHATSNEW.txt                                    | 107 +++++-
 docs-xml/smbdotconf/security/serverschannel.xml |  69 +++-
 libcli/auth/credentials.c                       |  44 ++-
 libcli/auth/netlogon_creds_cli.c                |   3 +-
 libcli/auth/proto.h                             |   3 +
 libcli/auth/wscript_build                       |   2 +-
 source3/rpc_server/netlogon/srv_netlog_nt.c     | 212 +++++++++++-
 source4/rpc_server/netlogon/dcerpc_netlogon.c   | 175 +++++++++-
 source4/torture/rpc/lsa.c                       |   2 +-
 source4/torture/rpc/netlogon.c                  | 433 ++++++++++++++++++++----
 11 files changed, 941 insertions(+), 111 deletions(-)


Changeset truncated at 500 lines:

diff --git a/VERSION b/VERSION
index ea5f2684baf..d54bada6061 100644
--- a/VERSION
+++ b/VERSION
@@ -25,7 +25,7 @@
 ########################################################
 SAMBA_VERSION_MAJOR=4
 SAMBA_VERSION_MINOR=12
-SAMBA_VERSION_RELEASE=6
+SAMBA_VERSION_RELEASE=7
 
 ########################################################
 # If a official release has a serious bug              #
diff --git a/WHATSNEW.txt b/WHATSNEW.txt
index dfeb80b6a6b..4eac328a7c1 100644
--- a/WHATSNEW.txt
+++ b/WHATSNEW.txt
@@ -1,3 +1,106 @@
+                   ==============================
+                   Release Notes for Samba 4.12.7
+                         September 18, 2020
+                   ==============================
+
+
+This is a security release in order to address the following defect:
+
+o CVE-2020-1472: Unauthenticated domain takeover via netlogon ("ZeroLogon").
+
+The following applies to Samba used as domain controller only (most
+seriously the Active Directory DC, but also the classic/NT4-style DC).
+
+Installations running Samba as a file server only are not directly
+affected by this flaw, though they may need configuration changes to
+continue to talk to domain controllers (see "file servers and domain
+members" below).
+
+The netlogon protocol contains a flaw that allows an authentication
+bypass. This was reported and patched by Microsoft as CVE-2020-1472.
+Since the bug is a protocol level flaw, and Samba implements the
+protocol, Samba is also vulnerable.
+
+However, since version 4.8 (released in March 2018), the default
+behaviour of Samba has been to insist on a secure netlogon channel,
+which is a sufficient fix against the known exploits. This default is
+equivalent to having 'server schannel = yes' in the smb.conf.
+
+Therefore versions 4.8 and above are not vulnerable unless they have
+the smb.conf lines 'server schannel = no' or 'server schannel = auto'.
+
+Samba versions 4.7 and below are vulnerable unless they have 'server
+schannel = yes' in the smb.conf.
+
+Note each domain controller needs the correct settings in its smb.conf.
+
+Vendors supporting Samba 4.7 and below are advised to patch their
+installations and packages to add this line to the [global] section if
+their smb.conf file.
+
+The 'server schannel = yes' smb.conf line is equivalent to Microsoft's
+'FullSecureChannelProtection=1' registry key, the introduction of
+which we understand forms the core of Microsoft's fix.
+
+Some domains employ third-party software that will not work with a
+'server schannel = yes'. For these cases patches are available that
+allow specific machines to use insecure netlogon. For example, the
+following smb.conf:
+
+   server schannel = yes
+   server require schannel:triceratops$ = no
+   server require schannel:greywacke$ = no
+
+will allow only "triceratops$" and "greywacke$" to avoid schannel.
+
+More details can be found here:
+https://www.samba.org/samba/security/CVE-2020-1472.html
+
+
+Changes since 4.12.6
+--------------------
+
+o  Jeremy Allison <jra at samba.org>
+   * BUG 14497: CVE-2020-1472(ZeroLogon): s3:rpc_server/netlogon: Protect
+     netr_ServerPasswordSet2 against unencrypted passwords.
+
+o  Günther Deschner <gd at samba.org>
+   * BUG 14497: CVE-2020-1472(ZeroLogon): s3:rpc_server/netlogon: Support
+     "server require schannel:WORKSTATION$ = no" about unsecure configurations.
+
+o  Gary Lockyer <gary at catalyst.net.nz>
+   * BUG 14497: CVE-2020-1472(ZeroLogon): s4 torture rpc: repeated bytes in
+     client challenge.
+
+o  Stefan Metzmacher <metze at samba.org>
+   * BUG 14497: CVE-2020-1472(ZeroLogon): libcli/auth: Reject weak client
+     challenges in netlogon_creds_server_init()
+     "server require schannel:WORKSTATION$ = no".
+
+
+#######################################
+Reporting bugs & Development Discussion
+#######################################
+
+Please discuss this release on the samba-technical mailing list or by
+joining the #samba-technical IRC channel on irc.freenode.net.
+
+If you do report problems then please try to send high quality
+feedback. If you don't provide vital information to help us track down
+the problem then you will probably be ignored.  All bug reports should
+be filed under the Samba 4.1 and newer product in the project's Bugzilla
+database (https://bugzilla.samba.org/).
+
+
+======================================================================
+== Our Code, Our Bugs, Our Responsibility.
+== The Samba Team
+======================================================================
+
+
+Release notes for older releases follow:
+----------------------------------------
+
                    ==============================
                    Release Notes for Samba 4.12.6
                           August 13, 2020
@@ -69,8 +172,8 @@ database (https://bugzilla.samba.org/).
 ======================================================================
 
 
-Release notes for older releases follow:
-----------------------------------------
+----------------------------------------------------------------------
+
 
                    ==============================
                    Release Notes for Samba 4.12.5
diff --git a/docs-xml/smbdotconf/security/serverschannel.xml b/docs-xml/smbdotconf/security/serverschannel.xml
index 489492d79b1..b682d086f76 100644
--- a/docs-xml/smbdotconf/security/serverschannel.xml
+++ b/docs-xml/smbdotconf/security/serverschannel.xml
@@ -7,26 +7,65 @@
 <description>
 
     <para>
-	This option is deprecated with Samba 4.8 and will be removed in future.
-	At the same time the default changed to yes, which will be the
-	hardcoded behavior in future. If you have the need for the behavior of "auto"
-	to be kept, please file a bug at https://bugzilla.samba.org.
+	This option is deprecated and will be removed in future,
+	as it is a security problem if not set to "yes" (which will be
+	the hardcoded behavior in future).
     </para>
 
     <para>
-	This controls whether the server offers or even demands the use of the netlogon schannel.
-	<smbconfoption name="server schannel">no</smbconfoption> does not offer the schannel, <smbconfoption
-	name="server schannel">auto</smbconfoption> offers the schannel but does not enforce it, and <smbconfoption
-	name="server schannel">yes</smbconfoption> denies access if the client is not able to speak netlogon schannel.
-	This is only the case for Windows NT4 before SP4.
-	</para>
-
+	Samba will complain in the log files at log level 0,
+	about the security problem if the option is not set to "yes".
+    </para>
     <para>
-	Please note that with this set to <literal>no</literal>, you will have to apply the WindowsXP
-	<filename>WinXP_SignOrSeal.reg</filename> registry patch found in the docs/registry subdirectory of the Samba distribution tarball.
-	</para>
+	See CVE-2020-1472(ZeroLogon) https://bugzilla.samba.org/show_bug.cgi?id=14497
+    </para>
+
+    <para>If you still have legacy domain members use the <smbconfoption name="server require schannel:COMPUTERACCOUNT"/> option.
+    </para>
+
+    <para>This option yields precedence to the <smbconfoption name="server require schannel:COMPUTERACCOUNT"/> option.</para>
+
 </description>
 
 <value type="default">yes</value>
-<value type="example">auto</value>
+</samba:parameter>
+
+<samba:parameter name="server require schannel:COMPUTERACCOUNT"
+                 context="G"
+                 type="string"
+                 xmlns:samba="http://www.samba.org/samba/DTD/samba-doc">
+<description>
+
+    <para>If you still have legacy domain members, which required "server schannel = auto" before,
+	it is possible to specify explicit expection per computer account
+	by using 'server require schannel:COMPUTERACCOUNT = no' as option.
+	Note that COMPUTERACCOUNT has to be the sAMAccountName value of
+	the computer account (including the trailing '$' sign).
+    </para>
+
+    <para>
+	Samba will complain in the log files at log level 0,
+	about the security problem if the option is not set to "no",
+	but the related computer is actually using the netlogon
+	secure channel (schannel) feature.
+    </para>
+
+    <para>
+	Samba will warn in the log files at log level 5,
+	if a setting is still needed for the specified computer account.
+    </para>
+
+    <para>
+	See CVE-2020-1472(ZeroLogon) https://bugzilla.samba.org/show_bug.cgi?id=14497
+    </para>
+
+    <para>This option takes precedence to the <smbconfoption name="server schannel"/> option.</para>
+
+    <programlisting>
+	server require schannel:LEGACYCOMPUTER1$ = no
+	server require schannel:NASBOX$ = no
+	server require schannel:LEGACYCOMPUTER2$ = no
+    </programlisting>
+</description>
+
 </samba:parameter>
diff --git a/libcli/auth/credentials.c b/libcli/auth/credentials.c
index c541eeff470..23339d98bfa 100644
--- a/libcli/auth/credentials.c
+++ b/libcli/auth/credentials.c
@@ -24,6 +24,7 @@
 #include "system/time.h"
 #include "libcli/auth/libcli_auth.h"
 #include "../libcli/security/dom_sid.h"
+#include "lib/util/util_str_escape.h"
 
 #ifndef HAVE_GNUTLS_AES_CFB8
 #include "lib/crypto/aes.h"
@@ -33,6 +34,33 @@
 #include <gnutls/gnutls.h>
 #include <gnutls/crypto.h>
 
+bool netlogon_creds_is_random_challenge(const struct netr_Credential *challenge)
+{
+	/*
+	 * If none of the first 5 bytes of the client challenge is unique, the
+	 * server MUST fail session-key negotiation without further processing
+	 * of the following steps.
+	 */
+
+	if (challenge->data[1] == challenge->data[0] &&
+	    challenge->data[2] == challenge->data[0] &&
+	    challenge->data[3] == challenge->data[0] &&
+	    challenge->data[4] == challenge->data[0])
+	{
+		return false;
+	}
+
+	return true;
+}
+
+void netlogon_creds_random_challenge(struct netr_Credential *challenge)
+{
+	ZERO_STRUCTP(challenge);
+	while (!netlogon_creds_is_random_challenge(challenge)) {
+		generate_random_buffer(challenge->data, sizeof(challenge->data));
+	}
+}
+
 static NTSTATUS netlogon_creds_step_crypt(struct netlogon_creds_CredentialState *creds,
 					  const struct netr_Credential *in,
 					  struct netr_Credential *out)
@@ -677,7 +705,7 @@ struct netlogon_creds_CredentialState *netlogon_creds_server_init(TALLOC_CTX *me
 
 	struct netlogon_creds_CredentialState *creds = talloc_zero(mem_ctx, struct netlogon_creds_CredentialState);
 	NTSTATUS status;
-
+	bool ok;
 
 	if (!creds) {
 		return NULL;
@@ -690,6 +718,20 @@ struct netlogon_creds_CredentialState *netlogon_creds_server_init(TALLOC_CTX *me
 	dump_data_pw("Server chall", server_challenge->data, sizeof(server_challenge->data));
 	dump_data_pw("Machine Pass", machine_password->hash, sizeof(machine_password->hash));
 
+	ok = netlogon_creds_is_random_challenge(client_challenge);
+	if (!ok) {
+		DBG_WARNING("CVE-2020-1472(ZeroLogon): "
+			    "non-random client challenge rejected for "
+			    "client_account[%s] client_computer_name[%s]\n",
+			    log_escape(mem_ctx, client_account),
+			    log_escape(mem_ctx, client_computer_name));
+		dump_data(DBGLVL_WARNING,
+			  client_challenge->data,
+			  sizeof(client_challenge->data));
+		talloc_free(creds);
+		return NULL;
+	}
+
 	creds->computer_name = talloc_strdup(creds, client_computer_name);
 	if (!creds->computer_name) {
 		talloc_free(creds);
diff --git a/libcli/auth/netlogon_creds_cli.c b/libcli/auth/netlogon_creds_cli.c
index 407cb471cbc..12cb3149ff6 100644
--- a/libcli/auth/netlogon_creds_cli.c
+++ b/libcli/auth/netlogon_creds_cli.c
@@ -1177,8 +1177,7 @@ static void netlogon_creds_cli_auth_challenge_start(struct tevent_req *req)
 
 	TALLOC_FREE(state->creds);
 
-	generate_random_buffer(state->client_challenge.data,
-			       sizeof(state->client_challenge.data));
+	netlogon_creds_random_challenge(&state->client_challenge);
 
 	subreq = dcerpc_netr_ServerReqChallenge_send(state, state->ev,
 						state->binding_handle,
diff --git a/libcli/auth/proto.h b/libcli/auth/proto.h
index 88f4a7c6c50..a62668f088f 100644
--- a/libcli/auth/proto.h
+++ b/libcli/auth/proto.h
@@ -13,6 +13,9 @@
 
 /* The following definitions come from /home/jeremy/src/samba/git/master/source3/../source4/../libcli/auth/credentials.c  */
 
+bool netlogon_creds_is_random_challenge(const struct netr_Credential *challenge);
+void netlogon_creds_random_challenge(struct netr_Credential *challenge);
+
 NTSTATUS netlogon_creds_des_encrypt_LMKey(struct netlogon_creds_CredentialState *creds,
 					  struct netr_LMSessionKey *key);
 NTSTATUS netlogon_creds_des_decrypt_LMKey(struct netlogon_creds_CredentialState *creds,
diff --git a/libcli/auth/wscript_build b/libcli/auth/wscript_build
index 41937623630..2a6a7468e45 100644
--- a/libcli/auth/wscript_build
+++ b/libcli/auth/wscript_build
@@ -18,7 +18,7 @@ bld.SAMBA_SUBSYSTEM('NTLM_CHECK',
 
 bld.SAMBA_SUBSYSTEM('LIBCLI_AUTH',
 	source='credentials.c session.c smbencrypt.c smbdes.c',
-	public_deps='MSRPC_PARSE gnutls GNUTLS_HELPERS',
+	public_deps='MSRPC_PARSE gnutls GNUTLS_HELPERS util_str_escape',
 	public_headers='credentials.h:domain_credentials.h'
 	)
 
diff --git a/source3/rpc_server/netlogon/srv_netlog_nt.c b/source3/rpc_server/netlogon/srv_netlog_nt.c
index 52b17c10e61..9ef74447b84 100644
--- a/source3/rpc_server/netlogon/srv_netlog_nt.c
+++ b/source3/rpc_server/netlogon/srv_netlog_nt.c
@@ -47,6 +47,7 @@
 #include "../lib/tsocket/tsocket.h"
 #include "lib/param/param.h"
 #include "libsmb/dsgetdcname.h"
+#include "lib/util/util_str_escape.h"
 
 extern userdom_struct current_user_info;
 
@@ -840,8 +841,7 @@ NTSTATUS _netr_ServerReqChallenge(struct pipes_struct *p,
 
 	pipe_state->client_challenge = *r->in.credentials;
 
-	generate_random_buffer(pipe_state->server_challenge.data,
-			       sizeof(pipe_state->server_challenge.data));
+	netlogon_creds_random_challenge(&pipe_state->server_challenge);
 
 	*r->out.return_credentials = pipe_state->server_challenge;
 
@@ -1073,20 +1073,25 @@ static NTSTATUS netr_creds_server_step_check(struct pipes_struct *p,
 {
 	NTSTATUS status;
 	bool schannel_global_required = (lp_server_schannel() == true) ? true:false;
+	bool schannel_required = schannel_global_required;
+	const char *explicit_opt = NULL;
 	struct loadparm_context *lp_ctx;
+	struct netlogon_creds_CredentialState *creds = NULL;
+	enum dcerpc_AuthType auth_type = DCERPC_AUTH_TYPE_NONE;
+	uint16_t opnum = p->opnum;
+	const char *opname = "<unknown>";
+	static bool warned_global_once = false;
 
 	if (creds_out != NULL) {
 		*creds_out = NULL;
 	}
 
-	if (schannel_global_required) {
-		if (p->auth.auth_type != DCERPC_AUTH_TYPE_SCHANNEL) {
-			DBG_ERR("[%s] is not using schannel\n",
-				computer_name);
-			return NT_STATUS_ACCESS_DENIED;
-		}
+	if (opnum < ndr_table_netlogon.num_calls) {
+		opname = ndr_table_netlogon.calls[opnum].name;
 	}
 
+	auth_type = p->auth.auth_type;
+
 	lp_ctx = loadparm_init_s3(mem_ctx, loadparm_s3_helpers());
 	if (lp_ctx == NULL) {
 		DEBUG(0, ("loadparm_init_s3 failed\n"));
@@ -1095,9 +1100,97 @@ static NTSTATUS netr_creds_server_step_check(struct pipes_struct *p,
 
 	status = schannel_check_creds_state(mem_ctx, lp_ctx,
 					    computer_name, received_authenticator,
-					    return_authenticator, creds_out);
+					    return_authenticator, &creds);
 	talloc_unlink(mem_ctx, lp_ctx);
-	return status;
+
+	if (!NT_STATUS_IS_OK(status)) {
+		ZERO_STRUCTP(return_authenticator);
+		return status;
+	}
+
+	/*
+	 * We don't use lp_parm_bool(), as we
+	 * need the explicit_opt pointer in order to
+	 * adjust the debug messages.
+	 */
+
+	explicit_opt = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+					    "server require schannel",
+					    creds->account_name,
+					    NULL);
+	if (explicit_opt != NULL) {
+		schannel_required = lp_bool(explicit_opt);
+	}
+
+	if (schannel_required) {
+		if (auth_type == DCERPC_AUTH_TYPE_SCHANNEL) {
+			*creds_out = creds;
+			return NT_STATUS_OK;
+		}
+
+		DBG_ERR("CVE-2020-1472(ZeroLogon): "
+			"%s request (opnum[%u]) without schannel from "
+			"client_account[%s] client_computer_name[%s]\n",
+			opname, opnum,
+			log_escape(mem_ctx, creds->account_name),
+			log_escape(mem_ctx, creds->computer_name));
+		DBG_ERR("CVE-2020-1472(ZeroLogon): Check if option "
+			"'server require schannel:%s = no' is needed! \n",
+			log_escape(mem_ctx, creds->account_name));
+		TALLOC_FREE(creds);
+		ZERO_STRUCTP(return_authenticator);
+		return NT_STATUS_ACCESS_DENIED;
+	}
+
+	if (!schannel_global_required && !warned_global_once) {
+		/*
+		 * We want admins to notice their misconfiguration!
+		 */
+		DBG_ERR("CVE-2020-1472(ZeroLogon): "
+			"Please configure 'server schannel = yes', "
+			"See https://bugzilla.samba.org/show_bug.cgi?id=14497\n");
+		warned_global_once = true;
+	}
+
+	if (auth_type == DCERPC_AUTH_TYPE_SCHANNEL) {
+		DBG_ERR("CVE-2020-1472(ZeroLogon): "
+			"%s request (opnum[%u]) WITH schannel from "
+			"client_account[%s] client_computer_name[%s]\n",
+			opname, opnum,
+			log_escape(mem_ctx, creds->account_name),
+			log_escape(mem_ctx, creds->computer_name));
+		DBG_ERR("CVE-2020-1472(ZeroLogon): "
+			"Option 'server require schannel:%s = no' not needed!?\n",
+			log_escape(mem_ctx, creds->account_name));
+
+		*creds_out = creds;
+		return NT_STATUS_OK;
+	}
+
+	if (explicit_opt != NULL) {
+		DBG_INFO("CVE-2020-1472(ZeroLogon): "
+			 "%s request (opnum[%u]) without schannel from "
+			 "client_account[%s] client_computer_name[%s]\n",
+			 opname, opnum,
+			 log_escape(mem_ctx, creds->account_name),
+			 log_escape(mem_ctx, creds->computer_name));
+		DBG_INFO("CVE-2020-1472(ZeroLogon): "
+			 "Option 'server require schannel:%s = no' still needed!\n",
+			 log_escape(mem_ctx, creds->account_name));
+	} else {
+		DBG_ERR("CVE-2020-1472(ZeroLogon): "
+			"%s request (opnum[%u]) without schannel from "
+			"client_account[%s] client_computer_name[%s]\n",
+			opname, opnum,
+			log_escape(mem_ctx, creds->account_name),
+			log_escape(mem_ctx, creds->computer_name));
+		DBG_ERR("CVE-2020-1472(ZeroLogon): Check if option "
+			"'server require schannel:%s = no' might be needed!\n",
+			log_escape(mem_ctx, creds->account_name));
+	}
+
+	*creds_out = creds;
+	return NT_STATUS_OK;
 }
 
 
@@ -1344,9 +1437,14 @@ NTSTATUS _netr_ServerPasswordSet2(struct pipes_struct *p,
 {
 	NTSTATUS status;
 	struct netlogon_creds_CredentialState *creds = NULL;
-	DATA_BLOB plaintext;
+	DATA_BLOB plaintext = data_blob_null;
+	DATA_BLOB new_password = data_blob_null;
+	size_t confounder_len;
+	DATA_BLOB dec_blob = data_blob_null;


-- 
Samba Shared Repository



More information about the samba-cvs mailing list