{"record":{"id":"09fe861ec0d8c6f2","repo":"peass-ng/PEASS-ng","slug":"win32exception","errorCode":null,"errorMessage":"Win32Exception","messagePattern":"Win32Exception","errorType":"exception","errorClass":"Win32Exception","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskEditor/Native/NTDSAPI.cs","lineNumber":89,"sourceCode":"                if (res == null || res.Length == 0 || res[0].status != DS_NAME_ERROR.DS_NAME_NO_ERROR)\n                    throw new SecurityException(\"Unable to resolve user name.\");\n                return res[0].pName;\n            }\n\n            /// <summary>\n            /// Converts an array of directory service object names from one format to another. Name conversion enables client applications to map between the multiple names used to identify various directory service objects. \n            /// </summary>\n            /// <param name=\"names\">The names to convert.</param>\n            /// <param name=\"flags\">Values used to determine how the name syntax will be cracked.</param>\n            /// <param name=\"formatOffered\">Format of the input names.</param>\n            /// <param name=\"formatDesired\">Desired format for the output names.</param>\n            /// <returns>An array of DS_NAME_RESULT_ITEM structures. Each element of this array represents a single converted name.</returns>\n            public DS_NAME_RESULT_ITEM[] CrackNames(string[] names = null, DS_NAME_FLAGS flags = DS_NAME_FLAGS.DS_NAME_NO_FLAGS, DS_NAME_FORMAT formatOffered = DS_NAME_FORMAT.DS_UNKNOWN_NAME, DS_NAME_FORMAT formatDesired = DS_NAME_FORMAT.DS_USER_PRINCIPAL_NAME)\n            {\n                IntPtr pResult;\n                uint err = Ntdsapi.DsCrackNames(handle, flags, formatOffered, formatDesired, (uint)(names?.Length ?? 0), names, out pResult);\n                if (err != (uint)DS_NAME_ERROR.DS_NAME_NO_ERROR)\n                    throw new System.ComponentModel.Win32Exception((int)err);\n                try\n                {\n                    // Next convert the returned structure to managed environment\n                    DS_NAME_RESULT Result = (DS_NAME_RESULT)Marshal.PtrToStructure(pResult, typeof(DS_NAME_RESULT));\n                    return Result.Items;\n                }\n                finally\n                {\n                    Ntdsapi.DsFreeNameResult(pResult);\n                }\n            }\n\n            public void Dispose()\n            {\n                uint ret = Ntdsapi.DsUnBind(ref handle);\n                System.Diagnostics.Debug.WriteLineIf(ret != 0, \"Error unbinding :\\t\" + ret.ToString());\n            }\n        }","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskEditor/Native/NTDSAPI.cs#L71-L107","documentation":"CrackNames calls DsCrackNames and throws Win32Exception when the API itself fails (returned error code is not DS_NAME_NO_ERROR), e.g. RPC failures to the DC, invalid handle, or access denied. This is an API-level failure distinct from error 306's per-name status failure: here the whole call failed.","triggerScenarios":"Calling CrackNames when the DsCrackNames P/Invoke returns a Win32 error — invalid DsBind handle, no DC reachable, RPC unavailable, or access-denied conditions — propagating the raw error code into Win32Exception at NTDSAPI.cs:89.","commonSituations":"Client machine not domain-joined or DC offline/firewalled (RPC ports blocked); expired machine credentials; calling name translation with a handle bound to an unavailable domain.","solutions":["Confirm DsBind succeeded and domain controller connectivity (test RPC/LSA access to the DC)","Check Win32Exception.NativeErrorCode to identify the specific failure (5=access denied, 1722=RPC unavailable) and fix network/permissions accordingly","Retry on transient RPC errors after connectivity is restored","Catch Win32Exception around CrackNames and degrade to unconverted names"],"exampleFix":"// before\nvar items = ntdsApi.CrackNames(new[] { name });\n// after\ntry { items = ntdsApi.CrackNames(new[] { name }); }\ncatch (Win32Exception ex) { Log($\"DsCrackNames failed: {ex.NativeErrorCode}\"); items = null; }","handlingStrategy":"try-catch","validationCode":"using (var ctx = new System.DirectoryServices.AccountManagement.PrincipalContext(System.DirectoryServices.AccountManagement.ContextType.Domain)) { /* validates domain access */ }","typeGuard":null,"tryCatchPattern":"try { items = api.CrackNames(names); } catch (Win32Exception ex) { Log($\"DsCrackNames error {ex.NativeErrorCode}\"); items = null; }","preventionTips":["Ensure DsBind succeeded and RPC to the DC is open (port 135 + dynamic ports)","Inspect NativeErrorCode to diagnose access vs connectivity failures","Fall back to untranslated names on API failure"],"tags":["active-directory","win32exception","rpc","domain-controller"],"backgroundTag":"win32-native-call-failed","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}