Coverage for /private/tmp/im/impacket/impacket/dcerpc/v5/wkst.py : 96%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# SECUREAUTH LABS. Copyright 2018 SecureAuth Corporation. All rights reserved. # # This software is provided under under a slightly modified version # of the Apache Software License. See the accompanying LICENSE file # for more information. # # Author: Alberto Solino (@agsolino) # # Description: # [MS-WKST] Interface implementation # # Best way to learn how to use these calls is to grab the protocol standard # so you understand what the call does, and then read the test case located # at https://github.com/SecureAuthCorp/impacket/tree/master/tests/SMB_RPC # # Some calls have helper functions, which makes it even easier to use. # They are located at the end of this file. # Helper functions start with "h"<name of the call>. # There are test cases for them too. # NDRPOINTER LPULONG, LPLONG
else:
################################################################################ # CONSTANTS ################################################################################
# 2.2.1.1 JOIN_MAX_PASSWORD_LENGTH
# 2.2.1.2 JOIN_OBFUSCATOR_LENGTH
# 2.2.1.3 MAX_PREFERRED_LENGTH
# 2.2.5.22 USE_INFO_1
# 3.2.4.9 NetrUseDel (Opnum 10) # Force Level
# 3.2.4.13 NetrJoinDomain2 (Opnum 22) # Options
# 3.2.4.14 NetrUnjoinDomain2 (Opnum 23) # Options
# 3.2.4.15 NetrRenameMachineInDomain2 (Opnum 24) # Options
################################################################################ # STRUCTURES ################################################################################
# 2.2.2.1 WKSSVC_IDENTIFY_HANDLE ('Data', WSTR), )
('Data', WKSSVC_IDENTIFY_HANDLE), )
# 2.2.2.2 WKSSVC_IMPERSONATE_HANDLE ('Data',WSTR), )
('Data', WKSSVC_IMPERSONATE_HANDLE), )
# 2.2.3.1 NETSETUP_JOIN_STATUS
# 2.2.3.2 NETSETUP_NAME_TYPE
# 2.2.3.3 NET_COMPUTER_NAME_TYPE
# 2.2.5.1 WKSTA_INFO_100 ('wki100_platform_id', ULONG), ('wki100_computername', LPWSTR), ('wki100_langroup', LPWSTR), ('wki100_ver_major', ULONG), ('wki100_ver_minor', ULONG), )
('Data', WKSTA_INFO_100), )
# 2.2.5.2 WKSTA_INFO_101 ('wki101_platform_id', ULONG), ('wki101_computername', LPWSTR), ('wki101_langroup', LPWSTR), ('wki101_ver_major', ULONG), ('wki101_ver_minor', ULONG), ('wki101_lanroot', LPWSTR), )
('Data', WKSTA_INFO_101), )
# 2.2.5.3 WKSTA_INFO_102 ('wki102_platform_id', ULONG), ('wki102_computername', LPWSTR), ('wki102_langroup', LPWSTR), ('wki102_ver_major', ULONG), ('wki102_ver_minor', ULONG), ('wki102_lanroot', LPWSTR), ('wki102_logged_on_users', ULONG), )
('Data', WKSTA_INFO_102), )
# 2.2.5.4 WKSTA_INFO_502 ('wki502_char_wait', ULONG), ('wki502_collection_time', ULONG), ('wki502_maximum_collection_count', ULONG), ('wki502_keep_conn', ULONG), ('wki502_max_cmds', ULONG), ('wki502_sess_timeout', ULONG), ('wki502_siz_char_buf', ULONG), ('wki502_max_threads', ULONG), ('wki502_lock_quota', ULONG), ('wki502_lock_increment', ULONG), ('wki502_lock_maximum', ULONG), ('wki502_pipe_increment', ULONG), ('wki502_pipe_maximum', ULONG), ('wki502_cache_file_timeout', ULONG), ('wki502_dormant_file_limit', ULONG), ('wki502_read_ahead_throughput', ULONG), ('wki502_num_mailslot_buffers', ULONG), ('wki502_num_srv_announce_buffers', ULONG), ('wki502_max_illegal_datagram_events', ULONG), ('wki502_illegal_datagram_event_reset_frequency', ULONG), ('wki502_log_election_packets', LONG), ('wki502_use_opportunistic_locking', LONG), ('wki502_use_unlock_behind', LONG), ('wki502_use_close_behind', LONG), ('wki502_buf_named_pipes', LONG), ('wki502_use_lock_read_unlock', LONG), ('wki502_utilize_nt_caching', LONG), ('wki502_use_raw_read', LONG), ('wki502_use_raw_write', LONG), ('wki502_use_write_raw_data', LONG), ('wki502_use_encryption', LONG), ('wki502_buf_files_deny_write', LONG), ('wki502_buf_read_only_files', LONG), ('wki502_force_core_create_mode', LONG), ('wki502_use_512_byte_max_transfer', LONG), )
('Data', WKSTA_INFO_502), )
# 2.2.5.5 WKSTA_INFO_1013 ('wki1013_keep_conn', ULONG), )
('Data', WKSTA_INFO_1013), )
# 2.2.5.6 WKSTA_INFO_1018 ('wki1018_sess_timeout', ULONG), )
('Data', WKSTA_INFO_1018), )
# 2.2.5.7 WKSTA_INFO_1046 ('wki1046_dormant_file_limit', ULONG), )
('Data', WKSTA_INFO_1046), )
# 2.2.4.1 WKSTA_INFO ('tag', ULONG), ) 100: ('WkstaInfo100', LPWKSTA_INFO_100), 101: ('WkstaInfo101', LPWKSTA_INFO_101), 102: ('WkstaInfo102', LPWKSTA_INFO_102), 502: ('WkstaInfo502', LPWKSTA_INFO_502), 1013: ('WkstaInfo1013', LPWKSTA_INFO_1013), 1018: ('WkstaInfo1018', LPWKSTA_INFO_1018), 1046: ('WkstaInfo1046', LPWKSTA_INFO_1046), }
('Data', WKSTA_INFO), )
# 2.2.5.8 WKSTA_TRANSPORT_INFO_0 ('wkti0_quality_of_service', ULONG), ('wkti0_number_of_vcs', ULONG), ('wkti0_transport_name', LPWSTR), ('wkti0_transport_address', LPWSTR), ('wkti0_wan_ish', ULONG), )
# 2.2.5.9 WKSTA_USER_INFO_0 ('wkui0_username', LPWSTR), )
# 2.2.5.10 WKSTA_USER_INFO_1 ('wkui1_username', LPWSTR), ('wkui1_logon_domain', LPWSTR), ('wkui1_oth_domains', LPWSTR), ('wkui1_logon_server', LPWSTR), )
# 2.2.5.11 STAT_WORKSTATION_0 ('StatisticsStartTime', LARGE_INTEGER), ('BytesReceived', LARGE_INTEGER), ('SmbsReceived', LARGE_INTEGER), ('PagingReadBytesRequested', LARGE_INTEGER), ('NonPagingReadBytesRequested', LARGE_INTEGER), ('CacheReadBytesRequested', LARGE_INTEGER), ('NetworkReadBytesRequested', LARGE_INTEGER), ('BytesTransmitted', LARGE_INTEGER), ('SmbsTransmitted', LARGE_INTEGER), ('PagingWriteBytesRequested', LARGE_INTEGER), ('NonPagingWriteBytesRequested', LARGE_INTEGER), ('CacheWriteBytesRequested', LARGE_INTEGER), ('NetworkWriteBytesRequested', LARGE_INTEGER), ('InitiallyFailedOperations', ULONG), ('FailedCompletionOperations', ULONG), ('ReadOperations', ULONG), ('RandomReadOperations', ULONG), ('ReadSmbs', ULONG), ('LargeReadSmbs', ULONG), ('SmallReadSmbs', ULONG), ('WriteOperations', ULONG), ('RandomWriteOperations', ULONG), ('WriteSmbs', ULONG), ('LargeWriteSmbs', ULONG), ('SmallWriteSmbs', ULONG), ('RawReadsDenied', ULONG), ('RawWritesDenied', ULONG), ('NetworkErrors', ULONG), ('Sessions', ULONG), ('FailedSessions', ULONG), ('Reconnects', ULONG), ('CoreConnects', ULONG), ('Lanman20Connects', ULONG), ('Lanman21Connects', ULONG), ('LanmanNtConnects', ULONG), ('ServerDisconnects', ULONG), ('HungSessions', ULONG), ('UseCount', ULONG), ('FailedUseCount', ULONG), ('CurrentCommands', ULONG), )
('Data', STAT_WORKSTATION_0), )
# 2.2.5.12 WKSTA_USER_INFO_0_CONTAINER
('Data', WKSTA_USER_INFO_0_ARRAY), )
('EntriesRead', ULONG), ('Buffer', LPWKSTA_USER_INFO_0_ARRAY), )
('Data', WKSTA_USER_INFO_0_CONTAINER), )
# 2.2.5.13 WKSTA_USER_INFO_1_CONTAINER
('Data', WKSTA_USER_INFO_1_ARRAY), )
('EntriesRead', ULONG), ('Buffer', LPWKSTA_USER_INFO_1_ARRAY), )
('Data', WKSTA_USER_INFO_1_CONTAINER), )
# 2.2.5.14 WKSTA_USER_ENUM_STRUCT ('tag', ULONG), )
0: ('Level0', LPWKSTA_USER_INFO_0_CONTAINER), 1: ('Level1', LPWKSTA_USER_INFO_1_CONTAINER), }
('Level', ULONG), ('WkstaUserInfo', WKSTA_USER_ENUM_UNION), )
# 2.2.5.15 WKSTA_TRANSPORT_INFO_0_CONTAINER
('Data', WKSTA_TRANSPORT_INFO_0_ARRAY), )
('EntriesRead', ULONG), ('Buffer', LPWKSTA_TRANSPORT_INFO_0_ARRAY), )
('Data', WKSTA_TRANSPORT_INFO_0_CONTAINER), )
# 2.2.5.16 WKSTA_TRANSPORT_ENUM_STRUCT ('tag', ULONG), )
0: ('Level0', LPWKSTA_TRANSPORT_INFO_0_CONTAINER), }
('Level', ULONG), ('WkstaTransportInfo', WKSTA_TRANSPORT_ENUM_UNION), )
# 2.2.5.17 JOINPR_USER_PASSWORD return JOIN_MAX_PASSWORD_LENGTH
return JOIN_OBFUSCATOR_LENGTH
('Obfuscator', CHAR_ARRAY), ('Buffer', WCHAR_ARRAY), )
# 2.2.5.18 JOINPR_ENCRYPTED_USER_PASSWORD ('Buffer', '524s=b""'), )
('Data', JOINPR_ENCRYPTED_USER_PASSWORD), )
# 2.2.5.19 UNICODE_STRING ('Data', UNICODE_STRING), )
# 2.2.5.20 NET_COMPUTER_NAME_ARRAY
('Data', UNICODE_STRING_ARRAY), )
('EntriesRead', ULONG), ('ComputerNames', PUNICODE_STRING_ARRAY), )
('Data', NET_COMPUTER_NAME_ARRAY), )
# 2.2.5.21 USE_INFO_0 ('ui0_local', LPWSTR), ('ui0_remote', LPWSTR), )
('Data', USE_INFO_0), )
# 2.2.5.22 USE_INFO_1 ('ui1_local', LPWSTR), ('ui1_remote', LPWSTR), ('ui1_password', LPWSTR), ('ui1_status', ULONG), ('ui1_asg_type', ULONG), ('ui1_refcount', ULONG), ('ui1_usecount', ULONG), )
('Data', USE_INFO_1), )
# 2.2.5.23 USE_INFO_2 ('ui2_useinfo', USE_INFO_1), ('ui2_username', LPWSTR), ('ui2_domainname', LPWSTR), )
('Data', USE_INFO_2), )
# 2.2.5.24 USE_INFO_3 ('ui3_ui2', USE_INFO_2), ('ui3_flags', ULONG), )
('Data', USE_INFO_3), )
# 2.2.4.2 USE_INFO ('tag', ULONG), )
0: ('UseInfo0', LPUSE_INFO_0), 1: ('UseInfo1', LPUSE_INFO_1), 2: ('UseInfo2', LPUSE_INFO_2), 3: ('UseInfo3', LPUSE_INFO_3), }
# 2.2.5.25 USE_INFO_0_CONTAINER ('EntriesRead', ULONG), ('Buffer', LPUSE_INFO_0), )
('Data', USE_INFO_0_CONTAINER), )
# 2.2.5.26 USE_INFO_1_CONTAINER ('EntriesRead', ULONG), ('Buffer', LPUSE_INFO_1), )
('Data', USE_INFO_1_CONTAINER), )
# 2.2.5.27 USE_INFO_2_CONTAINER ('EntriesRead', ULONG), ('Buffer', LPUSE_INFO_2), )
('Data', USE_INFO_2_CONTAINER), )
# 2.2.5.28 USE_ENUM_STRUCT ('tag', ULONG), )
0: ('Level0', LPUSE_INFO_0_CONTAINER), 1: ('Level1', LPUSE_INFO_1_CONTAINER), 2: ('Level2', LPUSE_INFO_2_CONTAINER), }
('Level', ULONG), ('UseInfo', USE_ENUM_UNION), )
################################################################################ # RPC CALLS ################################################################################
# 3.2.4.1 NetrWkstaGetInfo (Opnum 0) ('ServerName', LPWKSSVC_IDENTIFY_HANDLE), ('Level', ULONG), )
('WkstaInfo',WKSTA_INFO), ('ErrorCode',ULONG), )
# 3.2.4.2 NetrWkstaSetInfo (Opnum 1) ('ServerName', LPWKSSVC_IDENTIFY_HANDLE), ('Level', ULONG), ('WkstaInfo',WKSTA_INFO), ('ErrorParameter',LPULONG), )
('ErrorParameter',LPULONG), ('ErrorCode',ULONG), )
# 3.2.4.3 NetrWkstaUserEnum (Opnum 2) ('ServerName', LPWKSSVC_IDENTIFY_HANDLE), ('UserInfo', WKSTA_USER_ENUM_STRUCT), ('PreferredMaximumLength', ULONG), ('ResumeHandle', LPULONG), )
('UserInfo',WKSTA_USER_ENUM_STRUCT), ('TotalEntries',ULONG), ('ResumeHandle',ULONG), ('ErrorCode',ULONG), )
# 3.2.4.4 NetrWkstaTransportEnum (Opnum 5) ('ServerName', LPWKSSVC_IDENTIFY_HANDLE), ('TransportInfo', WKSTA_TRANSPORT_ENUM_STRUCT), ('PreferredMaximumLength', ULONG), ('ResumeHandle', LPULONG), )
('TransportInfo',WKSTA_TRANSPORT_ENUM_STRUCT), ('TotalEntries',ULONG), ('ResumeHandle',ULONG), ('ErrorCode',ULONG), )
# 3.2.4.5 NetrWkstaTransportAdd (Opnum 6) ('ServerName', LPWKSSVC_IDENTIFY_HANDLE), ('Level', ULONG), ('TransportInfo',WKSTA_TRANSPORT_INFO_0), ('ErrorParameter',LPULONG), )
('ErrorParameter',LPULONG), ('ErrorCode',ULONG), )
# 3.2.4.7 NetrUseAdd (Opnum 8) ('ServerName', LPWKSSVC_IMPERSONATE_HANDLE), ('Level', ULONG), ('InfoStruct',USE_INFO), ('ErrorParameter',LPULONG), )
('ErrorParameter',LPULONG), ('ErrorCode',ULONG), )
# 3.2.4.8 NetrUseGetInfo (Opnum 9) ('ServerName', LPWKSSVC_IMPERSONATE_HANDLE), ('UseName', WSTR), ('Level',ULONG), )
('InfoStruct',USE_INFO), ('ErrorCode',ULONG), )
# 3.2.4.9 NetrUseDel (Opnum 10) ('ServerName', LPWKSSVC_IMPERSONATE_HANDLE), ('UseName', WSTR), ('ForceLevel',ULONG), )
('ErrorCode',ULONG), )
# 3.2.4.10 NetrUseEnum (Opnum 11) ('ServerName', LPWKSSVC_IMPERSONATE_HANDLE), ('InfoStruct', USE_ENUM_STRUCT), ('PreferredMaximumLength',ULONG), ('ResumeHandle',LPULONG), )
('InfoStruct',USE_ENUM_STRUCT), ('TotalEntries',ULONG), ('ResumeHandle',LPULONG), ('ErrorCode',ULONG), )
# 3.2.4.11 NetrWorkstationStatisticsGet (Opnum 13) ('ServerName', LPWKSSVC_IDENTIFY_HANDLE), ('ServiceName', LPWSTR), ('Level',ULONG), ('Options',ULONG), )
('Buffer',LPSTAT_WORKSTATION_0), ('ErrorCode',ULONG), )
# 3.2.4.12 NetrGetJoinInformation (Opnum 20) ('ServerName', LPWKSSVC_IMPERSONATE_HANDLE), ('NameBuffer', LPWSTR), )
('NameBuffer',LPWSTR), ('BufferType',NETSETUP_JOIN_STATUS), ('ErrorCode',ULONG), )
# 3.2.4.13 NetrJoinDomain2 (Opnum 22) ('ServerName', LPWSTR), ('DomainNameParam', WSTR), ('MachineAccountOU', LPWSTR), ('AccountName', LPWSTR), ('Password', PJOINPR_ENCRYPTED_USER_PASSWORD), ('Options', ULONG), )
('ErrorCode',ULONG), )
# 3.2.4.14 NetrUnjoinDomain2 (Opnum 23) ('ServerName', LPWSTR), ('AccountName', LPWSTR), ('Password', PJOINPR_ENCRYPTED_USER_PASSWORD), ('Options', ULONG), )
('ErrorCode',ULONG), )
# 3.2.4.15 NetrRenameMachineInDomain2 (Opnum 24) ('ServerName', LPWSTR), ('MachineName', LPWSTR), ('AccountName', LPWSTR), ('Password', PJOINPR_ENCRYPTED_USER_PASSWORD), ('Options', ULONG), )
('ErrorCode',ULONG), )
# 3.2.4.16 NetrValidateName2 (Opnum 25) ('ServerName', LPWSTR), ('NameToValidate', WSTR), ('AccountName', LPWSTR), ('Password', PJOINPR_ENCRYPTED_USER_PASSWORD), ('NameType', NETSETUP_NAME_TYPE), )
('ErrorCode',ULONG), )
# 3.2.4.17 NetrGetJoinableOUs2 (Opnum 26) ('ServerName', LPWSTR), ('DomainNameParam', WSTR), ('AccountName', LPWSTR), ('Password', PJOINPR_ENCRYPTED_USER_PASSWORD), ('OUCount', ULONG), )
('OUCount', LPLONG), ('OUs',PUNICODE_STRING_ARRAY), ('ErrorCode',ULONG), )
# 3.2.4.18 NetrAddAlternateComputerName (Opnum 27) ('ServerName', LPWSTR), ('AlternateName', LPWSTR), ('DomainAccount', LPWSTR), ('EncryptedPassword', PJOINPR_ENCRYPTED_USER_PASSWORD), ('Reserved', ULONG), )
('ErrorCode',ULONG), )
# 3.2.4.19 NetrRemoveAlternateComputerName (Opnum 28) ('ServerName', LPWSTR), ('AlternateName', LPWSTR), ('DomainAccount', LPWSTR), ('EncryptedPassword', PJOINPR_ENCRYPTED_USER_PASSWORD), ('Reserved', ULONG), )
('ErrorCode',ULONG), )
# 3.2.4.20 NetrSetPrimaryComputerName (Opnum 29) ('ServerName', LPWSTR), ('PrimaryName', LPWSTR), ('DomainAccount', LPWSTR), ('EncryptedPassword', PJOINPR_ENCRYPTED_USER_PASSWORD), ('Reserved', ULONG), )
('ErrorCode',ULONG), )
# 3.2.4.21 NetrEnumerateComputerNames (Opnum 30) ('ServerName', LPWKSSVC_IMPERSONATE_HANDLE), ('NameType', NET_COMPUTER_NAME_TYPE), ('Reserved', ULONG), )
('ComputerNames',PNET_COMPUTER_NAME_ARRAY), ('ErrorCode',ULONG), )
################################################################################ # OPNUMs and their corresponding structures ################################################################################ 0 : (NetrWkstaGetInfo, NetrWkstaGetInfoResponse), 1 : (NetrWkstaSetInfo, NetrWkstaSetInfoResponse), 2 : (NetrWkstaUserEnum, NetrWkstaUserEnumResponse), 5 : (NetrWkstaTransportEnum, NetrWkstaTransportEnumResponse), 6 : (NetrWkstaTransportAdd, NetrWkstaTransportAddResponse), # 7 : (NetrWkstaTransportDel, NetrWkstaTransportDelResponse), 8 : (NetrUseAdd, NetrUseAddResponse), 9 : (NetrUseGetInfo, NetrUseGetInfoResponse), 10 : (NetrUseDel, NetrUseDelResponse), 11 : (NetrUseEnum, NetrUseEnumResponse), 13 : (NetrWorkstationStatisticsGet, NetrWorkstationStatisticsGetResponse), 20 : (NetrGetJoinInformation, NetrGetJoinInformationResponse), 22 : (NetrJoinDomain2, NetrJoinDomain2Response), 23 : (NetrUnjoinDomain2, NetrUnjoinDomain2Response), 24 : (NetrRenameMachineInDomain2, NetrRenameMachineInDomain2Response), 25 : (NetrValidateName2, NetrValidateName2Response), 26 : (NetrGetJoinableOUs2, NetrGetJoinableOUs2Response), 27 : (NetrAddAlternateComputerName, NetrAddAlternateComputerNameResponse), 28 : (NetrRemoveAlternateComputerName, NetrRemoveAlternateComputerNameResponse), 29 : (NetrSetPrimaryComputerName, NetrSetPrimaryComputerNameResponse), 30 : (NetrEnumerateComputerNames, NetrEnumerateComputerNamesResponse), }
################################################################################ # HELPER FUNCTIONS ################################################################################
else:
request['Password'] = NULL else:
request['Password'] = NULL else:
request['Password'] = NULL else:
else: request['Password']['Buffer'] = password
else: request['Password']['Buffer'] = password
else: request['EncryptedPassword']['Buffer'] = encryptedPassword
else: request['EncryptedPassword']['Buffer'] = encryptedPassword
else: request['EncryptedPassword']['Buffer'] = encryptedPassword
|