Advertisement
andyipod1437

Untitled

Nov 20th, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. $headers = apache_request_headers();
  5.  
  6. if (!isset($headers['Authorization'])){
  7. header('HTTP/1.1 401 Unauthorized');
  8. header('WWW-Authenticate: NTLM');
  9. exit;
  10. }
  11.  
  12. $auth = $headers['Authorization'];
  13.  
  14. if (substr($auth,0,5) == 'NTLM ') {
  15. $msg = base64_decode(substr($auth, 5));
  16. if (substr($msg, 0, 8) != "NTLMSSP\x00")
  17. die('error header not recognised');
  18.  
  19. if ($msg[8] == "\x01") {
  20. $msg2 = "NTLMSSP\x00\x02\x00\x00\x00".
  21. "\x00\x00\x00\x00". // target name len/alloc
  22. "\x00\x00\x00\x00". // target name offset
  23. "\x01\x02\x81\x00". // flags
  24. "\x11\x22\x33\x44\x55\x66\x77\x88". // challenge
  25. "\x00\x00\x00\x00\x00\x00\x00\x00". // context
  26. "\x00\x00\x00\x00\x00\x00\x00\x00"; // target info len/alloc/offset
  27.  
  28. header('HTTP/1.1 401 Unauthorized');
  29. header('WWW-Authenticate: NTLM '.trim(base64_encode($msg2)));
  30. exit;
  31. }
  32. else if ($msg[8] == "\x03") {
  33. function get_msg_str($msg, $start, $unicode = true) {
  34. $len = (ord($msg[$start+1]) * 256) + ord($msg[$start]);
  35. $off = (ord($msg[$start+5]) * 256) + ord($msg[$start+4]);
  36. if ($unicode)
  37. return str_replace("\0", '', substr($msg, $off, $len));
  38. else
  39. return substr($msg, $off, $len);
  40. }
  41. $user = get_msg_str($msg, 36);
  42. $domain = get_msg_str($msg, 28);
  43. $workstation = get_msg_str($msg, 44);
  44.  
  45. print "You are $user from $domain/$workstation";
  46. }
  47. }
  48.  
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement