Exploit-DB #17846
Description: Nortel Contact Recording Centralized Archive 6.5.1 - SQL Injection
Type: webapps
Platform: jsp
Date: 2011-09-15
Author: rgod

Exploit:
<?php
/*
Nortel Contact Recording Centralized Archive 6.5.1 EyrAPIConfiguration 
Web Service getSubKeys() Remote SQL Injection Exploit

tested against:
Microsoft Windows Server 2003 r2 sp2
Microsoft SQL Server 2005 Express

download uri:
ftp://ftp.avaya.com/incoming/Up1cku9/tsoweb/web1/software/c/contactcenter/crqm/6_5_CS1K_2/Nortel-DVD3-Archive-6_5.iso

background:

This software installs a Tomcat http server which listens on
port 8080 for incoming connections. It exposes the
following servlet as declared inside
c:\Program Files\[choosen folder]\Tomcat5\webapps\EyrAPI\WEB-INF\web.xml :

...
   <servlet-mapping>
      <servlet-name>EyrAPIConfiguration</servlet-name>
      <url-pattern>/EyrAPIConfiguration/*</url-pattern>
   </servlet-mapping>
...

at the following url:

http://[host]:8080/EyrAPI/EyrAPIConfiguration/EyrAPIConfigurationIf


Vulnerability:

without prior authentication, you can reach a web service
with various methods availiable, as described inside
the associated wsdl, see file:

c:\Program Files\[choosen folder]\Tomcat5\webapps\EyrAPI\WEB-INF\classes\EyrAPIConfiguration.wsdl 

among them, the getSubKeys() method.

Now look at getSubKeys() inside the decompiled
c:\Program Files\[choosen folder]\Tomcat5\webapps\EyrAPI\WEB-INF\classes\com\eyretel\eyrapi\EyrAPIConfigurationImpl.class

:
...
 public String getSubKeys(boolean iterateSubKeys, boolean includeValues, String systemId, String componentId, String sysCompId, String userName)
        throws RemoteException
    {
        StringBuffer xml;
        ConfigOwnerId configOwnerId;
        Connection conn;
        PreparedStatement pStmt;
        ResultSet rs;
        PreparedStatement pStmt2;
        ResultSet rs2;
        log.info((new StringBuilder()).append("Request getSubKeys: iterateSubKeys=").append(iterateSubKeys).append(", includeValues=").append(includeValues).append(", SystemId=").append(systemId).append(", componentId=").append(componentId).append(", sysCompId=").append(sysCompId).append(", userName=").append(userName).toString());
        xml = new StringBuffer("<ConfigurationNodeList>");
        configOwnerId = null;
        conn = null;
        pStmt = null;
        rs = null;
        pStmt2 = null;
        rs2 = null;
        try
        {
            conn = SiteDatabase.getInstance().getConnection();
            if(EyrAPIProperties.getInstance().getProperty("database", "MSSQLServer").equalsIgnoreCase("Oracle"))
            {
                if(componentId.compareToIgnoreCase("") == 0)
                    componentId = "*";
                if(systemId.compareToIgnoreCase("") == 0)
                    systemId = "*";
                if(sysCompId.compareToIgnoreCase("") == 0)
                    sysCompId = "*";
                if(userName.compareToIgnoreCase("") == 0)
                    userName = "*";
                pStmt = conn.prepareStatement((new StringBuilder()).append("SELECT ConfigOwnerID FROM ConfigOwnerView WHERE nvl(ComponentID, '*') = '").append(componentId).append("' AND ").append("nvl(SystemID, '*') = '").append(systemId).append("' AND ").append("nvl(SysCompID, '*') = '").append(sysCompId).append("' AND ").append("nvl(UserName, '*') = '").append(userName).append("'").toString());
                rs = pStmt.executeQuery();
            } else
            {
                pStmt = conn.prepareStatement((new StringBuilder()).append("SELECT ConfigOwnerID FROM ConfigOwnerView WHERE ISNULL(CONVERT(varchar(36), ComponentID), '') = '").append(unpunctuate(componentId)).append("' AND ").append("ISNULL(CONVERT(varchar(36), SystemID), '') = '").append(unpunctuate(systemId)).append("' AND ").append("ISNULL(CONVERT(varchar(36), SysCompID), '') = '").append(unpunctuate(sysCompId)).append("' AND ").append("ISNULL(UserName, '') = '").append(unpunctuate(userName)).append("'").toString());
                rs = pStmt.executeQuery();
            }
            if(rs.next())
            {
                String strConfigOwnerId = rs.getString(1);
                if(!rs.wasNull())
                    configOwnerId = new ConfigOwnerId(strConfigOwnerId);
                pStmt2 = conn.prepareStatement((new StringBuilder()).append("SELECT ConfigGroupID, ConfigGroupName FROM ConfigGroupView WHERE ConfigOwnerID = '").append(configOwnerId.toString()).append("'").toString());
                for(rs2 = pStmt2.executeQuery(); rs2.next(); xml.append(getSubKeyValuesInc(new Integer(rs2.getInt(1)), iterateSubKeys, includeValues)));
            }
        }
        catch(SQLException e)
        {
            String msg = "Unable to get subkeys";
            log.error(msg, e);
            throw new RemoteException(msg, e);
        }
        catch(GenericDatabaseException e)
        {
            String msg = "Unable to get subkeys";
            log.error(msg, e);
            throw new RemoteException(msg, e);
        }
        DbHelper.closeStatement(log, pStmt);
        DbHelper.closeResultSet(log, rs);
        DbHelper.closeStatement(log, pStmt2);
        DbHelper.closeResultSet(log, rs2);
        DbHelper.closeConnection(log, conn);
        break MISSING_BLOCK_LABEL_646;
        Exception exception;
        exception;
        DbHelper.closeStatement(log, pStmt);
        DbHelper.closeResultSet(log, rs);
        DbHelper.closeStatement(log, pStmt2);
        DbHelper.closeResultSet(log, rs2);
        DbHelper.closeConnection(log, conn);
        throw exception;
        xml.append("\n</ConfigurationNodeList>");
        log.info((new StringBuilder()).append("Response createKey= ").append(xml).toString());
        return xml.toString();
    }
...

This function uses unproperly the prepareStatement() function, a SELECT query is concatenated
inside of it and using user supplied values.

Note also that the unpunctuate() function is unuseful to clean the passed values:

...
protected String unpunctuate(String id)