Wednesday, November 18, 2009

Appendix B. Flowershop Bugs

 
 
  

 


 


Security and Cryptography Security Software Engineering Internet/Online Mike Andrews James A. Whittaker Addison-Wesley Professional How to Break Web Software: Functional and Security Testing of Web Applications and Web Services

Appendix B. Flowershop Bugs


URL

sendmessage.php

Bug Type

Direct Request

Description

By sending a direct request to the sendmessage.php script, an attacker can get the Web application to send an e-mail of its choice, with whatever subject, return address, and message that it likes, and any number of times it wants (open mailer). The Web application protects against this by checking the HTTP-Referer field, but you cannot rely on this. You can specify it in a direct request.

Repro Steps

Use Netcat to send a request to the server by connecting to the server's port 80 and echoing the following. You can't use TELNET because it echoes at the end of each line and will terminate after the blank like in the request.


POST /hackerland/sendmessage.php HTTP/1.0
Referer:
http://crash.se.fit.edu/hackerland/tellfriend.php
Content-Type: application/x-www-form-urlencoded
Content-Length: 148
subject=Money+making+scheme&email=myemail@scam.net&start
txt=Free+Money!!!&endtxt=&from=A+Friend&to=user
@hotmail.com&message=email+me+to+find+out+how


If you change the field values, make sure you update the Content-Length field to reflect the new site (count of characters in the parameters string).


This is one of the hardest bugs to find and exploit in the Flowershop application.

Bug Output

The server will respond with the message that an e-mail would have been sent with the data provided in the preceding query. For example, the response from the server for the preceding query would be as follows:


   HTTP/1.1 200 OK
Date: Thu, 18 Dec 2003 04:49:01 GMT
Server: Apache/2.0.40 (Red Hat Linux)
Accept-Ranges: bytes
X-Powered-By: PHP/4.2.2
Content-Length: 2690
Connection: close
Content-Type: text/html; charset=ISO-8859-1


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN">
<html>
[...cut HTML page formatting code...]
<pre>This is the fakemail system, this email will NOT be
delivered and is intended for testing purposes ONLY!
Here's the e-mail that would have been sent:
Sent From: myemail@scam.net
Sent To: user@hotmail.com
Subject: Money making scheme
Message: Free Money!!!email me to find out how
</pre>
[...cut HTML page formatting code...]
</html>



URL

sendmessage.php (called from tellfriend.php)

Bug Type

Command Injection

Description

The Send Message page calls (what would be) an external program to send e-mail to another user. It is possible to submit information to this page that will cause it to execute command-line programs on the server and echo the results back to the browser.

Repro Steps

In the Tell a Friend form, enter any data for the From and To fields. Within the Message field, enter the following: '; ls –al ; <cr> The initial ' terminates the parameter, the ; starts a new command, ls –al is the command to execute (could easily be something else), the final ; makes the ' that is appended to the intended command be the start of a new command (although it's an invalid one), and the <cr> (carriage return) executes the invalid final command.

Bug Output

All depends on the command to execute. If using the preceding example, the expected output should be this:


This is the fakemail system, this email will NOT be
delivered and is intended for testing purposes ONLY!
Here's the e-mail that would have been sent:
Sent From: noreply@nowhere.com
Sent To: on
Subject: Message from Flos Flowershop
Message: You have been sent a message from Flos
Flowershop. Message follows\n—-\n\n
total 352
drwxrwxrwx 9 root root 4096 Dec 12 14:09
.
drwxrwxrwx 9 root root 4096 Dec 3 14:42
..
-rwxr—r— 1 nobody nobody 4079 Dec 10 15:00 account.php
-rwxr—r— 1 nobody nobody 3084 Dec 8 16:08
addmessage.php

...
[rest of directory listing]



URL

guestbook.php

Bug Type

Cross-Site Scripting

Description

The page that posts data for this page (Addmessage.php) doesn't check for illegal input; therefore, you can include script elements in this page that will (depending on browser settings) be executed automatically whenever a user views this page.

Repro Steps

The most obvious way of exploiting this vulnerability is to post a message that includes the following text:


<script>alert("hello, world")</script>


This code results in a message box containing hello, world. However, for further exploitation, the attacker could post a script that writes an invisible element—such as a 1x1 transparent GIF—gathered from a remote server and passes CGI parameters that contain cookie/session information. (The server would ignore them, but they would be posted in the log file.) You can include scripting in a page in numerous places. An exhaustive list is not appropriate in this document.

Bug Output

In the first case, a message box displays when a user views the page. In extended cases, the user sees nothing out of the ordinary, but information, such as session information, is leaked to a malicious user.



URL

selectflowers.php

Bug Type

Validation Tampering

Description

To ensure that users choose appropriate input for the quantity of flowers to purchase, the Input field on this page calls a JavaScript function to validate input whenever the focus on the field is lost. Removing this validation allows an attacker to enter any value he likes into the field. The field is not rechecked when the form is posted.

Repro Steps

Save the page to the local machine and edit the source. To remove the validation, either delete the body of the checkqty function or the onBlur action of the Quantity field. Finally, change the form's action to an absolute URL. Save the page and reload it into the browser.


You can enter any input into the field (even SQL injection is possible), but the easiest way to exploit this vulnerability is to select some flowers and enter a negative number as the quantity. Submitting the page and navigating to one that shows the cart's value (either the Flowers/Arrangements Selection page or the Checkout page) demonstrates the total as a negative amount (the cost of items multiplied by the user's input).

Bug Output

A negative value appears in the cart's total, but there is also the potential for an SQL injection attack on the INSERT statement executed on the server with the data provided from this input. (It's much harder than the negative quantity exploit.)



URL

selectarrangements.php

Bug Type

Validation Tampering

Description

To ensure that users choose appropriate input for the quantity of arrangements to purchase, the user interface provides a drop-down menu allowing the user only to select quantities from 1 to 10. However, an attacker can modify the page and insert his own values that are not validated on the server.

Repro Steps

Save the page to the local machine and edit the source. For one of the Select fields, modify an existing option or add a new one. Finally, change the form's action to an absolute URL. Save the page and reload it into the browser.


Via this new option, you can now post any input (an SQL injection exploit is even possible), but the easiest way to exploit this vulnerability is to use a negative number as the quantity. Submitting the page and navigating to one that shows the cart's value (either the Flowers/Arrangements Selection page or the Checkout page) demonstrates the total as a negative amount (the cost of items multiplied by the user's input).

Bug Output

A negative value appears in the cart's total as in the preceding example, but there is also the potential for an SQL injection attack on the INSERT statement executed on the server with the data provided from this input. (That's much harder than the negative quantity exploit, though.)



URL

showdetails.php (called from selectflowers.php and selectarrangements.php)

Bug Type

SQL Injection

Description

By modifying either the type or id CGI parameter, the attacker can change the SQL query.

Repro Steps

Rather than modifying how the Calling page (selectflowers.php or selectarrangements.php) sends data to the pop-up window, go to the Show Details page directly by entering it into the main browser window with some relevant parameters (for example, showdetails.php?type=flowers&id=1). Append the string <sp>or 1=1 --<sp> to the end of the URL, and all the flowers' details will be displayed on the page. However, this information isn't very useful, so we modify the query to select information out of a database table that we shouldn't be able to access by appending the following to the original page request:


<sp>or 1=2 union select password from users --<sp>

Bug Output

The output from the SQL query is either a list of flower/arrangement descriptions or other information from the database.



URL

search.php

Bug Type

Hidden Field Manipulation/Directory Traversal

Description

To help the search component format the page so that it looks like part of the site, two hidden fields specify the header and footer to apply to the results. You can modify these fields to point to other files on the file system and include them in the output.

Repro Steps

Save the page to the local machine and edit the source to set the field(s) h and f to point to alternative files on the server. Save the page, reload it into the browser, and perform a search. The files will be included in the output.

Bug Output

On most occasions, the files that h and f point to will be shown in the browser window. However, sometimes the browser can't understand the output and will display nothing, even though the output is still available by viewing the source of the page.



URL

saveuser.php (called from register.php)

Bug Type

Buffer Overflow

Description

When a user forces more than 50 characters into the Card Number field on the Register.php page and submits it to the server, the user is redirected to a Buffer Overflow page. We use a descriptive page rather than an overflow because it is difficult to achieve a real overflow in a PHP, and an actual overflow would most likely stop the server and interrupt other users' testing.

Repro Steps

Save the page, remove the maxlength attribute from the cardnumber field, reload and post the data, or use a direct post request like in the direct request vulnerability.

Bug Output

The user should be redirected to the Buffer Overflow page.



URL

checksession.php/login.php

Bug Type

SQL Injection

Description

An attacker can utilize SQL injection in the Login field to allow him to log in as the first user in the database.

Repro Steps

Insert the string ' or 1=1 --<sp> into the Login field. (Leave the Password field blank.)

Bug Output

The login/password will be accepted, and the attacker will be logged in as the first registered user.



URL

account.php (calls userdetails.php)

Bug Type

Session Hijacking

Description

The sequence numbers generated for a user's cart and a token generated to "remember" them whenever they return to the site are easily guessable. Although the cart number is a temporary cookie that is stored in memory and deleted when the browser is closed, the session cookie that is used to remember users is stored in the local file system and can easily be changed.

Repro Steps

Use the Flowershop application and register a user to create the required cookie. On the local file system, open the cookie file (usually in c:/documents and settings/%userprofile%/cookies/%userprofile%@hackerland). The second line in the file is the session value of the user. Changing this value allows a user to revisit the site and masquerade as a different user.

Bug Output

If a valid session is chosen, the user will be able to use the site as another user (purchases, details, and so on). If the session is invalid, the application will ask the user to log in.



URL

delivery.php

Bug Type

Forceful Browsing

Description

After the user has selected the flowers and arrangements that he would like and navigated to the Checkout page (registering himself or logging in as an existing user), he can jump directly to the Delivery.php page and bypass the payment mechanism.

Repro Steps

Select some flowers or arrangements and proceed to the Checkout page (either with an existing user and logging in if necessary or registering first). The user can then jump directly to the Delivery page without providing payment information and with no error being raised.

Bug Output

A payment received message appears and the flowers/arrangements purchased is printed.



     
     
      

     


     


     


    No comments: