NetExec/cme/modules/test_connection.py

39 lines
1.1 KiB
Python
Raw Normal View History

2017-03-27 21:09:36 +00:00
from cme.helpers.powershell import create_ps_command
from sys import exit
class CMEModule:
'''
2017-10-25 06:45:58 +00:00
Executes the Test-Connection PowerShell cmdlet
2017-03-27 21:09:36 +00:00
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!')
2017-10-25 06:45:58 +00:00
exit(1)
2017-03-27 21:09:36 +00:00
self.host = module_options['HOST']
def on_admin_login(self, context, connection):
command = 'Test-Connection {} -quiet -count 1'.format(self.host)
2017-10-25 06:45:58 +00:00
output = connection.ps_execute(command, get_output=True)
2017-03-27 21:09:36 +00:00
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')