The security hole left with JNDI for server resources

In Java world, JNDI (Java Naming and Directory Interface) is one very common method for applications to access server resources like data sources, EJB's, JMS queues, file stores etc.
The security risk is that: Not only JNDI can be called by applications hosted in the same container, but also remotely.
In an organization, application server admins do not take care of security risks unknowingly or neglect by assuming they or on a secure LAN. This exposes the resources to grave risk as anyone within LAN can access unauthorized data without being detected and abuse the system.


ctx = null;
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "CONTEXT_FACTORY");
env.put(Context.PROVIDER_URL, "CONTEXT_PROVIDER_URL");
DataSource datasource = (DataSource)initialContext.lookup("DATASOURCE_CONTEXT_NAME");
try {
    ctx = new InitialContext(env);
    Connection conn = datasource.getConnection();
    //perfrom queries with the connection
    conn.close();
} catch (Exception e) {
    e.printStackTrace();
}

So one can query the database just by knowing three things.
  1. Context.INITIAL_CONTEXT_FACTORY : this is container object reference
  2. Context.PROVIDER_URL : remote url of the container
  3.  DATASOURCE_CONTEXT_NAME : name of the datasource configured in container
One can know about INITIAL_CONTEXT_FACTORY if they know the type of container, example it would be "com.ibm.websphere.naming.WsnInitialContextFactory"

Provider URL is the URL of the container, also provide the port of the container.

Datasource name is little tricky to know, but assume you know it (by guessing it, by asking or by reading it from some other place), you can connect to database without knowing database username and password.

Server administrators need to set following parameters to avoid this kind of bypass

Context.SECURITY_PRINCIPAL
Context.SECURITY_CREDENTIALS
 
This attack is limited in Intranet environment only.

Comments

Popular posts from this blog

Caused by: java.sql.SQLTimeoutException: ORA-01013: user requested cancel of current operation

HashiCorp Vault Integration with Ansible Etower using approle

utility to extract date from text with java