Skip to content

Commit ed4e4a1

Browse files
author
Aurélien CHALOT
committed
Add the taskkill option
1 parent bbca423 commit ed4e4a1

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

nxc/protocols/smb.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,33 @@ def enumerate_sessions_info(self, sessions):
974974
except Exception as e:
975975
self.logger.debug(f"Error getting client address for session {SessionId}: {e}")
976976

977+
@requires_admin
978+
def taskkill(self):
979+
with TSTS.LegacyAPI(self.conn, self.host, self.kerberos) as legacy:
980+
handle = legacy.hRpcWinStationOpenServer()
981+
if self.args.taskkill.isdigit():
982+
pidList = [int(self.args.taskkill)]
983+
else:
984+
r = legacy.hRpcWinStationGetAllProcesses(handle)
985+
if not r:
986+
self.logger.error("Could not get process list")
987+
return
988+
989+
pidList = [i["UniqueProcessId"] for i in r if i["ImageName"].lower() == self.args.taskkill.lower()]
990+
if not pidList:
991+
self.logger.fail(f"Could not find process named {self.args.taskkill}")
992+
return
993+
994+
for pid in pidList:
995+
try:
996+
if legacy.hRpcWinStationTerminateProcess(handle, pid)["ErrorCode"]:
997+
self.logger.highlight(f"Terminated PID {pid} ({self.args.taskkill})")
998+
else:
999+
self.logger.fail(f"Failed terminating PID {pid}")
1000+
except Exception:
1001+
import traceback
1002+
self.logger.error(f"Error terminating PID {pid}: {traceback.format_exc()}")
1003+
9771004
@requires_admin
9781005
def qwinsta(self):
9791006
desktop_states = {

nxc/protocols/smb/proto_args.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def proto_args(parser, parents):
5555
mapping_enum_group.add_argument("--rid-brute", nargs="?", type=int, const=4000, metavar="MAX_RID", help="Enumerate users by bruteforcing RIDs")
5656
mapping_enum_group.add_argument("--qwinsta", action="store_true", help="Enumerate RDP connections")
5757
mapping_enum_group.add_argument("--tasklist", action="store_true", help="Enumerate running processes")
58+
mapping_enum_group.add_argument("--taskkill", type=str, help="Kills a specific PID or a proces name's PID's")
5859

5960
wmi_group = smb_parser.add_argument_group("WMI", "Options for WMI Queries")
6061
wmi_group.add_argument("--wmi", metavar="QUERY", type=str, help="issues the specified WMI query")

tests/e2e_commands.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --users-exp
1717
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --computers
1818
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --rid-brute
1919
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --local-groups
20+
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --qwinsta
21+
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --tasklist
22+
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --taskkill PID
23+
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --taskkill PROCESS_NAME
2024
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --gen-relay-list /tmp/relaylistOutputFilename.txt
2125
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --local-auth
2226
netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --delegate LOGIN_USERNAME

0 commit comments

Comments
 (0)