Skip to content

Commit b01d410

Browse files
author
Aurélien CHALOT
committed
Updates tasklist
1 parent 991f871 commit b01d410

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

nxc/protocols/smb.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,16 @@ def qwinsta(self):
10601060

10611061
@requires_admin
10621062
def tasklist(self):
1063+
# Formats a row to be printed on screen
1064+
def format_row(procInfo):
1065+
return template.format(
1066+
procInfo["ImageName"],
1067+
procInfo["UniqueProcessId"],
1068+
procInfo["SessionId"],
1069+
procInfo["pSid"],
1070+
"{:,} K".format(procInfo["WorkingSetSize"] // 1000),
1071+
)
1072+
10631073
try:
10641074
with TSTS.LegacyAPI(self.conn, self.host, self.kerberos) as legacy:
10651075
try:
@@ -1077,15 +1087,24 @@ def tasklist(self):
10771087
template = "{: <%d} {: <8} {: <11} {: <%d} {: >12}" % (maxImageNameLen, maxSidLen) # noqa: UP031
10781088
self.logger.highlight(template.format("Image Name", "PID", "Session#", "SID", "Mem Usage"))
10791089
self.logger.highlight(template.replace(": ", ":=").format("", "", "", "", ""))
1090+
found_task = False
1091+
1092+
# For each process on the remote host
10801093
for procInfo in res:
1081-
row = template.format(
1082-
procInfo["ImageName"],
1083-
procInfo["UniqueProcessId"],
1084-
procInfo["SessionId"],
1085-
procInfo["pSid"],
1086-
"{:,} K".format(procInfo["WorkingSetSize"] // 1000),
1087-
)
1088-
self.logger.highlight(row)
1094+
# If args.tasklist is not True then a process name was supplied
1095+
if self.args.tasklist is not True:
1096+
# So we look for it and print its information if found
1097+
if self.args.tasklist.lower() == procInfo["ImageName"].lower():
1098+
found_task = True
1099+
self.logger.highlight(format_row(procInfo))
1100+
# Else, no process was supplied, we print the entire list of remote processes
1101+
else:
1102+
self.logger.highlight(format_row(procInfo))
1103+
1104+
# If a process was suppliad to args.tasklist and it was not found, we print a fail message
1105+
if self.args.tasklist is not True and not found_task:
1106+
self.logger.fail(f"Didn't find process {self.args.tasklist}")
1107+
10891108
except SessionError:
10901109
self.logger.fail("Cannot list remote tasks, RDP is probably disabled.")
10911110

nxc/protocols/smb/proto_args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def proto_args(parser, parents):
5454
mapping_enum_group.add_argument("--pass-pol", action="store_true", help="dump password policy")
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")
57-
mapping_enum_group.add_argument("--tasklist", action="store_true", help="Enumerate running processes")
57+
mapping_enum_group.add_argument("--tasklist", type=str, nargs="?", const=True, help="Enumerate running processes and filter for the specified one if specified")
5858

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

0 commit comments

Comments
 (0)