Testing for Error Code (OTG-ERR-001)
Often during a penetration test on web applications we come up against many error codes generated from applications or web servers. It's possible to cause these errors to be displayed by using a particular request, either specially crafted with tools or created manually. These codes are very useful to penetration testers during their activities because they reveal a lot of information about databases, bugs, and other technological components directly linked with web applications. Within this section we'll analyse the more common codes (error messages) and bring into focus the steps of vulnerability assessment. The most important aspect for this activity is to focus one's attention on these errors, seeing them as a collection of information that will aid in the next steps of our analysis. A good collection can facilitate assessment efficiency by decreasing the overall time taken to perform the penetration test.
Description of the Issue
A common error that we can see during our search is the HTTP 404 Not Found. Often we can see this error code with many details about web server and other components. For Example:
Not Found The requested URL /page.html was not found on this server. Apache/2.2.3 (Unix) mod_ssl/2.2.3 OpenSSL/0.9.7g DAV/2 PHP/5.1.2 Server at localhost Port 80
This error message can be generated with the insertion of non-existing URL. After the common message that shows a page not found, there is information about web server version, OS, modules and other products used. This information can be very important both for OS and for applications during a penetration test, but web server errors aren't the only errors useful in a security analysis.
We will therefore the next occurrence that shows abnormal behavior:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005) [DBNETLIB][ConnectionOpen(Connect())] - SQL server does not exist or access denied
What's happened? We'll proceed step by step.
For example, the 80004005 is a generic IIS error code which indicates that isn't possible to access a database.
In many cases we can see that this code is followed by the version of the database. With this information, the pentester can plan an appropriate strategy for the security test.
Microsoft OLE DB Provider for ODBC Drivers error '80004005' [Microsoft][ODBC Access 97 ODBC driver Driver]General error Unable to open registry key 'DriverId'
The first example shows a connection error message obtained by SQL Server Database because the database server which linked into application is down or credentials don't allow access. However, this isn't the only information that we know; in fact, in this way we have discovered the kind of operating system. In this case we could verify if the web application permits change of variables value to connect to the database. In the second case we can see a generic error in the same situation (we know the database version) but with a different error message and database server. But in the end...It's the same thing!
Now we will look at a practical example with a security test on web application that loses the link with the database server because there is badly written code (the next error message is caused by the application, which can't resolve the database server name or when the variable value is modified) or other network problems.
For example, we have a database administration web portal which can be connected to db server after a log-on phase to realize queries, create tables and modify database fields. During POST of credentials for the log-on phase meet this message that evidences the presence of a MySQL database server:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005) [MySQL][ODBC 3.51 Driver]Unknown MySQL server host
If we see in the HTML code of the log-on page the presence of a hidden field with a database IP, we can try to change this value in the URL with the address of another database (our database, for example). Another example: knowing the database server that services a web application, we can take advantage of this information to carry out a SQL Injection for that kind of database or a persistent XSS test.
Information Gathering on web applications with server-side technology is quite difficult, but the information discovered can be useful for the correct execution of an attempted exploit and can reduce false positives.
Black Box testing and example
telnet <host target> 80 GET /<wrong page> HTTP/1.1 <CRLF><CRLF>
HTTP/1.1 404 Not Found Date: Sat, 04 Nov 2006 15:26:48 GMT Server: Apache/2.2.3 (Unix) mod_ssl/2.2.3 OpenSSL/0.9.7g Content-Length: 310 Connection: close Content-Type: text/html; charset=iso-8859-1
1. network problems 2. bad configuration about host database address
Microsoft OLE DB Provider for ODBC Drivers (0x80004005) ' [MySQL][ODBC 3.51 Driver]Unknown MySQL server host
1. Authentication Failed 2. Credentials not inserted
Firewall version used for authentication
Error 407 FW-1 at <firewall>: Unauthorized to access the document. • Authorization is needed for FW-1. • The authentication required by FW-1 is: unknown. • Reason for failure of last attempt: no user
Gray Box testing and example
Enumeration of the directories with access denied.
Directory Listing Denied This Virtual Directory does not allow contents to be listed.
Forbidden You don't have permission to access /<dir> on this server.
-  [RFC2616] Hypertext Transfer Protocol -- HTTP/1.1
OWASP Testing Guide v2
Here is the OWASP Testing Guide v2 Table of Contents