Skip to content

Commit bfcc735

Browse files
committed
Merge branch 'main' into tasklist-filter
2 parents 1865d42 + dc239da commit bfcc735

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

nxc/protocols/smb.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,32 @@ def enumerate_sessions_info(self, sessions):
978978
except SessionError:
979979
self.logger.fail("RDP is probably not enabled, cannot list remote IPv4 addresses.")
980980

981+
@requires_admin
982+
def taskkill(self):
983+
with TSTS.LegacyAPI(self.conn, self.host, self.kerberos) as legacy:
984+
handle = legacy.hRpcWinStationOpenServer()
985+
if self.args.taskkill.isdigit():
986+
pidList = [int(self.args.taskkill)]
987+
else:
988+
res = legacy.hRpcWinStationGetAllProcesses(handle)
989+
if not res:
990+
self.logger.error("Could not get process list")
991+
return
992+
993+
pidList = [i["UniqueProcessId"] for i in res if i["ImageName"].lower() == self.args.taskkill.lower()]
994+
if not pidList:
995+
self.logger.fail(f"Could not find process named {self.args.taskkill}")
996+
return
997+
998+
for pid in pidList:
999+
try:
1000+
if legacy.hRpcWinStationTerminateProcess(handle, pid)["ErrorCode"]:
1001+
self.logger.highlight(f"Terminated PID {pid} ({self.args.taskkill})")
1002+
else:
1003+
self.logger.fail(f"Failed terminating PID {pid}")
1004+
except Exception as e:
1005+
self.logger.exception(f"Error terminating PID {pid}: {e}")
1006+
9811007
@requires_admin
9821008
def qwinsta(self):
9831009
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", type=str, nargs="?", const=True, help="Enumerate running processes and filter for the specified one if specified")
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)