Files
Pennyw0rth-NetExec/cme/modules/test_connection.py
T
Marshall Hallenbeck 713f4bcd9d clean up imports
2023-04-07 13:12:56 -04:00

41 lines
1.1 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from sys import exit
class CMEModule:
"""
Executes the Test-Connection PowerShell cmdlet
Module by @byt3bl33d3r
"""
name = 'test_connection'
description = "Pings a host"
supported_protocols = ['smb', 'mssql']
opsec_safe = True
multiple_hosts = True
def options(self, context, module_options):
"""
HOST Host to ping
"""
self.host = None
if 'HOST' not in module_options:
context.log.error('HOST option is required!')
exit(1)
self.host = module_options['HOST']
def on_admin_login(self, context, connection):
command = 'Test-Connection {} -quiet -count 1'.format(self.host)
output = connection.ps_execute(command, get_output=True)
if output:
output = output.strip()
if bool(output) is True:
context.log.success('Pinged successfully')
elif bool(output) is False:
context.log.error('Host unreachable')