BlockchainC2 是一个小型 POC 服务器/代理,用于评估攻击者如何利用区块链(特别是以太坊的智能合约功能)进行 C2 通信。
有关此应用程序的详细信息可在此处找到。
此 POC 中使用的智能合约非常简单:
pragma solidity ^0.5.0;
contract EventC2 {
address owner;
event _ServerData(bool f, bool enc, int seq, string agentID, string data);
event _ClientData(bool f, bool enc, int seq, string agentID, string data);
constructor() public {
owner = msg.sender;
}
function AddClientData(string memory agentID, string memory d, int id, bool f, bool enc) public {
emit _ClientData(f, enc, id, agentID, d);
}
function AddServerData(string memory agentID, string memory d, int id, bool f, bool enc) public {
emit _ServerData(f, enc, id, agentID, d);
}
}
这段 Solidity 代码的核心是以事件(event)的形式在服务器与多个客户端之间传递数据。
BlockchainC2 被设计为在 MacOS/Linux 上运行,但代理可以编译为在 MacOS、Windows 或 Linux 上执行。
使用 brew 在 MacOS 上构建:
# Install solidity and ethereum
brew tap ethereum/ethereum
brew install ethereum
brew install solidity
# Build
make all
在 Ubuntu 上构建:
# Install solidity and ethereum
sudo add-apt-repository ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install solc ethereum
# Build
make all
为 Windows 交叉编译代理:
CGO_ENABLED=1 CC="x86_64-w64-mingw32-gcc" GOOS=windows go build blockchainc2/cmd/bc2agent
你需要设置一个可供服务器组件使用的账户。最简单的方法是使用 geth:
geth account new --keystore /tmp/mykeystore/
cat /tmp/mykeystore/*
你可以通过 https://faucet.ropsten.be/ 向 Ropsten 测试网上的钱包添加以太币。
将密钥库添加到你的 config.json 中,例如:
{
"Key": "{\"address\":\"ADDRESS\",\"crypto\":{\"cipher\":\"aes-128-ctr\",\"ciphertext\":\"CT\",\"cipherparams\":{\"iv\":\"IV\"},\"kdf\":\"scrypt\",\"kdfparams\":{\"dklen\":32,\"n\":262144,\"p\":1,\"r\":8,\"salt\":\"06470fcc2121994e014f85e5ab9cdb3714c76b873a1f1186c3e623e87abc4a7a\"},\"mac\":\"SALT\"},\"id\":\"ID\",\"version\":3}",
"Endpoint": "wss://ropsten.infura.io/_ws",
"ContractAddress": "TODO_VIA_SETUP",
"GasPrice": 0
}
使用 bc2server 部署合约:
./bin/bc2server -config ./config.json -pass Passw0rd -setup
合约部署完成后,将合约地址添加到你的 config.json 中,并使用以下命令启动服务器:
./bin/bc2server -config ./config.json -pass Passw0rd
在服务器运行的情况下,可以使用以下命令连接代理:
./bin/bc2agent -config ./agent_config.json -pass Passw0rd
建议为代理使用全新的账户,以避免因待处理交易而产生错误。