打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
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'],0,4) == 'NTLM') //Check whether Authorization Header is valid    {        $message = base64_decode(substr($headers['Authorization'], 5)) //Get NTLM Message from Authrization header        if(substr($message, 0, 8) == "NTLMSSP\x00") //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, 0, $info['header_size']);                $body = substr($result, $info['header_size'], $info['download_content_length']-$info['header_size']);                $c_headers = explode("\r\n", $header);                for($i = 0; $i < (count($c_headers) - 2); $i  )                {                    header($c_headers[$i]);                    if(substr($c_headers[$i], 0, 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, 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>);                $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

我希望它会对你有所帮助.随意评论.

来源:https://www.icode9.com/content-1-252151.html
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
php以post形式发送xml的方法
【新提醒】封装CURL扩展php分享
利用 PHP 和 Follow5 同步腾讯微博 | SimonLeung's Blog
php执行https接口get的方式
php获取通过http协议post提交过来xml数据及解析xml
PHP curl
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服