以太坊区块链安全学习

一、区块链安全学习参考

1、https://cryptozombies.io/zh/course

2、https://ethernaut.zeppelin.solutions/  这个区块链CTF

3、https://blog.trailofbits.com/2017/11/06/hands-on-the-ethernaut-ctf/

4、漏洞:

https://medium.com/@ranimes/alert-new-batchoverflow-bug-in-multiple-erc20-smart-contracts-cve-2018-10299-511067db6536

 

二、知名团队

慢雾安全团

top 10参考 https://github.com/slowmist/Knowledge-Base/blob/master/DASP-top10-chinese.pdf

 

三、源码获取


从https://etherscan.io/tokens获取目标以太坊区块链应用,爬取已经ICO,且交易量大的区块链应用代码,方便以后进行安全性分析获得源码:

直接上代码

<?php
function getbody($url){
	if(!function_exists('curl_init')){
		echo "no curl support";
		exit();
	}
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);	
	curl_setopt($ch, CURLOPT_HTTPGET, 1);
	curl_setopt($ch, CURLOPT_USERAGENT, 'okhttp/3.7.0.6');

	$result = curl_exec($ch);
	curl_close($ch);	
	return $result;
}
$page = 1;
$tokens = array();
for ($i = $page; ; $i++) {
	$url = "https://etherscan.io/tokens?p=$i";
	$data = getbody($url);

	preg_match_all("/\/0x[A-Za-z0-9]{40}'/", $data, $result);	
	if(count($result[0])){
		$out = array_unique($result[0]);
		foreach ($out as $key => $value) {
			$tokens[] = ltrim(rtrim($value, "'"), "/");
		}
		//echo count($out).'<BR>';
	}else{
		echo count($tokens);
		break;
	}
}
foreach ($tokens as $key => $value) {
	echo $value.'<BR>';
}

// $tokenstr = '';
// $tokens = explode("\n", $tokenstr);
//echo 'Total: '.count($tokens);
//$tokenurl = "https://etherscan.io/token/{token}";

ini_set("max_execution_time", 0);
foreach ($tokens as $k => $t) {
	$t = trim($t);
	if(file_exists($t)){//不重复下载code
		continue;
	}else{
		echo $t;
	}
	$url = "https://etherscan.io/address/$t";
	$data = getbody($url);
	if(preg_match("/dividcode\".*?<\/pre>/s", $data, $result)){
		$tmp = str_replace("</pre>", "", $result[0]);
		$i = strpos($tmp, 'sourcecopyarea');
		if($i){
			$tmp = substr($tmp, $i);
			$i = strpos($tmp, '>');
			if($i){
				$tmp = substr($tmp, $i+1);
			}
		}
		file_put_contents($t, htmlspecialchars_decode($tmp, ENT_QUOTES));
	}else{
		echo 'none<br>';
	}
}

代码大概70行,首先下载页面https://etherscan.io/tokens?p=$i,正则匹配到区块链address;然后下载页面https://etherscan.io/address/$t,正则匹配到应用代码;保存代码到以address为名的文件中

没有使用额外的xml解析模块,轻量级的。增量更新时可以设置$page=9(目前最大页数)

 

四、工具

工具参考 https://github.com/ConsenSys/mythril

mythril测试环境:

阿里云centos7

python3.6

1、首先安装mythril: wget https://github.com/ConsenSys/mythril/archive/v0.16.25.tar.gz

tar xf解压,然后python3.6 setup.py install

2、mythril采用符号分析原理,构建路径图,分析的进过编译的solidity代码,需要安装solc

wget https://github.com/ethereum/solidity/releases/download/v0.4.23/solc-static-linux

然后添加到可执行路径 ln -s /path/solc-static-linux /usr/bin/solc

3、接着开工

myth -x 0x0aef06dcccc531e581f0440059e6ffcc206039ee

结果如下,发现了几个小问题

4、该工具可以发现的问题类型:https://github.com/ConsenSys/mythril/blob/master/security_checks.md

 

 

  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值