#Define TokenUser 1 &&#Define TokenGroups 2 &&#Define TokenPrivileges 3 &&#Define TokenOwner 4 &&#Define TokenPrimaryGroup 5 &&#Define TokenDefaultDacl 6 &&#Define TokenSource 7 &&#Define TokenType 8 &&#Define TokenImpersonationLevel 9 &&#Define TokenStatistics 10 &&#Define TokenRestrictedSids 11 &&#Define TokenSessionId 12 &&#Define TokenGroupsAndPrivileges 13 &&#Define TokenSessionReference 14#Define TokenSandBoxInert 15#Define TokenAuditPolicy 16#Define TokenOrigin 17#Define TokenElevationType 18#Define TokenLinkedToken 19#Define TokenElevation 20#Define TokenHasRestrictions 21#Define TokenAccessInformation 22#Define TokenVirtualizationAllowed 23#Define TokenVirtualizationEnabled 24#Define TokenIntegrityLevel 25#Define TokenUIAccess 26#Define TokenMandatoryPolicy 27#Define TokenLogonSid 28#Define TokenPrimary 1#Define TokenImpersonation 2#Define SecurityAnonymous = 0#Define SecurityIdentification = 1#Define SecurityImpersonation = 2#Define SecurityDelegation = 3#Define SidTypeUser 1#Define SidTypeGroup 2#Define SidTypeDomain 3#Define SidTypeAlias 4#Define SidTypeWellKnownGroup 5#Define SidTypeDeletedAccount 6#Define SidTypeInvalid 7#Define SidTypeUnknown 8#Define SidTypeComputer 9#Define SidTypeLabel 10***********************************************!* The SID is enabled for access checks.*!* When the system performs an access check, it checks for access-allowed*!* and access-denied access control entries (ACEs) that apply to the SID.*!* A SID without this attribute is ignored during an access check unless*!* the #DEFINE SE_GROUP_USE_FOR_DENY_ONLY attribute is set.#Define SE_GROUP_ENABLED 0x00000004#Define SE_GROUP_ENABLED_BY_DEFAULT 0x00000002 && The SID is enabled by default.#Define SE_GROUP_INTEGRITY 0x00000020 && Yet To Be Determined#Define SE_GROUP_INTEGRITY_ENABLED 0x00000040 && Yet To Be Determined#Define SE_GROUP_LOGON_ID 0xC0000000 && The SID is a logon SID that identifies the logon session associated with an access token.***********************************************!* The SID cannot have the #DEFINE SE_GROUP_ENABLED attribute cleared*!* by a call to the AdjustTokenGroups function. However, you can use*!* the CreateRestrictedToken function to convert a mandatory SID to a deny-only SID.#Define SE_GROUP_MANDATORY 0x00000001***********************************************!* The SID identifies a group account for which the user of the token is the owner of the group,*!* or the SID can be assigned as the owner of the token or objects.#Define SE_GROUP_OWNER 0x00000008#Define SE_GROUP_RESOURCE 0x20000000 && The SID identifies a domain-local group. Windows NT: This value is not supported.***********************************************!* The SID is a deny-only SID in a restricted token. When the system performs an access check,*!* it checks for access-denied ACEs that apply to the SID; it ignores access-allowed ACEs for the SID.*!* If this attribute is set, SE_GROUP_ENABLED is not set, and the SID cannot be reenabled.*!* Windows NT: This value is not supported.#Define SE_GROUP_USE_FOR_DENY_ONLY 0x00000010#Define SE_PRIVILEGE_ENABLED_BY_DEFAULT 0x00000001#Define SE_PRIVILEGE_ENABLED 0x00000002#Define SE_PRIVILEGE_REMOVED 0x00000004#Define SE_PRIVILEGE_USED_FOR_ACCESS 0x80000000#Define NO_MULTIPLE_TRUSTEE 0#Define TRUSTEE_IS_IMPERSONATE 1#Define TRUSTEE_IS_SID 0#Define TRUSTEE_IS_NAME 1#Define TRUSTEE_BAD_FORM 2#Define TRUSTEE_IS_OBJECTS_AND_SID 3#Define TRUSTEE_IS_OBJECTS_AND_NAME 4#Define TRUSTEE_IS_UNKNOWN 0#Define TRUSTEE_IS_USER 1#Define TRUSTEE_IS_GROUP 2#Define TRUSTEE_IS_DOMAIN 3#Define TRUSTEE_IS_ALIAS 4#Define TRUSTEE_IS_WELL_KNOWN_GROUP 5#Define TRUSTEE_IS_DELETED 6#Define TRUSTEE_IS_INVALID 7#Define TRUSTEE_IS_COMPUTER 8#Define NOT_USED_ACCESS 0#Define GRANT_ACCESS 1#Define SET_ACCESS 2#Define DENY_ACCESS 3#Define REVOKE_ACCESS 4#Define SET_AUDIT_SUCCESS 5#Define SET_AUDIT_FAILURE 6#Define MaxTokenInfoClass 29#Define MAXIMUM_ALLOWED 33554432#Define TOKEN_SOURCE_LENGTH 8#Define GPTR 0x0040#Define ERROR_SUCCESS 0#define RIGHTS_DELETE 0x00010000 && Was DELETE#define READ_CONTROL 0x00020000#define WRITE_DAC 0x00040000#define WRITE_OWNER 0x00080000#define SYNCHRONIZE 0x00100000#define STANDARD_RIGHTS_REQUIRED 0x000f0000#define STANDARD_RIGHTS_READ READ_CONTROL#define STANDARD_RIGHTS_WRITE READ_CONTROL#define STANDARD_RIGHTS_EXECUTE READ_CONTROL#define STANDARD_RIGHTS_ALL 0x001f0000#define SPECIFIC_RIGHTS_ALL 0x0000ffff#define GENERIC_READ 0x80000000#define GENERIC_WRITE 0x40000000#define GENERIC_EXECUTE 0x20000000#define GENERIC_ALL 0x10000000#define NO_INHERITANCE 0x0#define SUB_OBJECTS_ONLY_INHERIT 0x1#define SUB_CONTAINERS_ONLY_INHERIT 0x2#define SUB_CONTAINERS_AND_OBJECTS_INHERIT 0x3#define INHERIT_NO_PROPAGATE 0x4#define INHERIT_ONLY 0x8#define INHERITED_ACCESS_ENTRY 0x10#define INHERITED_PARENT 0x10000000#define INHERITED_GRANDPARENT 0x20000000#define ACE_OBJECT_TYPE_PRESENT 0x1 #define ACE_INHERITED_OBJECT_TYPE_PRESENT 0x2 #define SE_UNKNOWN_OBJECT_TYPE 0#define SE_FILE_OBJECT 1#define SE_SERVICE 2#define SE_PRINTER 3#define SE_REGISTRY_KEY 4#define SE_LMSHARE 5#define SE_KERNEL_OBJECT 6#define SE_WINDOW_OBJECT 7#define SE_DS_OBJECT 8#define SE_DS_OBJECT_ALL 9#define SE_PROVIDER_DEFINED_OBJECT 10#define SE_WMIGUID_OBJECT 11#define SE_REGISTRY_WOW64_32KEY 12#define OBJECT_INHERIT_ACE 0x1#define CONTAINER_INHERIT_ACE 0x02#define NO_PROPAGATE_INHERIT_ACE 0x04#define INHERIT_ONLY_ACE 0x08#define INHERITED_ACE 0x10#define VALID_INHERIT_FLAGS 0x0F#define VALID_INHERIT_FLAGS 0x1F #DEFINE CRLF CHR(13) + CHR(10)Declare Integer GetTokenInformation In "Advapi32" As GetTokenInformationC ; LONG nTokenHandle, ; LONG nTokenInformationClass, ; STRING @cTokenInformation, ; LONG nTokenInformationSize, ; LONG @nReturnLengthDeclare Integer GetTokenInformation In "Advapi32" As GetTokenInformationN ; LONG nTokenHandle, ; LONG nTokenInformationClass, ; LONG @nTokenInformation, ; LONG nTokenInformationSize, ; LONG @nReturnLengthDeclare Integer GetTokenInformation In "Advapi32" As GetTokenInformationP ; LONG nTokenHandle, ; LONG nTokenInformationClass, ; LONG nTokenInformation, ; LONG nTokenInformationSize, ; LONG @nReturnLengthDeclare Integer OpenProcessToken In "Advapi32" ; LONG nProcessHandle, ; LONG nDesiredAccess, ; LONG @nTokenHandleDeclare Integer IsTokenRestricted In "Advapi32" ; LONG nTokenHandleDeclare Long GetLengthSid In "Advapi32" As GetLengthSidC ; STRING pSIDDeclare Long GetLengthSid In "Advapi32" As GetLengthSidN ; LONG pSIDDeclare Integer CopySid In "Advapi32" ; LONG nDestinationSidLength, ; STRING @pDestinationSid, ; STRING @pSourceSidDeclare Integer LookupAccountSid In "Advapi32" ; STRING lpSystemName, ; STRING lpSid, ; STRING @lpName, ; LONG @cchName, ; STRING @lpReferencedDomainName, ; LONG @cchReferencedDomainName, ; LONG @peUseDeclare Integer IsValidSid In advapi32 ; STRING pSidDeclare FreeSid In "Advapi32" ; STRING pSidDeclare Integer LookupPrivilegeName In "advapi32" ; STRING lpSystemName, ; LONG lpLuid, ; STRING @lpName, ; LONG @chNameDeclare Long GetExplicitEntriesFromAcl In advapi32 ; LONG pacl, ; LONG @pcCountOfExplicitEntries, ; LONG @pListOfExplicitEntriesDECLARE String strcpy IN "msvcr71" String@, LongDeclare Long GlobalAlloc In "kernel32" ; LONG wFlags, ; LONG dwBytesDeclare Long GlobalFree In "kernel32" ; LONG HmemDeclare Long LocalFree In "kernel32" ; LONG HmemDeclare Integer CloseHandle In "Kernel32" ; LONG nHandleDeclare Long GetCurrentProcess In "Kernel32"Declare Integer GetLastError In win32apiLocal lnToken, lnResult, lcType, lnSize, lnImpersonationLevel, lcStatistics, lnSessionID, lcOwnerSID, lcLogFilem.lcLogFile = ADDBS(SYS(2023)) + SYS(2015) + ".log"m.lnToken = 0m.lnType = 0m.lnResult = OpenProcessToken(GetCurrentProcess(), MAXIMUM_ALLOWED, @m.lnToken)If m.lnResult != 0 SET CONSOLE OFF SET ALTERNATE TO (m.lcLogFile) SET ALTERNATE ON ?"Restricted:" + Transform(IsTokenRestricted(m.lnToken)) m.lnSize = 0 If GetTokenInformationN(m.lnToken, TokenType, @m.lnType, 4, @m.lnSize) != 0 ?"Type: " + Iif(m.lnType = TokenPrimary, "Primary", "Impersonation") If m.lnType = TokenImpersonation m.lnSize = 0 m.lnImpersonationLevel = 0 If GetTokenInformationN(m.lnToken, TokenImpersonationLevel, @m.lnImpersonationLevel, 4, @m.lnSize) != 0 Do Case Case m.lnImpersonationLevel = SecurityAnonymous ?"Impersonation Level: Anonymous" Case m.lnImpersonationLevel = SecurityIdentification ?"Impersonation Level: Identification" Case m.lnImpersonationLevel = SecurityImpersonation ?"Impersonation Level: Impersonation" Case m.lnImpersonationLevel = SecurityDelegation ?"Impersonation Level: Delegation" Endcase Else ? "GetTokenInformation Failed: TokenImpersonationLevel" + CRLF + GetLastErrorMessage(GetLastError()) Endif Endif Else ? "GetTokenInformation Failed: TokenType" + CRLF + GetLastErrorMessage(GetLastError()) Endif m.lnSize = 0 GetTokenInformationC(m.lnToken, TokenStatistics, Null, 0, @m.lnSize) If m.lnSize > 0 m.lcStatistics = Replicate(Chr(0), m.lnSize) If GetTokenInformationC(m.lnToken, TokenStatistics, @m.lcStatistics, m.lnSize, @m.lnSize) != 0 ? "TokenId (low part): " + Transform(CToBin(Substr(m.lcStatistics,1,4), "4RS")) ? "TokenId (high part): " + Transform(CToBin(Substr(m.lcStatistics,5,4), "4RS")) ? "AuthenticationId (low part): " + Transform(CToBin(Substr(m.lcStatistics,9,4), "4RS")) ? "AuthenticationId (high part): " + Transform(CToBin(Substr(m.lcStatistics,13,4), "4RS")) ? "ExpirationTime (low part):" + Transform(CToBin(Substr(m.lcStatistics,17,4), "4RS")) ? "ExpirationTime (high part):" + Transform(CToBin(Substr(m.lcStatistics,21,4), "4RS")) GetFileTime(Substr(m.lcStatistics,17,8)) ? "TokenType: " + Transform(CToBin(Substr(m.lcStatistics,25,4), "4RS")) ? "ImpersonationLevel: " + Transform(CToBin(Substr(m.lcStatistics,29,4), "4RS")) ? "DynamicCharged: " + Transform(CToBin(Substr(m.lcStatistics,33,4), "4RS")) ? "DynamicAvailable: " + Transform(CToBin(Substr(m.lcStatistics,37,4), "4RS")) ? "GroupCount: " + Transform(CToBin(Substr(m.lcStatistics,41,4), "4RS")) ? "PrivilegeCount: " + Transform(CToBin(Substr(m.lcStatistics,45,4), "4RS")) ? "ModifiedId (low part): " + Transform(CToBin(Substr(m.lcStatistics,49,4), "4RS")) ? "ModifiedId (high part): " + Transform(CToBin(Substr(m.lcStatistics,53,4), "4RS")) Else ? "GetTokenInformation Failed: TokenStatistics" + CRLF + GetLastErrorMessage(GetLastError()) Endif Endif m.lnSize = 0 m.lnSessionID = 0 If GetTokenInformationN(m.lnToken, TokenSessionId, @m.lnSessionID, 4, @m.lnSize) != 0 ? "Terminal Services Session ID: " + Transform(m.lnSessionID) Else ? "GetTokenInformation Failed: TokenSessionId" + CRLF + GetLastErrorMessage(GetLastError()) Endif m.lnSize = 0 ?GetTokenInformationN(m.lnToken, TokenOwner, 0, 0, @m.lnSize) If m.lnSize > 0 m.lnOwner = 0 m.lnOwner = GlobalAlloc(GPTR,m.lnSize) If GetTokenInformationP(m.lnToken, TokenOwner, m.lnOwner, m.lnSize, @m.lnSize) != 0 m.lnPSID = CToBin(Sys(2600,lnOwner,4),"4rs") m.lcOwner = Sys(2600,m.lnPSID,m.lnSize-4) GetSidInformation(m.lcOwner) FreeSid(m.lcOwner) Else ? "GetTokenInformation Failed: TokenOwner" + CRLF + GetLastErrorMessage(GetLastError()) Endif GlobalFree(m.lnOwner) Endif m.lnSize = 0 GetTokenInformationP(m.lnToken, TokenUser, 0, 0, @m.lnSize) If m.lnSize > 0 m.lnUser = 0 m.lnUser = GlobalAlloc(GPTR, m.lnSize) If GetTokenInformationP(m.lnToken, TokenUser, m.lnUser, m.lnSize, @m.lnSize) != 0 m.lnPSID = CToBin(Sys(2600,lnUser,4),"4rs") m.lcUser = Sys(2600,m.lnPSID,m.lnSize-8) GetSidInformation(m.lcUser) m.lnAttributes = CToBin(Sys(2600,m.lnUser+4,4),"4rs") GetBitFlags(m.lnAttributes, "SID Attributes: ") FreeSid(m.lcUser) Else ? "GetTokenInformation Failed: TokenUser" + CRLF + GetLastErrorMessage(GetLastError()) Endif GlobalFree(m.lnUser) Endif m.lnSize = 0 GetTokenInformationN(m.lnToken, TokenPrimaryGroup, 0, 0, @m.lnSize) If m.lnSize > 0 m.lnPrimaryGroup = 0 m.lnPrimaryGroup = GlobalAlloc(GPTR,m.lnSize) If GetTokenInformationP(m.lnToken, TokenPrimaryGroup, m.lnPrimaryGroup, m.lnSize, @m.lnSize) != 0 m.lnPSID = CToBin(Sys(2600,lnPrimaryGroup,4),"4rs") m.lcPrimaryGroup = Sys(2600,m.lnPSID,m.lnSize-4) GetSidInformation(m.lcPrimaryGroup) FreeSid(m.lcPrimaryGroup) Else ? "GetTokenInformation Failed: TokenPrimaryGroup" + CRLF + GetLastErrorMessage(GetLastError()) Endif GlobalFree(m.lnPrimaryGroup) Endif m.lnSize = 0 GetTokenInformationC(m.lnToken, TokenSource, Null, 0, @m.lnSize) If m.lnSize > 0 m.lcSource = Replicate(Chr(0), m.lnSize) If GetTokenInformationC(m.lnToken, TokenSource, @m.lcSource, m.lnSize, @m.lnSize) != 0 ? "SourceName: " + Substr(m.lcSource,1,TOKEN_SOURCE_LENGTH) ? "SourceIdentifier (low part): " + Transform(CToBin(Substr(m.lcSource,1+TOKEN_SOURCE_LENGTH,4), "4RS")) ? "SourceIdentifier (high part): " + Transform(CToBin(Substr(m.lcSource,5+TOKEN_SOURCE_LENGTH,4), "4RS")) Else ? "GetTokenInformation Failed: TokenSource" + CRLF + GetLastErrorMessage(GetLastError()) Endif Endif m.lnSize = 0 GetTokenInformationP(m.lnToken, TokenRestrictedSids, 0, 0, @m.lnSize) If m.lnSize > 0 m.lnRestrictedSids = 0 m.lnRestrictedSids = GlobalAlloc(GPTR, m.lnSize) If GetTokenInformationP(m.lnToken, TokenRestrictedSids, m.lnRestrictedSids, m.lnSize, @m.lnSize) != 0 m.lnGroupCount = CToBin(Sys(2600,lnRestrictedSids,4),"4rs") ? "Group Count: " + Transform(m.lnGroupCount) If m.lnGroupCount > 0 For m.lnCounter = 1 To m.lnGroupCount m.lnRestrictedSids = m.lnRestrictedSids + 4 m.lnPSID = CToBin(Sys(2600,lnRestrictedSids,4),"4rs") m.lnSize = GetLengthSidN(m.lnPSID) m.lcRestrictedSids = Sys(2600,m.lnPSID,m.lnSize) GetSidInformation(m.lcRestrictedSids) m.lnRestrictedSids = m.lnRestrictedSids + 4 m.lnAttributes = CToBin(Sys(2600,lnRestrictedSids,4),"4rs") GetBitFlags(m.lnAttributes, "SID Attributes: ") m.lcAttributeCaption = "Group" + Transform(m.lnCounter) + ": " If m.lnAttributes = 0 ? m.lcAttributeCaption + "Disabled" Else If Bitand(m.lnAttributes, SE_GROUP_ENABLED) != 0 If Bitand(m.lnAttributes, SE_GROUP_ENABLED_BY_DEFAULT) != 0 ? m.lcAttributeCaption + "Enabled By Default" Else ? m.lcAttributeCaption + "Enabled" Endif Endif If Bitand(m.lnAttributes, SE_GROUP_LOGON_ID) != 0 ? m.lcAttributeCaption + "Logon ID" Endif If Bitand(m.lnAttributes, SE_GROUP_MANDATORY) != 0 ? m.lcAttributeCaption + "Mandatory" Endif If Bitand(m.lnAttributes, SE_GROUP_USE_FOR_DENY_ONLY) != 0 ? m.lcAttributeCaption + "Use For Deny Only" Endif If Bitand(m.lnAttributes, SE_GROUP_INTEGRITY) != 0 ? m.lcAttributeCaption + "Integrity" Endif If Bitand(m.lnAttributes, SE_GROUP_INTEGRITY_ENABLED) != 0 ? m.lcAttributeCaption + "Integrity Enabled" Endif If Bitand(m.lnAttributes, SE_GROUP_OWNER) != 0 ? m.lcAttributeCaption + "Owner" Endif If Bitand(m.lnAttributes, SE_GROUP_RESOURCE) != 0 ? m.lcAttributeCaption + "Resource" Endif Endif FreeSid(m.lcRestrictedSids) Endfor Endif Else ? "GetTokenInformation Failed: TokenRestrictedSids" + CRLF + GetLastErrorMessage(GetLastError()) Endif GlobalFree(m.lnRestrictedSids) Endif m.lnSize = 0 GetTokenInformationN(m.lnToken, TokenPrivileges, 0, 0, @m.lnSize) If m.lnSize > 0 m.lnPrivileges = 0 m.lnPrivileges = GlobalAlloc(GPTR, m.lnSize) If GetTokenInformationP(m.lnToken, TokenPrivileges, m.lnPrivileges, m.lnSize, @m.lnSize) != 0 m.lnPrivilegeCount = CToBin(Sys(2600, m.lnPrivileges, 4),"4rs") ? "Privilege Count: " + Transform(m.lnPrivilegeCount) If m.lnPrivilegeCount > 0 For m.lnCounter = 1 To m.lnPrivilegeCount m.lnPrivileges = m.lnPrivileges + 4 m.lnSize = 0 LookupPrivilegeName(Null, m.lnPrivileges, Null, @m.lnSize) If m.lnSize > 0 m.lcPrivilegeName = Replicate(Chr(0), m.lnSize) LookupPrivilegeName(Null, m.lnPrivileges, @m.lcPrivilegeName, @m.lnSize) ?"Privilege Name: " + Left(m.lcPrivilegeName, m.lnSize) Endif ? "Privilege LUID (low part): " + Transform(CToBin(Sys(2600, m.lnPrivileges, 4),"4rs")) m.lnPrivileges = m.lnPrivileges + 4 ? "Privilege LUID (high part): " + Transform(CToBin(Sys(2600, m.lnPrivileges, 4),"4rs")) m.lnPrivileges = m.lnPrivileges + 4 m.lnAttributes = CToBin(Sys(2600, m.lnPrivileges, 4),"4rs") GetBitFlags(m.lnAttributes, "SID Attributes: ") m.lcAttributeCaption = "Privilege" + Transform(m.lnCounter) + ": " If m.lnAttributes = 0 ? m.lcAttributeCaption + "Disabled" Else If Bitand(m.lnAttributes, SE_PRIVILEGE_ENABLED) != 0 If Bitand(m.lnAttributes, SE_PRIVILEGE_ENABLED_BY_DEFAULT ) != 0 ? m.lcAttributeCaption + "Enabled By Default" Else ? m.lcAttributeCaption + "Enabled" Endif Endif If Bitand(m.lnAttributes, SE_PRIVILEGE_REMOVED) != 0 ? m.lcAttributeCaption + "Removed" Endif If Bitand(m.lnAttributes, SE_PRIVILEGE_USED_FOR_ACCESS) != 0 ? m.lcAttributeCaption + "Used For Access" Endif Endif Endfor Endif Else ? "GetTokenInformation Failed: TokenPrivileges" + CRLF + GetLastErrorMessage(GetLastError()) Endif ENDIF m.lnSize = 0 GetTokenInformationN(m.lnToken, TokenDefaultDacl, 0, 0, @m.lnSize) If m.lnSize > 0 m.lnDefaultDacl = 0 m.lnDefaultDacl = GlobalAlloc(GPTR, m.lnSize) If GetTokenInformationP(m.lnToken, TokenDefaultDacl, m.lnDefaultDacl, m.lnSize, @m.lnSize) != 0 m.lnPACL = CToBin(Sys(2600, m.lnDefaultDacl, 4),"4rs") ? "Acl Revision: " + Transform(CToBin(Sys(2600, m.lnPACL, 1), "1RS")) ? "Sbz1: " + Transform(CToBin(Sys(2600, m.lnPACL + 1, 1), "1RS")) && padding to 16-bit boundary m.lnSize = CToBin(Sys(2600, m.lnPACL + 2, 2), "2RS") ? "Acl Size: " + Transform(m.lnSize) m.lnAceCount = CToBin(Sys(2600, m.lnPACL + 4, 2), "2RS") ? "Ace Count: " + Transform(m.lnAceCount) ? "Sbz2: " + Transform(CToBin(Sys(2600, m.lnPACL + 4, 1), "1RS")) && padding to 32-bit boundary m.lnEntryCount = 0 m.lnPExplicitEntries = 0 If GetExplicitEntriesFromAcl(m.lnPACL, @m.lnEntryCount, @m.lnPExplicitEntries) = ERROR_SUCCESS For m.lnCounter = 1 To m.lnEntryCount m.lcExplicitEntry = Sys(2600, m.lnPExplicitEntries, 32) m.lnAccessPermissions = CToBin(Substr(m.lcExplicitEntry,1,4), "4RS") GetBitFlags(m.lnAccessPermissions, "Access Permissions: ") ? "Delete Access: " + IIF(BITTEST(m.lnAccessPermissions, 16), "TRUE", "FALSE") ? "Read Control: " + IIF(BITTEST(m.lnAccessPermissions, 17), "TRUE", "FALSE") ? "Write DAC: " + IIF(BITTEST(m.lnAccessPermissions, 18), "TRUE", "FALSE") ? "Write Owner: " + IIF(BITTEST(m.lnAccessPermissions, 19), "TRUE", "FALSE") ? "Synchronize: " + IIF(BITTEST(m.lnAccessPermissions, 20), "TRUE", "FALSE") ? "Maximum Allowed: " + IIF(BITTEST(m.lnAccessPermissions, 25), "TRUE", "FALSE") ? "Generic All: " + IIF(BITTEST(m.lnAccessPermissions, 28), "TRUE", "FALSE") ? "Generic Execute: " + IIF(BITTEST(m.lnAccessPermissions, 29), "TRUE", "FALSE") ? "Generic Write: " + IIF(BITTEST(m.lnAccessPermissions, 30), "TRUE", "FALSE") ? "Generic Read: " + IIF(BITTEST(m.lnAccessPermissions, 31), "TRUE", "FALSE") m.lnAccessMode = CToBin(Substr(m.lcExplicitEntry,5,4), "4RS") m.lcAccessModeCaption = "Access Mode: " DO Case CASE m.lnAccessMode = NOT_USED_ACCESS ? m.lcAccessModeCaption + "NOT USED ACCESS" CASE m.lnAccessMode = GRANT_ACCESS ? m.lcAccessModeCaption + "GRANT ACCESS" CASE m.lnAccessMode = SET_ACCESS ? m.lcAccessModeCaption + "SET ACCESS" CASE m.lnAccessMode = DENY_ACCESS ? m.lcAccessModeCaption + "DENY ACCESS" CASE m.lnAccessMode = REVOKE_ACCESS ? m.lcAccessModeCaption + "REVOKE ACCESS" CASE m.lnAccessMode = SET_AUDIT_SUCCESS ? m.lcAccessModeCaption + "SET AUDIT SUCCESS" CASE m.lnAccessMode = SET_AUDIT_FAILURE ? m.lcAccessModeCaption + "SET AUDIT FAILURE" ENDCASE m.lnInheritance = CToBin(Substr(m.lcExplicitEntry,9,4), "4RS") GetBitFlags(m.lnInheritance, "Inheritance: ") ?"Container Inherit Ace: " + IIF(BITTEST(m.lnInheritance, CONTAINER_INHERIT_ACE), "TRUE", "FALSE") ?"Inherit No Propogate: " + IIF(BITTEST(m.lnInheritance, INHERIT_NO_PROPAGATE), "TRUE", "FALSE") ?"Inherit Only: " + IIF(BITTEST(m.lnInheritance, INHERIT_ONLY), "TRUE", "FALSE") ?"Inherit Only Ace: " + IIF(BITTEST(m.lnInheritance, INHERIT_ONLY_ACE), "TRUE", "FALSE") ?"No Inheritance: " + IIF(BITTEST(m.lnInheritance, NO_INHERITANCE), "TRUE", "FALSE") ?"No Propogate Inherit Ace: " + IIF(BITTEST(m.lnInheritance, NO_PROPAGATE_INHERIT_ACE), "TRUE", "FALSE") ?"Object Inherit Ace: " + IIF(BITTEST(m.lnInheritance, OBJECT_INHERIT_ACE), "TRUE", "FALSE") ?"Sub Containers and Objects Inherit: " + IIF(BITTEST(m.lnInheritance, SUB_CONTAINERS_AND_OBJECTS_INHERIT), "TRUE", "FALSE") ?"Sub Containers Only Inherit: " + IIF(BITTEST(m.lnInheritance, SUB_CONTAINERS_ONLY_INHERIT), "TRUE", "FALSE") ?"Sub Objects Only Inherit: " + IIF(BITTEST(m.lnInheritance, SUB_OBJECTS_ONLY_INHERIT), "TRUE", "FALSE") m.lnPTrustee = CToBin(Substr(m.lcExplicitEntry,13,4), "4RS") If m.lnPTrustee != 0 m.lcTrustee = Sys(2600, m.lnPTrustee, 32) m.lnPMultipleTrustee = CToBin(Substr(m.lcTrustee,1,4), "4RS") IF m.lnPMultipleTrustee != 0 && However this is always 0 right now *!* A pointer to a TRUSTEE structure that identifies a server *!* account that can impersonate the user identified by the ptstrName *!* member. This member is not currently supported and must be NULL. ELSE ?"Multiple Trustee: NULL" ENDIF m.lnMultipleTrusteeOperation = CToBin(Substr(m.lcTrustee,5,4), "4RS") DO case CASE m.lnMultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE ?"Multiple Trustee: NO" CASE m.lnMultipleTrusteeOperation = TRUSTEE_IS_IMPERSONATE ?"Multiple Trustee: Impersonate" ENDCASE m.lnTrusteeForm = CToBin(Substr(m.lcTrustee,9,4), "4RS") ? "Trustee Form: " DO case CASE m.lnTrusteeForm = TRUSTEE_IS_SID ?? "SID" CASE m.lnTrusteeForm = TRUSTEE_IS_NAME ?? "Name" CASE m.lnTrusteeForm = TRUSTEE_BAD_FORM ?? "Bad Form" CASE m.lnTrusteeForm = TRUSTEE_IS_OBJECTS_AND_SID ?? "Objects and SID" CASE m.lnTrusteeForm = TRUSTEE_IS_OBJECTS_AND_NAME ?? "Objects and Name" ENDCASE m.lnTrusteeType = CToBin(Substr(m.lcTrustee,13,4), "4RS") ? "Trustee Type: " DO case CASE m.lnTrusteeType = TRUSTEE_IS_UNKNOWN ?? "Unknown" CASE m.lnTrusteeType = TRUSTEE_IS_USER ?? "User" CASE m.lnTrusteeType = TRUSTEE_IS_GROUP ?? "Group" CASE m.lnTrusteeType = TRUSTEE_IS_DOMAIN ?? "Domain" CASE m.lnTrusteeType = TRUSTEE_IS_ALIAS ?? "Alias" CASE m.lnTrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP ?? "Well Known Group" CASE m.lnTrusteeType = TRUSTEE_IS_DELETED ?? "Deleted" CASE m.lnTrusteeType = TRUSTEE_IS_INVALID ?? "Invalid" CASE m.lnTrusteeType = TRUSTEE_IS_COMPUTER ?? "Computer" ENDCASE m.lnPName = CToBin(Substr(m.lcTrustee,17,4), "4RS") DO case CASE m.lnTrusteeForm = TRUSTEE_IS_SID m.lnSize = GetLengthSidN(m.lnPName) m.lcSID = SYS(2600,m.lnPName,m.lnSize) GetSidInformation(m.lcSID) CASE m.lnTrusteeForm = TRUSTEE_IS_NAME m.lcBuffer = REPLICATE(CHR(0), 256) ? "Trustee Name: " + strcpy(@m.lcBuffer, m.lnPName) CASE m.lnTrusteeForm = TRUSTEE_IS_OBJECTS_AND_SID m.lcObjectsAndSID = SYS(2600,m.lnPName, 40) m.lnObjectsPresent = CTOBIN(SUBSTR(m.lcObjectsAndSID, 1, 4), "4RS") ? "ACE Object Type Present: " + IIF(BITTEST(m.lnObjectsPresent, ACE_OBJECT_TYPE_PRESENT), "TRUE", "FALSE") ? "ACE Inherited Object Type Present: " + IIF(BITTEST(m.lnObjectsPresent, ACE_INHERITED_OBJECT_TYPE_PRESENT), "TRUE", "FALSE") m.lcObjectTypeGuid = StringFromGUID(SUBSTR(m.lcObjectsAndSID, 5, 16)) m.lcInheritedObjectTypeGuid = StringFromGUID(SUBSTR(m.lcObjectsAndSID, 21, 16)) m.lnPSID = CTOBIN(SUBSTR(m.lcObjectsAndSID, 37, 4), "4RS") m.lnSize = GetLengthSidN(m.lnPName) m.lcSID = SYS(2600, m.lnPSID, m.lnSize) GetSidInformation(m.lcSID) CASE m.lnTrusteeForm = TRUSTEE_IS_OBJECTS_AND_NAME m.lcObjectsAndSID = SYS(2600, m.lnPName, 20) m.lnObjectsPresent = CTOBIN(SUBSTR(m.lcObjectsAndSID, 1, 4), "4RS") ? "ACE Object Type Present: " + IIF(BITTEST(m.lnObjectsPresent, ACE_OBJECT_TYPE_PRESENT), "TRUE", "FALSE") ? "ACE Inherited Object Type Present: " + IIF(BITTEST(m.lnObjectsPresent, ACE_INHERITED_OBJECT_TYPE_PRESENT), "TRUE", "FALSE") m.lnObjectType = CTOBIN(SUBSTR(m.lcObjectsAndSID, 5, 4), "4RS") ? "Object Type: " DO case Case m.lnObjectType = SE_UNKNOWN_OBJECT_TYPE 0 ?? "Unknown" Case m.lnObjectType = SE_FILE_OBJECT 1 ?? "File" Case m.lnObjectType = SE_SERVICE 2 ?? "Service" Case m.lnObjectType = SE_PRINTER 3 ?? "Printer" Case m.lnObjectType = SE_REGISTRY_KEY 4 ?? "Registry Key" Case m.lnObjectType = SE_LMSHARE 5 ?? "LM Share" Case m.lnObjectType = SE_KERNEL_OBJECT 6 ?? "Kernel" Case m.lnObjectType = SE_WINDOW_OBJECT 7 ?? "Window" Case m.lnObjectType = SE_DS_OBJECT 8 ?? "DS" Case m.lnObjectType = SE_DS_OBJECT_ALL 9 ?? "DS All" Case m.lnObjectType = SE_PROVIDER_DEFINED_OBJECT 10 ?? "Provider Defined" Case m.lnObjectType = SE_WMIGUID_OBJECT 11 ?? "WMI Guid" Case m.lnObjectType = SE_REGISTRY_WOW64_32KEY 12 ?? "Registry WOW64 Key" ENDCASE m.lcBuffer = REPLICATE(CHR(0), 256) ? "Object Type Name: " + strcpy(@m.lcBuffer, CTOBIN(SUBSTR(m.lcObjectsAndSID, 9, 4), "4RS")) ? "Inherited Object Type Name: " + strcpy(@m.lcBuffer, CTOBIN(SUBSTR(m.lcObjectsAndSID, 13, 4), "4RS")) ? "Trustee Name: " + strcpy(@m.lcBuffer, CTOBIN(SUBSTR(m.lcObjectsAndSID, 17, 4), "4RS")) ENDCASE Endif Endfor LocalFree(m.lnPExplicitEntries) Endif Else ? "GetTokenInformation Failed: TokenDefaultDacl" + CRLF + GetLastErrorMessage(GetLastError()) Endif GlobalFree(m.lnDefaultDacl) ENDIF m.lnSize = 0 GetTokenInformationN(m.lnToken, TokenGroups, 0, 0, @m.lnSize) If m.lnSize > 0 m.lnGroups = 0 m.lnGroups = GlobalAlloc(GPTR, m.lnSize) If GetTokenInformationP(m.lnToken, TokenGroups, m.lnGroups, m.lnSize, @m.lnSize) != 0 m.lnGroupCount = CToBin(Sys(2600,lnGroups,4),"4rs") ? "Group Count: " + Transform(m.lnGroupCount) If m.lnGroupCount > 0 For m.lnCounter = 1 To m.lnGroupCount m.lnGroups = m.lnGroups + 4 m.lnPSID = CToBin(Sys(2600,lnGroups,4),"4rs") m.lnSize = GetLengthSidN(m.lnPSID) m.lcGroups = Sys(2600,m.lnPSID,m.lnSize) GetSidInformation(m.lcGroups) m.lnGroups = m.lnGroups + 4 m.lnAttributes = CToBin(Sys(2600,lnGroups,4),"4rs") GetBitFlags(m.lnAttributes, "SID Attributes: ") m.lcAttributeCaption = "Group" + Transform(m.lnCounter) + ": " If m.lnAttributes = 0 ? m.lcAttributeCaption + "Disabled" Else If Bitand(m.lnAttributes, SE_GROUP_ENABLED) != 0 If Bitand(m.lnAttributes, SE_GROUP_ENABLED_BY_DEFAULT) != 0 ? m.lcAttributeCaption + "Enabled By Default" Else ? m.lcAttributeCaption + "Enabled" Endif Endif If Bitand(m.lnAttributes, SE_GROUP_LOGON_ID) != 0 ? m.lcAttributeCaption + "Logon ID" Endif If Bitand(m.lnAttributes, SE_GROUP_MANDATORY) != 0 ? m.lcAttributeCaption + "Mandatory" Endif If Bitand(m.lnAttributes, SE_GROUP_USE_FOR_DENY_ONLY) != 0 ? m.lcAttributeCaption + "Use For Deny Only" Endif If Bitand(m.lnAttributes, SE_GROUP_INTEGRITY) != 0 ? m.lcAttributeCaption + "Integrity" Endif If Bitand(m.lnAttributes, SE_GROUP_INTEGRITY_ENABLED) != 0 ? m.lcAttributeCaption + "Integrity Enabled" Endif If Bitand(m.lnAttributes, SE_GROUP_OWNER) != 0 ? m.lcAttributeCaption + "Owner" Endif If Bitand(m.lnAttributes, SE_GROUP_RESOURCE) != 0 ? m.lcAttributeCaption + "Resource" Endif Endif FreeSid(m.lcGroups) Endfor Endif Else ? "GetTokenInformation Failed: TokenGroups" + CRLF + GetLastErrorMessage(GetLastError()) Endif GlobalFree(m.lnGroups) ENDIF m.lnSize = 0 GetTokenInformationN(m.lnToken, TokenGroupsAndPrivileges, 0, 0, @m.lnSize) If m.lnSize > 0 m.lnGroupsAndPrivileges = 0 m.lnGroupsAndPrivileges = GlobalAlloc(GPTR, m.lnSize) If GetTokenInformationP(m.lnToken, TokenGroupsAndPrivileges, m.lnGroupsAndPrivileges, m.lnSize, @m.lnSize) != 0 m.lcGroupsAndPrivileges = Sys(2600,lnGroupsAndPrivileges,44) ? "SID Count: " + TRANSFORM(CToBin(SUBSTR(m.lcGroupsAndPrivileges, 1, 4),"4rs")) ? "SIDs Length: " + TRANSFORM(CToBin(SUBSTR(m.lcGroupsAndPrivileges, 5, 4),"4rs")) ? "Restricted Sid Count: " + TRANSFORM(CToBin(SUBSTR(m.lcGroupsAndPrivileges, 13, 4),"4rs")) ? "Restricted Sids Length: " + TRANSFORM(CToBin(SUBSTR(m.lcGroupsAndPrivileges, 17, 4),"4rs")) ? "Privilege Count: " + TRANSFORM(CToBin(SUBSTR(m.lcGroupsAndPrivileges, 25, 4),"4rs")) ? "Privileges Length: " + TRANSFORM(CToBin(SUBSTR(m.lcGroupsAndPrivileges, 29, 4),"4rs")) ? "Authentication ID (low part): " + TRANSFORM(CToBin(SUBSTR(m.lcGroupsAndPrivileges, 37, 4),"4rs")) ? "Authentication ID (high part): " + TRANSFORM(CToBin(SUBSTR(m.lcGroupsAndPrivileges, 41, 4),"4rs")) Else ? "GetTokenInformation Failed: TokenGroupsAndPrivileges" + CRLF + GetLastErrorMessage(GetLastError()) Endif GlobalFree(m.lnGroups) ENDIF m.lnSize = 0 m.lnSandBoxInsertFlag = 0 GetTokenInformationN(m.lnToken, TokenSandBoxInert, 0, 0, @m.lnSize) ? "Sand Box Insert Flag: " + IIF(m.lnSandBoxInsertFlag != 0, "TRUE", "FALSE") m.lnSize = 0 GetTokenInformationN(m.lnToken, TokenOrigin, 0, 0, @m.lnSize) If m.lnSize > 0 m.lnOrigin = 0 m.lcOrigin = REPLICATE(CHR(0), m.lnSize) If GetTokenInformationC(m.lnToken, TokenOrigin, @m.lcOrigin, m.lnSize, @m.lnSize) != 0 ? "Originating Logon Session (low part): " + TRANSFORM(CTOBIN(SUBSTR(m.lcOrigin, 1, 4),"4RS")) ? "Originating Logon Session (high part): " + TRANSFORM(CTOBIN(SUBSTR(m.lcOrigin, 5, 4),"4RS")) ENDIF ENDIF CloseHandle(m.lnToken) SET ALTERNATE TO SET ALTERNATE OFF SET CONSOLE ON MODIFY FILE (m.lcLogFile) NOWAITENDIF*****************************FUNCTION GetFileTime(tcFileTime)*****************************LOCAL lcSystemTimeDeclare Integer FileTimeToSystemTime IN "kernel32" String, String@m.lcSystemTime = REPLICATE(CHR(0), 16)FileTimeToSystemTime(m.tcFileTime, @m.lcSystemTime)? "Expiration Year: " + Transform(CToBin(Substr(m.lcSystemTime,1,2), "2RS"))? "Expiration Month: " + Transform(CToBin(Substr(m.lcSystemTime,3,2), "2RS"))? "Expiration DOW: " + Transform(CToBin(Substr(m.lcSystemTime,5,2), "2RS"))? "Expiration Day: " + Transform(CToBin(Substr(m.lcSystemTime,7,2), "2RS"))? "Expiration Hour: " + Transform(CToBin(Substr(m.lcSystemTime,9,2), "2RS"))? "Expiration Minute: " + Transform(CToBin(Substr(m.lcSystemTime,11,2), "2RS"))? "Expiration Second: " + Transform(CToBin(Substr(m.lcSystemTime,13,2), "2RS"))? "Expiration Millisecond: " + Transform(CToBin(Substr(m.lcSystemTime,15,2), "2RS"))endfunc*****************************FUNCTION StringFromGUID(tcGUID)***************************** LOCAL lcBuffer, lnBufsize, lcReturn DECLARE INTEGER StringFromGUID2 IN "ole32" STRING rguid, STRING @lpsz, INTEGER cchMax m.lnBufsize = 82 m.lcBuffer = REPLICATE(CHR(0), m.lnBufsize) StringFromGUID2(m.tcGUID, @m.lcBuffer, m.lnBufsize) m.lcBuffer = SUBSTR(m.lcBuffer, 1, AT(CHR(0)+CHR(0), m.lcBuffer)) m.lcReturn = STRCONV(m.lcBuffer, 6) RETURN m.lcReturn = ENDFUNC*****************************Function GetBitFlags(tnValue, tcCaption)*****************************Local lnReturn, lnCounterm.lnReturn = 1? tcCaptionFor m.lnCounter = 0 To 31 ?? Iif(Bittest(m.tnValue, m.lnCounter),"1","0")EndforReturn m.lnReturnEndfunc*****************************Function GetSidInformation(tcSid)*****************************Local lnReturn, lnSize, lcUserName, lcDomainName, ; lcPrivilegeName, lnSIDType, lnLenUserName, lnLenDomainNamem.lnReturn = 0If IsValidSid(m.tcSid) != 0 m.lnSize = GetLengthSidC(m.tcSid) m.lcSidCopy = Replicate(Chr(0), m.lnSize) CopySid(m.lnSize, @m.lcSidCopy, m.tcSid) If IsValidSid(m.lcSidCopy) != 0 m.lcUserName = Replicate(Chr(0), 64) m.lcDomainName = Replicate(Chr(0), 64) m.lcPrivilegeName = Replicate(Chr(0), 64) m.lnSIDType = 0 m.lnLenUserName = Len(m.lcUserName) m.lnLenDomainName = Len(m.lcDomainName) If LookupAccountSid(Null, m.lcSidCopy, @m.lcUserName, @m.lnLenUserName, @m.lcDomainName, @m.lnLenDomainName, @m.lnSIDType) != 0 m.lcUserName = Left(m.lcUserName,m.lnLenUserName) m.lcDomainName = Left(m.lcDomainName,m.lnLenDomainName) ?m.lcUserName ?m.lcDomainName Do Case Case m.lnSIDType = SidTypeUser ?"SID Type: User" Case m.lnSIDType = SidTypeGroup ?"SID Type: Group" Case m.lnSIDType = SidTypeDomain ?"SID Type: Domain" Case m.lnSIDType = SidTypeAlias ?"SID Type: Alias" Case m.lnSIDType = SidTypeWellKnownGroup ?"SID Type: Well Known Group" Case m.lnSIDType = SidTypeDeletedAccount ?"SID Type: Deleted Account" Case m.lnSIDType = SidTypeInvalid ?"SID Type: Invalid" Case m.lnSIDType = SidTypeUnknown ?"SID Type: Unknown" Case m.lnSIDType = SidTypeComputer ?"SID Type: Computer" Endcase Endif FreeSid(m.lcSidCopy) EndifEndifEndfunc*****************************Function GetLastErrorMessage(tnError)*****************************#Define FORMAT_MESSAGE_FROM_SYSTEM 0x00001000Local lcBufferDeclare Integer FormatMessage In kernel32.Dll ; INTEGER dwFlags, ; STRING @lpSource, ; INTEGER dwMessageId, ; INTEGER dwLanguageId, ; STRING @lpBuffer, ; INTEGER nSize, ; INTEGER Argumentsm.lcBuffer = Space(128)FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 'WINERROR.H', m.tnError, 0, @m.lcBuffer, 128 , 0)Return m.lcBufferEndfunc
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u