by orf · 11y ago · 0 comments
I mean, is it unexpected if `./my_command --execute-this-right-now=somescript.sh` executes somescript.sh?
In other words, even if it's not obvious, doing this creates a security vulnerability:
tar bla bla ${user input}Yes, it does. E.g:
x = STDIN.gets
puts x.tainted?
y = "hello "+x
puts y.tainted?
z = "foo"
puts z.tainted?
The two first will return "true", and the last will print "false". If you set the safe-level appropriately some methods will be disallowed for x and y above (e.g. eval()), though I would not trust that as comprehensive, but it's a lot better than nothing.It does:
irb(main):001:0> gets.tainted?
foo
=> true
You can even set $SAFE to 1 or higher to disallow the use of tainted strings in potentially dangerous commands: freya:~ flgr$ ruby -e '$SAFE = 1; system "tar bla bla #{gets}"'
foo
-e:1:in `system': Insecure operation: -r (SecurityError)
from -e:1:in `<main>'
See http://phrogz.net/programmingruby/taint.html for more information. && sudo rm -rf /
anyway? Which would render the whole point of the article moot. tar c -- "$directory_to_tar"For those sysadmins, yeah, it's unexpected.
the most determined of attackers will always find a way in.
Did you read the manpage of every utility on your computers to know that they won't execute a user supplied program? If you didn't you are up to nasty surprises.
That $HOME trick alone would give privilege escalation to anybody that gets a user-level access to a server of mine. Gota change it.
echo `somescript.sh`