PrivilegeSeparation メモ 春山 征吾 (haruyama@unixuser.org) OpenSSH付属のREADME.privsep (拙訳: http://www.unixuser.org/%7Eharuyama/security/openssh/README.privsep_nihongo.txt) もご覧下さい。 使い方 OpenSSH の Privilege Separation を利用するためには, まず OpenSSH 3.2.2 以降のリリース を利用する必要があります -----README.privsep より----- Privsep requires operating system support for file descriptor passing. Compression will be disabled on systems without a working mmap MAP_ANON. Privsep は ファイルディスクリプタの転送を必要とする. mmap MAP_ANON が働かないシステムでは、圧縮が無効になる. ---------- 以上のように, Privilege Separation が利用できない環境や 圧縮を有効にしていると接続できない場合があります. そして以下の作業を行ないます. ・対応している OpenSSH をインストールする ・ sshd_config で UsePrivilegeSeparation yes とするなどして, PrivilegeSeparation を使うようにする (OpenSSH 3.3以降では デフォルト) ・ pathnames.h で 定義されているディレクトリを掘ったり、 (#define _PATH_PRIVSEP_CHROOT_DIR "/var/empty") sshd で指定されているユーザ を設定する。 (#define SSH_PRIVSEP_USER "sshd") 以上は configure の オプションで変更できる # mkdir /var/empty # chown root:sys /var/empty # chmod 755 /var/empty # groupadd sshd # useradd -g sshd -c 'sshd privsep' -d /var/empty -s /bin/false sshd (README.privsep より) そして sshd を (再) 起動します. 例 特権の分離がどのように行なわれるかを見てみます. (参考: http://marc.theaimsgroup.com/?l=openssh-unix-dev&m=101680346025114&w=2) 1. root で sshd が起動しています % ps waux | grep sshd | grep -v grep ( grep 1回ですませたいなら % ps waux | grep "[s]shd" などとする) root 7028 0.0 0.3 2872 1188 ? S 20:46 0:00 /usr/local/sbin/sshd 2. ここでクライアントがログインしようと します $ env -u SSH_AUTH_SOCK ssh localhost 3. このとき % ps waux | grep sshd | grep -v grep root 7028 0.0 0.3 2872 1188 ? S 20:46 0:00 /usr/local/sbin/sshd root 7756 1.0 0.4 4388 1548 ? S 21:42 0:00 /usr/local/sbin/sshd sshd 7757 7.0 0.3 4388 1540 ? S 21:42 0:00 /usr/local/sbin/sshd となります. このとき # lsof -p 7757 COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME sshd 7757 sshd cwd DIR 3,72 4096 144299 /var/empty sshd 7757 sshd rtd DIR 3,72 4096 144299 /var/empty sshd 7757 sshd txt REG 3,69 283100 376225 /usr/local/sbin/sshd ..... となっており chroot していることがわかります.( 環境によっては USER が root となる場合もあるようです) PID 7756 は このセッション用の子プロセスモニタ用親プロセスです. 4. クライアント側でログインします 5. すると % ps waux | grep sshd | grep -v grep root 7028 0.0 0.3 2872 1188 ? S 20:46 0:00 /usr/local/sbin/sshd root 7756 0.0 0.4 5660 1640 ? S 21:42 0:00 /usr/local/sbin/sshd haruyama 7766 0.0 0.4 5660 1692 ? S 21:43 0:00 /usr/local/sbin/sshd となります ################################################################################ # http://www.citi.umich.edu/u/provos/ssh/privsep.html の一部の訳 # 古いです # (もとのページには図があります) # 現在のページの新山さんによる訳が http://www.citi.umich.edu/u/provos/ssh/privsep-j.html にあります Privilege Separated OpenSSH 特権を分離する OpenSSH The goal of this work is complete privilege separation within in OpenSSH. この仕事の目標は, OpenSSH 中での完全な特権の分離だ. Privilege separation uses two processes: The privileged parent process that monitors the progress of the unprivileged child process. The child process is unprivileged and the only process that processes network data. The privileged parent can be modelled by a very small finite-state machine so that it is easy to reason about the code that is being executed with privileges. 特権の分離では, 2 つのプロセスを使う. 特権を持たない子プロセスの経過を モニタする特権を持つ親プロセス. 子プロセスは, 特権を持たずただ ネットワークデータを処理するだけのプロセスだ. 特権を持つ親は, 非常の小さい有限状態マシンとして設計することができ, よって 特権を持って実行されるコードについて理解することは容易だ. A well defined interface between privileged parent and unprivileged child allows the child to delegate operations that require privileges to the parent. Successful authentication is determined by the parent process. 特権を持つ親と持たない子の間の明確なインタフェイスは 子が親に対して特権を必要とする操作を委任することを許している. 認証が成功するかどうかは, 親プロセスによって決定される. Communication between the privileged and the unprivileged process is achieved by pipes. Shared memory stores state that can not be otherwise exported. The child has to ask the privileged parent to determine if authentication was successful or not. 特権を持つプロセスと持たないプロセス間の通信は, パイプによって 実現されている. 共有メモリに, 他の方法では持ち出せない状態を 保持する. 子プロセスは, 認証が成功したか否かを判断するには 特権を持つ親に聞かなければならない. If the child process gets corrupted and believes that the remote user has been authenticated, access will not be granted unless the parent has reached the same decision. 子プロセスが攻撃を受けてリモートユーザは認証されたと 思ってしまっても, 親が同じ結論に達していないのなら アクセスは許されない. Previously any corruption in the sshd could lead to an immediate remote root compromise if it happened before authentication, and to local root compromise if it happend after authentication. Privilege Separation will make such compromise very difficult if not impossible. これまでの sshd への攻撃は, それが認証の前に行なわれたら即時に リモートでの root の不正使用に繋がり, 認証の後に行なわれたら ローカルでの root の不正使用に繋がっていた. 特権の分離によって これらの危険を利用した不正使用が不可能ではないにしても難しく なる. $Id: privsep.txt,v 1.7 2004/08/18 01:13:48 haruyama Exp $