diff --git a/nxc/protocols/smb.py b/nxc/protocols/smb.py index fe77919f..add05d05 100755 --- a/nxc/protocols/smb.py +++ b/nxc/protocols/smb.py @@ -978,6 +978,32 @@ class smb(connection): except SessionError: self.logger.fail("RDP is probably not enabled, cannot list remote IPv4 addresses.") + @requires_admin + def taskkill(self): + with TSTS.LegacyAPI(self.conn, self.host, self.kerberos) as legacy: + handle = legacy.hRpcWinStationOpenServer() + if self.args.taskkill.isdigit(): + pidList = [int(self.args.taskkill)] + else: + res = legacy.hRpcWinStationGetAllProcesses(handle) + if not res: + self.logger.error("Could not get process list") + return + + pidList = [i["UniqueProcessId"] for i in res if i["ImageName"].lower() == self.args.taskkill.lower()] + if not pidList: + self.logger.fail(f"Could not find process named {self.args.taskkill}") + return + + for pid in pidList: + try: + if legacy.hRpcWinStationTerminateProcess(handle, pid)["ErrorCode"]: + self.logger.highlight(f"Terminated PID {pid} ({self.args.taskkill})") + else: + self.logger.fail(f"Failed terminating PID {pid}") + except Exception as e: + self.logger.exception(f"Error terminating PID {pid}: {e}") + @requires_admin def qwinsta(self): desktop_states = { diff --git a/nxc/protocols/smb/proto_args.py b/nxc/protocols/smb/proto_args.py index cc914988..8095ec4b 100644 --- a/nxc/protocols/smb/proto_args.py +++ b/nxc/protocols/smb/proto_args.py @@ -55,6 +55,7 @@ def proto_args(parser, parents): mapping_enum_group.add_argument("--rid-brute", nargs="?", type=int, const=4000, metavar="MAX_RID", help="Enumerate users by bruteforcing RIDs") mapping_enum_group.add_argument("--qwinsta", action="store_true", help="Enumerate RDP connections") mapping_enum_group.add_argument("--tasklist", action="store_true", help="Enumerate running processes") + mapping_enum_group.add_argument("--taskkill", type=str, help="Kills a specific PID or a proces name's PID's") wmi_group = smb_parser.add_argument_group("WMI", "Options for WMI Queries") wmi_group.add_argument("--wmi", metavar="QUERY", type=str, help="issues the specified WMI query") diff --git a/tests/e2e_commands.txt b/tests/e2e_commands.txt index e6f8dcf1..9b78892f 100644 --- a/tests/e2e_commands.txt +++ b/tests/e2e_commands.txt @@ -17,6 +17,10 @@ netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --users-exp netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --computers netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --rid-brute netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --local-groups +netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --qwinsta +netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --tasklist +netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --taskkill PID +netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --taskkill PROCESS_NAME netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --gen-relay-list /tmp/relaylistOutputFilename.txt netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --local-auth netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --delegate LOGIN_USERNAME