无为清净楼资源网 Design By www.qnjia.com

前几天在问答区提了一下这个问题,所有回答问题的朋友都说不可能通过PHP实现,碰巧我的实习负责人帮我找到了一个方法,貌似是通过NTLM来实现的,我是新手,对具体原理也知之不详,只是自己测试了一下,很好用.
所以赶快拿出来与大家分享.这是一个法国人写的,所以编码中的注释都是法语,如果有朋友很想了解某行的注释含义,请回帖说明,我可以试着翻译一下.

<"Proxy bypass!";
}
elseif($headers['Authorization'] == NULL){  //si l'entete autorisation est inexistante如果许可头不存在
 header( "HTTP/1.0 401 Unauthorized" );  //envoi au client le mode d'identification
 header( "WWW-Authenticate: NTLM" );  //dans notre cas le NTLM
 exit;    //on quitte
}
if(isset($headers['Authorization']))   //dans le cas d'une authorisation (identification)
{ 
 if(substr($headers['Authorization'],0,5) == 'NTLM '){ // 确认client是否在ntlm下

  $chaine=$headers['Authorization'];   
  $chaine=substr($chaine, 5);  // 获取 base64-encoded type1 信息
  $chained64=base64_decode($chaine); // 解码 base64 到 $chained64
  
  if(ord($chained64{8}) == 1){   
  //   |_ byte signifiant l'etape du processus d'identification (etape 3) 
 
  // verification du drapeau NTLM "0xb2" "NTLM Flag error!";
   exit;
  }

  $retAuth = "NTLMSSP".chr(000).chr(002).chr(000).chr(000).chr(000).chr(000).chr(000).chr(000);
  $retAuth .= chr(000).chr(040).chr(000).chr(000).chr(000).chr(001).chr(130).chr(000).chr(000);
  $retAuth .= chr(000).chr(002).chr(002).chr(002).chr(000).chr(000).chr(000).chr(000).chr(000);
  $retAuth .= chr(000).chr(000).chr(000).chr(000).chr(000).chr(000).chr(000);
  
  $retAuth64 =base64_encode($retAuth); // encode en base64
  $retAuth64 = trim($retAuth64);  // enleve les espaces de debut et de fin
  header( "HTTP/1.0 401 Unauthorized" );  // envoi le nouveau header
  header( "WWW-Authenticate: NTLM $retAuth64" ); // avec l'identification suppl閙entaire
  exit;
  
  }
  
  else if(ord($chained64{8}) == 3){
  //     |_ byte signifiant l'etape du processus d'identification (etape 5)

  // on recupere le domaine
  $lenght_domain = (ord($chained64[31])*256 + ord($chained64[30])); // longueur du domain
  $offset_domain = (ord($chained64[33])*256 + ord($chained64[32])); // position du domain. 
  $domain = str_replace("\0","",substr($chained64, $offset_domain, $lenght_domain)); // decoupage du du domain
  
  //le login
  $lenght_login = (ord($chained64[39])*256 + ord($chained64[38])); // longueur du login.
  $offset_login = (ord($chained64[41])*256 + ord($chained64[40])); // position du login.
  $login = str_replace("\0","",substr($chained64, $offset_login, $lenght_login)); // decoupage du login
  
  if ( $login != NULL){
   // stockage des donn閑s dans des variable de session
   $_SESSION['Login']=$login;
   header("Location: newpage.php");
   exit;
  }
  else{
   echo "NT Login empty!";
  }
   
 
  }
 }
}
?>

标签:
PHP,获取windows用户名

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com