Scientific Linux 6のバッファオーバーフロー攻撃対策をします。
[root@sl6 ~]# cat /proc/sys/kernel/exec-shield
1
# 現在の設定は1でした。なお設定値の意味ですが
0 : 無効
1 : 無効(実行ファイルごとに有効にする)
2 : 有効(実行ファイルごとに無効にする)
3 : 常に有効
です。
# ここでは2の「有効(実行ファイルごとに無効にする)」に変更します
[root@sl6 ~]# echo 2 > /proc/sys/kernel/exec-shield
これで設定が変更されましたが、OSの再起動をすると値が元に戻ってしまうので設定ファイルから変更します。
# viエディタが起動するので設定ファイルを変更します
# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.
# Controls IP packet forwarding
net.ipv4.ip_forward = 0
# Controls source route verification
net.ipv4.conf.default.rp_filter = 1
# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0
# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0
# Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
kernel.core_uses_pid = 1
# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1
# Disable netfilter on bridges.
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
# exec-shieldの設定を追記します
# exec-shield
kernel.exec-shield = 2
内容を保存しviエディタを終了します
Exec-Shieldの動作確認を行うためにlibsafeというツールを使用します。
libsafeとはLinux用に開発されているバッファオーバーフローによる攻撃を防止するためのライブラリなのですがこの中に、テスト用のバッファオーバーフロー攻撃ツールがありますのでそれを使います。
[root@sl6 ~]# wget http://pubs.research.avayalabs.com/src/libsafe-2.0-16.i386.rpm
--2011-06-08 00:15:26-- http://pubs.research.avayalabs.com/src/libsafe-2.0-16.i386.rpm
pubs.research.avayalabs.com をDNSに問いあわせています... 198.152.240.29
pubs.research.avayalabs.com|198.152.240.29|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 374371 (366K) [text/plain]
`libsafe-2.0-16.i386.rpm' に保存中
100%[===========================>] 374,371 49.5K/s 時間 7.9s
2011-06-08 00:15:37 (46.4 KB/s) - `libsafe-2.0-16.i386.rpm' へ保存完了 [374371/374371]
# libsafeのインストールします
[root@sl6 ~]# rpm -ivh libsafe-2.0-16.i386.rpm
エラー: 依存性の欠如:
ld-linux.so.2 は libsafe-2.0-16.i386 に必要とされています
libc.so.6 は libsafe-2.0-16.i386 に必要とされています
libdl.so.2 は libsafe-2.0-16.i386 に必要とされています
libdl.so.2(GLIBC_2.0) は libsafe-2.0-16.i386 に必要とされています
libc.so.6(GLIBC_2.1) は libsafe-2.0-16.i386 に必要とされています
libc.so.6(GLIBC_2.0) は libsafe-2.0-16.i386 に必要とされています
# 関連パッケージが足りないので追加します
[root@sl6 ~]# yum install ld-linux.so.2 libc.so.6 libdl.so.2
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package glibc.i686 0:2.12-1.7.el6_0.5 set to be updated
--> Processing Dependency: libfreebl3.so for package: glibc-2.12-1.7.el6_0.5.i686
--> Processing Dependency: libfreebl3.so(NSSRAWHASH_3.12.3) for package: glibc-2.12-1.7.el6_0.5.i686
--> Running transaction check
---> Package nss-softokn-freebl.i686 0:3.12.8-1.el6_0 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================
Package Arch Version Repository Size
===========================================================
Installing:
glibc i686 2.12-1.7.el6_0.5 sl-security 4.3 M
Installing for dependencies:
nss-softokn-freebl i686 3.12.8-1.el6_0 sl-security 108 k
Transaction Summary
===========================================================
Install 2 Package(s)
Upgrade 0 Package(s)
Total download size: 4.4 M
Installed size: 13 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): glibc-2.12-1.7.el6_0.5.i686.rpm | 4.3 MB 00:04
(2/2): nss-softokn-freebl-3.12.8-1.el6_0.i686.rpm | 108 kB 00:00
-----------------------------------------------------------------------------------------------------------------------
Total 433 kB/s | 4.4 MB 00:10
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : nss-softokn-freebl-3.12.8-1.el6_0.i686 1/2
Installing : glibc-2.12-1.7.el6_0.5.i686 2/2
Installed:
1libc.i6860:2.12-1.7.el6_0.5
Dependency Installed:
nss-softokn-freebl.i6860:3.12.8-1.el6_0
Complete!
# 再度libsafeのインストールします
[root@sl6 ~]# rpm -ivh libsafe-2.0-16.i386.rpm
準備中... ########################################### [100%]
1:libsafe ########################################### [100%]
Adding libsafe to ld.so.preload for system wide protection
# テスト用のバッファオーバーフロー攻撃ツールをホームディレクトリにコピーします
[root@sl6 ~]# cp -p /usr/doc/libsafe-2.0/exploits/t1 ./
ERROR: ld.so: object '/lib/libsafe.so.2' from /etc/ld.so.preload cannot be preloaded: ignored.
# テスト用のバッファオーバーフロー攻撃ツールを実行します
[root@sl6 ~]# ./t1
This program tries to use strcpy() to overflow the buffer.
If you get a /bin/sh prompt, then the exploit has worked.
Press any key to continue...a ← # 何か文字を入力して[Enter]キーを押下します。ここでは a と入力します
セグメンテーション違反です
# 「Exec-Shield」が有効になっている為、「セグメンテーション違反です」のメッセージとともにテスト用バッファオーバーフロー攻撃ツールが停止されます
# テスト用バッファオーバーフロー攻撃ツールを削除します
[root@sl6 ~]# rm -f ./t1
ERROR: ld.so: object '/lib/libsafe.so.2' from /etc/ld.so.preload cannot be preloaded: ignored.
# libsafeをアンインストールします
[root@sl6 ~]# rpm -e libsafe
ERROR: ld.so: object '/lib/libsafe.so.2' from /etc/ld.so.preload cannot be preloaded: ignored.
ERROR: ld.so: object '/lib/libsafe.so.2' from /etc/ld.so.preload cannot be preloaded: ignored.
Removing libsafe from /etc/ld.so.preload (if exists)
ERROR: ld.so: object '/lib/libsafe.so.2' from /etc/ld.so.preload cannot be preloaded: ignored.
ERROR: ld.so: object '/lib/libsafe.so.2' from /etc/ld.so.preload cannot be preloaded: ignored.
ERROR: ld.so: object '/lib/libsafe.so.2' from /etc/ld.so.preload cannot be preloaded: ignored.
「ERROR: ld.so: object '/lib/libsafe.so.2' from /etc/ld.so.preload cannot be preloaded: ignored.」はlibsafeをインストールすると出るようで削除すれば出なくなりますとのこと。
はじめての自宅サーバ構築 - Fedora/CentOS - バッファオーバーフロー攻撃防御機構(Exec-Shield)
■関連記事
Scientific Linux 6で自宅サーバー構築 その1 サーバー機Express 5800 GT110bのオンボードRAIDでRAID1設定
Scientific Linux 6で自宅サーバー構築 その2 Scientific Linux 6をExpress5800/GT110bにインストール
Scientific Linux 6で自宅サーバー構築 その3 Scientific Linux 6インストール後の初期設定
Scientific Linux 6で自宅サーバー構築 番外編その1 Scientific Linux 6のcronについて
Scientific Linux 6で自宅サーバー構築 その4 Scientific Linux 6 にClamAVをインストールしてウィルス対策
Scientific Linux 6で自宅サーバー構築 その5 Scientific Linux 6 にTripwireをインストールしてファイル改ざんを検知する
Scientific Linux 6で自宅サーバー構築 その6 Scientific Linux 6 にchkrootkitをインストールしてrootkit感染を検知する
Scientific Linux 6で自宅サーバー構築 その7 NTPサーバーで自動時刻合わせ
Scientific Linux 6で自宅サーバー構築 その8 バッファオーバーフロー攻撃対策を行う
Scientific Linux 6で自宅サーバー構築 その9 logwatchでサーバー監視
Scientific Linux 6で自宅サーバー構築 その10 DNSサーバーを構築
Scientific Linux 6で自宅サーバー構築 番外編その2 Scientific Linuxを6.0から6.1にアップグレードする
Scientific Linux 6で自宅サーバー構築 その11 PostfixとDovecotとSMTP-AUTHでメールサーバーを構築する
Scientific Linux 6で自宅サーバー構築 その12 メールサーバーにSSLを導入する
Scientific Linux 6で自宅サーバー構築 その13 Apache PHP MySQLをインストール
Scientific Linux 6で自宅サーバー構築 その14 WebサーバーにSSLを導入する
Scientific Linux 6で自宅サーバー構築 その15 WordPressを導入する
Scientific Linux 6で自宅サーバー構築 その16 Piwikでアクセスログ集計
Scientific Linux 6で自宅サーバー構築 その17 Squidをインストール
Scientific Linux 6で自宅サーバー構築 その18 sshで鍵認証を導入
Scientific Linux 6で自宅サーバー構築 その19 WebDavの設定
Scientific Linux 6で自宅サーバー構築 その20 lm_sensorをインストール
