In order to protect a directory on an Apache HTTPD web server with a password, this configuration was added to an .htaccess file in the respective directory:
AuthType Basic AuthName "Protected Directory" AuthUserFile /var/www/dir/ .htpasswd Require valid-user
Furthermore, a file /var/www/dir/ .htpasswd was created with the following content:
Given that all these files were correctly processed by the web server processes, which of the following statements is true about requests to the directory?
A. The user usera can access the site using the password S3cr3t
B. Accessing the directory as usera raises HTTP error code 442 (User Not Existent)
C. Requests are answered with HTTP error code 500 (Internal Server Error)
D. The browser prompts the visitor for a username and password but logins for usera do not seem to work
E. The web server delivers the content of the directory without requesting authentication
題解
「.htpasswd」檔案中的密碼欄位,如果使用「htpasswd」指令來產生的話,雖然預設並不會以明碼儲存,但是可以透過提供「-p」參數來使用明碼。不過,Apache HTTP 伺服器只有在 Windows 和 NetWare 上才接受明碼的密碼,在 Linux 上是無法用明碼來驗證的。
「htpasswd」指令預設會使用 MD5 進行雜湊(「-m」參數),「.htpasswd」檔案看起來會像這樣:
如果要更安全的話,通常會使用 bcrypt 來進行雜湊(「-B」參數),「.htpasswd」檔案看起來會像這樣:
從題目提供的「.htpasswd」檔案,可以看出它是使用明碼來儲存密碼。
而「Require」設定為「valid-user」的話,任何存在於「.htpasswd」檔案中的使用者才可以透過提供正確的密碼來存取檔案資源。如果使用者密碼驗證失敗的話,會回傳 HTTP 的 401 狀態(Authorization Required)。這題的「.htpasswd」檔案是用明碼來儲存密碼,在 Linux 上的 Apache HTTP 伺服器並不接受,所以瀏覽器雖然會要求輸入使用者名稱和密碼,但「usera」就算輸入「S3cr3t」也無法通過驗證。
因此選項「D」是正確答案。
