5 Business logic vulnerabilities 业务逻辑漏洞

5 Business logic vulnerabilities 业务逻辑漏洞

  1. In this section, we’ll introduce the concept of business logic vulnerabilities and explain how they can arise due to flawed assumptions about user behavior. 它们是如何因对用户行为的错误假设而产生的。
  2. We’ll discuss the potential impact of logic flaws and teach you how they can be exploited. You can also practice what you’ve learned using our interactive labs, which are based on real bugs that we’ve encountered in the wild.
  3. Finally, we’ll provide some general best practices to help you prevent these kinds of logic flaws arising in your own applications.
    在这里插入图片描述

一、What

  • Business logic vulnerabilities are flaws in the design and implementation of an application that allow an attacker to elicit unintended behavior. 应用程序的设计和实现中允许攻击者引发意外行为

  • This potentially enables attackers to manipulate legitimate functionality to achieve a malicious怀有恶意的;恶毒的goal. 操作合法功能

  • These flaws are generally the result of failing to anticipate unusual application states that may occur and, consequently, failing to handle them safely.由于未能预料到可能发生的不寻常的应用程序状态

  • In this context, the term “business logic” simply refers to the set of rules that define how the application operates. As these rules aren’t always directly related to a business, the associated vulnerabilities are also known as “application logic vulnerabilities” or simply “logic flaws”.术语“业务逻辑”只是指定义应用程序如何操作的规则集。由于这些规则并不总是与业务直接相关,因此相关的漏洞也称为“应用程序逻辑漏洞”或简单地称为“逻辑缺陷”。

  • Logic flaws are often invisible to people who aren’t explicitly looking for them as they typically won’t be exposed by normal use of the application. 通常不会被公开

  • However, an attacker may be able to exploit behavioral quirks by interacting with the application in ways that developers never intended.攻击者可能通过与应用程序以开发人员从未想过的方式交互来利用行为怪癖。

  • One of the main purposes of business logic is to enforce the rules and constraints that were defined when designing the application or functionality. Broadly speaking, the business rules dictate how the application should react when a given scenario occurs. This includes preventing users from doing things that will have a negative impact on the business or that simply don’t make sense.业务逻辑的主要目的之一是实施在设计应用程序或功能时定义的规则和约束。一般来说,业务规则规定了当给定场景发生时应用程序应该如何作出反应。这包括防止用户做那些会对业务产生负面影响或根本没有意义的事情。

  • Flaws in the logic can allow attackers to circumvent these rules. 绕过

  • For example, they might be able to complete a transaction without going through the intended purchase workflow. 他们可以在不经过预期的购买工作流的情况下完成交易

  • In other cases, broken or non-existent validation of user-supplied data might allow users to make arbitrary changes to transaction-critical values or submit nonsensical input. By passing unexpected values into server-side logic, an attacker can potentially induce the application to do something that it isn’t supposed to.损坏或不存在用户提供的数据验证可能允许用户对事务临界值进行任意更改或提交无意义的输入。通过向服务器端逻辑传递意外的值,攻击者可以潜在地诱导应用程序做一些它不应该做的事情

  • Logic-based vulnerabilities can be extremely diverse and are often unique to the application and its specific functionality. 应用程序功能特有的

  • Identifying them often requires a certain amount of human knowledge, such as an understanding of the business domain or what goals an attacker might have in a given context. This makes them difficult to detect using automated vulnerability scanners. As a result, logic flaws are a great target for bug bounty hunters and manual testers in general. 逻辑漏洞成为了属类中的赏金猎人和手动测试人员的理想目标

二、业务逻辑漏洞如何产生

  • Business logic vulnerabilities often arise because the design and development teams make flawed assumptions about how users will interact with the application.缺陷的假设:用户和应用交互

  • These bad assumptions can lead to inadequate validation of user input. 可能导致用户输入的验证不足 For example, if the developers assume that users will pass data exclusively via a web browser, the application may rely entirely on weak client-side controls to validate input. These are easily bypassed by an attacker using an intercepting proxy. 仅通过Web浏览器传递数据,应用程序可能完全依赖弱客户端控件来验证输入。攻击者可以使用拦截代理很容易地绕过它们。

  • Ultimately, this means that when an attacker deviates from the expected user behavior, the application fails to take appropriate steps to prevent this and, subsequently, fails to handle the situation safely.最终,这意味着当攻击者偏离预期的用户行为时,应用程序无法采取适当的步骤来防止这种情况,进而无法安全地处理这种情况。

  • Logic flaws are particularly common in overly complicated systems that even the development team themselves do not fully understand.在开发团队自己都不能完全理解的过于复杂的系统中逻辑缺陷尤其常见。

  • To avoid logic flaws, developers need to understand the application as a whole.

  • This includes being aware of how different functions can be combined in unexpected ways. 了解不同的功能如何以意想不到的方式组合。- - Developers working on large code bases may not have an intimate understanding of how all areas of the application work. 在大型代码基础上工作的开发人员可能不了解应用程序的所有领域是如何工作的。

  • Someone working on one component could make flawed assumptions about how another component works and, as a result, inadvertently introduce serious logic flaws. 在一个组件上工作的人可能会对另一个组件的工作方式做出有缺陷的假设,从而无意中引入严重的逻辑缺陷。

  • If the developers do not explicitly document any assumptions that are being made, it is easy for these kinds of vulnerabilities to creep into an application. 如果开发人员没有明确地记录正在进行的任何假设,那么这些类型的漏洞很容易潜入应用程序

三、impacts

  • The impact of business logic vulnerabilities can, at times, be fairly trivial. It is a broad category and the impact is highly variable.业务逻辑漏洞的影响有时可能相当微不足道。这是一个广泛的类别,影响是高度可变的。

  • However, any unintended behavior can potentially lead to high-severity attacks if an attacker is able to manipulate the application in the right way. For this reason, quirky logic should ideally be fixed even if you can’t work out how to exploit it yourself. There is always a risk that someone else will be able to.如果攻击者能够以正确的方式操作应用程序,那么任何意外的行为都可能导致严重的攻击。因此,理想情况下,古怪的逻辑应该是固定的,即使你自己不能想出如何利用它。总有一个风险,别人也有可能。

  • Fundamentally, the impact of any logic flaw depends on what functionality it is related to. If the flaw is in the authentication mechanism, for example, this could have a serious impact on your overall security. Attackers could potentially exploit this for privilege escalation, or to bypass authentication entirely, gaining access to sensitive data and functionality. This also exposes an increased attack surface for other exploits.从根本上说,任何逻辑缺陷的影响取决于它与什么功能相关。例如,如果缺陷是在身份验证机制中,这可能会对您的整体安全性产生严重影响。攻击者可能利用这一点来升级权限,或者完全绕过身份验证,获得对敏感数据和功能的访问权。这也增加了其他漏洞的攻击面。

  • Flawed logic in financial transactions can obviously lead to massive losses for the business through stolen funds, fraud, and so on.金融交易中的错误逻辑显然会通过资金被盗、欺诈等方式给企业带来巨大损失

  • You should also note that even though logic flaws may not allow an attacker to benefit directly, they could still allow a malicious party to damage the business in some way. 即使逻辑缺陷可能不允许攻击者直接受益,他们仍然可能允许恶意方以某种方式破坏业务。

四、examples

The best way to understand business logic vulnerabilities is to look at real-world cases and learn from the mistakes that were made. We’ve provided concrete examples of a variety of common logic flaws, as well as some deliberately vulnerable websites so that you can practice exploiting these vulnerabilities yourself.

  • Business logic vulnerabilities are relatively specific to the context in which they occur. However, although individual instances of logic flaws differ hugely, they can share many common themes. In particular, they can be loosely grouped based on the initial mistakes that introduced the vulnerability in the first place.业务逻辑漏洞相对特定于它们发生的上下文。然而,尽管逻辑缺陷的个别实例差别很大,但它们可以共享许多共同的主题。特别是,可以根据最初引入漏洞的错误松散地对它们进行分组。

In this section, we’ll look at examples of some typical mistakes that design and development teams make and show you how they can directly lead to business logic flaws. Whether you’re developing your own applications, or auditing 审计existing ones, you can take the lessons learned from these examples and apply the same critical thinking to other applications that you encounter.

1.对客户端控件的过度信任

Excessive trust in client-side controls

  • A fundamentally flawed assumption is that users will only interact with the application via the provided web interface. This is especially dangerous because it leads to the further assumption that client-side validation will prevent users from supplying malicious input. However, an attacker can simply use tools such as Burp Proxy to tamper with the data after it has been sent by the browser but before it is passed into the server-side logic. This effectively renders the client-side controls useless.一个根本错误的假设是,用户只会通过提供的web界面与应用程序交互。这尤其危险,因为它会导致进一步的假设,即客户端验证将阻止用户提供恶意输入。然而,攻击者可以简单地使用Burp Proxy等工具篡改由浏览器发送的数据,但在数据被传递到服务器端逻辑之前。这有效地使客户端控件变得无用。

  • Accepting data at face value, without performing proper integrity checks and server-side validation, can allow an attacker to do all kinds of damage with relatively minimal effort. Exactly what they are able to achieve is dependent on the functionality and what it is doing with the controllable data. In the right context, this kind of flaw can have devastating consequences for both business-related functionality and the security of the website itself. 按表面价值接受数据,而不执行适当的完整性检查和服务器端验证,可能使攻击者以相对较小的努力进行各种破坏。它们所能达到的效果取决于其功能以及对可控数据的处理。在适当的情况下,这种缺陷可能会对商业相关的功能和网站本身的安全造成毁灭性的后果

Lab: Excessive trust in client-side controls

This lab doesn’t adequately validate user input. You can exploit a logic flaw in its purchasing workflow to buy items for an unintended price. To solve the lab, buy a "Lightweight l33t leather jacket".
You can log in to your own account using the following credentials:
wiener:peter

  1. With Burp running, log in and attempt to buy the leather jacket. The order is rejected because you don’t have enough store credit.
  2. In Burp, go to “Proxy” > “HTTP history” and study the order process. Notice that when you add an item to your cart, the corresponding request contains a price parameter. Send the POST /cart request to Burp Repeater.
  3. In Burp Repeater, change the price to an arbitrary integer and send the request. Refresh the cart and confirm that the price has changed based on your input.
  4. Repeat this process to set the price to any amount less than your available store credit. Complete the order to solve the lab. 重复此过程,将价格设置为低于可用商店积分的任何金额

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

Lab: 2FA broken logic

This lab’s two-factor authentication is vulnerable due to its flawed logic. To solve the lab, access Carlos’s account page.

Your credentials: wiener:peter
Victim's username: carlos

You also have access to the email server to receive your 2FA verification code.

  1. With Burp running, log in to your own account and investigate the 2FA verification process. Notice that in the POST /login2 request, the verify parameter is used to determine which user’s account is being accessed.
  2. Log out of your account.
  3. Send the GET /login2 request to Burp Repeater. Change the value of the verify parameter to carlos and send the request. This ensures that a temporary 2FA code is generated for Carlos.
  4. Go to the login page and enter your username and password. Then, submit an invalid 2FA code.
  5. Send the POST /login2 request to Burp Intruder. In Burp Intruder, set the verify parameter to carlos and add a payload position to the mfa-code parameter. Brute-force the verification code.
  6. Load the 302 response in your browser.
  7. Click “My account” to solve the lab.

在这里插入图片描述

<think>嗯,用户希望根据他们提供的系统级指令,重新编写一个业务逻辑漏洞检测相关的代码,并且要详细的代码内容。首先,我需要理解用户的具体需求是什么。业务逻辑漏洞检测通常涉及验证系统的核心流程是否存在安全隐患,比如支付、身份验证、库存管理等方面。用户可能希望有一个示例代码,展示如何检测这些漏洞。 接下来,我需要考虑用户提供的系统级指令。他们要求所有行内数学表达式用$...$,独立公式用$$...$$,并且用中文回答。但当前的问题是关于代码编写,可能不涉及数学公式,所以这部分可能暂时用不上。不过,在解释漏洞原理时,可能需要用到数学表达式,比如在计算折扣时的条件判断,这时候可以用行内公式,比如$discount\_rate <= 0.3$。 然后,用户需要结构清晰的回答,逐步解决问题。因此,我应该分步骤介绍代码的编写过程,可能包括漏洞场景分析、检测思路、代码实现示例和关键点说明。这样用户可以一步步理解如何构建这样的检测代码。 用户可能没有明确说明是哪种业务逻辑漏洞,所以需要涵盖常见的类型,比如订单金额篡改、重复提交、权限绕过等。在代码示例中,可以创建几个检测函数,每个针对一种漏洞类型,并给出示例调用和输出结果。 同时,需要注意代码的规范性和注释,确保用户能够理解每个部分的作用。比如,在检测订单金额篡改时,比较客户端传入的价格和服务器端计算的价格是否一致,如果不一致则可能存在篡改。 还要考虑代码的可扩展性,比如使用类来组织检测方法,或者提供扩展点让用户可以根据自己的业务添加新的检测规则。此外,异常处理也很重要,确保代码的健壮性。 最后,需要提醒用户实际应用中的注意事项,比如结合具体业务、使用自动化测试框架、日志记录和权限控制等。这些建议能帮助用户更好地将示例代码应用到实际项目中,而不仅仅是理论上的示例。 总结来说,我需要构建一个结构清晰、包含常见业务逻辑漏洞检测方法的代码示例,用中文详细解释每个部分,并确保符合用户提供的格式要求。同时,提供扩展建议和注意事项,使回答全面且有实用价值。</think>根据您的需求,我将以清晰的步骤为您构建业务逻辑漏洞检测代码框架。以下是根据OWASP Top 10和常见业务场景设计的检测逻辑: ```python """ 业务逻辑漏洞检测模块 版本:1.2 更新日期:2023-08-20 """ class BusinessLogicValidator: def __init__(self, request_data, server_data): """ :param request_data: 客户端请求数据(dict) :param server_data: 服务端存储数据(dict) """ self.request = request_data self.server = server_data self.vulnerabilities = [] def check_price_tampering(self): """检测订单金额篡改漏洞""" try: # 对比客户端价格与服务端计算价格 $client\_price \neq server\_price$ client_price = float(self.request.get('total_price', 0)) server_price = self._calculate_server_price() if abs(client_price - server_price) > 0.01: self._log_vulnerability("金额篡改漏洞", f"客户端提交金额({client_price}) ≠ 服务端计算金额({server_price})") return False return True except ValueError: self._log_vulnerability("数据格式异常", "非法数值类型") def check_duplicate_operations(self, interval=2): """检测重复提交漏洞(单位:秒)""" from datetime import datetime last_submit = datetime.strptime(self.server.get('last_submit_time'), '%Y-%m-%d %H:%M:%S') current_time = datetime.now() # 时间间隔判断公式 $\Delta t < threshold$ if (current_time - last_submit).seconds < interval: self._log_vulnerability("重复提交漏洞", f"操作间隔{interval}秒内重复提交") return False return True def check_privilege_escalation(self): """检测垂直越权漏洞""" user_role = self.server.get('user_role') requested_role = self.request.get('role') # 角色权限矩阵验证 role_hierarchy = ['guest', 'user', 'admin'] if requested_role and (role_hierarchy.index(requested_role) > role_hierarchy.index(user_role)): self._log_vulnerability("权限提升漏洞", f"请求角色[{requested_role}]超越当前角色[{user_role}]") return False return True def _calculate_server_price(self): """服务端价格计算(模拟真实业务逻辑)""" unit_price = self.server['product_price'] quantity = self.request.get('quantity', 1) discount = min(self.request.get('discount_rate', 0), 0.3) # 折扣上限30% $discount\_rate \leq 0.3$ return unit_price * quantity * (1 - discount) def _log_vulnerability(self, vuln_type, details): """统一记录漏洞信息""" self.vulnerabilities.append({ 'type': vuln_type, 'level': '高危' if vuln_type in ['金额篡改', '权限提升'] else '中危', 'details': details, 'timestamp': datetime.now().isoformat() }) def generate_report(self): """生成检测报告""" return { 'request_id': self.request.get('id'), 'vulnerability_count': len(self.vulnerabilities), 'issues': self.vulnerabilities } # 使用示例 if __name__ == '__main__': # 模拟请求数据 malicious_request = { 'total_price': 99.99, 'quantity': 5, 'discount_rate': 0.5, 'role': 'admin' } # 模拟服务端数据 server_data = { 'product_price': 25.00, 'user_role': 'user', 'last_s
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值