• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 13369
  • Last Modified:

NT User Login Capture

Hi,

I was wondering if there is anyway to capture the NT user Login in PHP. The ASP code is Request.ServerVariables("logon_user"), does anyone know if PHP has somethign similar. I am running PHP, Apache and MySQL as my Intranet server and need to capture the login to provide indivual pupils timetables on login (I work for a school).

Thanks for any help,

Paul
0
doconline
Asked:
doconline
  • 4
  • 3
  • 2
  • +3
1 Solution
 
ShockwaveRKCommented:
Paul,

Login to a website and call the function phpinfo(); in a script. When you find your username in the output you will also find the variable that has your value in it. If not it is not stored in the server vars of your php.

--
Greetz,
Robert, The Netherlands.
0
 
Richard QuadlingSenior Software DeveloperCommented:
Something you could try is adding a line to the NT login script which creates an environment variable with their name.

SET WHOAMI=%USERNAME%

or something similar.

Then, you could use $_ENV['WHOAMI'];

Not very secure, but you could put an encrypted output for the name.
0
 
VGRCommented:
huh ?!?

I thought $_ENV[] was server-side ?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Richard QuadlingSenior Software DeveloperCommented:
Doh!

Of course!

Erm.

He he!

0
 
KriekCommented:
PHP does not support NTLM authentication. ASP does, Java does, Perl does, Python does, but PHP don't =)

However you might try this:

<?php
echo "Your username is: ".$_SERVER["AUTH_USER"];
echo "<br>";
echo "The authentication type is: ".$_SERVER["AUTH_TYPE"];
echo "The digest of your password is: ".$_SERVER["HTTP_AUTHORIZATION"];
echo "<br>";
echo "The username of the server user is: ".$_SERVER["LOGON_USER"];
?>

This will only work under IIS, for Apache you will need to install a additional module (mod_ntlm).
0
 
KriekCommented:
PHP does not support NTLM authentication. ASP does, Java does, Perl does, Python does, but PHP don't =)

However you might try this:

<?php
echo "Your username is: ".$_SERVER["AUTH_USER"];
echo "<br>";
echo "The authentication type is: ".$_SERVER["AUTH_TYPE"];
echo "The digest of your password is: ".$_SERVER["HTTP_AUTHORIZATION"];
echo "<br>";
echo "The username of the server user is: ".$_SERVER["LOGON_USER"];
?>

This will only work under IIS, for Apache you will need to install a additional module (mod_ntlm).
0
 
KriekCommented:
So techically NTLM authentication "is" possible with PHP assuming

A) you run it on a NT/2000/.NET box,

B) IIS is used.
0
 
VGRCommented:
well, there is also the solution of using the HTTP Basic Authentication, or to use cookies...

OR (and this is the best solution), and BECAUSE you know that your customers willcome from a soecific network (so that you've their NT login, for example an Intranet) :
-give each and every client (for example free or automatic download on some index.html page of your site) a small program that runs in the background on their NT box and sends NT auth data along with @IP to the server, thus enabling him to "recognize" the people being connected from the $REMOTE_ADDR afterwards.
At least that's what I would do if I were you 8-)
0
 
psadacCommented:
If all your clients are netbios enabled (generally true) and you just need the username and station, this should help you :

<?php
    /*
     Getting netbios info
     CopyLeft 2002 (GNU GPL V2) by polo
    */    
   
    error_reporting(E_ALL);
   
    /* get the ip of the client */
    if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
 {
     $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
    } else {
     $ip = $_SERVER["REMOTE_ADDR"];
    }
    echo 'ip : '.$ip.'<br>';
   
    /* send a "special" packet */
    $fp = fsockopen('udp://'.$ip, 137);
    fwrite($fp, "\x80b\0\0\0\1\0\0\0\0\0\0 CKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\0\0!\0\1");

    /* wait 2 secs, and get the data */
    socket_set_timeout($fp, 2);
    $data = fread($fp, 256);
   
    /* get netbios records number */
    $nbrec = ord($data[56]);
   
    /* display nebios records : the username is a record of type 3 */
    echo '<table border="1">';
    echo '<tr><th>no</th><th>type</th><th>value</th></tr>';
    for($i = 0; $i < $nbrec; $i++) {
     $offset = 18 * $i;
     printf ("<tr><td>%02d</td><td>%02X</td><td>%s</td></tr>",
         $i,
         ord($data[72 + $offset]),
         trim(substr($data, 57 + $offset, 15)));
    }
    echo '</table>';
?>
0
 
VGRCommented:
hack hack hack hack

wonderful 8-)
0
 
VGRCommented:
So it works ? :D
How amazing :D
It wouldn't work for my machine, I closed those silly ports 8-)
0
 
psadacCommented:
Of course it works, and it's not a hack, it's just netbios that works this way.
special thanks to snort (http://www.snort.org :)
0
 
Timothy GoldenBrand AmbassadorCommented:
psadac,

so how can i use this?

I want to look at the user name and set it to a varialbe then do a few if/then  statements with the variable

How do i set the user name to a variable?

0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 4
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now