2018-05-09 以太坊SMT漏洞(CVE-2018–10376)验证

1. 安装以太坊私链,搭建环境

安装geth,以太坊的 go 语言命令行客户端,也是最流行的客户端。

sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum

geth安装成功

建立private network

http://www.ethdocs.org/en/latest/network/test-networks.html#id3

创建 CustomGenesis.json 文件。这个文件定义了创世区块

{
"nonce": "0x0000000000000042",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x",
"gasLimit": "0x8000000",
"difficulty": "0x400",
"config":{},
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x3333333333333333333333333333333333333333",
"alloc": { }
}

注意 extraData, config,两个字段与官方不同。官方的有错。

初始化节点

geth --identity "MyNodeName" --rpc --rpcport "8080" --rpccorsdomain "*" --datadir "~/eth/data" --port "30303" --nodiscover --rpcapi "db,eth,net,personal,web3" --networkid 1999 init ./CustomGenesis.json

启动了节点

geth --identity "MyNodeName" --rpc --rpcport "8080" --rpccorsdomain "*" --datadir "~/eth/data" --port "30303" --nodiscover --rpcapi "db,eth,net,personal,web3" --networkid 1999 console

eth.accounts 查看当前节点上的帐户;最初应该是没有一个帐户的
personal.newAccount() 创建一个帐户
miner.start() 开始挖矿。 最开始,要等待区块链创建到100%,才真正开始。

挖了一会儿后,查看挖到了多少:

eth.getBalance(eth.accounts[0])
4.885e+21

不为0,说明已经挖出来了。

2. 部署SMT合约

使用apt install py-solc
设置环境变量,WEB3_PROVIDER_URI="http://127.0.0.1:8080/"

在geth启动命令中,注意打开各类调用界面

从geth console得到的地址,在PYTHON代码中,需要做一次转换。
Web3.toChecksumAddress()

下载SMT合约:
https://etherscan.io/address/0x55f93985431fc9304077687a35a1ba103dc1e081#code

robert@ubuntu:~/eth$ python3 deploy_SMT.py
Contract Address: 0x3A52aDBEe5055B551aa81aD66C18143FB457faFd
RECEIPT: AttributeDict({'blockNumber': 3217, 'gasUsed': 27464, 'contractAddress': None, 'logs': [], 'root': '0xc012de26307f26de268f6c89ab9b69c6c34e2669bdec50264dc952ebd2d6fde6', 'logsBloom': HexBytes('0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'), 'to': '0x3a52adbee5055b551aa81ad66c18143fb457fafd', 'cumulativeGasUsed': 27464, 'transactionHash': HexBytes('0xce66c79928f134aef6f99f3c41740e7f741f46b50077100d85b0da5468005cf5'), 'blockHash': HexBytes('0xab3e6104bd2314e222cca8a62c7461cd56c8870e10102db010bb208590adff79'), 'from': '0x747803126c15cfe81fc982d7e164329110e3f592', 'transactionIndex': 0})

3. 再创建一个节点,并连接到原来的这个节点

使用相同的创世文件,再init一次(注意要删除掉原来的data目录)

在第一个节点上使用:

admin.nodeInfo

查看节点信息

在新的节点上使用

admin.addPeer("enode://f08435f227a79bcb2047b35cc35cd44afb62bd09ab43f2254aab0d51315e4fbc973b0ccaa65252436e68da3e1acbf742a947d7d57f1b3a7bb7e419171028ad9e@192.168.72.145:30303")

配置成功后,可以使用

admin.peers

查看。

两个节点都调用 miner.start()开始挖矿。在LOG文件中看到"Imported"就说明两边同步起来了。

参考:https://bitshuo.com/topic/58a1a51c598da39107dd7e4d

4. 验证

在后面一个节点上创建两个帐户
下载 test_SMT.py 。修改里面的帐户信息,以及合约地址
执行这个 python 程序,结果如下:

== 待续 ==

BEC 智能合约
(https://etherscan.io/address/0xc5d105e63711398af9bbff092d4b6769c82f793d)

虚拟货币为SmartMesh(简称SMT) https://etherscan.io/address/0x55f93985431fc9304077687a35a1ba103dc1e081#code

你可能感兴趣的:(2018-05-09 以太坊SMT漏洞(CVE-2018–10376)验证)