is it 开发者_StackOverflowpossible to call a shellscript or the shellcode in a java class?
My Code (in a static method):
Runtime rtime = Runtime.getRuntime();
Process child = rtime.exec("/bin/bash");
BufferedWriter outCommand = new BufferedWriter(new
OutputStreamWriter(child.getOutputStream()));
outCommand.write("streamer -c /dev/video0 -b32 -o test.jpeg");
outCommand.flush();
outCommand.close();
child.destroy();
But I get this error, if i try this code in my jsp page (tomcat6):
java.security.AccessControlException: access denied (java.io.FilePermission /bin/bash execute)
Any solution for this problem?
EDIT: ls -l /bin/bash shows me follwing line:
-rwxr-xr-x 1 root root 875596 2009-09-14 07:09 /bin/bash
Thanks
If you want to keep the security manager running, and you may have good reasons for doing so, then you can simply change the policy file that Tomcat is using. The files may be located in /var/lib/tomcat6/conf/policy.d
.
A nice SO thread discusses this already. Even if you grant AllPermissions
to your application, running with the SecurityManager
will allow you to use sandboxes with limited security. You might want to do that, say, to run JavaScript that could be uploaded at runtime or something similar, or there may be some other code in your application that you don't trust for some reason.
Try to disable the security manager. Edit /etc/init.d/tomcat6
and change:
TOMCAT_SECURITY=yes
Change that to:
TOMCAT_SECURITY=no
And then restart Tomcat:
/etc/init.d/tomcat6 restart
If it works, it's up to you to see if fully disabling the security manager is acceptable or not (using it is actually unusual IMO).
Also if possible, attempt to run it in the single exec call.
Process p = Runtime.getRuntime().exec(args);
where args is a string array of arguments.
String[] args = new String[] {"/bin/bash", "streamer", "-c", "/dev/video0", "-b32", "-o", "test.jpeg" };
精彩评论