Back to Blog

#5:鸭嘴兽金融:幸运化解三次攻击

February 15, 2024
6 min read

摘要

Platypus Finance 是 Avalanche 区块链上的一个 AMM 协议。它遭受了三次攻击,如下所示:

  • 2023 年 2 月 17 日,由于错误的偿付能力检查,该协议遭到黑客攻击,总损失约 905 万美元。其中,在 BlockSec 的帮助下挽回了 240 万美元。大约 38 万个代币被锁定在 Aave 合约中,随后被归还。
  • 2023 年 7 月 12 日,该协议遭到黑客攻击,由于忽略了稳定币之间的价格差,损失约 5 万美元。
  • 2023 年 10 月 12 日,该协议遭受了价格操纵攻击,损失约 220 万美元。在与攻击者协商后,90% 的被盗资金被归还。

该项目能够从所有这些攻击中幸存下来,这无疑是幸运的。我们对这三次漏洞利用的分析表明,如果能够进行仔细的审计或采取更积极的安全措施,就可以避免这些逻辑上的缺陷。

第一次攻击

要理解这次安全事件,必须了解几个智能合约的工作流程。大致流程是:

  • 用户可以将代币存入一个池子,成为 LP 并获得 LP 代币。
  • LP 代币可以在 MasterPlatypus 中质押以获得奖励。在此过程中,LP 代币将被转移到 MasterPlatypus 合约。
  • LP 代币可以用作抵押品来借入其他资产,以提高资产效率。

下图显示了它们之间的交互。

漏洞分析

漏洞存在于 MasterPlatypus 合约中的一个名为 emergencyWithdraw 的函数。在紧急情况下,此函数用于从 MasterPlatypus 合约中提取质押的 LP 代币。在此函数中,合约会检查用户是否“有偿付能力”(Solvent)以允许提款。该逻辑检查用户是否拥有任何不良债务(即抵押品是否可以用于偿还债务)。如果用户没有不良债务,则可以提取质押的 LP 代币。

然而,这个逻辑存在缺陷。用户“有偿付能力”仅意味着用户的抵押品可以支付其债务。但是,它会检查用户在“紧急提取质押代币”后是否仍然“有偿付能力”。攻击者可以利用这个缺陷,在借入资产后,再紧急提取质押的 LP 代币(而无需偿还债务)。有关详细分析,请参阅 Immunefi 的博客

攻击分析

我们以一个攻击交易为例,展示整个攻击过程。

步骤 1:从 AAVE 借入 4400 万 USDC 闪电贷

步骤 2:将 4400 万 USDC 存入池子以获得 LP-USDC

步骤 3:将 LP-USDC 存入 MasterPlatypus

步骤 4:使用 LP-USDC 作为抵押品借入 USP

步骤 5:执行 emergencyWithdraw 函数发起攻击

攻击者在未偿还 USP 债务的情况下获得了 LP-USDC。

步骤 6:从池子中提取 LP-USDC 以获得 USDC

步骤 7:出售 USP 以获利

然而,利润留在了攻击合约中。事实上,攻击者可以设置一个新的接收地址来进行兑换以获取利润。

BlockSec 的救援

我们发现攻击者将利润留在了攻击合约中。此外,攻击合约中没有提取资产的逻辑。但是,我们在攻击合约中发现了一个漏洞,可以利用该漏洞进行回滚以提取合约中的部分资产。

具体来说,闪电贷回调函数存在访问控制,这意味着任何人都可以调用此回调函数。这也是许多 MEV 机器人被攻击的根本原因。

此外,在回调函数中,攻击合约将 USDC 代币批准给了 Platypus वित्त 交易池合约。而这个交易池合约是可升级的!

通过结合以上两点,我们可以通过以下方式从攻击合约中挽回 USDC:

  • 升级 Platypus वित्त 交易池合约,加入从合约中提取 USDC 的逻辑。
  • 调用攻击合约的回调函数,将 USDC 批准给交易池合约。
  • 交易池合约可以替换任何(将被攻击合约执行的)函数,以从攻击合约转移 USDC(因为攻击合约已将 USDC 批准给交易池合约)。

这是挽回 240 万 USDC 的交易

其他两次攻击

有关另外两次攻击的更多详细信息,请参阅以下链接。

  • 攻击二:2023 年 7 月 11 日,该协议假设 USDC 和 USDT 的比例为 1:1,这与市场波动不符,导致了错误的提款逻辑。一次攻击交易。还有其他一些攻击交易。

  • 攻击三:2023 年 10 月 12 日,由于操纵的“现金”(cash)和“负债”(liability)影响了兑换价格。第一次攻击交易 | 第二次攻击交易]

摘要

这三次攻击利用了协议中不同的漏洞。尽管一些其他供应商已经审计了该协议,但攻击者仍然找到了漏洞并成功利用了该协议。幸运的是,一部分资产被挽回了,但我们不能期望永远这么幸运。应采取更多的安全措施,包括攻击监控和自动响应,以保护协议和用户资产。

阅读本系列中的其他文章:

Sign up for the latest updates
~$4.72M Lost: TAC, Transit Finance & More | BlockSec Weekly
Security Insights

~$4.72M Lost: TAC, Transit Finance & More | BlockSec Weekly

This BlockSec weekly security report covers 3 notable attack incidents identified between May 11 and May 17, 2026, across TRON, TON, and Ethereum, with total estimated losses of approximately $4.72M. Three incidents are analyzed in detail: the highlighted $1.88M Transit Finance exploit on TRON, where a deprecated swap bridge contract with lingering token approvals was exploited through arbitrary calldata forwarding; the $2.8M TAC TON-to-EVM bridge exploit caused by missing canonical wallet verification in the jetton deposit flow; and the $46.75K Boost Hook exploit on Ethereum, where spot price manipulation on a Uniswap V4 hook-based perpetual protocol forced the protocol to buy tokens at inflated prices using its own reserves.

~$15.9M Lost: Trusted Volumes, Wasabi & More | BlockSec Weekly
Security Insights

~$15.9M Lost: Trusted Volumes, Wasabi & More | BlockSec Weekly

This BlockSec bi-weekly security report covers 11 notable attack incidents identified between April 27 and May 10, 2026, across Sui, Ethereum, BNB Chain, Base, Blast, and Berachain, with total estimated losses of approximately $15.9M. Three incidents are analyzed in detail: the highlighted $1.14M Aftermath Finance exploit on Sui, where a signed/unsigned semantic mismatch in the builder-fee validation allowed an attacker to inject a negative fee that was converted into positive collateral during settlement; the $5.87M Trusted Volumes RFQ authorization mismatch on Ethereum; and the $5.7M Wasabi Protocol infrastructure-to-contract-control compromise across multiple EVM chains.

Newsletter - April 2026
Security Insights

Newsletter - April 2026

In April 2026, the DeFi ecosystem experienced three major security incidents. KelpDAO lost ~$290M due to an insecure 1-of-1 DVN bridge configuration exploited via RPC infrastructure compromise, Drift Protocol suffered ~$285M from a multisig governance takeover leveraging Solana's durable nonce mechanism, and Rhea Finance incurred ~$18.4M following a business logic flaw in its margin-trading module that allowed circular swap path manipulatio