慢雾简析 OMNI 被黑原因:burn 函数会外部调用回调函数来造成重入问题

2022-07-11 10:36:00
Collection

链捕手消息,据慢雾安全团队情报,2022 年 7 月 10 号 OMNI Protocol 遭受闪电贷攻击。慢雾安全团队以简讯形式分享如下:

1. 攻击者首先通过 supplyERC721 函数抵押 doodle, 抵押后合约会给攻击者相应的凭证 NToken。

2. 调用 borrow 函数借出 WETH。

3. 调用 withdrawERC721 尝试提取 NFT, 跟进到内部函数 executeWithdrawERC721 发现,提款会先通过 burn 函数去燃烧凭证。

而 burn 函数中的 safeTransferFrom 函数会去外部调用接收地址的 OnERC721Received 函数,攻击者利用这点重入了合约的liquidationERC721 函数。

4. 在 liquidationERC721 函数中,攻击者先支付了 WETH 并接收 doodle nft,接着通过判断后会调用 _burnCollateralNTokens 函数去燃烧掉对应的凭证,同样的利用了 burn 函数外部调用的性质攻击者再次进行了重入操作, 先是抵押了清算获得的 nft, 接着调用 borrow 函数去借出了 81 个 WETH,但由于 vars 变量是在 liquidationERC721 函数中定义的,因此第二次借款不会影响到 liquidationERC721 函数中对用户负债的检查, 这导致了攻击者可以通过 userConfig.setBorrowing 函数将用户的借款标识设置为 false 即将攻击者设置成未在市场中有借款行为。

5. 在提款时会首先调用 userConfig.isBorrowingAny() 函数去判断用户的借款标识,假如借款标识为 false, 则不会判断用户的负债,故此重入后的 81 WETH 的负债并不会在提款时被判断, 使得攻击者可以无需还款则提取出所有的 NFT 获利。

此次攻击的主要原因在于 burn 函数会外部调用回调函数来造成重入问题,并且在清算函数中使用的是旧的 vars 的值进行判断,导致了即使重入后再借款,但用户的状态标识被设置为未借款导致无需还款。慢雾安全团队建议在关键函数采用重入锁来防止重入问题。

Related tags
ChainCatcher reminds readers to view blockchain rationally, enhance risk awareness, and be cautious of various virtual token issuances and speculations. All content on this site is solely market information or related party opinions, and does not constitute any form of investment advice. If you find sensitive information in the content, please click "Report", and we will handle it promptly.
Related tags
ChainCatcher Building the Web3 world with innovators