简体   繁体   English

使用ldap3 python进行Active Directory身份验证,如何避免明文密码

[英]Active Directory authentication using ldap3 python, how to avoid clear text password

I know the below question has been asked multiple times and answer which i could find is that get SSL certs. 我知道以下问题已被多次询问,我可以找到的答案是获得SSL证书。

But how to go around it without SSL? 但是如何在没有SSL的情况下解决呢?

Here is the problem: 这是问题所在:

I have been implementing a Rest based API which authenticates a user with Active Directory. 我一直在实现基于Rest的API,该API使用Active Directory对用户进行身份验证。

Our security team has concern that passing plain text password from UI to API is a security risk. 我们的安全团队担心将纯文本密码从UI传递到API存在安全风险。

But we are doing it because Active Directory needs password in plain text. 但是我们这样做是因为Active Directory需要纯文本形式的密码。 It just goes in JSON format in a POST request : 它只是在POST请求中采用JSON格式:

{"user":"uname","password":"password"}

Here is the AD auth code that i use from python ldap3 module. 这是我从python ldap3模块使用的AD身份验证代码。

    s = Server(AD_SERVER, port=AD_PORT, use_ssl=True, get_info=ALL)
    c = Connection(s, user=userName, password=password, authentication=NTLM)
    c.bind()

So in above is there a way to send password in any hash or any encrypted format. 因此,以上提供了一种以任何哈希或任何加密格式发送密码的方法。 I am not sure if Active Directory or ldap3 supports such mechanism for this connection. 我不确定Active Directory或ldap3是否支持这种连接机制。

Any leads would be appreciated. 任何线索将不胜感激。

LDAP (or the python ldap3 package) supports a variety of authentication (bind) schemes. LDAP(或python ldap3软件包)支持多种身份验证(绑定)方案。 Some transfer the user's password to the server more or less in plaintext, while others (eg NTLM) use cryptography (to prove that the client represents the user, without transmitting the password to the server, eg like only transmitting a hash of the password convolved with a unique challenge that was issued to the client by the server). 一些用户或多或少以明文形式将用户密码传输到服务器,而其他用户(例如NTLM)使用密码术(以证明客户端代表用户,而没有将密码传输到服务器,例如仅传输卷积的密码哈希)并由服务器向客户端发出独特的挑战)。

The problem is that ldap3 tries to implement its own computation of the challenge-response. 问题是ldap3尝试实现自己的质询响应计算。 (This requires the password to be available to python, and is insecure and inconvenient.) Instead it should utilise the SSP Interface, ie, pass the server's challenge to the client's operating system and let the OS compute the response for sending to the server. (这要求密码可用于python,并且不安全且不便。)相反,它应该利用SSP接口,即将服务器的质询传递给客户端的操作系统,并让OS计算发送给服务器的响应。 The OS will use the credentials from when the user logged on, and does not expose the password to python. 操作系统将使用用户登录时的凭据,并且不会将密码公开给python。

Similarly, the server application should not try to validate the response itself, but instead defer to the server's OS which forwards the challenge/response to the Domain Controller and returns whether they check out. 同样,服务器应用程序不应尝试验证响应本身,而应服从服务器的操作系统,该操作系统将质询/响应转发到域控制器,并返回是否签出。

Some coding will be necessary, but here is an example of python ntlm sspi (applied for http instead of ldap), and there are also some demos in the pywin32 de facto standard library. 一些编码将是必要的,但这里是蟒蛇NTLM SSPI(适用于HTTP,而不是LDAP)的例子,也有一些演示在pywin32事实上的标准库。

Probably however the correct way to do a restful application on a windows domain is to forget about ldap. 但是,在Windows域上执行宁静应用程序的正确方法可能是忘记ldap。 Instead try to enable Integrated Windows Authentication on your webserver, or try something like flask-Kerberos or PyAuthenNTLM2. 而是尝试在您的Web服务器上启用集成Windows身份验证,或尝试使用flask-Kerberos或PyAuthenNTLM2之类的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM