Difference between revisions of "Testing for Error Code (OWASP-IG-006)"

From OWASP
Jump to: navigation, search
(22 intermediate revisions by 8 users not shown)
Line 1: Line 1:
[[http://www.owasp.org/index.php/Web_Application_Penetration_Testing_AoC Up]] <br>
+
{{Template:OWASP Testing Guide v4}}
{{Template:OWASP Testing Guide v2}}
+
  
 
== Brief Summary ==
 
== Brief Summary ==
  
Often during a penetration test on web applications we come up against many error codes generated from applications or web servers.
+
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.
+
It's possible to cause these errors to be displayed by using a particular requests, either specially crafted with tools or created manually.
These codes are very useful to a pentester during his activities because they reveal a lot of information about databases, bugs, and other technological components directly linked with web applications.
+
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.
During the first part we'll analyse the more common codes (error messages) and bring into focus the steps of vulnerability assessment.
+
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 next steps of our analysis,. A good collection can facilitate the penetration test efficiency by decreasing the time taken to perform the overall pentest activity.
+
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 ==
 
== Description of the Issue ==
 
 
A common error that we can see during our search is the HTTP 404 Not Found.
 
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.
+
Often this error code provides useful details about the underlying web server and associated components. For example:  
For Example:
+
  
 
<pre>
 
<pre>
Line 22: Line 19:
 
</pre>
 
</pre>
  
This error message can be generated with the insertion of non-existing URL.
+
This error message can be generated by requesting a non-existant URL.
 
After the common message that shows a page not found, there is information about web server version, OS, modules and other products used.
 
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.
+
This information can be very important from an OS and application type and version identification point of view.
  
We will therefore the next occurrence that shows abnormal behavior:
+
Web server errors aren't the only useful output returned requiring security analysis. Consider the next example error message:
  
 
<pre>
 
<pre>
Line 33: Line 30:
 
</pre>
 
</pre>
  
What's happened? We'll proceed step by step.
+
What happened? We will explain step-by-step below.
  
For example, the 80004005 is a generic IIS error code which indicates that isn't possible to access a database.<br>
+
In this example, the 80004005 is a generic IIS error code which indicates that it could not establish a connection to its associated database. In many cases, the error message will detail the type of the database. This will often indicate the underlying operating system by association. With this information, the penetration tester can plan an appropriate strategy for the security test.
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.
+
 
 +
By manipulating the variables that are passed to the database connect string, we can invoke more detailed errors.
 
<pre>
 
<pre>
 
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
 
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
Line 42: Line 40:
 
</pre>
 
</pre>
  
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.
+
In this example, we can see a generic error in the same situation which reveals the type and version of the associated database system and a dependence on Windows operating system registry key values.
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.
+
Now we will look at a practical example with a security test against a web application that loses its link to its database server and does not handle the exception in a controlled manner. This could be caused by a database name resolution issue, processing of unexpected variable values, 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.
+
Consider the scenario where we have a database administration web portal, which can be used as a front end GUI to issue database queries, create tables, and modify database fields. During the POST of the logon credentials, the following error message is presented to the penetration tester. The message indicates the presence of a MySQL database server:
During POST of credentials for the log-on phase meet this message that evidences the presence of a MySQL database server:
+
  
 
<pre>
 
<pre>
Line 58: Line 51:
 
</pre>
 
</pre>
 
 
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).
+
If we see in the HTML code of the logon 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 database server under the penetration tester's control in an attempt to fool the application into thinking that the logon was successful.
 +
 
 
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.
 
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.
+
 
 +
'''Error Handling in IIS and ASP .net'''
 +
 
 +
ASP .net is a common framework from Microsoft used for developing web applications. IIS is one of the commonly used web server. Errors occur in all applications, we try to trap most errors but it is almost impossible to cover each and every exception.
 +
 
 +
IIS uses a set of custom error pages generally found in c:\winnt\help\iishelp\common to display errors like '404 page not found' to the user. These default pages can be changed and custom errors can be configured for IIS server. When IIS receives a request for an aspx page, the request is passed on to the dot net framework.
 +
 
 +
There are various ways by which errors can be handled in dot net framework. Errors are handled at three places in ASP .net:
 +
 
 +
# Inside Web.config customErrors section
 +
# Inside global.asax Application_Error Sub
 +
# At the the aspx or associated codebehind page in the Page_Error sub
 +
 
 +
 
 +
'''Handling errors using web.config'''
 +
<pre>
 +
<customErrors defaultRedirect="myerrorpagedefault.aspx" mode="On|Off|RemoteOnly">
 +
  <error statusCode="404" redirect="myerrorpagefor404.aspx"/>
 +
  <error statusCode="500" redirect="myerrorpagefor500.aspx"/>
 +
</customErrors>
 +
</pre>
 +
 
 +
mode="On" will turn on custom errors. mode=RemoteOnly will show custom errors to the remote web application users. A user accessing the server locally will be presented with the complete stack trace and custom errors will not be shown to him.
 +
 
 +
All the errors, except those explicitly specified, will cause a redirection to the resource specified by defaultRedirect, i.e., myerrorpagedefault.aspx.
 +
A status code 404 will be handled by myerrorpagefor404.aspx.
 +
 
 +
 
 +
'''Handling errors in Global.asax'''
 +
 
 +
When an error occurs, the Application_Error sub is called. A developer can write code for error handling/page redirection in this sub.
 +
 
 +
<pre>
 +
Private Sub Application_Error (ByVal sender As Object, ByVal e As System.EventArgs)
 +
    Handles MyBase.Error
 +
End Sub
 +
</pre>
 +
 
 +
 
 +
'''Handling errors in Page_Error sub'''
 +
 
 +
This is similar to application error.
 +
 
 +
<pre>
 +
Private Sub Page_Error (ByVal sender As Object, ByVal e As System.EventArgs)
 +
    Handles MyBase.Error
 +
End Sub
 +
</pre>
 +
 
 +
 
 +
'''Error hierarchy in ASP .net'''
 +
 
 +
Page_Error sub will be processed first, followed by global.asax Application_Error sub, and, finally, customErrors section in web.config file.
 +
 
 +
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 (for example, SQL injection or Cross Site Scripting (XSS) attacks) and can reduce false positives.
 +
 
 +
 
 +
'''How to test for ASP.net and IIS Error Handling'''
 +
 
 +
Fire up your browser and type a random page name
 +
 
 +
<pre>
 +
http:\\www.mywebserver.com\anyrandomname.asp
 +
</pre>
 +
 
 +
If the server returns
 +
 
 +
<pre>
 +
The page cannot be found
 +
 
 +
HTTP 404 - File not found
 +
Internet Information Services
 +
</pre>
 +
 
 +
it means that IIS custom errors are not configured. Please note the .asp extension.
 +
 
 +
Also test for .net custom errors. Type a random page name with aspx extension in your browser
 +
 
 +
<pre>
 +
http:\\www.mywebserver.com\anyrandomname.aspx
 +
</pre>
 +
 
 +
If the server returns
 +
 
 +
<pre>
 +
Server Error in '/' Application.
 +
--------------------------------------------------------------------------------
 +
 
 +
The resource cannot be found.
 +
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
 +
</pre>
 +
 
 +
custom errors for .net are not configured.
  
 
== Black Box testing and example ==
 
== Black Box testing and example ==
Line 82: Line 168:
 
'''Test:'''
 
'''Test:'''
 
<pre>
 
<pre>
1. network problems
+
1. Network problems
2. bad configuration about host database address
+
2. Bad configuration about host database address
 
</pre>
 
</pre>
 
'''Result:'''
 
'''Result:'''
Line 92: Line 178:
 
'''Test:'''
 
'''Test:'''
 
<pre>
 
<pre>
1. Authentication Failed
+
1. Authentication failed
 
2. Credentials not inserted
 
2. Credentials not inserted
 
</pre>
 
</pre>
 
'''Result:'''
 
'''Result:'''
  
Firewall version used for authentication<br>
+
Firewall version used for authentication:<br>
 
<pre>
 
<pre>
 
Error 407
 
Error 407
Line 110: Line 196:
 
'''Test:'''
 
'''Test:'''
  
Enumeration of the directories with access denied.<br>
+
Enumeration of the directories with access denied:<br>
 
<pre>
 
<pre>
 
http://<host>/<dir>
 
http://<host>/<dir>
Line 127: Line 213:
  
 
* [1] [[http://www.ietf.org/rfc/rfc2616.txt?number=2616 RFC2616]] Hypertext Transfer Protocol -- HTTP/1.1
 
* [1] [[http://www.ietf.org/rfc/rfc2616.txt?number=2616 RFC2616]] Hypertext Transfer Protocol -- HTTP/1.1
 
 
 
{{Category:OWASP Testing Project AoC}}
 

Revision as of 09:43, 9 October 2012

This article is part of the new OWASP Testing Guide v4. 
At the moment the project is in the REVIEW phase.

Back to the OWASP Testing Guide v4 ToC: https://www.owasp.org/index.php/OWASP_Testing_Guide_v4_Table_of_Contents Back to the OWASP Testing Guide Project: http://www.owasp.org/index.php/OWASP_Testing_Project

Contents


Brief Summary

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 requests, 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 this error code provides useful details about the underlying web server and associated 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 by requesting a non-existant 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 from an OS and application type and version identification point of view.

Web server errors aren't the only useful output returned requiring security analysis. Consider the next example error message:

Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[DBNETLIB][ConnectionOpen(Connect())] - SQL server does not exist or access denied 

What happened? We will explain step-by-step below.

In this example, the 80004005 is a generic IIS error code which indicates that it could not establish a connection to its associated database. In many cases, the error message will detail the type of the database. This will often indicate the underlying operating system by association. With this information, the penetration tester can plan an appropriate strategy for the security test.

By manipulating the variables that are passed to the database connect string, we can invoke more detailed errors.

Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC Access 97 ODBC driver Driver]General error Unable to open registry key 'DriverId'

In this example, we can see a generic error in the same situation which reveals the type and version of the associated database system and a dependence on Windows operating system registry key values.

Now we will look at a practical example with a security test against a web application that loses its link to its database server and does not handle the exception in a controlled manner. This could be caused by a database name resolution issue, processing of unexpected variable values, or other network problems.

Consider the scenario where we have a database administration web portal, which can be used as a front end GUI to issue database queries, create tables, and modify database fields. During the POST of the logon credentials, the following error message is presented to the penetration tester. The message indicates 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 logon 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 database server under the penetration tester's control in an attempt to fool the application into thinking that the logon was successful.

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.


Error Handling in IIS and ASP .net

ASP .net is a common framework from Microsoft used for developing web applications. IIS is one of the commonly used web server. Errors occur in all applications, we try to trap most errors but it is almost impossible to cover each and every exception.

IIS uses a set of custom error pages generally found in c:\winnt\help\iishelp\common to display errors like '404 page not found' to the user. These default pages can be changed and custom errors can be configured for IIS server. When IIS receives a request for an aspx page, the request is passed on to the dot net framework.

There are various ways by which errors can be handled in dot net framework. Errors are handled at three places in ASP .net:

  1. Inside Web.config customErrors section
  2. Inside global.asax Application_Error Sub
  3. At the the aspx or associated codebehind page in the Page_Error sub


Handling errors using web.config

<customErrors defaultRedirect="myerrorpagedefault.aspx" mode="On|Off|RemoteOnly">
   <error statusCode="404" redirect="myerrorpagefor404.aspx"/>
   <error statusCode="500" redirect="myerrorpagefor500.aspx"/>
</customErrors>

mode="On" will turn on custom errors. mode=RemoteOnly will show custom errors to the remote web application users. A user accessing the server locally will be presented with the complete stack trace and custom errors will not be shown to him.

All the errors, except those explicitly specified, will cause a redirection to the resource specified by defaultRedirect, i.e., myerrorpagedefault.aspx. A status code 404 will be handled by myerrorpagefor404.aspx.


Handling errors in Global.asax

When an error occurs, the Application_Error sub is called. A developer can write code for error handling/page redirection in this sub.

Private Sub Application_Error (ByVal sender As Object, ByVal e As System.EventArgs) 
     Handles MyBase.Error
End Sub


Handling errors in Page_Error sub

This is similar to application error.

Private Sub Page_Error (ByVal sender As Object, ByVal e As System.EventArgs) 
     Handles MyBase.Error
End Sub


Error hierarchy in ASP .net

Page_Error sub will be processed first, followed by global.asax Application_Error sub, and, finally, customErrors section in web.config file.

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 (for example, SQL injection or Cross Site Scripting (XSS) attacks) and can reduce false positives.


How to test for ASP.net and IIS Error Handling

Fire up your browser and type a random page name

http:\\www.mywebserver.com\anyrandomname.asp

If the server returns

The page cannot be found

HTTP 404 - File not found
Internet Information Services

it means that IIS custom errors are not configured. Please note the .asp extension.

Also test for .net custom errors. Type a random page name with aspx extension in your browser

http:\\www.mywebserver.com\anyrandomname.aspx

If the server returns

Server Error in '/' Application.
--------------------------------------------------------------------------------

The resource cannot be found. 
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. 

custom errors for .net are not configured.

Black Box testing and example

Test:

telnet <host target> 80
GET /<wrong page> HTTP/1.1
<CRLF><CRLF>

Result:

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

Test:

1. Network problems
2. Bad configuration about host database address

Result:

Microsoft OLE DB Provider for ODBC Drivers (0x80004005) '
[MySQL][ODBC 3.51 Driver]Unknown MySQL server host

Test:

1. Authentication failed
2. Credentials not inserted

Result:

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

Test:

Enumeration of the directories with access denied:

http://<host>/<dir>

Result:

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.

References

  • [1] [RFC2616] Hypertext Transfer Protocol -- HTTP/1.1