SQL injection vulnerabilities arise when user-controllable data is incorporated into database SQL queries in an unsafe manner. An attacker can supply crafted input to break out of the data context in which their input appears and interfere with the structure of the surrounding query.
Various attacks can be delivered via SQL injection, including reading or modifying critical application data, interfering with application logic, escalating privileges within the database and executing operating system commands.
Issue remediation
The most effective way to prevent SQL injection attacks is to use parameterised queries (also known as prepared statements) for all database access. This method uses two steps to incorporate potentially tainted data into SQL queries: first, the application specifies the structure of the query, leaving placeholders for each item of user input; second, the application specifies the contents of each placeholder. Because the structure of the query has already defined in the first step, it is not possible for malformed data in the second step to interfere with the query structure. You should review the documentation for your database and application platform to determine the appropriate APIs which you can use to perform parameterised queries. It is strongly recommended that you parameterise every variable data item that is incorporated into database queries, even if it is not obviously tainted, to prevent oversights occurring and avoid vulnerabilities being introduced by changes elsewhere within the code base of the application.
You should be aware that some commonly employed and recommended mitigations for SQL injection vulnerabilities are not always effective:
One common defense is to double up any single quotation marks appearing within user input before incorporating that input into a SQL query. This defense is designed to prevent malformed data from terminating the string in which it is inserted. However, if the data being incorporated into queries is numeric, then the defense may fail, because numeric data may not be encapsulated within quotes, in which case only a space is required to break out of the data context and interfere with the query. Further, in second-order SQL injection attacks, data that has been safely escaped when initially inserted into the database is subsequently read from the database and then passed back to it again. Quotation marks that have been doubled up initially will return to their original form when the data is reused, allowing the defense to be bypassed.
Another often cited defense is to use stored procedures for database access. While stored procedures can provide security benefits, they are not guaranteed to prevent SQL injection attacks. The same kinds of vulnerabilities that arise within standard dynamic SQL queries can arise if any SQL is dynamically constructed within stored procedures. Further, even if the procedure is sound, SQL injection can arise if the procedure is invoked in an unsafe manner using user-controllable data.
The Referer HTTP header appears to be vulnerable to SQL injection attacks. A single quote was submitted in the Referer HTTP header, and a general error message was returned. Two single quotes were then submitted and the error message disappeared. You should review the contents of the error message, and the application's handling of other input, to confirm whether a vulnerability is present.
Request 1
GET /LoggingAgent/LoggingAgent?url=//antifung.yolasite.com/&pagename=index&siteid=8a4986cb2dc8c27e012dcd5a0c3a4596&resolution=1920x1200&colorDepth=16&flash=1&java=1&sitereferer=&visitorId=C4A762FB-9ED0-0001-2F15-1374B3C317AE&visitId=C4A762FB-9EE0-0001-23F0-168637A01F71&LoggingAgentReturnType=script HTTP/1.1 Host: pixel.yola.com Proxy-Connection: keep-alive Referer: http://www.google.com/search?hl=en&q=' Accept: */* User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.94 Safari/534.13 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
<html><head><title>JBossWeb/2.0.1.GA - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-se ...[SNIP]... </b> Exception report</p> ...[SNIP]... <u>The full stack trace of the root cause is available in the JBossWeb/2.0.1.GA logs.</u> ...[SNIP]...
Request 2
GET /LoggingAgent/LoggingAgent?url=//antifung.yolasite.com/&pagename=index&siteid=8a4986cb2dc8c27e012dcd5a0c3a4596&resolution=1920x1200&colorDepth=16&flash=1&java=1&sitereferer=&visitorId=C4A762FB-9ED0-0001-2F15-1374B3C317AE&visitId=C4A762FB-9EE0-0001-23F0-168637A01F71&LoggingAgentReturnType=script HTTP/1.1 Host: pixel.yola.com Proxy-Connection: keep-alive Referer: http://www.google.com/search?hl=en&q='' Accept: */* User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.94 Safari/534.13 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
The sitereferer parameter appears to be vulnerable to SQL injection attacks. A single quote was submitted in the sitereferer parameter, and a general error message was returned. Two single quotes were then submitted and the error message disappeared. You should review the contents of the error message, and the application's handling of other input, to confirm whether a vulnerability is present.
Request 1
GET /LoggingAgent/LoggingAgent?url=//antifung.yolasite.com/&pagename=index&siteid=8a4986cb2dc8c27e012dcd5a0c3a4596&resolution=1920x1200&colorDepth=16&flash=1&java=1&sitereferer='&visitorId=C4A762FB-9ED0-0001-2F15-1374B3C317AE&visitId=C4A762FB-9EE0-0001-23F0-168637A01F71&LoggingAgentReturnType=script HTTP/1.1 Host: pixel.yola.com Proxy-Connection: keep-alive Referer: http://antifung.yolasite.com/ Accept: */* User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.94 Safari/534.13 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
<html><head><title>JBossWeb/2.0.1.GA - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-se ...[SNIP]... </b> Exception report</p> ...[SNIP]... <u>The full stack trace of the root cause is available in the JBossWeb/2.0.1.GA logs.</u> ...[SNIP]...
Request 2
GET /LoggingAgent/LoggingAgent?url=//antifung.yolasite.com/&pagename=index&siteid=8a4986cb2dc8c27e012dcd5a0c3a4596&resolution=1920x1200&colorDepth=16&flash=1&java=1&sitereferer=''&visitorId=C4A762FB-9ED0-0001-2F15-1374B3C317AE&visitId=C4A762FB-9EE0-0001-23F0-168637A01F71&LoggingAgentReturnType=script HTTP/1.1 Host: pixel.yola.com Proxy-Connection: keep-alive Referer: http://antifung.yolasite.com/ Accept: */* User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.94 Safari/534.13 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
If the HttpOnly attribute is set on a cookie, then the cookie's value cannot be read or set by client-side JavaScript. This measure can prevent certain client-side attacks, such as cross-site scripting, from trivially capturing the cookie's value via an injected script.
Issue remediation
There is usually no good reason not to set the HttpOnly flag on all cookies. Unless you specifically require legitimate client-side scripts within your application to read or set a cookie's value, you should set the HttpOnly flag by including this attribute within the relevant Set-cookie directive.
You should be aware that the restrictions imposed by the HttpOnly flag can potentially be circumvented in some circumstances, and that numerous other serious attacks can be delivered by client-side script injection, aside from simple cookie stealing.
The following cookie was issued by the application and does not have the HttpOnly flag set:
Coyote-2-ac9068e=ac90680:0; path=/
The cookie does not appear to contain a session token, which may reduce the risk associated with this issue. You should review the contents of the cookie to determine its function.
Request
GET /LoggingAgent/LoggingAgent?url=//infert.yolasite.com/&pagename=index&siteid=8a4986c82dc8c274012dcef0ba811d6e&resolution=1920x1200&colorDepth=16&flash=1&java=1&sitereferer=&visitorId=C4A762FC-34B0-0001-1BB0-19A685B01680&visitId=C4A762FC-34C0-0001-F593-CB3089C097E0&LoggingAgentReturnType=script HTTP/1.1 Host: pixel.yola.com Proxy-Connection: keep-alive Referer: http://infert.yolasite.com/ Accept: */* User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.94 Safari/534.13 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 Cookie: Coyote-2-ac9068e=ac90680:0
The following cookie was issued by the application and does not have the HttpOnly flag set:
Coyote-2-ac9068e=ac90680:0; path=/
The cookie does not appear to contain a session token, which may reduce the risk associated with this issue. You should review the contents of the cookie to determine its function.
Request
GET /favicon.ico HTTP/1.1 Host: pixel.yola.com Proxy-Connection: keep-alive Accept: */* User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.94 Safari/534.13 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 Cookie: Coyote-2-ac9068e=ac90680:0
Response
HTTP/1.1 404 Not Found SynthaSite-ID: hs5 (127.0.10.5) Content-Type: text/html Server: lighttpd/1.5.0 ntCoent-Length: 213 Date: Thu, 10 Feb 2011 17:03:34 GMT X-Varnish: 645181986 645181825 Age: 1 Via: 1.1 varnish Connection: keep-alive X-Cache: HIT Set-Cookie: Coyote-2-ac9068e=ac90680:0; path=/ Cache-Control: private Content-Length: 213
<div style='background-color: #f3f3f3;border: 1px solid #ccc;width:400px;margin-left:auto;margin-right:auto;margin-top:100px;padding:10px;font-family:verdana;'> 404. Sorry, we can't seem to find that ...[SNIP]...
If a web response states that it contains HTML content but does not specify a character set, then the browser may analyse the HTML and attempt to determine which character set it appears to be using. Even if the majority of the HTML actually employs a standard character set such as UTF-8, the presence of non-standard characters anywhere in the response may cause the browser to interpret the content using a different character set. This can have unexpected results, and can lead to cross-site scripting vulnerabilities in which non-standard encodings like UTF-7 can be used to bypass the application's defensive filters.
In most cases, the absence of a charset directive does not constitute a security flaw, particularly if the response contains static content. You should review the contents of the response and the context in which it appears to determine whether any vulnerability exists.
Issue remediation
For every response containing HTML content, the application should include within the Content-type header a directive specifying a standard recognised character set, for example charset=ISO-8859-1.
Request
GET /favicon.ico HTTP/1.1 Host: pixel.yola.com Proxy-Connection: keep-alive Accept: */* User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.94 Safari/534.13 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 Cookie: Coyote-2-ac9068e=ac90680:0
Response
HTTP/1.1 404 Not Found SynthaSite-ID: hs5 (127.0.10.5) Content-Type: text/html Server: lighttpd/1.5.0 ntCoent-Length: 213 Date: Thu, 10 Feb 2011 17:03:34 GMT X-Varnish: 645181986 645181825 Age: 1 Via: 1.1 varnish Connection: keep-alive X-Cache: HIT Set-Cookie: Coyote-2-ac9068e=ac90680:0; path=/ Cache-Control: private Content-Length: 213
<div style='background-color: #f3f3f3;border: 1px solid #ccc;width:400px;margin-left:auto;margin-right:auto;margin-top:100px;padding:10px;font-family:verdana;'> 404. Sorry, we can't seem to find that ...[SNIP]...