经典再现|详解Cream.Finance的ERC777重入攻击

This article is not available in the current language yet. Showing the original version.
8 月 30 日,Cream.Finance 遭到重入攻击,PeckShield「派盾」第一时间预警并定位。由于 AMP 支持类似 ERC-777 的代币标准,而它的特性与某些协议不相兼容,此次 Cream.Finance 的重入攻击正是操纵了此漏洞。攻击者总共发起来 17 笔攻击交易, Peck

8 月 30 日,Cream.Finance 遭到重入攻击,PeckShield「派盾」第一时间预警并定位。

由于 AMP 支持类似 ERC-777 的代币标准,而它的特性与某些协议不相兼容,此次 Cream.Finance 的重入攻击正是操纵了此漏洞。

攻击者总共发起来 17 笔攻击交易, PeckShield「派盾」简述其中一笔交易的攻击过程:

首先,攻击者创建攻击合约 A,从 UniSwap V2 中借出闪电贷 500 WETH;

第二步,攻击者将所借 500 WETH 质押到到 Cream.Finance,获得 24,172.2 crETH;

第三步,攻击合约 A 利用第二步所获得的质押物,通过函数 CErc20Delegator.borrow() 借出 1,948 万 AMP。同时,利用重入漏洞,在用户的信息未更新前,又借出 crETH 代币,获得 355 ETH。

第四步,攻击者创建攻击合约 B,并将 974 万 AMP 代币从攻击合约 A 转入攻击合约 B 中。因为第三步的重入攻击,使得攻击合约 A 已经资不抵债。所以攻击者利用攻击合约 B 中的 974 万 AMP,清算了攻击合约 A,并获得 9,068.6 crETH。

第五步,攻击合约 B 赎回 9,068.6 crETH,获得 187.58 ETH;此时,合约 B 的 balanceof() 为 187.58 WETH;

第六步,合约 B 将 187.58 WETH 转给合约 A,并调用函数 selfdestruct();合约 A 的余额为 542.58 ETH;

最终,攻击者归还闪电贷,获利 1,880 万美元。

PeckShield

防御方法

在进行代币交换的时候,先扣除用户的代币,再将 ETH 发送给用户。

多个合约进行交互的时候需要考虑 DeFi 业务组合可能存在的系统性风险问题,平台方不仅要确保在产品上线前有过硬的代码审计和漏洞排查,还要在不同产品做业务组合时考虑因各自不同业务逻辑而潜在的系统性风控问题。

阅读原文

Share to:

Author: PeckShield

Opinions belong to the column author and do not represent PANews.

This content is not investment advice.

Image source: PeckShield. If there is any infringement, please contact the author for removal.

Follow PANews official accounts, navigate bull and bear markets together
Related Topics
PANews APP
The SpaceX leveraged ETF saw trading volume exceed $1 billion on its first day, with LeverageShares leading the trading volume charts.
PANews Newsflash