搬起“石头”,竟砸了自己的脚? | DODO攻击事件分析

init函数在solidity中也仅仅只是一个普通函数,切记不要误以为取名为“init”,就只能进行一次调用。

一、事件概览

北京时间2021年3月9日,根据【链必安-区块链安全态势感知平台(Beosin-Eagle Eye)】舆情监测显示,去中心化交易所DODO上的wCRES/USDT资金池似乎被黑客攻击,转移走价值近98万美元的Wrapped CRES(wCRES)和近114万美元的USDT。据DODO官方回复目前团队正在进行调查。原文链接如下: <u style="text-decoration: none; border-bottom: 1px dashed grey;"><a href="https://link.zhihu.com/?target=https%3A//www.odaily.com/newsflashes/235047.html" class=" external" target="_blank" rel="nofollow noreferrer" data-za-detail-view-id="1043" style="color: inherit; text-decoration: none; cursor: pointer; border-bottom: 1px solid grey;"><span class="invisible" style="font: 0px / 0 a; color: transparent; text-shadow: none; background-color: transparent;">https://www.&lt;/span>&lt;span class="visible">odaily.com/newsflashes/</span><span class="invisible" style="font: 0px / 0 a; color: transparent; text-shadow: none; background-color: transparent;">235047.html</span><span class="ellipsis"></span></a></u>

<figure data-size="normal" style="margin: 1.4em 0px; color: rgb(18, 18, 18); font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC", "Noto Sans CJK SC", "WenQuanYi Micro Hei", sans-serif; font-size: medium; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><img src="https://pic2.zhimg.com/80/v2-30918e24e2ea40a3e037683248971045_720w.jpg" data-caption="" data-size="normal" data-rawwidth="736" data-rawheight="571" class="origin_image zh-lightbox-thumb lazy" width="736" data-original="https://pic2.zhimg.com/v2-30918e24e2ea40a3e037683248971045_r.jpg" data-actualsrc="https://pic2.zhimg.com/v2-30918e24e2ea40a3e037683248971045_b.jpg" data-lazy-status="ok" style="display: block; max-width: 100%; margin: 0px auto; cursor: zoom-in; background-color: transparent; animation: 0.5s ease-in 0s 1 normal none running fxRichTextFadeIn;"/></figure>

图1

成都链安(Beosin)安全团队第一时间针对该事件启动安全应急响应,并将事件细节分析进行梳理,以供参考。其实,该事件本身来说并不复杂,其攻击流程也非常简单。但因该事件涉及到“闪电贷”“重入攻击”等热门话题,因此成都链安认为有必要对该事件进行发声。

二、事件分析

该事件的攻击原因主要在于合约的init函数未进行限制,从而导致攻击者有权利进行调用,如图2所示:

<figure data-size="normal" style="margin: 1.4em 0px; color: rgb(18, 18, 18); font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC", "Noto Sans CJK SC", "WenQuanYi Micro Hei", sans-serif; font-size: medium; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><img src="https://pic2.zhimg.com/80/v2-909b9352776660f5335ca16d86609029_720w.jpg" data-caption="" data-size="normal" data-rawwidth="752" data-rawheight="697" class="origin_image zh-lightbox-thumb lazy" width="752" data-original="https://pic2.zhimg.com/v2-909b9352776660f5335ca16d86609029_r.jpg" data-actualsrc="https://pic2.zhimg.com/v2-909b9352776660f5335ca16d86609029_b.jpg" data-lazy-status="ok" style="display: block; max-width: 100%; margin: 0px auto; cursor: zoom-in; background-color: transparent; animation: 0.5s ease-in 0s 1 normal none running fxRichTextFadeIn;"/></figure>

图2

经分析,攻击者利用了DODO合约中提供的闪电贷工具,首先向合约转移了两种空气币。紧接着,发起了一笔闪电贷交易。在交易结束之前,调用合约的init函数将币种指向空气币,从而躲过了闪电贷的归还校验,如图3所示。

<figure data-size="normal" style="margin: 1.4em 0px; color: rgb(18, 18, 18); font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC", "Noto Sans CJK SC", "WenQuanYi Micro Hei", sans-serif; font-size: medium; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><img src="https://pic4.zhimg.com/80/v2-e821a88ce3924183dfa8e8b2fe825b37_720w.jpg" data-caption="" data-size="normal" data-rawwidth="1400" data-rawheight="714" class="origin_image zh-lightbox-thumb lazy" width="1400" data-original="https://pic4.zhimg.com/v2-e821a88ce3924183dfa8e8b2fe825b37_r.jpg" data-actualsrc="https://pic4.zhimg.com/v2-e821a88ce3924183dfa8e8b2fe825b37_b.jpg" data-lazy-status="ok" style="display: block; max-width: 100%; margin: 0px auto; cursor: zoom-in; background-color: transparent; animation: 0.5s ease-in 0s 1 normal none running fxRichTextFadeIn;"/></figure>

图3

三、安全建议

成都链安(Beosin)安全团队认为,本起事件并不复杂,但值得敲响警钟,引起广大项目方的注意。具体而言,首先是DODO的闪电贷函数是进行了重入校验的,但由于init函数并没有添加重入校验,所以导致了类似重入攻击的发生。

另外,结合成都链安审计团队以往对项目方的安全审计经验,由于目前代码的复杂度越来越高,模块化也随之越来越多,有许多项目方虽然都使用了init函数进行管理,但需要提醒的是,init函数在solidity中也仅仅只是一个普通函数,在此呼吁广大项目方与开发者引起重视。切记,不要误以为取名为“init”,就只能进行一次调用。

同时,我们建议,在日常的安全防护中,项目方也需要做好事无巨细的安全加固工作;通过借助第三方安全公司的专业力量,采用“形式化验证与人工审核”结合的复合式审计方法,方能实现对项目面面俱到的全方位护航。

点赞 1
收藏 0
分享
本文参与登链社区写作激励计划 ,好文好收益,欢迎正在阅读的你也加入。

0 条评论

请先 登录 后评论
成都链安
成都链安
成都链安,让区块链生态更安全。