4 ms·
Do not try this but off the top of my head, I think this vector could be slightly unnice: /send/exec/rm%20-rf%20%2F .. Will give it a go when I'm off the iPad :
by petercooper 16y ago
Do not try this but off the top of my head, I think this vector could be slightly unnice: /send/exec/rm%20-rf%20%2F .. Will give it a go when I'm off the iPad :-)
Update: I forgot exec wants its input in a different format. /send/exec/date prints the date and stops the server so this vector is certainly potent. /send/exec/ls/-l/%2f does NOT do what I expect though as Rack seems to turn / back into %2f server side but /send/exec/ls/-l/. does what I'd expect.
Update 2: James Golick notes that calling ` works through send too and suggests using /`/. This has the benefit of returning the output of what was run like cat /etc/passwd, for example ;-)
- steveklabnik 16y agoI don't think it'd actually work, since it sends all of the calls to an Array. Array doesn't respond_to exec.
- petercooper 16y ago[18:54:40 ~]$ irb >> [].send('exec', 'date') Tue Nov 16 18:54:48 GMT 2010 You can call Kernel's methods on any object (usually - there are some cases where not) through send, e.g. [].send(:puts, 10) .. I was working with Sven Fuchs on some "sandboxing" stuff a couple of years ago and we discovered this little doozy! (Though it's possible to figure out by noting that [].puts tells you private method `puts' called and send gets you around that problem.) Typically you pass a symbol as the first argument but a string works too which, I believe, would make my attack vector work. Going to try it now. Update: /send/exec/date works as expected (and stops the server).
- steveklabnik 16y agoWeird... ruby-1.8.7-p302 > [].respond_to? :exec => false Guess I shouldn't trust it. (Also, I originally ran Array.respond_to?...)
- petercooper 16y agoTry: [].respond_to?(:exec, true) # => true respond_to? doesn't include private methods by default but can be made to do so with the second argument. I didn't know this either till I just looked it up. This made sense to me since I'd assume respond_to? would only yield true if it were possible to make the call without error. Yet, this logic does not hold true: class X; def y; respond_to? :exec; end; end X.new.y # => FALSE So it seems it doesn't matter if the private method is callable or not, respond_to? won't give you a true for any private method, accessible in the current scope or not, unless you pass the extra flag. (I'm not really writing all of this to give you an education, more to give me one. I was totally unaware of all this and found it interesting :-))
- steveklabnik 16y agoNo, don't feel bad. That's awesome. I knew that thing about adding true, I just didn't realize that exec was private.