Accueil > > > NTLM GET LOGIN WINDOWS WITH PHP
NTLM GET LOGIN WINDOWS WITH PHP
Information sur la source
Description
Récuperation du login NTLM en php pour une identification de l'user automatique.
(verification du l'user uniquement pour petite application en PHP pour les intranet Windows ;) )
Pour plus d'information : http://www.secusquad.com/ntlm/
Source
- <?php
- /***********************************************************************
-
- ************************************************************************
- *
- * PHP NTLM GET LOGIN
- * Version 0.2.1
- * http://www.secusquad.com/ntlm/
- * Copyright (c) 2004 Nicolas GOLLET ( Nicolas (dot) gollet (at) secusquad (dot) com )
- * Copyright (c) 2004 Flextronics Saint-Etienne
- *
- * This program is free software. You can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License.
- *
- ***********************************************************************/
-
- session_start();
-
- $headers = apache_request_headers(); // Récupération des l'entêtes client
-
- if (@$_SERVER['HTTP_VIA'] != NULL){ // nous verifions si un proxy est utilisé : parceque l'identification par ntlm ne peut pas passer par un proxy
- echo "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 '){ // on vérifit que le client soit en NTLM
-
- $chaine=$headers['Authorization'];
- $chaine=substr($chaine, 5); // recuperation du base64-encoded type1 message
- $chained64=base64_decode($chaine); // decodage base64 dans $chained64
-
- if(ord($chained64{8}) == 1){
- // |_ byte signifiant l'etape du processus d'identification (etape 3)
-
- // verification du drapeau NTLM "0xb2" à l'offset 13 dans le message type-1-message (comp ie 5.5+) :
- if (ord($chained64[13]) != 178){
- echo "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émentaire
- 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ées dans des variable de session
- $_SESSION['Login']=$login;
- header("Location: newpage.php");
- exit;
- }
- else{
- echo "NT Login empty!";
- }
-
-
- }
- }
-
- }
-
- ?>
-
<?php
/***********************************************************************
************************************************************************
*
* PHP NTLM GET LOGIN
* Version 0.2.1
* http://www.secusquad.com/ntlm/
* Copyright (c) 2004 Nicolas GOLLET ( Nicolas (dot) gollet (at) secusquad (dot) com )
* Copyright (c) 2004 Flextronics Saint-Etienne
*
* This program is free software. You can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License.
*
***********************************************************************/
session_start();
$headers = apache_request_headers(); // Récupération des l'entêtes client
if (@$_SERVER['HTTP_VIA'] != NULL){ // nous verifions si un proxy est utilisé : parceque l'identification par ntlm ne peut pas passer par un proxy
echo "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 '){ // on vérifit que le client soit en NTLM
$chaine=$headers['Authorization'];
$chaine=substr($chaine, 5); // recuperation du base64-encoded type1 message
$chained64=base64_decode($chaine); // decodage base64 dans $chained64
if(ord($chained64{8}) == 1){
// |_ byte signifiant l'etape du processus d'identification (etape 3)
// verification du drapeau NTLM "0xb2" à l'offset 13 dans le message type-1-message (comp ie 5.5+) :
if (ord($chained64[13]) != 178){
echo "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émentaire
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ées dans des variable de session
$_SESSION['Login']=$login;
header("Location: newpage.php");
exit;
}
else{
echo "NT Login empty!";
}
}
}
}
?>
Conclusion
Merci de me faire parvenir tous vos commentaires...
Mise à jour ;)
Re mise a jour merci barth pour la modication des commetaires ;)
mise a jour afichage erreur :)
Historique
- 09 août 2004 18:27:15 :
- Verification des Flags NTLM...
Récuperation des infos: host, domaine :)
- 09 août 2004 23:20:36 :
- 02 mars 2005 14:23:14 :
- Ajout du controle proxy bypass
Quelques corrections ;)
- 02 mars 2005 14:27:24 :
- Mise à jour du ZIP ;)
- 22 avril 2005 14:02:27 :
- Modif adresse mail
- 05 mai 2005 01:20:09 :
- 28 mai 2005 18:47:13 :
- Mise à jour @ devant test proxy
- 11 août 2005 23:02:35 :
- Mise a jour de l'url du site de mon script ;)
Sources du même auteur
Sources de la même categorie
SONDAGE - VOTE - POLL (AVEC MYSQL)SONDAGE - VOTE - POLL (AVEC MYSQL) Vous souhaitez inclure un sondage en ligne sur votre site. Certes, l'interface admin n'est pas de toute beauté mais ça fonctionne ;-)
- Gestion/sto...
par hornet_bzz
LISTENGEN GÉNÉRATEUR DE FICHIER PLAYLISTLISTENGEN GÉNÉRATEUR DE FICHIER PLAYLISTLisTenGEN
Générateur de fichier playlist pour webradio
Extension compatible : .pls, .m3u, .m3u8, .ram, .qtl, asx, wax, wpl....
par AGG
IP CALCULATORIP CALCULATOR Cette classe est la version PHP du programme unix ipcalc. Il permet de calculer à partir d'une adresse IP (en binaire, hexadécimal ou au format xxx.xx...
par X_Cli
WHOIS DOMAIN CLASS : LOOKUP & AVAIBILITYWHOIS DOMAIN CLASS : LOOKUP & AVAIBILITYCe script vous permettra de lancer une requette whois. Le whois vous renseigne les informations d'un nom de domaine, et éventuellement vous indique si...
par aKheNathOn
Commentaires et avis
|
Derniers Blogs
L'INTERFACE NATURELLE DE WINDOWS PHONE 7 SERIESL'INTERFACE NATURELLE DE WINDOWS PHONE 7 SERIES par odewit
La tendance est aux interfaces naturelles (NUI), et le keynote de Bill Buxton au MIX l'a bien souligné.
La charte graphique et ergonomique de Windows Phone 7 a donc été entièrement repensée en vue d'obtenir un maximum d'efficacité sur ce point. En re...
Cliquez pour lire la suite de l'article par odewit COMMENT MAPPER UNE VUE SQL SUR UNE COLLECTION DE COMPLEX TYPE?COMMENT MAPPER UNE VUE SQL SUR UNE COLLECTION DE COMPLEX TYPE? par Matthieu MEZIL
Avec EF, les vues doivent être mappées sur des entity types. Le problème c'est que les entity types doivent avoir une clé. Avec EF, nous avons les complex type qui n'ont pas de clé mais les vues ne peuvent pas être mappées dessus. Avec EF4, il est possibl...
Cliquez pour lire la suite de l'article par Matthieu MEZIL [WF4] UN BINDING ACTIVITY/ACTIVITYDESIGNER QUI PASSE MAL?[WF4] UN BINDING ACTIVITY/ACTIVITYDESIGNER QUI PASSE MAL? par JeremyJeanson
Certain d'entre vous on peut être vécu cette situation embarrassante après quelques temps passer avec WF4 : Au début avec mon " ActivityDesigner" , tout allait bien. Et puis un jour j'ai au des problèmes de " Binding" . Alors nous sommes allé sur le site ...
Cliquez pour lire la suite de l'article par JeremyJeanson
Logiciels
Academy System (10.9.4.0)ACADEMY SYSTEM (10.9.4.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Xilisoft Convertisseur Vidéo Ultimate (5.1.39.0305)XILISOFT CONVERTISSEUR VIDéO ULTIMATE (5.1.39.0305)Xilisoft Convertisseur Vidéo Ultimate est un outil puissant de conversion vidéo, facile à utilise... Cliquez pour télécharger Xilisoft Convertisseur Vidéo Ultimate Xilisoft DVD Ripper Ultimate (5.0.64.0304)XILISOFT DVD RIPPER ULTIMATE (5.0.64.0304)Xilisoft DVD Ripper Ultimate est un logiciel excellent pour copier et convertir DVD vers presque ... Cliquez pour télécharger Xilisoft DVD Ripper Ultimate Rigs of Rods (63.3)RIGS OF RODS (63.3)c'est un jeu de multi-simulation camions,autobus voitures, avions, bateaux, hélicoptère avec défo... Cliquez pour télécharger Rigs of Rods
Comparez les prix

HTC Hero
Entre 550€ et 550€
|