2022年8月、ホームページを全面リニューアルしました! 情報を分かりやすくお伝えできるサイト作りを目指してまいります。

TrustedなBSDを使う!

「Trustedな」という言葉が流行ってる。直訳すると「信頼される」と訳せる。
この文書中に「TrustedBSD」と言う言葉が出てくるが、 TrustedBSDプロジェクト は、BSD OSにISOの認証取得が出来るような要件を実装するためのプロジェクトらしいです。その中に、ここで説明するようなアクセス制御を中心としたセキュリティモジュールの開発が行われてきた。アクセス制御に関しては、今まで説明してきたselinuxやLIDSやTomoyoLinuxと考え方は同じである。
やはり、サーバに関してのセキュリティでもっとも単純に考えやすいのは、「アクセスを制限する」ことであろう。俺も自分のサーバを今以上にTrustedなサーバにしたい。


1.FreeBSD-6.1-RELEASEをインスコする
別に、FreeBSD-6.1-RELEASEでなくてもFreeBSD-5.3-RELEASE以降なら、Trusted出来るらしい。
また、FreeBSDのインストールについてはネタ元は多いと思うので割愛。


2.TrustedBSDを使うためのkernelリコンパイル
1)kernelリコンパイル前準備
FreeBSDのインストールを終えたら、以下を参考にセキュリティブランチのアップデートを行うと良い。
FreeBSDセキュリティブランチアップデート!

さらに、以下を参考にPortsのアップグレードを行うと良い。
FreeBSD portupgradeコマンドを使う!

さらに、ShellのBashは入れておこう。

2)ソースをゲットしてくる
適当なディレクトリへ、FreeBSDのソースをゲットする。
ftpサイトのsrcディレクトリに有るので丸ごとゲットする。丸ごとゲットするなら、wgetが使いやすいと思う。まずは、wgetをインストールする。
bash-2.05b# cd /usr/ports/ftp/wget
bash-2.05b# make install clean
bash-2.05b# cd tmp
bash-2.05b# wget -r ftp://ftp.FreeBSD.org/pub/FreeBSD/releases/i386/6.1-RELEASE/src/

3)ソースをインストールする
bash-2.05b# cd ftp.freebsd.org/pub/FreeBSD/releases/i386/6.1-RELEASE/src/
bash-2.05b# sh ./install.sh all

4)TrustedBSDを使えるように設定する
基本的には、一行追加する。
bash-2.05b# vi /usr/src/sys/i386/conf/GENERIC
省略
options    MAC     # TrustedBSD Setting
省略

5)kernelビルド
bash-2.05b# cd /usr/src
bash-2.05b# make buildkernel

6)kernelリンク
bash-2.05b# make installkernel


3.起動設定
1)ブートしたときに、TrustedBSDになるようにパラメータを設定する

bash-2.05b# vi /boot/loader.conf
“NO”がモジュールをロードしない、”YES”がモジュールをロードする。
“0”がDisable、”1″がEnable。

mac_biba_load=”YES”
mac_bsdextended_load=”YES”
mac_ifoff_load=”YES”
mac_lomac_load=”YES”
mac_mls_load=”YES”
mac_none_load=”YES”
mac_patition_load=”YES”
mac_seeotheruids_load=”YES”
mac_portacl_load=”YES”
mac_stub_load=”YES”
mac_test_load=”YES”

security.mac.biba.enabled=0
security.mac.bsdextend.enabled=1
security.mac.ifoff.enabled=0
security.mac.lomac.enabled=0
security.mac.mls.enabled=0
security.mac.none.enabled=0
security.mac.patition.enabled=0
security.mac.seeotheruids.enabled=1
security.mac.portacl.enabled=0
security.mac.stub.enabled=0
security.mac.test.enabled=0

パラメータを書き込んだら、rebootしてみる。図1と図2は起動時にMACモジュールがロードされてる様子を表す。

図1
図2

2)設定を確認する

bash-2.05b# sysctl -a | more
省略
security.jail.set_hostname_allowed: 1
security.jail.socket_unixiproute_only: 1
security.jail.sysvipc_allowed: 0
security.jail.enforce_statfs: 2
security.jail.allow_raw_sockets: 0
security.jail.chflags_allowed: 0
security.jail.jailed: 0
security.mac.max_slots: 4
security.mac.enforce_network: 1
security.mac.enforce_pipe: 1
security.mac.enforce_posix_sem: 1
security.mac.enforce_process: 1
security.mac.enforce_vm: 1
security.mac.mmap_revocation: 1
security.mac.mmap_revocation_via_cow: 0
security.mac.enforce_suid: 1
security.mac.enforce_socket: 1
security.mac.enforce_kld: 1
security.mac.enforce_system: 1
security.mac.enforce_sysv_msg: 1
security.mac.enforce_sysv_sem: 1
security.mac.enforce_sysv_shm: 1
security.mac.enforce_fs: 1
security.mac.biba.revocation_enabled: 0
security.mac.biba.interfaces_equal: 0
security.mac.biba.ptys_equal: 0
security.mac.biba.max_compartments: 256
security.mac.biba.trusted_interfaces:
security.mac.biba.trust_all_interfaces: 0
security.mac.biba.destroyed_not_inited: 0
security.mac.biba.enabled: 0
security.mac.biba.label_size: 112
security.mac.bsdextended.firstmatch_enabled: 0
security.mac.bsdextended.logging: 0
security.mac.bsdextended.rule_slots: 0
security.mac.bsdextended.rule_count: 0
security.mac.bsdextended.enabled: 1
security.mac.mls.max_compartments: 256
security.mac.mls.revocation_enabled: 0
security.mac.mls.ptys_equal: 0
security.mac.mls.destroyed_not_inited: 0
security.mac.mls.enabled: 0
security.mac.mls.label_size: 112
security.mac.none.enabled: 1
security.mac.seeotheruids.specificgid: 0
security.mac.seeotheruids.specificgid_enabled: 0
security.mac.seeotheruids.primarygroup_enabled: 0
security.mac.seeotheruids.enabled: 1
security.mac.ifoff.bpfrecv_enabled: 0
security.mac.ifoff.other_enabled: 0
security.mac.ifoff.lo_enabled: 1
security.mac.ifoff.enabled: 0
security.mac.lomac.revocation_enabled: 1
security.mac.lomac.ptys_equal: 0
security.mac.lomac.trusted_interfaces:
security.mac.lomac.trust_all_interfaces: 0
security.mac.lomac.destroyed_not_inited: 0
security.mac.lomac.enabled: 0
security.mac.lomac.label_size: 20
security.mac.portacl.rules:
security.mac.portacl.port_high: 1023
security.mac.portacl.autoport_exempt: 1
security.mac.portacl.suser_exempt: 1
security.mac.portacl.enabled: 0
security.mac.stub.enabled: 1
security.mac.test.internalize_count: 0
security.mac.test.externalize_count: 12
security.mac.test.destroy_count_vnode: 194181
security.mac.test.destroy_count_proc: 2870
security.mac.test.destroy_count_posixsems: 0
security.mac.test.destroy_count_pipe: 1078
security.mac.test.destroy_count_socket_peerlabel: 549
security.mac.test.destroy_count_socket: 549
security.mac.test.destroy_count_mount_fslabel: 0
security.mac.test.destroy_count_mount: 0
security.mac.test.destroy_count_mbuf: 1267
security.mac.test.destroy_count_ipq: 0
security.mac.test.destroy_count_sysv_shm: 0
security.mac.test.destroy_count_sysv_sem: 0
security.mac.test.destroy_count_sysv_msq: 0
security.mac.test.destroy_count_sysv_msg: 0
security.mac.test.destroy_count_inpcb: 148
security.mac.test.destroy_count_ifnet: 3
security.mac.test.destroy_count_devfsdirent: 1
security.mac.test.destroy_count_cred: 12274
security.mac.test.destroy_count_bpfdesc: 0
security.mac.test.init_count_vnode: 209757
security.mac.test.init_count_proc: 2932
security.mac.test.init_count_posixsems: 0
security.mac.test.init_count_pipe: 1080
security.mac.test.init_count_socket_peerlabel: 560
security.mac.test.init_count_socket: 560
security.mac.test.init_count_mount_fslabel: 2
security.mac.test.init_count_mount: 2
security.mac.test.init_count_mbuf: 1395
security.mac.test.init_count_ipq: 0
security.mac.test.init_count_sysv_shm: 192
security.mac.test.init_count_sysv_sem: 10
security.mac.test.init_count_sysv_msq: 40
security.mac.test.init_count_sysv_msg: 40
security.mac.test.init_count_inpcb: 175
security.mac.test.init_count_ifnet: 6
security.mac.test.init_count_devfsdirent: 89
security.mac.test.init_count_cred: 12288
security.mac.test.init_count_bpfdesc: 0
security.mac.test.slot: 3
security.mac.test.enabled: 1
security.bsd.suser_enabled: 1
security.bsd.see_other_uids: 1
security.bsd.see_other_gids: 1
security.bsd.conservative_signals: 1
security.bsd.unprivileged_proc_debug: 1
security.bsd.unprivileged_read_msgbuf: 1
security.bsd.hardlink_check_uid: 0
security.bsd.hardlink_check_gid: 0
security.bsd.unprivileged_get_quota: 0
省略


4.MACモジュールの説明と実際に使ってみる
1)動的にMACモジュールをON・OFFする
コマンドライン上で起動設定したMACモジュールをON・OFFするには以下のようにする。
bash-2.05b# sysctl security.mac.seeotheruids.enabled=0
security.mac.seeotheruids.enabled: 1 -> 0
bash-2.05b# sysctl security.mac.seeotheruids.enabled=1
security.mac.seeotheruids.enabled: 0 -> 1

設定を確認するときは、
bash-2.05b# sysctl -a security.mac.seeotheruids.enabled
security.mac.seeotheruids.enabled: 1
で確認できる。

注:ただし、動的に切り替えられるMACモジュールと起動設定のみのMACモジュールが有るので注意すること。

2)MACモジュールの説明

■ biba
Bibaセキュリティポリシーモデル。
情報の完全性を目的としてもので、情報の書き込み・更新を管理・制御して、間違った更新や不正な更新を防ぐ。

■ bsdextended
ユーザ権限や属性を制御するセキュリティモデル。

■ ifoff
ネットワークI/Fを制御するセキュリティモデル。

■ lomac
Lomacセキュリティポリシーモデル。
bibaセキュリティポリシーモデルと同じ系列のモデル。
やはり、間違った情報の更新や不正な更新を防ぐ。

■ mls
MLSセキュリティポリシーモデル。
情報の秘匿性を目的としたセキュリティモデル。

■ patition
MACのラベルを扱うセキュリティモデル。

■ seeotheruids
プロセス可視制御セキュリティモデル。
ユーザから他のユーザのプロセスの可視を制御するためのモジュール。

■ portacl
port制御セキュリティモデル。
root権限では、すべてのportを使うことが出来る。
その他のユーザ権限では、1023port以上がオープン使うことが出来る。

とまぁ、簡単に説明してきたけど、結局なんなのよ。って感じ。
使ってみなければ解らないし、全てを使いこなすには時間と労力が必要のようだ。試しに、seeotheruids MACモジュールを使ってみることにする。

3)seeotheruidsを使ってみる
他のプロセスを何も見えなくする。

seeotheruids機能を有効にする。
bash-2.05b# sysctl security.mac.seeotheruids.enabled=1
security.mac.seeotheruids.enabled: 0 -> 1

killコマンドを打ってみる。何もプロセスが見えない。
bash-2.05b$ kill 1
bash: kill: (1) – No such process

seeotheruids機能を無効にする。
bash-2.05b$ su –
Password:
bash-2.05b# sysctl security.mac.seeotheruids.enabled=0
security.mac.seeotheruids.enabled: 1 -> 0
bash-2.05b# exit
exit
bsd# exit
logout
プロセスは見えるが、権限が無いからOperationが出来ない。
bash-2.05b$ kill 1
bash: kill: (1) – Operation not permitted

seeotheruids機能を無効な状態。
bash-2.05b# sysctl -a security.mac.seeotheruids.enabled
security.mac.seeotheruids.enabled: 0
bash-2.05b$ ps -axw
PID TT STAT TIME COMMAND
0 ?? WLs 0:00.00 [swapper]
1 ?? ILs 0:00.02 /sbin/init —
2 ?? DL 0:00.03 [g_event]
3 ?? DL 0:00.07 [g_up]
4 ?? DL 0:00.11 [g_down]
5 ?? DL 0:00.00 [kqueue taskq]
6 ?? DL 0:00.00 [acpi_task0]
7 ?? DL 0:00.00 [acpi_task1]
8 ?? DL 0:00.00 [acpi_task2]
9 ?? DL 0:00.00 [thread taskq]
10 ?? DL 0:00.00 [ktrace]
11 ?? RL 5:16.88 [idle]
12 ?? WL 0:00.01 [swi1: net]
13 ?? WL 0:01.12 [swi4: clock sio]
14 ?? WL 0:00.00 [swi3: vm]
15 ?? DL 0:00.04 [yarrow]
16 ?? WL 0:00.00 [swi5: +]
17 ?? WL 0:00.00 [swi2: cambio]
18 ?? WL 0:00.00 [swi6: task queue]
19 ?? WL 0:00.00 [swi6: +]
20 ?? WL 0:00.00 [irq9: acpi0]
21 ?? WL 0:00.04 [irq14: ata0]
22 ?? WL 0:00.00 [irq15: ata1]
23 ?? WL 0:00.02 [irq10: xl0 uhci0]
24 ?? DL 0:00.00 [usb0]
25 ?? DL 0:00.00 [usbtask]
26 ?? DL 0:00.00 [fdc0]
27 ?? WL 0:00.00 [irq7: ppc0]
28 ?? WL 0:00.00 [swi0: sio]
29 ?? WL 0:00.00 [irq1: atkbd0]
30 ?? DL 0:00.00 [pagedaemon]
31 ?? DL 0:00.00 [vmdaemon]
32 ?? DL 0:01.35 [pagezero]
33 ?? DL 0:00.00 [bufdaemon]
34 ?? DL 0:00.02 [syncer]
35 ?? DL 0:00.00 [vnlru]
36 ?? DL 0:00.00 [softdepflush]
37 ?? IL 0:00.00 [nfsiod 0]
38 ?? IL 0:00.00 [nfsiod 1]
39 ?? IL 0:00.00 [nfsiod 2]
40 ?? IL 0:00.00 [nfsiod 3]
41 ?? DL 0:00.02 [schedcpu]
132 ?? Is 0:00.00 adjkerntz -i
244 ?? Is 0:00.00 /sbin/devd
278 ?? Ss 0:00.03 /usr/sbin/syslogd -s
360 ?? Ss 0:00.00 /usr/sbin/usbd
403 ?? Is 0:00.37 /usr/sbin/sshd
410 ?? Ss 0:00.02 /usr/sbin/cron -s
454 ?? Is 0:00.14 sshd: mity [priv] (sshd)
456 ?? S 0:00.07 sshd: mity@ttyp0 (sshd)
450 v0 Is+ 0:00.01 /usr/libexec/getty Pc ttyv0
451 v1 Is+ 0:00.01 /usr/libexec/getty Pc ttyv1
452 v2 Is+ 0:00.01 /usr/libexec/getty Pc ttyv2
453 v3 Is+ 0:00.01 /usr/libexec/getty Pc ttyv3
457 p0 Is 0:00.02 -sh (sh)
458 p0 S 0:00.04 bash
482 p0 R+ 0:00.00 ps -axw

seeotheruids機能を有効にする。
bash-2.05b$ su –
Password:
bash-2.05b# sysctl security.mac.seeotheruids.enabled=1
security.mac.seeotheruids.enabled: 0 -> 1
bash-2.05b# exit
exit
bsd# exit
logout
bash-2.05b$ ps -axw
PID TT STAT TIME COMMAND
456 ?? S 0:00.09 sshd: mity@ttyp0 (sshd)
457 p0 Is 0:00.02 -sh (sh)
458 p0 S 0:00.05 bash
489 p0 R+ 0:00.01 ps -axw
自分のプロセスしか見えない。

以上

コメント