Hướng dẫn dùng whoami exe trong PHP

Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

whoami

  • Article
  • 03/03/2021
  • 2 minutes to read

In this article

Displays user, group and privileges information for the user who is currently logged on to the local system. If used without parameters, whoami displays the current domain and user name.

Syntax

whoami [/upn | /fqdn | /logonid]
whoami {[/user] [/groups] [/priv]} [/fo ] [/nh]
whoami /all [/fo ] [/nh]

Parameters

ParameterDescription
/upn Displays the user name in user principal name (UPN) format.
/fqdn Displays the user name in fully qualified domain name (FQDN) format.
/logonid Displays the logon ID of the current user.
/user Displays the current domain and user name and the security identifier (SID).
/groups Displays the user groups to which the current user belongs.
/priv Displays the security privileges of the current user.
/fo Specifies the output format. Valid values include:
table Displays output in a table. This is the default value.
list Displays output in a list.
csv Displays output in comma-separated value (CSV) format.
/all Displays all information in the current access token, including the current user name, security identifiers (SID), privileges, and groups that the current user belongs to.
/nh Specifies that the column header should not be displayed in the output. This is valid only for table and CSV formats.
/? Displays help at the command prompt.

Examples

To display the domain and user name of the person who is currently logged on to this computer, type:

whoami

Output similar to the following appears:

DOMAIN1\administrator

To display all of the information in the current access token, type:

whoami /all

Additional References

  • Command-Line Syntax Key

Feedback

Submit and view feedback for

Skip to main content

Nội dung chính

  • In this article
  • Additional References
  • Tìm hiểu khi sử dụng các hàm băm tạo dữ liệu lưu trữ password
  • Sử dụng Salt tăng cường an toàn cho mật khẩu

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

whoami

  • Article
  • 03/03/2021
  • 2 minutes to read

In this article

Displays user, group and privileges information for the user who is currently logged on to the local system. If used without parameters, whoami displays the current domain and user name.

Syntax

whoami [/upn | /fqdn | /logonid]
whoami {[/user] [/groups] [/priv]} [/fo ] [/nh]
whoami /all [/fo ] [/nh]

Parameters

ParameterDescription
/upn Displays the user name in user principal name (UPN) format.
/fqdn Displays the user name in fully qualified domain name (FQDN) format.
/logonid Displays the logon ID of the current user.
/user Displays the current domain and user name and the security identifier (SID).
/groups Displays the user groups to which the current user belongs.
/priv Displays the security privileges of the current user.
/fo Specifies the output format. Valid values include:
table Displays output in a table. This is the default value.
list Displays output in a list.
csv Displays output in comma-separated value (CSV) format.
/all Displays all information in the current access token, including the current user name, security identifiers (SID), privileges, and groups that the current user belongs to.
/nh Specifies that the column header should not be displayed in the output. This is valid only for table and CSV formats.
/? Displays help at the command prompt.

Examples

To display the domain and user name of the person who is currently logged on to this computer, type:

whoami

Output similar to the following appears:

DOMAIN1\administrator

To display all of the information in the current access token, type:

whoami /all

Additional References

  • Command-Line Syntax Key

Feedback

Submit and view feedback for

Tìm hiểu khi sử dụng các hàm băm tạo dữ liệu lưu trữ password

Khi lưu trữ password vào CSDL thường sẽ sử dụng các hàm băm khác nhau được hỗ trợ bởi hệ CSDL hoặc ngôn ngữ lập trình (như MD5, SHA1 ...) để tạo dữ liệu mã hóa, dữ liệu mã hóa đó được lưu vào CSDL. Ví dụ:

$raw_password = 'abc123';
$crypt = md5($raw_password); //e99a18c428cb38d5f260853678922e03

Ví dụ trên, đã sử dụng hàm băm của PHP là md5 để mã hóa password abc123, kết quả mã hóa là e99a18c428cb38d5f260853678922e03

Bởi vì hàm băm tạo ra các giá trị không thể dịch ngược (không có thuật toán để giải giá trị hash e99a18c428cb38d5f260853678922e03 là chuỗi abc123, chỉ duy nhất một cách là thử), nên có cảm giác sẽ an toàn. Tuy nhiên với các mật khẩu yếu, nó có thể bị dò ra dựa trên giá trị băm của các mật khẩu phổ biến biết trước. Như trường hợp trên khi thấy e99a18c428cb38d5f260853678922e03 thì đoán được password là abc123. Để khắc phục điều này có thể sử dụng đến salt

Sử dụng Salt tăng cường an toàn cho mật khẩu

Để phức tạp hóa mật khẩu lưu trữ, thì các mật khẩu gốc trước khi mã hóa được nối thêm các chuỗi, các chuỗi thêm này gọi là salt

Ví dụ:

$raw_password = 'abc123';

//Sinh ra chuỗi dài 32 ngẫu nhiên, cũng cần lưu chuỗi này vào một cột trong DB
$salt = random_bytes(32);

//Sử dụng thêm một salt cố định
$staticSalt = 'G4334#';


$crypt = md5($staticSalt.$raw_password.$salt);

Giờ mật khẩu lưu trữ ở trên phức tạp hơn rất nhiều. Biết được $crypt đoán ra $raw_password là rất khó, kể cả khi là password yếu. Khó mà xây dựng được một từ điển chứa các mã hóa tương ứng với password.

Phiên bản ngắn của câu hỏi:

Sự khác biệt giữa get_current_user();và là exec('whoami');gì?

Phiên bản dài của câu hỏi:

  1. Tôi đang sử dụng Localhost XAMPP trên máy Mac.
  2. Tôi đang sử dụng Apache, xây dựng một trang web dựa trên PHP trong một thư mục (chúng ta hãy gọi nó là folderxyz ) trong thư mục htdocs (var / www trong một số phiên bản Linux + Apache).
  3. Tôi đã thử với kết nối cơ sở dữ liệu, thử nghiệm PDO :: ERRMODE_EXCEPTION được mô tả ở đây: Liên kết

Và tôi gặp lỗi này:

file_put_contents ( PDOErrors.txt ): không mở được luồng: Quyền bị từ chối ...

Vì vậy, tôi đã thực hiện một số thao tác và có vẻ như để khắc phục điều này, tôi cần thay đổi CHMODcài đặt của tệp PDOErrors.txt thành 777.

Tuy nhiên, câu hỏi của tôi là về một thứ khác. Trong quá trình này, tôi nhận ra rằng tôi không hiểu rõ ràng khái niệm về userApache, PHP và MySQL.

  • Hướng dẫn sử dụng PHP nói rằng get_current_user() "Lấy tên của chủ sở hữu của tập lệnh PHP hiện tại" Liên kết
  • Hướng dẫn sử dụng PHP nói rằng exec('whoami')trả về "tên người dùng sở hữu quá trình php / httpd đang chạy" Liên kết
  • Khi tôi sử dụng get_current_user(), tôi nhận được firstnamelastnametên tài khoản của tôi trên máy Mac.
  • Khi tôi sử dụng exec('whoami'), tôi nhận được daemon.

Vì thế...

  1. Mối quan hệ giữa firstnamelastnamevà là daemongì?
  2. Mối quan hệ giữa "chủ sở hữu của tập lệnh PHP hiện tại" và "tên người dùng sở hữu quy trình php / httpd đang chạy" là gì?
  3. Ai cần quyền ghi vào PDOErrors.txt ? Nó có firstnamelastnamehay daemonkhông?
  4. Ai cần quyền ghi vào PDOErrors.txt ? Đó là Apache hay PHP (hoặc cả hai)?
  5. Liệu khái niệm về một roottài khoản giống đơn vị có ở đâu ở đây không?

Chỉnh sửa: Tôi đã cập nhật điều này để phản ánh rằng đó không phải là thư mụcxyz mà tôi phải thay đổi cài đặt CHMOD. Tôi đã phải thay đổi cài đặt cho tệp PDOErrors.txt


Mở ở đây: để tham khảo trong tương lai, tôi đưa ra một câu hỏi song song cho nền tảng Linux tại đây (kèm theo lời giải thích trực quan về những gì đang xảy ra): https://stackoverflow.com/questions/31389892/why-is-the-output- www-data-in-one-case-and-root-in-another

17 hữu ích 1 bình luận 18k xem chia sẻ