Skip to content

Commit 198f8f8

Browse files
Merge pull request Pennyw0rth#314 from Pennyw0rth/marshall-tests-fix
Fix for tests referencing files, password/username variable, and a couple KERBEROS space issues
2 parents 5197a0e + 2f098f2 commit 198f8f8

2 files changed

Lines changed: 62 additions & 25 deletions

File tree

tests/e2e_commands.txt

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ netexec smb TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS -M spooler
150150
netexec smb TARGET_HOST -u '' -p '' -M zerologon
151151
netexec smb TARGET_HOST -u '' -p '' -M petitpotam
152152
##### SMB Auth File
153-
netexec smb TARGET_HOST -u data/test_users.txt -p data/test_passwords.txt --no-bruteforce
154-
netexec smb TARGET_HOST -u data/test_users.txt -p data/test_passwords.txt --no-bruteforce --continue-on-success
155-
netexec smb TARGET_HOST -u data/test_users.txt -p data/test_passwords.txt
153+
netexec smb TARGET_HOST -u TEST_USER_FILE -p TEST_PASSWORD_FILE--no-bruteforce
154+
netexec smb TARGET_HOST -u TEST_USER_FILE -p TEST_PASSWORD_FILE--no-bruteforce --continue-on-success
155+
netexec smb TARGET_HOST -u TEST_USER_FILE -p data/test_passwords.txt
156156
##### WMI
157157
netexec wmi TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS # need an extra space after this command due to regex
158158
netexec wmi TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --wmi-namespace root/cimv2
@@ -163,7 +163,9 @@ netexec wmi TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS -M spooler
163163
netexec wmi TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS -M zerologon
164164
netexec wmi TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS -M enum_dns
165165
netexec wmi TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS -M get_netconnections
166-
netexec wmi TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS -M rdp
166+
netexec wmi TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS -M rdp --options
167+
#netexec wmi TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS -M rdp -o ACTION=enable
168+
#netexec wmi TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS -M rdp -o ACTION=disable
167169
##### LDAP
168170
netexec ldap TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --users
169171
netexec ldap TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --groups
@@ -217,7 +219,7 @@ netexec winrm TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --port 59
217219
netexec winrm TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --check-proto http --port 5985
218220
netexec winrm TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --check-proto https --port 5986
219221
##### MSSQL
220-
netexec mssql TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS
222+
netexec mssql TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS # Need a space at the end for kerb regex
221223
##### MSSQL Modules
222224
# netexec mssql TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD -M empire_exec
223225
netexec mssql TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS -L
@@ -237,22 +239,22 @@ netexec mssql TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS -M web_de
237239
netexec rdp TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS # need an extra space after this command due to regex
238240
netexec rdp TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS --nla-screenshot
239241
##### SSH - Default test passwords and random key; switch these out if you want correct authentication
240-
netexec ssh TARGET_HOST -u USERNAME -p PASSWORD
241-
netexec ssh TARGET_HOST -u data/test_users.txt -p data/test_passwords.txt --no-bruteforce
242-
netexec ssh TARGET_HOST -u data/test_users.txt -p data/test_passwords.txt --no-bruteforce --continue-on-success
243-
netexec ssh TARGET_HOST -u data/test_users.txt -p data/test_passwords.txt
244-
netexec ssh TARGET_HOST -u USERNAME -p PASSWORD --key-file data/test_key.priv
245-
netexec ssh TARGET_HOST -u USERNAME -p '' --key-file data/test_key.priv
246-
netexec ssh TARGET_HOST -u USERNAME -p PASSWORD --sudo-check
247-
netexec ssh TARGET_HOST -u USERNAME -p PASSWORD --sudo-check --sudo-check-method sudo-stdin
248-
netexec ssh TARGET_HOST -u USERNAME -p PASSWORD --sudo-check --sudo-check-method sudo-stdin --get-output-tries 10
249-
netexec ssh TARGET_HOST -u USERNAME -p PASSWORD --sudo-check --sudo-check-method mkfifo
250-
netexec ssh TARGET_HOST -u USERNAME -p PASSWORD --sudo-check --sudo-check-method mkfifo --get-output-tries 10
242+
netexec ssh TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD
243+
netexec ssh TARGET_HOST -u TEST_USER_FILE -p TEST_PASSWORD_FILE--no-bruteforce
244+
netexec ssh TARGET_HOST -u TEST_USER_FILE -p TEST_PASSWORD_FILE--no-bruteforce --continue-on-success
245+
netexec ssh TARGET_HOST -u TEST_USER_FILE -p data/test_passwords.txt
246+
netexec ssh TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD --key-file data/test_key.priv
247+
netexec ssh TARGET_HOST -u LOGIN_USERNAME -p '' --key-file data/test_key.priv
248+
netexec ssh TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD --sudo-check
249+
netexec ssh TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD --sudo-check --sudo-check-method sudo-stdin
250+
netexec ssh TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD --sudo-check --sudo-check-method sudo-stdin --get-output-tries 10
251+
netexec ssh TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD --sudo-check --sudo-check-method mkfifo
252+
netexec ssh TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD --sudo-check --sudo-check-method mkfifo --get-output-tries 10
251253
##### FTP- Default test passwords and random key; switch these out if you want correct authentication
252-
netexec ftp TARGET_HOST -u USERNAME -p PASSWORD
253-
netexec ftp TARGET_HOST -u USERNAME -p PASSWORD --ls
254-
netexec ftp TARGET_HOST -u USERNAME -p PASSWORD --put data/test_file.txt test_file.txt
255-
netexec ftp TARGET_HOST -u USERNAME -p PASSWORD --get test_file.txt
256-
netexec ftp TARGET_HOST -u data/test_users.txt -p data/test_passwords.txt --no-bruteforce
257-
netexec ftp TARGET_HOST -u data/test_users.txt -p data/test_passwords.txt --no-bruteforce --continue-on-success
258-
netexec ftp TARGET_HOST -u data/test_users.txt -p data/test_passwords.txt
254+
netexec ftp TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD
255+
netexec ftp TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD --ls
256+
netexec ftp TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD --put data/test_file.txt test_file.txt
257+
netexec ftp TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD --get test_file.txt
258+
netexec ftp TARGET_HOST -u TEST_USER_FILE -p TEST_PASSWORD_FILE --no-bruteforce
259+
netexec ftp TARGET_HOST -u TEST_USER_FILE -p TEST_PASSWORD_FILE --no-bruteforce --continue-on-success
260+
netexec ftp TARGET_HOST -u TEST_USER_FILE -p TEST_PASSWORD_FILE

tests/e2e_tests.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44
from rich.console import Console
55
import platform
66

7+
script_dir = os.path.dirname(os.path.abspath(__file__))
8+
run_dir = os.path.dirname(os.path.abspath(__file__))
9+
possible_locations = [
10+
os.path.join(run_dir, "tests/data/test_users.txt"),
11+
os.path.join(run_dir, "data/test_users.txt"),
12+
]
13+
test_user_file = next((loc for loc in possible_locations if os.path.isfile(loc)), None)
14+
possible_locations = [
15+
os.path.join(script_dir, "tests/data/test_passwords.txt"),
16+
os.path.join(script_dir, "data/test_passwords.txt"),
17+
]
18+
test_password_file = next((loc for loc in possible_locations if os.path.isfile(loc)), None)
19+
720

821
def get_cli_args():
922
parser = argparse.ArgumentParser(description="Script for running end to end tests for nxc")
@@ -72,7 +85,21 @@ def get_cli_args():
7285
"--print-failures",
7386
action="store_true",
7487
required=False,
75-
help="Prints all the commands of failed tests at the end"
88+
help="Prints all the commands of failed tests at the end",
89+
)
90+
parser.add_argument(
91+
"--test-user-file",
92+
dest="test_user_file",
93+
required=False,
94+
default=test_user_file,
95+
help="Path to the file containing test usernames",
96+
)
97+
parser.add_argument(
98+
"--test-password-file",
99+
dest="test_password_file",
100+
required=False,
101+
default=test_password_file,
102+
help="Path to the file containing test passwords",
76103
)
77104
return parser.parse_args()
78105

@@ -119,7 +146,13 @@ def generate_commands(args):
119146
def replace_command(args, line):
120147
kerberos = "-k " if args.kerberos else ""
121148

122-
line = line.replace("TARGET_HOST", args.target).replace("LOGIN_USERNAME", f'"{args.username}"').replace("LOGIN_PASSWORD", f'"{args.password}"').replace("KERBEROS ", kerberos)
149+
line = line\
150+
.replace("TARGET_HOST", args.target)\
151+
.replace("LOGIN_USERNAME", f'"{args.username}"')\
152+
.replace("LOGIN_PASSWORD", f'"{args.password}"')\
153+
.replace("KERBEROS ", kerberos)\
154+
.replace("TEST_USER_FILE", args.test_user_file)\
155+
.replace("TEST_PASSWORD_FILE", args.test_password_file)
123156
if args.poetry:
124157
line = f"poetry run {line}"
125158
return line
@@ -147,6 +180,7 @@ def run_e2e_tests(args):
147180
# replace double quotes with single quotes for Linux due to special chars/escaping
148181
if platform.system() == "Linux":
149182
task = task.replace('"', "'")
183+
# we print the command before running because very often things will timeout and we want the last thing ran
150184
console.log(f"Running command: {task}")
151185
result = subprocess.Popen(
152186
task,
@@ -169,6 +203,7 @@ def run_e2e_tests(args):
169203

170204
if args.errors:
171205
raw_text = text.decode("utf-8")
206+
# this is not a good way to detect errors, but it does catch a lot of things
172207
if "error" in raw_text.lower() or "failure" in raw_text.lower():
173208
console.log("[bold red]Error Detected:")
174209
console.log(f"{raw_text}")

0 commit comments

Comments
 (0)