from enum import IntFlag from msdsalgs.utils import Mask class ShareCapabilitiesMask(IntFlag): SMB2_SHARE_CAP_DFS = 0x00000008, SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY = 0x00000010, SMB2_SHARE_CAP_SCALEOUT = 0x00000020, SMB2_SHARE_CAP_CLUSTER = 0x00000040, SMB2_SHARE_CAP_ASYMMETRIC = 0x00000080, SMB2_SHARE_CAP_REDIRECT_TO_OWNER = 0x00000100 ShareCapabilities = Mask.make_class(ShareCapabilitiesMask, prefix='SMB2_SHARE_CAP_')
from enum import IntFlag from msdsalgs.utils import Mask class CompletionFilterFlagMask(IntFlag): FILE_NOTIFY_CHANGE_FILE_NAME = 0x00000001, FILE_NOTIFY_CHANGE_DIR_NAME = 0x00000002, FILE_NOTIFY_CHANGE_ATTRIBUTES = 0x00000004, FILE_NOTIFY_CHANGE_SIZE = 0x00000008, FILE_NOTIFY_CHANGE_LAST_WRITE = 0x00000010, FILE_NOTIFY_CHANGE_LAST_ACCESS = 0x00000020, FILE_NOTIFY_CHANGE_CREATION = 0x00000040, FILE_NOTIFY_CHANGE_EA = 0x00000080, FILE_NOTIFY_CHANGE_SECURITY = 0x00000100, FILE_NOTIFY_CHANGE_STREAM_NAME = 0x00000200, FILE_NOTIFY_CHANGE_STREAM_SIZE = 0x00000400, FILE_NOTIFY_CHANGE_STREAM_WRITE = 0x00000800 CompletionFilterFlag = Mask.make_class(CompletionFilterFlagMask, prefix='FILE_NOTIFY_CHANGE_')
from enum import IntFlag from msdsalgs.utils import Mask from pytest import raises as pytest_raises class SCManagerAccessFlag(IntFlag): SC_MANAGER_LOCK = 0x00000008 SC_MANAGER_CREATE_SERVICE = 0x00000002 SC_MANAGER_ENUMERATE_SERVICE = 0x00000004 SC_MANAGER_CONNECT = 0x00000001 SC_MANAGER_QUERY_LOCK_STATUS = 0x00000010 SC_MANAGER_MODIFY_BOOT_CONFIG = 0x0020 SCManagerAccessFlagMask = Mask.make_class( int_flag_class=SCManagerAccessFlag, prefix='SC_MANAGER_' ) def test_empty_constructor(): mask = SCManagerAccessFlagMask() assert int(mask) == 0 assert all(not value for _, value in mask.items()) def test_from_int(): mask = SCManagerAccessFlagMask.from_int(7) assert mask.connect and mask.create_service and mask.enumerate_service
from enum import IntFlag from msdsalgs.utils import Mask class CloseFlagMask(IntFlag): SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB = 0x0001 CloseFlag = Mask.make_class(CloseFlagMask, prefix='SMB2_CLOSE_FLAG_')
from enum import IntFlag from itertools import chain from msdsalgs.security_types.access_mask import AccessMask from msdsalgs.utils import Mask # TODO: Add standard user rights? class RegsamFlag(IntFlag): KEY_QUERY_VALUE = 0x00000001 KEY_SET_VALUE = 0x00000002 KEY_CREATE_SUB_KEY = 0x00000004 KEY_ENUMERATE_SUB_KEYS = 0x00000008 KEY_CREATE_LINK = 0x00000020 KEY_WOW64_64KEY = 0x00000100 KEY_WOW64_32KEY = 0x00000200 Regsam = Mask.make_class(int_flag_class=IntFlag('Regsam', ( (enum_entry.name, enum_entry.value) for enum_entry in chain(AccessMask, RegsamFlag))))
from enum import IntFlag from msdsalgs.utils import Mask class ShareAccessFlag(IntFlag): FILE_SHARE_READ = 0x00000001, FILE_SHARE_WRITE = 0x00000002, FILE_SHARE_DELETE = 0x00000004 ShareAccess = Mask.make_class(ShareAccessFlag, prefix='FILE_SHARE_')
from enum import IntFlag from msdsalgs.utils import Mask class CapabilitiesFlagMask(IntFlag): SMB2_GLOBAL_CAP_DFS = 0x00000001 SMB2_GLOBAL_CAP_LEASING = 0x00000002 SMB2_GLOBAL_CAP_LARGE_MTU = 0x00000004 SMB2_GLOBAL_CAP_MULTI_CHANNEL = 0x00000008 SMB2_GLOBAL_CAP_PERSISTENT_HANDLES = 0x00000010 SMB2_GLOBAL_CAP_DIRECTORY_LEASING = 0x00000020 SMB2_GLOBAL_CAP_ENCRYPTION = 0x00000040 CapabilitiesFlag = Mask.make_class(CapabilitiesFlagMask, prefix='SMB2_GLOBAL_CAP_')
from enum import IntFlag from msdsalgs.utils import Mask class ServiceType(IntFlag): SERVICE_KERNEL_DRIVER = 0x00000001 SERVICE_FILE_SYSTEM_DRIVER = 0x00000002 SERVICE_WIN32_OWN_PROCESS = 0x00000010 SERVICE_WIN32_SHARE_PROCESS = 0x00000020 SERVICE_INTERACTIVE_PROCESS = 0x00000100 ServiceTypeMask = Mask.make_class( int_flag_class=ServiceType, name='ServiceTypeMask', prefix='SERVICE_' )
from enum import IntFlag from msdsalgs.utils import Mask class QueryDirectoryFlagMask(IntFlag): SMB2_NONE = 0x00 SMB2_RESTART_SCANS = 0x01 SMB2_RETURN_SINGLE_ENTRY = 0x02 SMB2_INDEX_SPECIFIED = 0x04 SMB2_REOPEN = 0x10 QueryDirectoryFlag = Mask.make_class(QueryDirectoryFlagMask, prefix='SMB2_')
from enum import IntFlag from msdsalgs.utils import Mask class RegOptionsFlag(IntFlag): REG_OPTION_VOLATILE = 0x00000001 REG_OPTION_BACKUP_RESTORE = 0x00000004 REG_OPTION_OPEN_LINK = 0x00000008 REG_OPTION_DONT_VIRTUALIZE = 0x00000010 RegOptions = Mask.make_class(int_flag_class=RegOptionsFlag, prefix='REG_OPTION_')
from enum import IntFlag from msdsalgs.utils import Mask class ReadRequestFlagMask(IntFlag): SMB2_READFLAG_READ_UNBUFFERED = 0x01, SMB2_READFLAG_REQUEST_COMPRESSED = 0x02 ReadRequestFlag = Mask.make_class(ReadRequestFlagMask, prefix='SMB2_READFLAG_')
STATUS_USER_SESSION_DELETED = 0xC0000203 STATUS_NETWORK_SESSION_EXPIRED = 0xC000035C STATUS_SMB_TOO_MANY_UIDS = 0xC000205A class SMBv1FlagMask(IntFlag): SMB_FLAGS_LOCK_AND_READ_OK = 0x01 SMB_FLAGS_BUF_AVAIL = 0x02 SMB_FLAGS_CASE_INSENSITIVE = 0x08 SMB_FLAGS_CANONICALIZED_PATHS = 0x10 SMB_FLAGS_OPLOCK = 0x20 SMB_FLAGS_OPBATCH = 0x40 SMB_FLAGS_REPLY = 0x80 SMBv1Flag = Mask.make_class(SMBv1FlagMask, prefix='SMB_FLAGS_') class SMBv1Flag2Mask(IntFlag): SMB_FLAGS2_LONG_NAMES = 0x0001 SMB_FLAGS2_EAS = 0x0002 SMB_FLAGS2_SMB_SECURITY_SIGNATURE = 0x0004 SMB_FLAGS2_IS_LONG_NAME = 0x0040 SMB_FLAGS2_DFS = 0x1000 SMB_FLAGS2_PAGING_IO = 0x2000 SMB_FLAGS2_NT_STATUS = 0x4000 SMB_FLAGS2_UNICODE = 0x8000 # SMB Header Extensions [MS-SMB] 2.2.3.1 SMB Header Extensions SMB_FLAGS2_COMPRESSED = 0x0008
from enum import IntFlag from msdsalgs.utils import Mask class ServiceAccessFlag(IntFlag): SERVICE_CHANGE_CONFIG = 0x00000002 SERVICE_ENUMERATE_DEPENDENTS = 0x00000008 SERVICE_INTERROGATE = 0x00000080 SERVICE_PAUSE_CONTINUE = 0x00000040 SERVICE_QUERY_CONFIG = 0x00000001 SERVICE_QUERY_STATUS = 0x00000004 SERVICE_START = 0x00000010 SERVICE_STOP = 0x00000020 SERVICE_USER_DEFINED_CONTROL = 0x00000100 SERVICE_SET_STATUS = 0x00008000 DELETE = 0x00010000 READ_CONTROL = 0x00020000 WRITE_DAC = 0x00040000 WRITE_OWNER = 0x00080000 ServiceAccessFlagMask = Mask.make_class(int_flag_class=ServiceAccessFlag, name='ServiceAccessFlagMask')
SE_DACL_AUTO_INHERITED = 0x0400 SE_DACL_DEFAULTED = 0x0008 SE_DACL_PRESENT = 0x0004 SE_DACL_PROTECTED = 0x1000 SE_GROUP_DEFAULTED = 0x0002 SE_OWNER_DEFAULTED = 0x0001 SE_RM_CONTROL_VALID = 0x4000 SE_SACL_AUTO_INHERIT_REQ = 0x0200 SE_SACL_AUTO_INHERITED = 0x0800 SE_SACL_DEFAULTED = 0x0008 SE_SACL_PRESENT = 0x0010 SE_SACL_PROTECTED = 0x2000 SE_SELF_RELATIVE = 0x8000 SecurityDescriptorControl = Mask.make_class( int_flag_class=SecurityDescriptorControlMask, prefix='SE_') @dataclass class SecurityDescriptor: """ [MS-DTYP]: SECURITY_DESCRIPTOR | Microsoft Docs https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-dtyp/7d4dac05-9cef-4563-a058-f108abecce1d """ control: SecurityDescriptorControlMask owner_sid: Optional[SID] group_sid: Optional[SID] sacl: Optional[SACL] dacl: Optional[DACL]
from msdsalgs.utils import Mask class NegotiateFlagsMask(IntFlag): NTLMSSP_NEGOTIATE_UNICODE = 0x00000001 NTLMSSP_NEGOTIATE_OEM = 0x00000002 NTLMSSP_REQUEST_TARGET = 0x00000004 NTLMSSP_NEGOTIATE_SIGN = 0x00000010 NTLMSSP_NEGOTIATE_SEAL = 0x00000020 NTLMSSP_NEGOTIATE_DATAGRAM = 0x00000040 NTLMSSP_NEGOTIATE_LM_KEY = 0x00000080 NTLMSSP_NEGOTIATE_NTLM = 0x00000200 # This capability does not have an alternate name. ANONYMOUS = 0x00000800 NTLMSSP_NEGOTIATE_OEM_DOMAIN_SUPPLIED = 0x00001000 NTLMSSP_NEGOTIATE_OEM_WORKSTATION_SUPPLIED = 0x00002000 NTLMSSP_NEGOTIATE_ALWAYS_SIGN = 0x00008000 NTLMSSP_TARGET_TYPE_DOMAIN = 0x00010000 NTLMSSP_TARGET_TYPE_SERVER = 0x00020000 NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY = 0x00080000 NTLMSSP_NEGOTIATE_IDENTIFY = 0x00100000 NTLMSSP_REQUEST_NON_NT_SESSION_KEY = 0x00400000 NTLMSSP_NEGOTIATE_TARGET_INFO = 0x00800000 NTLMSSP_NEGOTIATE_VERSION = 0x02000000 NTLMSSP_NEGOTIATE_128 = 0x20000000 NTLMSSP_NEGOTIATE_KEY_EXCH = 0x40000000 NTLMSSP_NEGOTIATE_56 = 0x80000000 NegotiateFlags = Mask.make_class(NegotiateFlagsMask, prefix='NTLMSSP_')
FILE_READ_ATTRIBUTES = 0x00000080, FILE_WRITE_ATTRIBUTES = 0x00000100, DELETE = 0x00010000, READ_CONTROL = 0x00020000, WRITE_DAC = 0x00040000, WRITE_OWNER = 0x00080000, SYNCHRONIZE = 0x00100000, ACCESS_SYSTEM_SECURITY = 0x01000000, MAXIMUM_ALLOWED = 0x02000000, GENERIC_ALL = 0x10000000, GENERIC_EXECUTE = 0x20000000, GENERIC_WRITE = 0x40000000, GENERIC_READ = 0x80000000 FilePipePrinterAccessMask = Mask.make_class(FilePipePrinterAccessMaskFlag) class DirectoryAccessMaskFlag(IntFlag): FILE_LIST_DIRECTORY = 0x00000001, FILE_ADD_FILE = 0x00000002, FILE_ADD_SUBDIRECTORY = 0x00000004, FILE_READ_EA = 0x00000008, FILE_WRITE_EA = 0x00000010, FILE_TRAVERSE = 0x00000020, FILE_DELETE_CHILD = 0x00000040, FILE_READ_ATTRIBUTES = 0x00000080, FILE_WRITE_ATTRIBUTES = 0x00000100, DELETE = 0x00010000, READ_CONTROL = 0x00020000, WRITE_DAC = 0x00040000,
from enum import IntFlag from msdsalgs.utils import Mask class FileAttributesFlag(IntFlag): FILE_ATTRIBUTE_ARCHIVE = 0x00000020, FILE_ATTRIBUTE_COMPRESSED = 0x00000800, FILE_ATTRIBUTE_DIRECTORY = 0x00000010, FILE_ATTRIBUTE_ENCRYPTED = 0x00004000, FILE_ATTRIBUTE_HIDDEN = 0x00000002, FILE_ATTRIBUTE_NORMAL = 0x00000080, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000, FILE_ATTRIBUTE_OFFLINE = 0x00001000, FILE_ATTRIBUTE_READONLY = 0x00000001, FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400, FILE_ATTRIBUTE_SPARSE_FILE = 0x00000200, FILE_ATTRIBUTE_SYSTEM = 0x00000004, FILE_ATTRIBUTE_TEMPORARY = 0x00000100, FILE_ATTRIBUTE_INTEGRITY_STREAM = 0x00008000, FILE_ATTRIBUTE_NO_SCRUB_DATA = 0x00020000 FileAttributes = Mask.make_class(FileAttributesFlag, prefix='FILE_ATTRIBUTE_')
from enum import IntFlag from msdsalgs.utils import Mask class TreeConnectFlagMask(IntFlag): SMB2_TREE_CONNECT_FLAG_CLUSTER_RECONNECT = 0x0001 SMB2_TREE_CONNECT_FLAG_REDIRECT_TO_OWNER = 0x0002 SMB2_TREE_CONNECT_FLAG_EXTENSION_PRESENT = 0x0004 TreeConnectFlag = Mask.make_class(TreeConnectFlagMask, prefix='SMB2_TREE_CONNECT_FLAG_')
from enum import IntFlag from msdsalgs.utils import Mask class SecurityModeFlag(IntFlag): SMB2_NEGOTIATE_SIGNING_ENABLED = 0x0001 SMB2_NEGOTIATE_SIGNING_REQUIRED = 0x0002 SecurityMode = Mask.make_class(int_flag_class=SecurityModeFlag, prefix='SMB2_NEGOTIATE_')
from struct import pack as struct_pack, unpack_from as struct_unpack_from from enum import IntFlag from msdsalgs.utils import Mask from ntlm.structures.av_pairs import AVPair, AvId # TODO: Not sure this is the right place to put this. class AvFlagsMask(IntFlag): ACCOUNT_AUTHENTICATION_CONSTRAINED = 0x00000001 USE_MIC = 0x00000002 SPN_UNTRUSTED_SOURCE = 0x00000004 AvFlags = Mask.make_class(AvFlagsMask) @AVPair.register @dataclass class FlagsAVPair(AVPair): AV_ID: ClassVar[AvId] = AvId.MsvAvFlags LABEL: ClassVar[str] = 'Configuration' flags: AvFlags def get_value(self) -> AvFlags: return self.flags @classmethod def from_value_bytes(cls, value_bytes: bytes) -> FlagsAVPair:
from enum import IntFlag from msdsalgs.utils import Mask class CreateOptionsFlag(IntFlag): FILE_DIRECTORY_FILE = 0x00000001, FILE_WRITE_THROUGH = 0x00000002, FILE_SEQUENTIAL_ONLY = 0x00000004, FILE_NO_INTERMEDIATE_BUFFERING = 0x00000008, FILE_SYNCHRONOUS_IO_ALERT = 0x00000010, FILE_SYNCHRONOUS_IO_NONALERT = 0x00000020, FILE_NON_DIRECTORY_FILE = 0x00000040, FILE_COMPLETE_IF_OPLOCKED = 0x00000100, FILE_NO_EA_KNOWLEDGE = 0x00000200, FILE_RANDOM_ACCESS = 0x00000800, FILE_DELETE_ON_CLOSE = 0x00001000, FILE_OPEN_BY_FILE_ID = 0x00002000, FILE_OPEN_FOR_BACKUP_INTENT = 0x00004000, FILE_NO_COMPRESSION = 0x00008000, FILE_OPEN_REMOTE_INSTANCE = 0x00000400, FILE_OPEN_REQUIRING_OPLOCK = 0x00010000, FILE_DISALLOW_EXCLUSIVE = 0x00020000, FILE_RESERVE_OPFILTER = 0x00100000, FILE_OPEN_REPARSE_POINT = 0x00200000, FILE_OPEN_NO_RECALL = 0x00400000, FILE_OPEN_FOR_FREE_SPACE_QUERY = 0x00800000 CreateOptions = Mask.make_class(CreateOptionsFlag, prefix='FILE_')
from enum import IntFlag from msdsalgs.utils import Mask class SMBv2FlagMask(IntFlag): SMB2_FLAGS_SERVER_TO_REDIR = 0x00000001 SMB2_FLAGS_ASYNC_COMMAND = 0x00000002 SMB2_FLAGS_RELATED_OPERATIONS = 0x00000004 SMB2_FLAGS_SIGNED = 0x00000008 SMB2_FLAGS_PRIORITY_MASK = 0x00000070 SMB2_FLAGS_DFS_OPERATIONS = 0x10000000 SMB2_FLAGS_REPLAY_OPERATION = 0x20000000 SMBv2Flag = Mask.make_class(SMBv2FlagMask, prefix='SMB2_FLAGS_')
from enum import IntFlag from msdsalgs.utils import Mask class ChangeNotifyFlagMask(IntFlag): SMB2_WATCH_TREE = 0x0001 ChangeNotifyFlag = Mask.make_class(ChangeNotifyFlagMask, prefix='SMB2_')
from enum import IntFlag from msdsalgs.utils import Mask class WriteFlagMask(IntFlag): SMB2_WRITEFLAG_NONE = 0x00000000 SMB2_WRITEFLAG_WRITE_THROUGH = 0x00000001 SMB2_WRITEFLAG_WRITE_UNBUFFERED = 0x00000002 WriteFlag = Mask.make_class(WriteFlagMask, prefix='SMB2_WRITEFLAG_')
from enum import IntFlag from msdsalgs.utils import Mask class ShareFlagMask(IntFlag): SMB2_SHAREFLAG_MANUAL_CACHING = 0x00000000, SMB2_SHAREFLAG_AUTO_CACHING = 0x00000010, SMB2_SHAREFLAG_VDO_CACHING = 0x00000020, SMB2_SHAREFLAG_NO_CACHING = 0x00000030, SMB2_SHAREFLAG_DFS = 0x00000001, SMB2_SHAREFLAG_DFS_ROOT = 0x00000002, SMB2_SHAREFLAG_RESTRICT_EXCLUSIVE_OPENS = 0x00000100, SMB2_SHAREFLAG_FORCE_SHARED_DELETE = 0x00000200, SMB2_SHAREFLAG_ALLOW_NAMESPACE_CACHING = 0x00000400, SMB2_SHAREFLAG_ACCESS_BASED_DIRECTORY_ENUM = 0x00000800, SMB2_SHAREFLAG_FORCE_LEVELII_OPLOCK = 0x00001000, SMB2_SHAREFLAG_ENABLE_HASH_V1 = 0x00002000, SMB2_SHAREFLAG_ENABLE_HASH_V2 = 0x00004000, SMB2_SHAREFLAG_ENCRYPT_DATA = 0x00008000, SMB2_SHAREFLAG_IDENTITY_REMOTING = 0x00040000 ShareFlag = Mask.make_class(ShareFlagMask, prefix='SMB2_SHAREFLAG_')