You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 6b31e55
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: AGENTS.md
+18-9Lines changed: 18 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,36 +7,45 @@
7
7
8
8
# Coding style
9
9
10
+
- Never add a comment or docstring at the top of a Python file unless that file already has a top-of-file comment or docstring.
11
+
- In parenthesized Python import blocks, group multiple imported names on each line instead of placing every name on its own line.
12
+
- Keep function and method call arguments on one line when practical, including `raise` and log calls; format object literals for readability.
13
+
- Keep comments short and precise. Use block form for docstrings and other long text.
10
14
- Assume ordinary LDAP searches and LDAP response parsing do not raise exceptions; do not wrap them in `try`/`except`.
11
15
- Always bind caught exceptions as `e`, not `error` or another name.
12
16
- Do not prefix function or method names with underscores; preserve required Python special methods such as `__init__`.
13
17
- Do not assume the host runs Linux; keep code and paths cross-platform unless the task explicitly targets one operating system.
18
+
- Keep implementations as short and concise as practical. Prefer direct control flow and shared error handling over wrappers, redundant branches, or defensive boilerplate.
19
+
- Avoid stub variables that merely hold a value for one immediate use. Pass data directly unless a local name improves clarity, prevents repeated work, or represents meaningful state.
20
+
- Do not use `.warning()` logging. Use `.fail()` when logic or an operation fails.
21
+
- If unsure about anything, ask for clarification before proceeding.
22
+
23
+
# NetExec protocol structure
24
+
25
+
- Protocol implementations must follow the lifecycle defined by `proto_flow()` in `nxc/connection.py`.
26
+
- Keep connection setup in `create_conn_obj()`, target enumeration in `enum_host_info()`, host information output in `print_host_info()`, authentication in the login methods, and cleanup in `disconnect()`.
27
+
- Keep protocol-specific behavior in the appropriate lifecycle methods and let `proto_flow()` control their order and dispatch command arguments and modules.
14
28
15
29
# NetExec module structure
16
30
17
31
- In files under `nxc/modules/`, do not define variables, constants, or helper functions at module scope.
18
32
- Keep all module-specific state, constants, and helper methods inside the `NXCModule` class.
19
33
- Module scope should contain only imports and the `NXCModule` class definition.
20
-
- When a module must terminate for invalid options, import `exit`with `from sys import exit` and call `exit(...)`; do not use `import sys` with `sys.exit(...)`.
34
+
- When module options are invalid, log the reason with `context.log.fail()` and `return False` from `options()`; do not call `exit()`.
21
35
- Do not over-validate module options. Check only that required arguments are present, mutually exclusive arguments are not combined, or a value would otherwise cause the module to fail before performing its normal lookup or operation.
22
36
- Do not validate whether user-supplied object names, identifiers, or similar values are semantically correct when the underlying protocol lookup can handle them; let a misspecified value produce the normal "not found" result.
23
-
- Avoid stub variables that merely hold a value for one immediate use. Pass data directly unless a local name improves clarity, prevents repeated work, or represents meaningful state.
24
-
- Keep module implementations as short and concise as practical. Prefer direct control flow and shared error handling over wrappers, redundant branches, or defensive boilerplate.
25
-
- Do not optimize module code for line length; long lines are acceptable when they keep straightforward logic together.
26
-
- Do not use `.warning()` logging in NetExec modules. Use `.fail()` when logic or an operation fails.
27
-
- Run `ruff check .` after every coding session.
28
37
29
38
# Development and validation
30
39
31
40
- To verify that a module works, run the module's actual NetExec command instead of pytest or compilation checks.
32
-
- Record every module-verification command in `tests/e2e_commands.txt`.
41
+
- Record every module-verification command in `tests/e2e_commands.txt` using the file's placeholders (`TARGET_HOST`, `LOGIN_USERNAME`, `LOGIN_PASSWORD`, `KERBEROS`), never real targets or credentials.
33
42
- Do not run compilation checks.
34
43
- Run Ruff after completing a coding session.
35
44
36
45
# Filesystem and source conventions
37
46
38
47
- Assume that the underlying operating system and its storage are fully secure. Files and other data produced by NetExec may intentionally contain readable plaintext credentials; do not add encryption, redaction, restrictive permission handling, or permission warnings unless explicitly requested.
39
-
- Before opening, creating, writing, renaming, moving, or deleting a file or directory, sanitize every path component derived from untrusted data and verify that the resulting path cannot traverse outside its intended base directory.
48
+
- Before opening, creating, writing, renaming, moving, or deleting a file or directory, sanitize every path component derived from untrusted data with `sanitize_path_component()` from `nxc/helpers/path.py`and verify that the resulting path cannot traverse outside its intended base directory.
40
49
- Place every file and directory produced by NetExec under `NXC_PATH` by default, using `TMP_PATH` for temporary artifacts. An explicit user-provided output path or task requirement may override this default.
41
50
-`NXC_PATH` defaults to `~/.nxc` but may be overridden by the environment. Import and use `NXC_PATH` or its derived path constants instead of hardcoding `~/.nxc`.
42
-
- Place imports at the top of files unless explicitly instructed otherwise.
51
+
- Place imports at the top of files unless explicitly instructed otherwise; only a heavy, rarely used dependency on a hot path, such as protocol loading, may be imported where it is used.
(self.certificate_authandnot (self.protocol=="ldap"andself.args.schannel)) or# PKINIT yields a TGT, while Schannel binds the certificate to the LDAP channel itself
152
118
(hasattr(self.args, "delegate") andself.args.delegate) or
153
119
(hasattr(self.args, "generate_st") andself.args.generate_st) or
self.has_reusable_secret=not (self.protocol=="ldap"andself.args.schannel) # a Schannel bind authenticates the LDAP connection only, leaving no secret for a second channel
ifself.login() or (self.username==""andself.password==""andself.protocol!="mssql"):
229
+
ifself.login() or (self.username==""andself.password==""andself.protocol!="mssql"andnotself.certificate_auth): # a failed certificate auth is not a null session
263
230
self.logger.debug("Calling command arguments")
264
231
self.call_cmd_args()
265
232
ifself.args.module:
@@ -561,20 +528,27 @@ def login(self):
561
528
ifself.args.use_kcache:
562
529
self.logger.debug("Trying to authenticate using Kerberos cache")
0 commit comments