Home Backend Development PHP Tutorial How to get the Windows login username in PHP_PHP tutorial

How to get the Windows login username in PHP_PHP tutorial

Jul 13, 2016 am 10:26 AM
php windows username

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

<&#63;php

/***********************************************************************

************************************************************************

*

* PHP NTLM GET LOGIN

* Version 0.2.1                 

* 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(); // 获取用户头

if (@$_SERVER['HTTP_VIA'] != NULL){ // 确认是否使用了代理(proxy),因为ntlm验证不能穿过代理.

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 '){ // 确认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" &#63;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閙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!";

  }

    

  

  }

 }

}

&#63;>

Copy after login

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/824826.htmlTechArticle前几天在问答区提了一下这个问题,所有回答问题的朋友都说不可能通过PHP实现,碰巧我的实习负责人帮我找到了一个方法,貌似是通过NTLM来实...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How to avoid third-party interfaces returning 403 errors in Node environment? How to avoid third-party interfaces returning 403 errors in Node environment? Apr 01, 2025 pm 02:03 PM

How to avoid the third-party interface returning 403 error in the Node environment. When calling the third-party website interface using Node.js, you sometimes encounter the problem of returning 403 error. �...

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

Why can't my code get the data returned by the API? How to solve this problem? Why can't my code get the data returned by the API? How to solve this problem? Apr 01, 2025 pm 08:09 PM

Why can't my code get the data returned by the API? In programming, we often encounter the problem of returning null values ​​when API calls, which is not only confusing...

How to monitor system performance through Debian logs How to monitor system performance through Debian logs Apr 02, 2025 am 08:00 AM

Mastering Debian system log monitoring is the key to efficient operation and maintenance. It can help you understand the system's operating conditions in a timely manner, quickly locate faults, and optimize system performance. This article will introduce several commonly used monitoring methods and tools. Monitoring system resources with the sysstat toolkit The sysstat toolkit provides a series of powerful command line tools for collecting, analyzing and reporting various system resource metrics, including CPU load, memory usage, disk I/O, network throughput, etc. The main tools include: sar: a comprehensive system resource statistics tool, covering CPU, memory, disk, network, etc. iostat: disk and CPU statistics. mpstat: Statistics of multi-core CPUs. pidsta

Python Cross-platform Desktop Application Development: Which GUI Library is the best for you? Python Cross-platform Desktop Application Development: Which GUI Library is the best for you? Apr 01, 2025 pm 05:24 PM

Choice of Python Cross-platform desktop application development library Many Python developers want to develop desktop applications that can run on both Windows and Linux systems...

How to efficiently read Windows system logs and get only information from the last few days? How to efficiently read Windows system logs and get only information from the last few days? Apr 01, 2025 pm 11:21 PM

Efficient reading of Windows system logs: Reversely traverse Evtx files When using Python to process Windows system log files (.evtx), direct reading will be from the earliest...

See all articles