daveagp / java_jail

chroot java jail, and JSON java trace printer
GNU Affero General Public License v3.0
78 stars 33 forks source link

Java Visualizer not working #6

Closed nileshtakale closed 8 years ago

nileshtakale commented 8 years ago

Hi, I followed all the steps on my RHEL 7 64 bit OS to install Java Visualizer, but still it is not working. safeexec is working properly. In Java jail when I execute below command ,

./java/bin/java -cp .:cp:cp/javax.json-1.0.jar:java/lib/tools.jar traceprinter.InMemory < cp/traceprinter/test-input.txt it gives me below output.

{"code":"public class Test { public static void main(String[] args) { int x = 3; x += x; } }","stdin":"","trace":[{"stdout":"","event":"call","line":1,"stack_to_render":[{"func_name":"main:1","encoded_locals":{},"ordered_varnames":[],"parent_frame_id_list":[],"is_highlighted":true,"is_zombie":false,"is_parent":false,"unique_hash":"1","frame_id":1}],"globals":{},"ordered_globals":[],"func_name":"main","heap":{}},{"stdout":"","event":"step_line","line":1,"stack_to_render":[{"func_name":"main:1","encoded_locals":{},"ordered_varnames":[],"parent_frame_id_list":[],"is_highlighted":true,"is_zombie":false,"is_parent":false,"unique_hash":"2","frame_id":2}],"globals":{},"ordered_globals":[],"func_name":"main","heap":{}},{"stdout":"","event":"step_line","line":1,"stack_to_render":[{"func_name":"main:1","encoded_locals":{"x":3},"ordered_varnames":["x"],"parent_frame_id_list":[],"is_highlighted":true,"is_zombie":false,"is_parent":false,"unique_hash":"4","frame_id":4}],"globals":{},"ordered_globals":[],"func_name":"main","heap":{}},{"stdout":"","event":"step_line","line":1,"stack_to_render":[{"func_name":"main:1","encoded_locals":{"x":6},"ordered_varnames":["x"],"parent_frame_id_list":[],"is_highlighted":true,"is_zombie":false,"is_parent":false,"unique_hash":"8","frame_id":8}],"globals":{},"ordered_globals":[],"func_name":"main","heap":{}},{"stdout":"","event":"return","line":1,"stack_to_render":[{"func_name":"main:1","encoded_locals":{"x":6,"return":["VOID"]},"ordered_varnames":["x","return"],"parent_frame_id_list":[],"is_highlighted":true,"is_zombie":false,"is_parent":false,"unique_hash":"9","frame_id":9}],"globals":{},"ordered_globals":[],"func_name":"main","heap":{}}],"userlog":"Debugger VM maxMemory: 3513M\n"}

everything is blank inside {}.

I also tried accessing Java Visualizer by http://localhost/java_visualize. but its not working.

Please help.

Thanks.

daveagp commented 8 years ago

You need it in the exact same subfolder of jail as it appears in the root. So instead of java_jail-master/lib64, put it in java_jail-master/lib/x86_64-linux-gnu

nileshtakale commented 8 years ago

After copying all files from /jai/lib64 to /jail/lib, I executed below command and it gave me output.

/usr/java_visualizer/safeexec-master/safeexec --chroot_dir /usr/java_visualizer/java_jail-master --exec_dir / --share_newnet --nproc 50 --mem 30000000 --nfile 30 --env_vars CLASSPATH=./cp/:./cp/javax.json-1.0.jar:./java/lib/tools.jar --exec /java/bin/java traceprinter.InMemory < /usr/java_visualizer/java_jail-master/cp/traceprinter/test-input.txt

now what next?

daveagp commented 8 years ago

If that output looks more or less correct, try using the web interface again.

nileshtakale commented 8 years ago

Yeah, I tried but as you said "configuring the glue to the webserver" is what we need to do

daveagp commented 8 years ago

So what happens when you try to use the visualizer webpage now?

nileshtakale commented 8 years ago

Faced below error safeexec

daveagp commented 8 years ago

Go into java_safe_maketrace.php, uncomment the line "// echo $jv_cmd; // for debugging" and try again.

nileshtakale commented 8 years ago

Below is the error description, error_dev

nileshtakale commented 8 years ago

I do not know if I am correct or not but why it is looking at below location?

:/cp/visualizer-stdlib traceprinter.InMemory. Class file is not at that location.

daveagp commented 8 years ago

Not sure what you are asking me. Is "class file is not at that location" an error message? It should be there. And this worked, no?

/usr/java_visualizer/safeexec-master/safeexec --chroot_dir /usr/java_visualizer/java_jail-master --exec_dir / --share_newnet --nproc 50 --mem 30000000 --nfile 30 --env_vars CLASSPATH=./cp/:./cp/javax.json-1.0.jar:./java/lib/tools.jar --exec /java/bin/java traceprinter.InMemory < /usr/java_visualizer/java_jail-master/cp/traceprinter/test-input.txt

In that error message there is the command-line string. Try running it at the command-line manually.

nileshtakale commented 8 years ago

Yes, I did get output from above command. That's what I am telling you there is no file InMemory.class at /jail/cp/visualizer-stdlib.

Command from error message

/usr/java_visualizer/safeexec-master/safeexec --chroot_dir /usr/java_visualizer/java_jail-master/ --clock 15 --cpu 10 --mem 4000000 --exec_dir / --env_vars '' --nproc 50 --nfile 50 --share_newnet --exec /usr/java_visualizer/java_jail-master/java/bin/java -Xmx512M -cp /cp/:/cp/javax.json-1.0.jar:/java/lib/tools.jar:/cp/visualizer-stdlib traceprinter.InMemory

error 2 (No such file or directory): execve error

Command exited with non-zero status (1) elapsed time: 0 seconds memory usage: 0 kbytes cpu usage: 0.000 seconds

daveagp commented 8 years ago

I don't think you are correctly understanding what the command line is doing. It's telling java there are 4 classpath elements. The traceprinter.InMemory need not be in the 4th one.

The problem I DO see is that the generated command is wrong. Where it says "--exec /usr/java_visualizer/java_jail-master/java/bin/java" it should just say "--exec /java/bin/java" because that's the correct path once you've been chrooted. Did you make further changes to the config.json file or did you make alterations to java_safe_ram_maketrace.php?

nileshtakale commented 8 years ago

Ok. I had done changes in java_safe_ram_maketrace.php and changed config.json for jail and safeexec paths. After reverting changes in java_safe_ram_maketrace.php facing below error.

error_php

nileshtakale commented 8 years ago

Command from error message and its message,

/usr/java_visualizer/safeexec-master/safeexec --chroot_dir /usr/java_visualizer/java_jail-master/ --clock 15 --cpu 10 --mem 4000000 --exec_dir / --env_vars '' --nproc 50 --nfile 50 --share_newnet --exec /java/bin/java -Xmx512M -cp /cp/:/cp/javax.json-1.0.jar:/java/lib/tools.jar:/cp/visualizer-stdlib traceprinter.InMemory

Time Limit Exceeded elapsed time: 15 seconds memory usage: 2799760 kbytes cpu usage: 0.116 seconds

daveagp commented 8 years ago

Try increasing the memory limit specified in the json file to 30000000.

nileshtakale commented 8 years ago

Same error,

Server error. Report a bug to daveagp@gmail.com (click 'Generate URL' and include it). Debug info (also copied to console): textStatus: parsererror errorThrown: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data Server reply: /usr/java_visualizer/safeexec-master/safeexec --chroot_dir /usr/java_visualizer/java_jail-master/ --clock 15 --cpu 10 --mem 30000000 --exec_dir / --env_vars '' --nproc 50 --nfile 50 --share_newnet --exec /java/bin/java -Xmx512M -cp /cp/:/cp/javax.json-1.0.jar:/java/lib/tools.jar:/cp/visualizer-stdlib traceprinter.InMemory{"code":"public class ClassNameHere {\n public static void main(String[] args) {\n \n }\n}","stdin":"","trace":[{"stdout":"","event":"call","line":4,"stack_to_render":[{"func_name":"main:4","encoded_locals":{},"ordered_varnames":[],"parent_frame_id_list":[],"is_highlighted":true,"is_zombie":false,"is_parent":false,"unique_hash":"1","frame_id":1}],"globals":{},"ordered_globals":[],"func_name":"main","heap":{}},{"stdout":"","event":"step_line","line":4,"stack_to_render":[{"func_name":"main:4","encoded_locals":{},"ordered_varnames":[],"parent_frame_id_list":[],"is_highlighted":true,"is_zombie":false,"is_parent":false,"unique_hash":"2","frame_id":2}],"globals":{},"ordered_globals":[],"func_name":"main","heap":{}},{"stdout":"","event":"return","line":4,"stack_to_render":[{"func_name":"main:4","encoded_locals":{"return":["VOID"]},"ordered_varnames":["return"],"parent_frame_id_list":[],"is_highlighted":true,"is_zombie":false,"is_parent":false,"unique_hash":"3","frame_id":3}],"globals":{},"ordered_globals":[],"func_name":"main","heap":{}}],"userlog":"Debugger VM maxMemory: 455M\n"}

daveagp commented 8 years ago

Re-comment out the debugging line in java_safe_maketrace.php

nileshtakale commented 8 years ago

Hey..its working now.

working

daveagp commented 8 years ago

Excellent! Have fun!

nileshtakale commented 8 years ago

Thanks a lot!

nileshtakale commented 8 years ago

Sorry to bother you again but after fresh installation on AWS I am getting below error,

pytutor_ajax_timeout_millis is not defined. The variable is there in config.js.php. All commands for java jail and safeexec are executing properly.

Could you please help?

Thanks.

daveagp commented 8 years ago

Please start a new issue thread, not this one.

Did you remember to copy jv-config.example.json to jv-config.json as specified in the README?

nileshtakale commented 8 years ago

Hey...we got it resolved..we updated the PHP version and it worked.

Thanks.

susobhang70 commented 8 years ago

Hi, I am having a similar issue to the one mentioned in this thread. I'm on CentOS release 5.8 (Final)

When I try this command from java_jail: /home/ssad1/safeexec/safeexec --share_newnet --nproc 50 --mem 30000000 --nfile 30 --env_vars CLASSPATH=./cp/:./cp/javax.json-1.0.jar:./java/lib/tools.jar --exec ./java/bin/java traceprinter.InMemory < cp/traceprinter/test-input.txt

Output is: Exception in thread "event-handler" java.lang.OutOfMemoryError: unable to create new native thread at java.lang.Thread.start0(Native Method) at java.lang.Thread.start(Thread.java:714) at traceprinter.JSONTracingThread.handleEvent(JSONTracingThread.java:221) at traceprinter.JSONTracingThread.run(JSONTracingThread.java:136) OK elapsed time: 2 seconds memory usage: 5092524 kbytes cpu usage: 1.585 seconds When I run this: /home/ssad1/safeexec/safeexec --chroot_dir . --exec_dir / --share_newnet --nproc 50 --mem 3000000 --nfile 30 --env_vars CLASSPATH=/cp/:/cp/javax.json-1.0.jar:/java/lib/tools.jar --exec /java/bin/java traceprinter.InMemory < cp/traceprinter/test-input.txt

Output is: Error occurred during initialization of VM Could not allocate metaspace: 1073741824 bytes Command exited with non-zero status (1) elapsed time: 0 seconds memory usage: 0 kbytes cpu usage: 0.000 seconds

Both are run from inside the java_jail

daveagp commented 8 years ago

Please use a new issue. There, tell me what happens when you increase the --mem argument.