Skip to content

Commit 35e3219

Browse files
committed
Functionalise and extract module displaying logic
1 parent e0f5097 commit 35e3219

2 files changed

Lines changed: 16 additions & 21 deletions

File tree

nxc/helpers/misc.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import re
55
import inspect
66
import os
7-
7+
from termcolor import colored
88
from ipaddress import ip_address
9+
from nxc.logger import nxc_logger
910

1011

1112
def identify_target_file(target_file):
@@ -148,6 +149,17 @@ def detect_if_ip(target):
148149
return False
149150

150151

152+
def display_modules(args, modules):
153+
for category, color in {CATEGORY.ENUMERATION: "green", CATEGORY.CREDENTIAL_DUMPING: "cyan", CATEGORY.PRIVILEGE_ESCALATION: "magenta"}.items():
154+
# Add category filter for module listing
155+
if args.list_modules and args.list_modules.lower() != category.name.lower():
156+
continue
157+
if len([module for module in modules.values() if module["category"] == category]) > 0:
158+
nxc_logger.highlight(colored(f"{category.name}", color, attrs=["bold"]))
159+
for name, props in sorted(modules.items()):
160+
if props["category"] == category:
161+
nxc_logger.display(f"{name:<25} {props['description']}")
162+
151163
class CATEGORY(Enum):
152164
ENUMERATION = "Enumeration"
153165
CREDENTIAL_DUMPING = "Credential Dumping"

nxc/netexec.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# PYTHON_ARGCOMPLETE_OK
22
import sys
3-
from termcolor import colored
43
from nxc.helpers.logger import highlight
5-
from nxc.helpers.misc import identify_target_file, CATEGORY
4+
from nxc.helpers.misc import identify_target_file, display_modules
65
from nxc.parsers.ip import parse_targets
76
from nxc.parsers.nmap import parse_nmap_xml
87
from nxc.parsers.nessus import parse_nessus_file
@@ -168,27 +167,11 @@ def main():
168167

169168
# List low privilege modules
170169
nxc_logger.highlight("LOW PRIVILEGE MODULES")
171-
for category, color in {CATEGORY.ENUMERATION: "green", CATEGORY.CREDENTIAL_DUMPING: "cyan", CATEGORY.PRIVILEGE_ESCALATION: "magenta"}.items():
172-
# Add category filter for module listing
173-
if args.list_modules and args.list_modules.lower() != category.name.lower():
174-
continue
175-
if len([module for module in low_privilege_modules.values() if module["category"] == category]) > 0:
176-
nxc_logger.highlight(colored(f"{category.name}", color, attrs=["bold"]))
177-
for name, props in sorted(low_privilege_modules.items()):
178-
if props["category"] == category:
179-
nxc_logger.display(f"{name:<25} {props['description']}")
170+
display_modules(args, low_privilege_modules)
180171

181172
# List high privilege modules
182173
nxc_logger.highlight("\nHIGH PRIVILEGE MODULES (requires admin privs)")
183-
for category, color in {CATEGORY.ENUMERATION: "green", CATEGORY.CREDENTIAL_DUMPING: "cyan", CATEGORY.PRIVILEGE_ESCALATION: "magenta"}.items():
184-
# Add category filter for module listing
185-
if args.list_modules and args.list_modules.lower() != category.name.lower():
186-
continue
187-
if len([module for module in high_privilege_modules.values() if module["category"] == category]) > 0:
188-
nxc_logger.highlight(colored(f"{category.name}", color, attrs=["bold"]))
189-
for name, props in sorted(high_privilege_modules.items()):
190-
if props["category"] == category:
191-
nxc_logger.display(f"{name:<25} {props['description']}")
174+
display_modules(args, high_privilege_modules)
192175
exit(0)
193176
elif args.module and args.show_module_options:
194177
for module in args.module:

0 commit comments

Comments
 (0)