Search This Blog

Tuesday, November 8, 2016

Inspect java code with javasnoop

To inspect the java code on run time for local jvms, download the javasnoop from the below url
https://code.google.com/archive/p/javasnoop/
Once downloaded extract and change the startup.bat to point to your JDK not jre.
i changed to this to make it work with jdk 8 
echo %JAVA_HOME% | find /i "8" > NUL
not startup snoop via the bat or shell.
 
image
 
 
Now either attach to a local jvm process or specify the new process
 
Let me attach to my local eclipse code which i want to debug.
image
 
image
 
image
Add new hook to your class methods
image
 
Now you can print the variables while hook is active and tamper with the parameter and return values at run time.
 
image
 
If hook is active you might see this
image
 
 
 
change the variables in the jvm from here
image
 
Let me rename the variable to another value and see what happens in the target jvm.
i changed the variable to India and return value to india1
image
image
 
 
 
You can see that target jvm has new values now
image
 
This is very helpfull in debugging the COTS products where we don’t have the souce code and neither we are able to regenrate the source code by looking at the decompiiled binaries via JAD or whatever.
 
This will display the actual variables values at run time inside the jvm.
 
Oh one more thing, you can also execute custom scripts after your hooks are active as shown below.
click on this
image
 
image
 
execute now
 
image
Another cool feature is you can track your input data across the methods and classes.
 
You can find out where is the user data going by going into the CANARY mode.
 
Lets see how to enable this.
Go to actions and enable canary mode.
 
Enter the data you are interested in.
image
 
As the code is executed which is operating on the input data there will be a chirp in the canary mode as shown above.
Now you can directly hook all the methods your data is flowing throw, Cool isn’t it ?
I think its a life saver, i used to decompile the binaries from different decompilers and attach the generated source in eclipse to debug earlier, but i guess this is better and faster.
 
Make sure you use JDK to run eclipse else you will get error “ target jvm doesn’t have providers to attach to kinda stuff”
 
Steps required to Demo
  • Run the below code in eclipse using JDK and put a breat point at “ String value = a(abhi);”
  • Now debug the code and let the breakpoint hit the above line.
  • Now seperate cmd window open snoop and attach to the existing jvm.
  • Attach the hook, once attached resume the breakpoint in the eclipse.
  • Your hook will become active and you are ready to rock.
 
 
My source which was running in eclipse,
//
package javacode;

import java.lang.Integer;
import java.util.HashMap;

public class Main
{
private static final String String = null;


public static void main (String[] args) throws java.lang.Exception
{
   
    String abhi="df";
String value = a(abhi);

Thread.sleep(10000);
   
System.out.println(value);
   
}


public static String a(String abhi ) {
    // TODO Auto-generated method stub
   
    System.out.println(abhi);
   
    return abhi;
   
}
}












































































Monday, November 7, 2016

No initial context if connecting to remove jvm via load balancer jdk 6 --> jdk 8

If you remote server is on jdk 8 and your client is on a lower version of java and you are trying to access the context via the load balancer.

you might face a bootstrap timed out error.

RJVMFinder unable to create or find remote jvm.

Please use this parameter in your target JVM and restart the target server.

enableprotocolswitch=true

It has nothing to do with the loadbalancer configuration , please don't trouble network guys.

Friday, July 15, 2016

JBOSS - not able to lookup the connection factory from remote host

If your jboss is clustered with HAJNDI and it is running on a host with another node.

You telnet it on 1100 and get a marshal object from the port

For example telnet host 1100 and you see a marshaled object in putty, it might be the serialized object,a stub from the remote server.

you might get the reply from 8083 and ha load balance proxy.

Now jboss while it boots acquires port 4447 and your default 8080 and other ports for bisocket connector.So these ports are required for jboss to function properly.

If you are facing issues with looking up the remote CF it might be due to the network connectivity with required ports.

Try following things

Do a lookup from local system if it works you can be sure that the CF jndi is correct.

Now check the firewall status of the your jboss server. $ service iptable status or ip6tables

If it says firewall is turned off, try doing telnet on all the ports required for JBOSS.

You should be able to telnet all the required ports which are required for JBOSS not just the 8080.

If you are not able to telnet required ports from your client it means that you wont be able to do any lookups on the remote naming url, you might get the context though.



Also check for listen ports by

$ netstat -an |grep LISTEN

Check for your source and target specific connection

$netstat -tcp | egrep "clientip|destinationip"








Monday, July 4, 2016

How to start vnc server, connect to it and change password

From putty -->

$vncserver
after you  press enter you will get

-bash-4.1$ vncserver



New 'xxxxx:17 (appltest)' desktop is xxxx:17

Starting applications specified in /homet/.vnc/xstartup
Log file is /home/.vnc/xxxx:17.log


now connect on port 17 in vnc box

host:17 and press connect, before that you can set the password as


vncpasswd

after you press enter it will ask for the new password , use it above to connect.

This is an alternative to export displays from the linux based systems.