
خادم ووكيل C2 (POC) لمجرد استكشاف ما إذا كان يمكن استخدام بلوكتشين إيثريوم لأغراض C2 وكيفية ذلك
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 هذا هو تمرير الأحداث بين الخادم والعديد من العملاء في شكل أحداث.
صُمم BlockchainC2 ليعمل على MacOS/Linux، لكن يمكن تجميع الوكيل ليعمل على MacOS أو Windows أو Linux.
للبناء على MacOS باستخدام brew:
# 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/*
يمكن إضافة Ether إلى محفظتك على شبكة Ropsten التجريبية باستخدام https://faucet.ropsten.be/.
أضف سلسلة المفاتيح إلى ملف 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
يُنصح باستخدام حساب جديد للوكيل لتجنب الأخطاء المتعلقة بالمعاملات المعلقة.