dRuby and Security
                          dRubyとセキュリティ

                            西山和広
                            日本Rubyの会



Powered by Rabbit 0.5.7
drubyを不特
定多数に向け
て公開するの
   は危険
Security in rdoc
rdocでのSecurityについての説明
  == Security

  As with all network services, security needs to be considered when
  using dRuby. By allowing external access to a Ruby object, you are
  not only allowing outside clients to call the methods you have
  defined for that object, but by default to execute arbitrary Ruby
  code on your server. Consider the following:

  参考訳:
  あらゆるネットワークサービスと同様に、dRuby を使う場合には
  セキュリティを考慮することが欠かせない。
  ある Ruby オブジェクトへの外部のアクセスを許すことによって、
  そのオブジェクト向けにあなたが定義したメソッドを
  外のクライアントが呼び出すことを許しているだけだはなく、
  そのままだとあなたのサーバ上で任意の Ruby コードを実行する
  ことを許していることになる。



                                                                       2/10
undef and
instance_eval
rdocに載っている方法 (undefと
instance_eval)
  # !!! UNSAFE CODE !!!
  ro = DRbObject::new_with_uri("druby://your.server.com:8989")
  class << ro
    undef :instance_eval # force call to be passed to remote object
  end
  ro.instance_eval("`rm -rf *`")




 本当にこのまま試すのは危険
                                                                  3/10
method_missing
method_missing 直接
  ro.method_missing("instance_eval", "`echo hello druby`")



  呼び出し側の記述が変わるだけ

  出来ることは undef との組み合わせと同じ




                                                         4/10
insecure methods
  # List of insecure methods.
  #
  # These methods are not callable via dRuby.
  INSECURE_METHOD = [
    :__send__
  ]


 drb/drb.rb で禁止されているメソッド
   直接呼べない

   instance_eval などと組み合わせれば呼べる

   send も呼べるのでほとんど制限はない                         5/10
Method
 send_method = ro.method_missing(:method, :__send__)
 send_method.call(:puts, "hello druby!")



 Method オブジェクト経由

 INSECURE_METHOD のチェックを回避可
 能




                                                   6/10
$SAFEをあげて制限
require 'drb'
DRb.start_service("druby://localhost:0", nil, :safe_level => 1)
puts DRb.uri
DRb.thread.join



instance_eval や system などは呼べない

safe level が 1 なら puts は呼べる




                                                              7/10
$SAFEでも防げないもの
DoSを狙うもの
 サーバ側で巨大な文字列を生成など

 rlimit などの OS の機能で制限

他にもあるかも




                        8/10
デモ
時間があればここでデモ




              9/10
まとめ
drubyを不特定多数に向けて公開するのは危険




Powered by Rabbit 0.5.7   10/10

dRuby and Security