Difference between revisions of "Unsafe JNI"

From OWASP
Jump to: navigation, search
(Reverting to last version not containing links to www.textsitdelro.com)
 
(One intermediate revision by one user not shown)
Line 1: Line 1:
[http://s1.shard.jp/olharder/auto-reply-business.html subaru auto dealer
 
] [http://s1.shard.jp/galeach/new29.html asian womens center
 
] [http://s1.shard.jp/olharder/autologous-cell.html game auto
 
] [http://s1.shard.jp/frhorton/2beniqaav.html african british defended queen that
 
] [http://s1.shard.jp/galeach/new151.html asian cups
 
] [http://s1.shard.jp/olharder/autopsy-picture.html maxson automatic machinery
 
] [http://s1.shard.jp/frhorton/y8fj1syi7.html star news paper in south africa
 
] [http://s1.shard.jp/galeach/new4.html hot asian schoolgirl
 
] [http://s1.shard.jp/losaul/wiremesh-australia.html australian population growth rate
 
] [http://s1.shard.jp/bireba/norton-antivirus.html antivirus for w32.spybot.worm
 
] [http://s1.shard.jp/losaul/wwe-wrestlemania.html australian artists female
 
] [http://s1.shard.jp/galeach/new172.html asian girl model thumbnail young
 
] [http://s1.shard.jp/losaul/upstream-petroleum.html map of melbourne suburbs australia
 
] [http://s1.shard.jp/bireba/computer-associates.html i run my antivirus and the computer shuts down
 
] [http://s1.shard.jp/losaul/unley-council-south.html australian book club
 
] [http://s1.shard.jp/losaul/bmw-australia.html bmw australia finance ltd] [http://s1.shard.jp/losaul/moosehead-beer.html lazy boy recliners australia
 
] [http://s1.shard.jp/olharder/bournes-auto.html automotive classified domain public script
 
] [http://s1.shard.jp/frhorton/c769e8i7o.html african flag picture
 
] [http://s1.shard.jp/galeach/new79.html asian gallery man
 
] [http://s1.shard.jp/galeach/new139.html teamasians
 
] [http://s1.shard.jp/frhorton/qpxrkrvqf.html african american line literature time
 
] [http://s1.shard.jp/galeach/new45.html buff asians
 
] [http://s1.shard.jp/bireba/avg-antivirus-linux.html serial for avg antivirus 7.1
 
] [http://s1.shard.jp/frhorton/dfj31yuuh.html bill gates africa donation] [http://s1.shard.jp/olharder/autoroll-654.html top] [http://s1.shard.jp/frhorton/tiwomyd3z.html africa forced removal south
 
] [http://s1.shard.jp/olharder/history-of-automobile.html james mangan automation
 
] [http://s1.shard.jp/losaul/job-agencies-sydney.html job agencies sydney australia] [http://s1.shard.jp/losaul/computer-pals.html australian education union tasmania
 
] [http://s1.shard.jp/galeach/new15.html asian gift store
 
] [http://s1.shard.jp/galeach/new34.html congentital adrenal hyperplasia
 
] [http://s1.shard.jp/olharder/autoroll-654.html top] [http://s1.shard.jp/olharder/automate-552.html auto upholstery in az
 
] [http://s1.shard.jp/losaul/australian-club.html car seat baby capsule australia
 
] [http://s1.shard.jp/olharder/alberta-auto.html auto service company toyota
 
] [http://s1.shard.jp/olharder/autoroll-654.html links] [http://s1.shard.jp/olharder/300m-auto.html automotive suspension part
 
] [http://s1.shard.jp/bireba/antivirus-software.html eztrust antivirus download
 
] [http://s1.shard.jp/olharder/autoroll-654.html top] [http://s1.shard.jp/frhorton/i13wxjnjb.html south african language dictionary
 
] [http://s1.shard.jp/losaul/new-england-university.html australian humour
 
] [http://s1.shard.jp/olharder/ontegra-automotive.html ontegra automotive] [http://s1.shard.jp/losaul/travel-shows-in.html budget car rental in australia
 
] [http://s1.shard.jp/galeach/new128.html asian chiks
 
] [http://s1.shard.jp/galeach/new19.html asian 4 u natalia
 
] [http://s1.shard.jp/bireba/review-zone-alarm.html inoculateit antivirus avboot
 
] [http://s1.shard.jp/olharder/arabian-automobiles.html auto restore windows xp
 
] [http://s1.shard.jp/bireba/norton-antivirus.html etrust antivirus 7.1 retail
 
] [http://s1.shard.jp/galeach/new52.html pretty asia women] 
 
http://www.textsitdelro.com
 
 
{{Template:Vulnerability}}
 
{{Template:Vulnerability}}
 
{{Template:Fortify}}
 
{{Template:Fortify}}
Line 126: Line 83:
 
==References==
 
==References==
  
* [1] B. Stearns. The Java™ Tutorial: The Java Native Interface. Sun Microsystems, 2005. http://java.sun.com/docs/books/tutorial/native1.1/
+
* [1] B. Stearns. The Java™ Tutorial: The Java Native Interface. Sun Microsystems, 2005. http://java.sun.com/docs/books/tutorial/native1.1/
 
* [2] Fortify Descriptions. http://vulncat.fortifysoftware.com.
 
* [2] Fortify Descriptions. http://vulncat.fortifysoftware.com.
  

Latest revision as of 13:28, 27 May 2009

This is a Vulnerability. To view all vulnerabilities, please see the Vulnerability Category page.


This article includes content generously donated to OWASP by Fortify.JPG.

Last revision (mm/dd/yy): 05/27/2009

Vulnerabilities Table of Contents

Description

Improper use of the Java Native Interface (JNI) can render Java applications vulnerable to security flaws in other languages.

Unsafe JNI errors occur when a Java application uses JNI to call code written in another programming language.


Risk Factors

TBD


Examples

The following Java code defines a class named Echo. The class declares one native method (defined below), which uses C to echo commands entered on the console back to the user.

	class Echo {
		public native void runEcho();
		
		static {
			System.loadLibrary("echo");
		}
		
		public static void main(String[] args) {
			new Echo().runEcho();
		}
	}

The following C code defines the native method implemented in the Echo class:

	#include <jni.h>
	#include "Echo.h"//the java class above compiled with javah
	#include <stdio.h>
	
	JNIEXPORT void JNICALL 
	Java_Echo_runEcho(JNIEnv *env, jobject obj) 
	{
		char buf[64]; 
		gets(buf);
		printf(buf);
	}

Because the example is implemented in Java, it may appear that it is immune to memory issues like buffer overflow vulnerabilities. Although Java does do a good job of making memory operations safe, this protection does not extend to vulnerabilities occurring in source code written in other languages that are accessed using the Java Native Interface. Despite the memory protections offered in Java, the C code in this example is vulnerable to a buffer overflow because it makes use of gets(), which does not perform any bounds checking on its input.

The Sun Java(TM) Tutorial provides the following description of JNI [2]:

The JNI framework lets your native method utilize Java objects in the same way that Java code uses these objects. A native method can create Java objects, including arrays and strings, and then inspect and use these objects to perform its tasks. A native method can also inspect and use objects created by Java application code. A native method can even update Java objects that it created or that were passed to it, and these updated objects are available to the Java application. Thus, both the native language side and the Java side of an application can create, update, and access Java objects and then share these objects between them.

The vulnerability in the example above could easily be detected through a source code audit of the native method implementation. This may not be practical or possible depending on the availability of the C source code and the way the project is built, but in many cases it may suffice. However, the ability to share objects between Java and native methods expands the potential risk to much more insidious cases where improper data handling in Java may lead to unexpected vulnerabilities in native code or unsafe operations in native code corrupt data structures in Java.

Vulnerabilities in native code accessed through a Java application are typically exploited in the same manner as they are in applications written in the native language. The only challenge to such an attack is for the attacker to identify that the Java application uses native code to perform certain operations. This can be accomplished in a variety of ways, including identifying specific behaviors that are often implemented with native code or by exploiting a system information leak in the Java application that exposes its use of JNI [2].

Related Attacks


Related Vulnerabilities


Related Controls

Related Technical Impacts


References