python和sliver交互

开源第三方库: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功能

posted @ 2024-08-07 11:51  干炸小黄鱼  阅读(3)  评论(0编辑  收藏  举报