PhpMyAdmin ログインを保護するために HTTPS (SSL 証明書) をセットアップする方法
このヒントを紹介するために、クライアント マシンと、前回の記事「変更と安全性」でデータベースのルート ユーザーの資格情報を使用してログインするという無実の間違いを犯したDebian 8 サーバー間の HTTP トラフィックを傍受してみましょう。デフォルトの PhpMyAdmin ログイン URL
前のヒントで述べたように、資格情報を公開したくない場合は、まだこれを実行しないでください。トラフィックのスニッフィングを開始するには、次のコマンドを入力して Enter キーを押しました。
tcpdump port http -l -A | egrep -i 'pass=|pwd=|log=|login=|user=|username=|pw=|passw=|passwd=|password=|pass:|user:|username:|password:|login:|pass |user ' --line-buffered -B20
次の tcpdump の切り詰められた出力でわかるように、ユーザー名とパスワードがプレーン テキスト形式でネットワーク経由で送信されたことに気づくのに、それほど時間はかかりません。下の画像。
root パスワードの一部を青いマークで隠していることに注意してください。
これを回避するには、ログイン ページを証明書で保護しましょう。これを行うには、CentOS ベースのディストリビューションに mod_ssl パッケージをインストールします。
yum install mod_ssl
Debian/Ubuntu のパスと名前を使用しますが、以下のコマンドとパスを置き換えれば、CentOS と RHEL にも同じ手順が有効です。 CentOS と同等のものです。
キーと証明書を保存するディレクトリを作成します。
mkdir /etc/apache2/ssl [On Debian/Ubuntu based systems]
mkdir /etc/httpd/ssl [On CentOS based systems]
キーと証明書を作成します。
----------- On Debian/Ubuntu based systems -----------
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt
----------- On CentOS based systems -----------
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/httpd/ssl/apache.key -out /etc/httpd/ssl/apache.crt
サンプル出力
........................+++
.....................................................+++
writing new private key to '/etc/httpd/ssl/apache.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:IN
State or Province Name (full name) []:Maharashtra
Locality Name (eg, city) [Default City]:Mumbai
Organization Name (eg, company) [Default Company Ltd]:TecMint
Organizational Unit Name (eg, section) []:TecMint
Common Name (eg, your name or your server's hostname) []:TecMint
Email Address []:[email
次に、キーと証明書を確認します。
cd /etc/apache2/ssl/ [On Debian/Ubuntu based systems]
cd /etc/httpd/ssl/ [On CentOS based systems]
ls -l
total 8
-rw-r--r--. 1 root root 1424 Sep 7 15:19 apache.crt
-rw-r--r--. 1 root root 1704 Sep 7 15:19 apache.key
Debian/Ubuntu では、Apache がデフォルト サイト (/etc/apache2/sites-) のポート 443 でリッスンしていることを確認します。 available/000-default.conf) を編集し、VirtualHost 宣言内に SSL 関連の 3 行を追加します。
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
CentOS ベースのディストリビューションでは、Apache にポート 443 でリッスンし、/etc/httpd/conf/ で Listen ディレクティブを探すように指示します。 httpd.conf を開き、その下に上記の行を追加します。
SSLEngine on
SSLCertificateFile /etc/httpd/ssl/apache.crt
SSLCertificateKeyFile /etc/httpd/ssl/apache.key
変更を保存し、Debian/Ubuntu ディストリビューションに SSL Apache モジュールをロードします (CentOS では、これは mod_ssl をインストールしたときに自動的にロードされます)以前):
a2enmod ssl
phpmyadmin に SSL の使用を強制します。次の行が /etc/phpmyadmin/config.inc.php または / に存在することを確認してください。 etc/phpMyAdmin/config.inc.php ファイル:
$cfg['ForceSSL'] = true;
そして Web サーバーを再起動します。
systemctl restart apache2 [On Debian/Ubuntu based systems]
systemctl restart httpd [On Debian/Ubuntu based systems]
次に、Web ブラウザを起動し、以下に示すように https://
と入力します (PhpMyAdmin ログイン URL を変更する方法をご覧ください)。
重要: 自己署名証明書を使用しているため、接続が安全ではないことを示しているだけであることに注意してください。 [詳細設定] をクリックし、セキュリティ例外を確認します。
セキュリティ例外を確認した後、ログインする前に、HTTP トラフィックと HTTPS トラフィックのスニッフィングを開始しましょう。
tcpdump port http or port https -l -A | egrep -i 'pass=|pwd=|log=|login=|user=|username=|pw=|passw=|passwd=|password=|pass:|user:|username:|password:|login:|pass |user ' --line-buffered -B20
次に、前と同じ資格情報を使用してログインします。トラフィック スニファーは、せいぜい意味不明な情報のみをキャプチャします。
現時点ではここまでです。次の記事では、ユーザー名とパスワードを使用して PhpMyAdmin へのアクセスを制限する方法について説明します。それまでは Tecmint に注目してください。