PHP单一登录使用NTLMv2
发布时间:2020-12-13 17:23:54 所属栏目:PHP教程 来源:网络整理
导读:我有一个nginx Web服务器,使用php-fpm执行脚本,我想获取浏览服务器的客户端的NTLMv2凭据.我在本地网络中有一个代理服务器来验证我的用户.问题是,如何让nginx服务器进行身份验证,或者 PHP使用NTLMv2获取用户的凭据并传回给我信息?我显然需要知道他们的用户名
我有一个nginx Web服务器,使用php-fpm执行脚本,我想获取浏览服务器的客户端的NTLMv2凭据.我在本地网络中有一个代理服务器来验证我的用户.问题是,如何让nginx服务器进行身份验证,或者
PHP使用NTLMv2获取用户的凭据并传回给我信息?我显然需要知道他们的用户名,至少要确保客户端在系统中获得正确的凭据.
我很好地建立了代理服务器的上游连接,例如我转到/login.php,只要它将有关客户端的信息传递回服务器关于客户端,例如在客户端找到的用户名. Type-3消息,然后我可以在他们的会话中保存这些信息并从那一点开始使用它. 我有一个Linux服务器在局域网内运行nginx,PHP和SQLite.连接到此服务器的计算机都是基于Windows的,使用Windows登录到网络.登录使用NTLMv2身份验证并通过代理访问网络外部的网站,所有客户端必须通过该代理连接到外部Web.我想要做的是使用NTLMv2身份验证信息登录到LAN Web服务器.有关如何做到这一点的任何建议? 解决方法
我认为最简单的方法是在nginx服务器上模拟NTLMv2身份验证,将请求重定向到代理并检查答案.
我无法重现您的设置,因此下面的代码未经过测试但它应该可以工作,或者它应该给您一些帮助. <?php $headers = getallheaders() //Equivalent to apache_request_headers() to get the headers of the request. if(!isset($headers['Authorization'])) //Check Authorization Header { header('HTTP/1.1 401 Unauthorized'); //Return Unauthorized Http-Header (NTLM protocol) header('WWW-Authenticate: NTLM'); //Authenticcation Information (NTLM protocol) } else { if(substr($headers['Authorization'],4) == 'NTLM') //Check whether Authorization Header is valid { $message = base64_decode(substr($headers['Authorization'],5)) //Get NTLM Message from Authrization header if(substr($message,8) == "NTLMSSPx00") //Check whether NTLM Message is valid { if($message[8] == "x01") //Check whether it's type-1-NTLM Message { //$message holds the base64 encoded type-1-NTLM message $ch = curl_init(); //Use cURL to connect to web via proxy curl_setopt($ch,CURLOPT_URL,"http://www.google.com"); curl_setopt($ch,CURLOPT_HTTPHEADER,array('Authorization: '.$headers['Authorization'])); curl_setopt($ch,CURLOPT_PROXY,<Your Proxy Adress>); curl_setopt($ch,CURLOPT_PROXYPORT,<Your Proxy Port>); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); $result = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); $header = substr($result,$info['header_size']); $body = substr($result,$info['header_size'],$info['download_content_length']-$info['header_size']); $c_headers = explode("rn",$header); for($i = 0; $i < (count($c_headers) - 2); $i++) { header($c_headers[$i]); if(substr($c_headers[$i],16) == "WWW-Authenticate") { //Thats your type-2-message header Format: WWW-Authenticate: NTLM <base64-type-2-message> } } } else if ($message[8] == "x03") //Check whether it's type-3-NTLM Message { $ch = curl_init(); //Use cURL to connect to web via proxy curl_setopt($ch,<Your Proxy Port>); $result = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); if($info['CURLINFO_HTTP_CODE'] == 200) { //Authenticated //$msg holds the base64 encoded type-3-NTLM message (which includes username,domain,workstation) } } } } }?> 我使用了NTLM协议的参考:http://davenport.sourceforge.net/ntlm.html 我希望它会对你有所帮助.随意评论. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |