Skip to content

Safe eval escapes sandbox #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
fooblahblah opened this issue Jun 6, 2012 · 1 comment
Open

Safe eval escapes sandbox #6

fooblahblah opened this issue Jun 6, 2012 · 1 comment

Comments

@fooblahblah
Copy link

I'm able to circumvent the sandbox by using a referenced namespace/module. Here's an example:

jruby-1.6.7 :001 > require 'sandbox'
 => true 
jruby-1.6.7 :002 > Foo = Struct.new(:foo)
 => Foo 
jruby-1.6.7 :003 > sand = Sandbox::Safe.new
 => #<Sandbox::Safe:0x2221bcd5> 
jruby-1.6.7 :004 > sand.activate!
 => ["%", "*", "+", "<<", "<=>", "==", "=~", "capitalize", "capitalize!", "casecmp", "center", "chomp", "chomp!", "chop", "chop!", "concat", "count", "crypt", "delete", "delete!", "downcase", "downcase!", "dump", "each", "each_byte", "each_line", "empty?", "eql?", "gsub", "gsub!", "hash", "hex", "include?", "index", "initialize", "initialize_copy", "insert", "inspect", "intern", "length", "ljust", "lines", "lstrip", "lstrip!", "match", "next", "next!", "oct", "replace", "reverse", "reverse!", "rindex", "rjust", "rstrip", "rstrip!", "scan", "size", "slice", "slice!", "split", "squeeze", "squeeze!", "strip", "strip!", "start_with?", "sub", "sub!", "succ", "succ!", "sum", "swapcase", "swapcase!", "to_f", "to_i", "to_s", "to_str", "to_sym", "tr", "tr!", "tr_s", "tr_s!", "upcase", "upcase!", "upto", "[]", "[]="] 
jruby-1.6.7 :005 > sand.ref Foo
 => nil 
jruby-1.6.7 :006 > sand.eval 'Foo.eval "`ls /etc/passwd`"'
 => "/etc/passwd\n" 
jruby-1.6.7 :007 > 

Shouldn't that be disallowed in the safe mode?

Note: Plain ls is not defined.

jruby-1.6.7 :007 > sand.eval '`ls`'
Sandbox::SandboxException: NoMethodError: undefined method ``' for main:Object
        from sandbox/SandboxFull.java:60:in `eval'
        from (irb):7:in `evaluate'
        from org/jruby/RubyKernel.java:1088:in `eval'
        from org/jruby/RubyKernel.java:1410:in `loop'
        from org/jruby/RubyKernel.java:1197:in `catch'
        from org/jruby/RubyKernel.java:1197:in `catch'
        from /home/jsimpson/.rvm/rubies/jruby-1.6.7/bin/jirb:17:in `(root)'
jruby-1.6.7 :008 > 
@adamfortuna
Copy link
Collaborator

Good catch! We removed access to these from the FakeFS objects that are passed in, but we probably need some kind of a "clean" way to pass in objects to the sandbox that strips them of eval, class_eval and instance_eval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants