【发布时间】:2018-01-31 06:38:17
【问题描述】:
我需要 NTLM 身份验证来获取 Windows 用户名,这与我当前的功能正常工作。
我面临的唯一问题是,它三次访问了同一页面,这使我的访问日志难以管理(在流量图中弹出),所以在向他们解释之前我想确保如果有任何其他方式来获取 Windows 会话数据(用户名)。
下面是当前代码。
function getSysId() {
$headers = apache_request_headers();
if (!isset($headers['Authorization'])) {
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: NTLM');
exit;
}
$auth = $headers['Authorization'];
if (substr($auth, 0, 5) == 'NTLM ') {
$msg = base64_decode(substr($auth, 5));
if (substr($msg, 0, 8) != "NTLMSSP\x00")
return '';
if ($msg[8] == "\x01") {
$msg2 = "NTLMSSP\x00\x02\x00\x00\x00" .
"\x00\x00\x00\x00" . // target name len/alloc
"\x00\x00\x00\x00" . // target name offset
"\x01\x02\x81\x00" . // flags
"\x00\x00\x00\x00\x00\x00\x00\x00" . // challenge
"\x00\x00\x00\x00\x00\x00\x00\x00" . // context
"\x00\x00\x00\x00\x00\x00\x00\x00"; // target info len/alloc/offset
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: NTLM ' . trim(base64_encode($msg2)));
exit;
} else if ($msg[8] == "\x03") {
function get_msg_str1($msg, $start, $unicode = true) {
$len = (ord($msg[$start + 1]) * 256) + ord($msg[$start]);
$off = (ord($msg[$start + 5]) * 256) + ord($msg[$start + 4]);
if ($unicode)
return str_replace("\0", '', substr($msg, $off, $len));
else
return substr($msg, $off, $len);
}
$user = get_msg_str1($msg, 36);
return $user;
}
}
return false;
}
【问题讨论】:
标签: php apache authentication ntlm