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
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

~$7.04M Lost: GiddyDefi, Volo Vault & More | BlockSec Weekly
Security Insights

~$7.04M Lost: GiddyDefi, Volo Vault & More | BlockSec Weekly

This BlockSec weekly security report covers eight attack incidents detected between April 20 and April 26, 2026, across Ethereum, Avalanche, Sui, Base, HyperLiquid, and MegaETH, with total estimated losses of approximately $7.04M. The highlighted incident is the $1.3M GiddyDefi exploit, where the attacker did not break any cryptography or use a flash loan but simply replayed an existing on-chain EIP-712 signature with the unsigned `aggregator` and `fromToken` fields swapped out for a malicious contract, demonstrating how partial signature coverage turns any historical signature into a generic permit. Other incidents include a $3.5M Volo Vault operator key compromise on Sui, a $1.5M Purrlend privileged-role takeover, a $413K SingularityFinance oracle misconfiguration, a $142.7K Scallop cross-pool index injection, a $72.35K Kipseli Router decimal mismatch, a $50.7K REVLoans (Juicebox) accounting pollution, and a $64K Custom Rebalancer arbitrary-call exploit.

Weekly Web3 Security Incident Roundup | Apr 13 – Apr 19, 2026
Security Insights

Weekly Web3 Security Incident Roundup | Apr 13 – Apr 19, 2026

This BlockSec weekly security report covers four attack incidents detected between April 13 and April 19, 2026, across multiple chains such as Ethereum, Unichain, Arbitrum, and NEAR, with total estimated losses of approximately $310M. The highlighted incident is the $290M KelpDAO rsETH bridge exploit, where an attacker poisoned the RPC infrastructure of the sole LayerZero DVN to fabricate a cross-chain message, triggering a cascading WETH freeze across five chains and an Arbitrum Security Council forced state transition that raises questions about the actual trust boundaries of decentralized systems. Other incidents include a $242K MMR proof forgery on Hyperbridge, a $1.5M signed integer abuse on Dango, and an $18.4M circular swap path exploit on Rhea Finance's Burrowland protocol.