Created
October 17, 2022 15:04
-
-
Save zimnyaa/7ea35c5c266c99f08063f431be4e5ffc to your computer and use it in GitHub Desktop.
Check live sliver sessions and configs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rich.console import Console | |
from rich.text import Text | |
from rich.table import Table, Column | |
from rich.markdown import Markdown | |
import os, asyncio | |
import time | |
from datetime import datetime | |
import sliver | |
console = Console() | |
CONFIG_DIR = os.path.join(os.path.expanduser("~"), ".sliver-client", "configs") | |
async def process_config(cfgfile): | |
text = Text() | |
config = sliver.SliverClientConfig.parse_config_file(cfgfile) | |
try: | |
client = sliver.SliverClient(config) | |
text.append('using '+str(os.path.basename(cfgfile))+'\n', style='bold') | |
await client.connect() | |
except: | |
return | |
version = await client.version() | |
text.append('\tsliver version {}.{}.{}\n'.format(version.Major, version.Minor, version.Patch)) | |
beacon_table = Table(Column("name", style="bold"), Column("connection"), Column("user/host"), Column("checks in", style="bold green"), title="beacons", box=None) | |
beacons = await client.beacons() | |
print_beacons = False | |
for beacon in beacons: | |
if beacon.NextCheckin > time.time(): | |
print_beacons = True | |
beacon_table.add_row("beacon {}".format(beacon.Name), "{}".format(beacon.RemoteAddress), "{}@{}".format(beacon.Username, beacon.Hostname), "{}".format(datetime.utcfromtimestamp(beacon.NextCheckin).strftime('%Y-%m-%d %H:%M:%S'))) | |
session_table = Table(Column("name", style="bold"), Column("connection"), Column("user/host"), Column("state", style="bold green"), title="sessions", box=None) | |
sessions = await client.sessions() | |
print_sessions = False | |
for session in sessions: | |
if not session.IsDead: | |
print_sessions = True | |
session_table.add_row("session {}".format(session.Name), "{}".format(session.RemoteAddress), "{}@{}".format(session.Username, session.Hostname), "ALIVE") | |
console.print(text) | |
if print_beacons: | |
console.print(beacon_table) | |
if print_sessions: | |
console.print(session_table) | |
console.print(Markdown("---")) | |
async def main(): | |
tasks = [asyncio.create_task(process_config(os.path.join(CONFIG_DIR, cfg))) for cfg in os.listdir(CONFIG_DIR)] | |
await asyncio.wait(tasks) | |
if __name__ == '__main__': | |
loop = asyncio.new_event_loop() | |
loop.run_until_complete(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment