druby and security

11

Click here to load reader

Upload: kazuhiro-nishiyama

Post on 12-Jun-2015

571 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: dRuby and Security

dRuby and SecuritydRubyとセキュリティ

西山和広日本Rubyの会

Powered by Rabbit 0.5.7

Page 2: dRuby and Security

drubyを不特定多数に向けて公開するのは危険

Page 3: dRuby and Security

Security in rdocrdocでのSecurityについての説明

== Security

As with all network services, security needs to be considered whenusing dRuby. By allowing external access to a Ruby object, you arenot only allowing outside clients to call the methods you havedefined for that object, but by default to execute arbitrary Rubycode on your server. Consider the following:

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

2/10

Page 4: dRuby and Security

undef and instance_evalrdocに載っている方法 (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

Page 5: dRuby and Security

method_missingmethod_missing 直接

ro.method_missing("instance_eval", "`echo hello druby`")

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

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

4/10

Page 6: dRuby and Security

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

drb/drb.rb で禁止されているメソッド

直接呼べない

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

send も呼べるのでほとんど制限はない 5/10

Page 7: dRuby and Security

Methodsend_method = ro.method_missing(:method, :__send__)send_method.call(:puts, "hello druby!")

Method オブジェクト経由

INSECURE_METHOD のチェックを回避可能

6/10

Page 8: dRuby and Security

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

instance_eval や system などは呼べない

safe level が 1 なら puts は呼べる

7/10

Page 9: dRuby and Security

$SAFEでも防げないものDoSを狙うもの

サーバ側で巨大な文字列を生成など

rlimit などの OS の機能で制限

他にもあるかも

8/10

Page 10: dRuby and Security

デモ時間があればここでデモ

9/10

Page 11: dRuby and Security

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

10/10Powered by Rabbit 0.5.7