2022-07-18 23:59:14 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2017-03-27 21:09:36 +00:00
|
|
|
from sys import exit
|
|
|
|
|
2023-05-02 15:17:59 +00:00
|
|
|
|
2023-09-17 20:20:40 +00:00
|
|
|
class NXCModule:
|
2023-04-07 16:40:48 +00:00
|
|
|
"""
|
2023-05-02 15:17:59 +00:00
|
|
|
Executes the Test-Connection PowerShell cmdlet
|
|
|
|
Module by @byt3bl33d3r
|
2023-04-07 16:40:48 +00:00
|
|
|
"""
|
2017-03-27 21:09:36 +00:00
|
|
|
|
2023-05-02 15:17:59 +00:00
|
|
|
name = "test_connection"
|
2017-03-27 21:09:36 +00:00
|
|
|
description = "Pings a host"
|
2023-05-02 15:17:59 +00:00
|
|
|
supported_protocols = ["smb", "mssql"]
|
2017-03-27 21:09:36 +00:00
|
|
|
opsec_safe = True
|
|
|
|
multiple_hosts = True
|
|
|
|
|
|
|
|
def options(self, context, module_options):
|
2023-04-07 16:40:48 +00:00
|
|
|
"""
|
2023-05-02 15:17:59 +00:00
|
|
|
HOST Host to ping
|
2023-04-07 16:40:48 +00:00
|
|
|
"""
|
2017-03-27 21:09:36 +00:00
|
|
|
self.host = None
|
|
|
|
|
2023-05-02 15:17:59 +00:00
|
|
|
if "HOST" not in module_options:
|
|
|
|
context.log.fail("HOST option is required!")
|
2017-10-25 06:45:58 +00:00
|
|
|
exit(1)
|
2017-03-27 21:09:36 +00:00
|
|
|
|
2023-05-02 15:17:59 +00:00
|
|
|
self.host = module_options["HOST"]
|
2017-03-27 21:09:36 +00:00
|
|
|
|
|
|
|
def on_admin_login(self, context, connection):
|
2023-05-07 03:11:28 +00:00
|
|
|
# $ProgressPreference = 'SilentlyContinue' prevents the "preparing modules for the first time" error
|
|
|
|
command = f"$ProgressPreference = 'SilentlyContinue'; Test-Connection {self.host} -quiet -count 1"
|
2023-05-07 03:12:36 +00:00
|
|
|
|
2023-05-07 03:11:28 +00:00
|
|
|
output = connection.ps_execute(command, get_output=True)[0]
|
|
|
|
|
|
|
|
context.log.debug(f"Output: {output}")
|
|
|
|
context.log.debug(f"Type: {type(output)}")
|
2017-03-27 21:09:36 +00:00
|
|
|
|
2023-05-07 03:11:28 +00:00
|
|
|
if output == "True":
|
|
|
|
context.log.success("Pinged successfully")
|
|
|
|
else:
|
|
|
|
context.log.fail("Host unreachable")
|