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.
Remediation background
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 PHPSESSID cookie appears to be vulnerable to SQL injection attacks. A single quote was submitted in the PHPSESSID cookie, 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.
The application attempts to block SQL injection attacks but this can be circumvented by double URL-encoding the blocked characters - for example, by submitting %2527 instead of the ' character.
Remediation detail
There is probably no need to perform a second URL-decode of the value of the PHPSESSID cookie as the web server will have already carried out one decode. In any case, the application should perform its input validation after any custom canonicalisation has been carried out.
Request 1
GET /peanut-labs-acquired-by-online-research-company-e-rewards-2/ HTTP/1.1 Host: www1.peanutlabs.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Connection: close Cookie: pl_user_id=d41d8cd98f-285ee847b9a2bf89ede3fbb81de1ea0f; SESSef469ce213eb8a405bbf25673950acca=0obr3bvubl5fq0qq2jj04d7pp6; pl_email=test4%40fastdial.net; __utmz=28928570.1294536852.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); PHPSESSID=3jamnj3v5les4euhv3rnmsdb04%2527; __utma=28928570.961439791.1294536852.1294536852.1294536852.1; __utmc=28928570; pl_lang=en_US; __utmb=28928570.3.10.1294536852;
Response 1
HTTP/1.1 500 Internal Server Error Date: Sun, 09 Jan 2011 07:24:43 GMT Server: Apache/2.2.14 (Ubuntu) X-Powered-By: PHP/5.3.2-1ubuntu4.5 Expires: Wed, 11 Jan 1984 05:00:00 GMT Last-Modified: Sun, 09 Jan 2011 07:24:43 GMT Cache-Control: no-cache, must-revalidate, max-age=0 Pragma: no-cache Vary: Accept-Encoding Content-Length: 369 Connection: close Content-Type: text/html; charset=utf-8
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <meta http-equiv="Conte ...[SNIP]...
Request 2
GET /peanut-labs-acquired-by-online-research-company-e-rewards-2/ HTTP/1.1 Host: www1.peanutlabs.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Connection: close Cookie: pl_user_id=d41d8cd98f-285ee847b9a2bf89ede3fbb81de1ea0f; SESSef469ce213eb8a405bbf25673950acca=0obr3bvubl5fq0qq2jj04d7pp6; pl_email=test4%40fastdial.net; __utmz=28928570.1294536852.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); PHPSESSID=3jamnj3v5les4euhv3rnmsdb04%2527%2527; __utma=28928570.961439791.1294536852.1294536852.1294536852.1; __utmc=28928570; pl_lang=en_US; __utmb=28928570.3.10.1294536852;
Response 2
HTTP/1.1 200 OK Date: Sun, 09 Jan 2011 07:24:43 GMT Server: Apache/2.2.14 (Ubuntu) X-Powered-By: PHP/5.3.2-1ubuntu4.5 X-Pingback: http://www1.peanutlabs.com/xmlrpc.php Link: <http://www1.peanutlabs.com/?p=568>; rel=shortlink Vary: Accept-Encoding Connection: close Content-Type: text/html; charset=UTF-8 Content-Length: 29570
The REST URL parameter 3 appears to be vulnerable to SQL injection attacks. A single quote was submitted in the REST URL parameter 3, 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.
The application attempts to block SQL injection attacks but this can be circumvented by double URL-encoding the blocked characters - for example, by submitting %2527 instead of the ' character.
Remediation detail
There is probably no need to perform a second URL-decode of the value of REST URL parameter 3 as the web server will have already carried out one decode. In any case, the application should perform its input validation after any custom canonicalisation has been carried out.
Request 1
GET /wp-content/plugins/contact-form-7%2527/scripts.js HTTP/1.1 Host: www1.peanutlabs.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Connection: close Cookie: pl_user_id=d41d8cd98f-285ee847b9a2bf89ede3fbb81de1ea0f; SESSef469ce213eb8a405bbf25673950acca=0obr3bvubl5fq0qq2jj04d7pp6; pl_email=test4%40fastdial.net; __utmz=28928570.1294536852.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); PHPSESSID=3jamnj3v5les4euhv3rnmsdb04; __utma=28928570.961439791.1294536852.1294536852.1294536852.1; __utmc=28928570; pl_lang=en_US; __utmb=28928570.3.10.1294536852;
Response 1
HTTP/1.1 500 Internal Server Error Date: Sun, 09 Jan 2011 07:24:33 GMT Server: Apache/2.2.14 (Ubuntu) X-Powered-By: PHP/5.3.2-1ubuntu4.5 Expires: Wed, 11 Jan 1984 05:00:00 GMT Last-Modified: Sun, 09 Jan 2011 07:24:33 GMT Cache-Control: no-cache, must-revalidate, max-age=0 Pragma: no-cache Vary: Accept-Encoding Content-Length: 369 Connection: close Content-Type: text/html; charset=utf-8
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <meta http-equiv="Conte ...[SNIP]...
Request 2
GET /wp-content/plugins/contact-form-7%2527%2527/scripts.js HTTP/1.1 Host: www1.peanutlabs.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Connection: close Cookie: pl_user_id=d41d8cd98f-285ee847b9a2bf89ede3fbb81de1ea0f; SESSef469ce213eb8a405bbf25673950acca=0obr3bvubl5fq0qq2jj04d7pp6; pl_email=test4%40fastdial.net; __utmz=28928570.1294536852.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); PHPSESSID=3jamnj3v5les4euhv3rnmsdb04; __utma=28928570.961439791.1294536852.1294536852.1294536852.1; __utmc=28928570; pl_lang=en_US; __utmb=28928570.3.10.1294536852;
Response 2
HTTP/1.1 404 Not Found Date: Sun, 09 Jan 2011 07:24:33 GMT Server: Apache/2.2.14 (Ubuntu) X-Powered-By: PHP/5.3.2-1ubuntu4.5 X-Pingback: http://www1.peanutlabs.com/xmlrpc.php Expires: Wed, 11 Jan 1984 05:00:00 GMT Last-Modified: Sun, 09 Jan 2011 07:24:34 GMT Cache-Control: no-cache, must-revalidate, max-age=0 Pragma: no-cache Vary: Accept-Encoding Connection: close Content-Type: text/html; charset=UTF-8 Content-Length: 40811
The User-Agent HTTP header appears to be vulnerable to SQL injection attacks. A single quote was submitted in the User-Agent 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.
The application attempts to block SQL injection attacks but this can be circumvented by double URL-encoding the blocked characters - for example, by submitting %2527 instead of the ' character.
Remediation detail
There is probably no need to perform a second URL-decode of the value of the User-Agent HTTP header as the web server will have already carried out one decode. In any case, the application should perform its input validation after any custom canonicalisation has been carried out.
Request 1
GET /xmlrpc.php HTTP/1.1 Host: www1.peanutlabs.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)%2527 Connection: close Cookie: pl_user_id=d41d8cd98f-285ee847b9a2bf89ede3fbb81de1ea0f; SESSef469ce213eb8a405bbf25673950acca=0obr3bvubl5fq0qq2jj04d7pp6; pl_email=test4%40fastdial.net; __utmz=28928570.1294536852.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); PHPSESSID=3jamnj3v5les4euhv3rnmsdb04; __utma=28928570.961439791.1294536852.1294536852.1294536852.1; __utmc=28928570; pl_lang=en_US; __utmb=28928570.3.10.1294536852;
Response 1
HTTP/1.1 500 Internal Server Error Date: Sun, 09 Jan 2011 07:24:40 GMT Server: Apache/2.2.14 (Ubuntu) X-Powered-By: PHP/5.3.2-1ubuntu4.5 Expires: Wed, 11 Jan 1984 05:00:00 GMT Last-Modified: Sun, 09 Jan 2011 07:24:40 GMT Cache-Control: no-cache, must-revalidate, max-age=0 Pragma: no-cache Vary: Accept-Encoding Content-Length: 369 Connection: close Content-Type: text/html; charset=utf-8
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <meta http-equiv="Conte ...[SNIP]...
Request 2
GET /xmlrpc.php HTTP/1.1 Host: www1.peanutlabs.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)%2527%2527 Connection: close Cookie: pl_user_id=d41d8cd98f-285ee847b9a2bf89ede3fbb81de1ea0f; SESSef469ce213eb8a405bbf25673950acca=0obr3bvubl5fq0qq2jj04d7pp6; pl_email=test4%40fastdial.net; __utmz=28928570.1294536852.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); PHPSESSID=3jamnj3v5les4euhv3rnmsdb04; __utma=28928570.961439791.1294536852.1294536852.1294536852.1; __utmc=28928570; pl_lang=en_US; __utmb=28928570.3.10.1294536852;
Response 2
HTTP/1.1 200 OK Date: Sun, 09 Jan 2011 07:24:40 GMT Server: Apache/2.2.14 (Ubuntu) X-Powered-By: PHP/5.3.2-1ubuntu4.5 Vary: Accept-Encoding Content-Length: 42 Connection: close Content-Type: text/plain
XML-RPC server accepts POST requests only.
2. Cross-domain script includepreviousnext There are 17 instances of this issue:
When an application includes a script from an external domain, this script is executed by the browser within the security context of the invoking application. The script can therefore do anything that the application's own scripts can do, such as accessing application data and performing actions within the context of the current user.
If you include a script from an external domain, then you are trusting that domain with the data and functionality of your application, and you are trusting the domain's own security to prevent an attacker from modifying the script to perform malicious actions within your application.
Issue remediation
Scripts should not be included from untrusted domains. If you have a requirement which a third-party script appears to fulfil, then you should ideally copy the contents of that script onto your own domain and include it from there. If that is not possible (e.g. for licensing reasons) then you should consider reimplementing the script's functionality within your own code.
Directory listings do not necessarily constitute a security vulnerability. Any sensitive resources within your web root should be properly access-controlled in any case, and should not be accessible by an unauthorised party who happens to know the URL. Nevertheless, directory listings can aid an attacker by enabling them to quickly identify the resources at a given path, and proceed directly to analysing and attacking them.
Issue remediation
There is not usually any good reason to provide directory listings, and disabling them may place additional hurdles in the path of an attacker. This can normally be achieved in two ways:
Configure your web server to prevent directory listings for all paths beneath the web root;
Place into each directory a default file (such as index.htm) which the web server will display instead of returning a directory listing.
Request
GET /wp-content/plugins/uBillboard/ HTTP/1.1 Host: www1.peanutlabs.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Connection: close Cookie: pl_user_id=d41d8cd98f-285ee847b9a2bf89ede3fbb81de1ea0f; SESSef469ce213eb8a405bbf25673950acca=0obr3bvubl5fq0qq2jj04d7pp6; pl_email=test4%40fastdial.net; __utmz=28928570.1294536852.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); PHPSESSID=3jamnj3v5les4euhv3rnmsdb04; __utma=28928570.961439791.1294536852.1294536852.1294536852.1; __utmc=28928570; pl_lang=en_US; __utmb=28928570.3.10.1294536852;
Response
HTTP/1.1 200 OK Date: Sun, 09 Jan 2011 03:10:38 GMT Server: Apache/2.2.14 (Ubuntu) Vary: Accept-Encoding Content-Length: 2631 Connection: close Content-Type: text/html;charset=UTF-8
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <html> <head> <title>Index of /wp-content/plugins/uBillboard</title> </head> <body> <h1>Index of /wp-content/plugins/uBillboard</h1> <table ...[SNIP]... <th><a href="?C=N;O=D">Name</a></th><th><a href="?C=M;O=A">Last modified</a></th><th><a href="?C=S;O=A">Size</a></th><th><a href="?C=D;O=A">Description</a> ...[SNIP]... <td><a href="/wp-content/plugins/">Parent Directory</a> ...[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 /wp-content/themes/showtime/scripts/timthumb.php HTTP/1.1 Host: www1.peanutlabs.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Connection: close Cookie: pl_user_id=d41d8cd98f-285ee847b9a2bf89ede3fbb81de1ea0f; SESSef469ce213eb8a405bbf25673950acca=0obr3bvubl5fq0qq2jj04d7pp6; pl_email=test4%40fastdial.net; __utmz=28928570.1294536852.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); PHPSESSID=3jamnj3v5les4euhv3rnmsdb04; __utma=28928570.961439791.1294536852.1294536852.1294536852.1; __utmc=28928570; pl_lang=en_US; __utmb=28928570.3.10.1294536852;
Response
HTTP/1.1 400 Bad Request Date: Sun, 09 Jan 2011 03:10:01 GMT Server: Apache/2.2.14 (Ubuntu) X-Powered-By: PHP/5.3.2-1ubuntu4.5 Vary: Accept-Encoding Content-Length: 58 Connection: close Content-Type: text/html
<pre>no image specified<br />TimThumb version : 1.14</pre>
The response contains the following Content-type statement:
Content-Type: image/jpeg
The response states that it contains a JPEG image. However, it actually appears to contain unrecognised content.
Issue background
If a web response specifies an incorrect content type, then browsers may process the response in unexpected ways. If the specified content type is a renderable text-based format, then the browser will usually attempt to parse and render the response in that format. If the specified type is an image format, then the browser will usually detect the anomaly and will analyse the actual content and attempt to determine its MIME type. Either case can lead to unexpected results, and if the content contains any user-controllable data may lead to cross-site scripting or other client-side vulnerabilities.
In most cases, the presence of an incorrect content type statement 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 a message body, the application should include a single Content-type header which correctly and unambiguously states the MIME type of the content in the response body.