Difference between revisions of "Testing for business logic"
(→A real world example)
m (Reviewed - Minor Edits)
|Line 4:||Line 4:|
== Brief Summary ==
== Brief Summary ==
Testing for business logic flaws in a multi-functional dynamic web application requires thinking in unconventional ways. If an application's authentication mechanism is developed with the intention of performing steps 1,2,3 in order to authenticate, what happens if you go from 1 straight to step 3? In this simplistic example does the application
Testing for business logic flaws in a multi-functional dynamic web application requires thinking in unconventional ways. If an application's authentication mechanism is developed with the intention of performing steps 1,2,3 in order to authenticate, what happens if you go from 1 straight to step 3? In this simplistic example does the application provide access by failing open, deny access, or just error out with a 500 message. There are many examples that can be made here but the one constant is thinking outside of conventional wisdom. This type of vulnerability be detected by a vulnerability scanner and relies upon the skill and creativity of the penetration tester. In addition this type of vulnerability is usually one of the hardest to detect but at the same usually one of the most detrimental to the application if exploited.
Business logic comprises :
* Business rules that express business policy (such as channels, location, logistics, prices, and products); and
* Business rules that express business policy (such as channels, location, logistics, prices, and products); and
* Workflows the ordered tasks of passing documents or data from one participant (a person or a software system) to another.
on the business logic of an application are dangerous, difficult to detectand specific to application .
==Description of the Issue==
==Description of the Issue==
Revision as of 10:46, 24 June 2008
Testing for business logic flaws in a multi-functional dynamic web application requires thinking in unconventional ways. If an application's authentication mechanism is developed with the intention of performing steps 1,2,3 in order to authenticate, what happens if you go from 1 straight to step 3? In this simplistic example does the application provide access by failing open, deny access, or just error out with a 500 message. There are many examples that can be made here but the one constant is thinking outside of conventional wisdom. This type of vulnerability cannot be detected by a vulnerability scanner and relies upon the skill and creativity of the penetration tester. In addition this type of vulnerability is usually one of the hardest to detect but at the same time usually one of the most detrimental to the application if exploited.
Business logic comprises may include:
- Business rules that express business policy (such as channels, location, logistics, prices, and products); and
- Workflows based on the ordered tasks of passing documents or data from one participant (a person or a software system) to another.
Attacks on the business logic of an application are dangerous, difficult to detect, and are usually specific to the application being tested.
Description of the Issue
Business logic can have security flaws that allow a user to do something that isn't allowed by the business. For example, if there is a limit on reimbursement of $1000, could an attacker misuse the system to request more money than is allowed? Or perhaps you are supposed to do operations in a particular order, but an attacker could invoke them out of sequence. Or can a user make a purchase for a negative amount of money? Frequently these business logic security checks simply are not present in the application.
Automated tools find it hard to understand context, hence it's up to a person to perform these kinds of tests. The following two examples will illustrate how understanding the functionality of the application, the developers intentions, and some creative "out-of-the-box" thinking can break the applications logic and pay huge dividends. The following examples start with a simplistic parameter manipulation, whereas the second is a real world example of a multi-step process leading to complete destruction of the application (Note that this was a real world application penetration test so complete destruction was not actually implemented but a proof of concept was done instead).
Business Limits and Restrictions
Consider the rules for the business function being provided by the application. Are there any limits or restrictions on people's behavior? Then consider whether the application enforces those rules. It's generally pretty easy to identify the test and analysis cases to verify the application if you're familiar with the business. If you are a third-party tester, then you're going to have to use your common sense and ask the business if different operations should be allowed by the application. Sometimes in very complex applications you will not have a full understanding of every aspect of the application initially. In these situations it is best to have the client walk you through the application so that you may gain a better of the limits and intended functionality of the application before the actual test begins. Additionally having a direct line to the developers (if possible) while the testing proceeds will help out greatly if any questions arise regarding the applications functionality.
Setting the quantity of a product on an e-commerce site as a negative number may result in funds being credited to the attacker. The countermeasure to this problem is to implement stronger data validation, as the application permits negative numbers to be entered in the quantity field of the shopping cart.
Another more complex real world example that the author has come across in the wild pertains to a commerical banking application that many large financial institutions employ for their business customers. This application provides banking ACH electronic debit and credit services to its business customers. Initially when a business purchases this service they are provided two administrative level accounts in which they can create users at different privilege levels, such as one user can make purchases, another can approve purchases (such as a manager) over a designated dollar amount, etc. When a user is created by an administrator account a new userid is associated with this account. The userid's that are created are predictable, whereas if an admin for Spacely Sprockets creates two accounts consecutively their respective userid's will be 815 and 816, for example. To make things worse if two more accounts are created and thier respective userid's are 817 and 819 then it can be assumed that another companies admin has created a user account for their company with the userid of 818.
The business logic error here is that the developers were under the assumption that no one would ever see the userid that was associated with the username when the account was created (since it was passed in a POST request) or especially try to manipulate this userid parameter. To make things worse this parameter is predictable (a linear sequence of numbers initiating from 1 and incrementing by 1), and in addition other users userid's can be enumerated within the application.
With the understanding of how the application functions and the understanding of the developers misguided assumptions, lets try to break the logic of the application. Now that we have enumerated an account for a user of a different company (remember userid 818 from above), lets create another user account of our own with very limited privileges. When the user account is created we are assigned the userid of 820. If we login with this newly created account we can't do anything but update our own user preferences within our profile. If we make any change to our profile our userid is submitted to the application with our preference change. If we trap this request within our intercepting proxy and change the userid to 818 of our enumerated account, then that user is effectively removed from the other company and added to our company. Two things will result from this. This will perform a denial of service for the other customer since they can no longer access this account, and secondly a user account that initially had no privileges can now run reports and see every transaction that the companies user performed (including money transfers with bank account numbers, routing numbers, balances, etc). Now lets take this a step further. Since our userids' started at 813 and 814 what would happen if we automated this attack using a fuzzer utilizing the same request but started at userid 0 and incremented to 812. If this was completed then our company would now have 813 new accounts, in which many of them would be admin accounts, and we could run as many reports as we like harvesting account numbers, routing numbers (of individuals and other companies), personal information, etc. Unfortunately once the account was removed from the previous company and added to our company we lost the capability to transfer money using the accounts of the previous company. Regardless the damage as been done since no other company can access the banking application any longer (effectively a complete DoS for every company but ours), and we can harvest all sensitive information from previous transactions.
This example shows how understanding the functionality of the application, the intentions of the developers, and some creative thinking can break the applications logic and pay huge dividends. Thankfully we are ethical penetration testers and can inform our clients of this vulnerability and remediate it before a malicious user exploits it.
Black Box Testing and Examples
Although uncovering logical vulnerabilities will probably always remain an art, one can attempt to go about it systematically to a great extent. Here is a suggested approach that consists of:
- Understanding the application
- Creating raw data for designing logical tests
- Designing the logical tests
- Standard prerequisites
- Execution of logical tests
Understanding the application
Understanding the application thoroughly is a prerequisite for designing logical tests. To start with:
- Get any documentation describing the application's functionality. Examples of this include:
- Application manuals
- Requirements documents
- Functional specifications
- Use or Abuse Cases
- Explore the application manually and try to understand all the different ways in which the application can be used, the acceptable usage scenarios and the authorization limits imposed on various users
Creating raw data for designing logical tests
In this phase, one should ideally come up with the following data:
- All application business scenarios. For example, for an e-commerce application this might look like,
- Product ordering
- Search for a product
- Workflows. This is different from business scenarios since it involves a number of different users. Examples include:
- Order creation and approval
- Bulletin board (one user posts an article that is reviewed by a moderator and ultimately seen by all users)
- Different user roles
- Different groups or departments (note that there could be a tree (e.g. the Sales group of the heavy engineering division) or tagged view (e.g. someone could be a member of Sales as well as marketing) associated with this.
- Access rights of various user roles and groups - The application allows various users privileges on some resource (or asset) and we need to specify the constraints of these privileges. One simple way to know these business rules/constraints is to make use of the application documentation effectively. For example, look for clauses like "If the administrator allows individual user access..", "If configured by the administrator.." and you know the restriction imposed by the application.
- Privilege Table – After learning about the various privileges on the resources along with the constraints, you are all set to create a Privilege Table. Get answers to:
- What can each user role do on which resource with what constraint? This will help you in deducing who cannot do what on which resource.
- What are the policies across groups?
Consider the following privileges: "Approve expense report", "Book a conference room", "Transfer money from own account to another user's account". A privilege could be thought of as a combination of a verb (e.g. Approve, Book, Withdraw) and one or more nouns (Expense report, conference room, account). The output of this activity is a grid with the various privileges forming the leftmost column while all user roles and groups would form the column headings of other columns. There would also be a “Comments” column that qualifies data in this grid.
Privilege Who can do this Comment Approve expense report Any supervisor may approve report submitted by his subordinate Submit expense report Any employee may do this for himself Transfer funds from one account to another An account holder may transfer funds from own account to another account View payslip Any employee may see his own
This data is a key input for designing logical tests.
Developing logical tests
Here are several guidelines to designing logical tests from the raw data gathered.
- Privilege Table - Make use of the privilege table as a reference while creating application specific logical threats. In general, develop a test for each admin privilege to check if it could be executed illegally by a user role with minimum privileges or no privilege. For example:
- Privilege: Operations Manager cannot approve a customer order
- Logical Test: Operations Manager approves a customer order
- Improper handling of special user action sequences - Navigating through an application in a certain way or revisiting pages out of synch can cause logical errors which may cause the application to do something it's not meant to. For example:
- A wizard application where one fills in forms and proceeds to the next step. One cannot in any normal way (according to the developers) enter the wizard in the middle of the process. Bookmarking a middle step (say step 4 of 7), then continuing with the other steps until completion or form submission, then revisiting the middle step that was bookmarked may "upset" the backend logic due to a weak state model.
- Cover all business transaction paths - While designing tests, check for all alternative ways to perform the same business transaction. For example, create tests for both cash and credit payment modes.
- Client-side validation - Look at all client side validations and see how they could be the basis for designing logical tests. For example, a funds transfer transaction has a validation for negative values in the amount field. This information can be used to design a logical test such as "A user transfers negative amount of money".
Typically, some initial activities useful as setup are:
- Create test users with different permissions
- Browse all the important business scenarios/workflows in the application
Execution of logical tests
Pick up each logical test and do the following:
- Analyze the HTTP/S requests underlying the acceptable usage scenario corresponding to the logical test
- Check the order of HTTP/S requests
- Understand the purpose of hidden fields, form fields, query string parameters being passed
- Try and subvert it by exploiting the known vulnerabilities
- Verify that the application fails for the test
A real world example
In order to provide the reader with a better understanding of this issue and how to test it, we describe another real world case that was investigated by one of the authors in 2006. At that time, a mobile telecom operator (we'll call it FlawedPhone.com) launched a webmail+SMS service for its customers, with the following characteristics:
- New customers, when buying a SIM card, can open a free, permanent email account with the flawedphone.com domain
- The email is preserved even if the customers “transfers” the SIM card to another telecom operator
- However, as long as the SIM card is registered to FlawedPhone, each time an email is received, a SMS message is sent to the customer, including sender and subject
- The SMS application checks that the target phone number is a legitimate customer from its own copy of the FlawedPhone customers list, which is automatically updated every ~8 hours.
The application had been developed following security best practices but it suffered from a business logic flaw and FlawedPhone was soon targeted by the following fraud attack:
- The attacker bought a new FlawedPhone SIM card
- The attacker immediately requested to transfer the SIM card to another mobile carrier, which credits 0.05 € for each received SMS message
- As soon as the SIM card was “transferred” to the new provider, the attacker started sending hundreds of emails to her FlawedPhone email account
- The attacker had a ~8 hours window before the email+SMS application had its list updated and stopped delivering messages
- By that time, the attacker had ~50-100 € in the card, and proceeded to sell it on eBay
The developers thought that SMS messages delivered during the 8 hours period would have introduced a negligible cost but failed to consider the likelihood of an automated attack like the one described. As we can see, the synchronization time, combined with the lack of a limit to the number of messages that could be delivered in a given period of time, introduced a critical flaw in the system that was soon exploited by malicious users.
- Business logic - http://en.wikipedia.org/wiki/Business_logic
- Prevent application logic attacks with sound app security practices - http://searchappsecurity.techtarget.com/qna/0,289202,sid92_gci1213424,00.html?bucket=NEWS&topic=302570
Automated tools are incapable of detecting logical vulnerabilities. For example, tools have no means of detecting if a bank’s "fund transfer" page allows a user to transfer a negative amount to another user (in other words, it allows a user to transfer a positive amount into his own account) nor do they have any mechanism to help the human testers to suspect this state of affairs.
Preventing transfer of a negative amount: Tools could be enhanced so that they can report client side validations to the tester. For example, the tool may have a feature whereby it fills a form with strange values and attempts to submit it using a full-fledged browser implementation. It should check to see whether the browser actually submitted the request. Detecting that the browser has not submitted the request would signal to the tool that submitted values are not being accepted due to client-side validation. This would be reported to the tester, who would then understand the need for designing appropriate logical tests that bypass client-side validation. In our "negative amount transfer" example, the tester would learn that the transfer of negative amounts may be an interesting test. He could then design a test wherein the tool bypasses the client-side validation code and checks to see if the resulting response contains the string "funds transfer successful". The point is not that the tool will be able to detect this or other vulnerabilities of this nature, rather that, with some thought, it would be possible to add many such features to enlist the tools in aiding human testers to find such logical vulnerabilities.
OWASP Testing Guide v2
Here is the OWASP Testing Guide v2 Table of Contents