開源第三方庫:https://sliverpy.readthedocs.io/en/latest/getting-started.html#connect-example
程式碼示例:
import os
import asyncio
from sliver import SliverClientConfig, SliverClient
CONFIG_PATH = os.path.join('../sliver/', 'moloch_127.0.0.1.cfg')
async def main():
''' Async client connect example '''
config = SliverClientConfig.parse_config_file(CONFIG_PATH)
client = SliverClient(config)
await client.connect()
# 獲取上線主機列表
sessions = await client.sessions()
print(sessions)
if __name__ == '__main__':
asyncio.run(main())
新增自定義功能後需要重新生成pb檔案
#!/bin/bash
#virtualenv venv
#source venv/bin/activate
OUT_DIR="./sliver_client/sliver/pb"
IN_DIR="./sliver/protobuf"
rm -rf $OUT_DIR/commonpb
rm -rf $OUT_DIR/sliverpb
rm -rf $OUT_DIR/clientpb
rm -rf $OUT_DIR/rpcpb
# shellcheck disable=SC2028
echo "生成python protobuf檔案....\n"
# Common Protobuf
python -m grpc_tools.protoc -I $IN_DIR --python_out=./$OUT_DIR $IN_DIR/commonpb/common.proto
# Sliver Protobuf
python -m grpc_tools.protoc -I $IN_DIR --python_out=./$OUT_DIR $IN_DIR/sliverpb/sliver.proto
# Client Protobuf
python -m grpc_tools.protoc -I $IN_DIR --python_out=./$OUT_DIR $IN_DIR/clientpb/client.proto
# gRPC
python -m grpc_tools.protoc -I $IN_DIR --python_out=./$OUT_DIR --grpc_python_out=./$OUT_DIR $IN_DIR/rpcpb/services.proto
# Re-write commonpb imports
sed -i "" -e \
"s/from commonpb import common_pb2 as commonpb_dot_common__pb2/from ..commonpb import common_pb2 as commonpb_dot_common__pb2/g" \
"$OUT_DIR/sliverpb/"*
sed -i "" -e \
"s/from commonpb import common_pb2 as commonpb_dot_common__pb2/from ..commonpb import common_pb2 as commonpb_dot_common__pb2/g" \
"$OUT_DIR/clientpb/"*
sed -i "" -e \
"s/from commonpb import common_pb2 as commonpb_dot_common__pb2/from ..commonpb import common_pb2 as commonpb_dot_common__pb2/g" \
"$OUT_DIR/rpcpb/"*
# Re-write sliverpb / clientpb imports
sed -i "" -e \
"s/from sliverpb import sliver_pb2 as sliverpb_dot_sliver__pb2/from ..sliverpb import sliver_pb2 as sliverpb_dot_sliver__pb2/g" \
"$OUT_DIR/rpcpb/"*
sed -i "" -e \
"s/from clientpb import client_pb2 as clientpb_dot_client__pb2/from ..clientpb import client_pb2 as clientpb_dot_client__pb2/g" \
"$OUT_DIR/rpcpb/"*
然後修改 sliver_client/sliver/interactive.py 新增port_scan功能