Coverage for /private/tmp/im/impacket/impacket/dcerpc/v5/rprn.py : 93%

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-RPRN] 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. #
else: return 'RPRN SessionError: unknown error code: 0x%x' % self.error_code
################################################################################ # CONSTANTS ################################################################################ # 2.2.1.1.7 STRING_HANDLE ('Data', STRING_HANDLE), )
# 2.2.3.1 Access Values
# 2.2.3.6.1 Printer Change Flags for Use with a Printer Handle
# 2.2.3.6.2 Printer Change Flags for Use with a Server Handle
# 2.2.3.7 Printer Enumeration Flags
# 2.2.3.8 Printer Notification Values
################################################################################ # STRUCTURES ################################################################################ # 2.2.1.1.4 PRINTER_HANDLE ('Data','20s=b""'), ) else:
# 2.2.1.2.1 DEVMODE_CONTAINER
('Data', BYTE_ARRAY), )
('cbBuf',DWORD), ('pDevMode',PBYTE_ARRAY), )
# 2.2.1.11.1 SPLCLIENT_INFO_1 ('dwSize',DWORD), ('pMachineName',LPWSTR), ('pUserName',LPWSTR), ('dwBuildNum',DWORD), ('dwMajorVersion',DWORD), ('dwMinorVersion',DWORD), ('wProcessorArchitecture',USHORT), )
('Data', SPLCLIENT_INFO_1), )
# 2.2.1.11.2 SPLCLIENT_INFO_2 ('notUsed',ULONGLONG), )
('Data', SPLCLIENT_INFO_2), ) # 2.2.1.11.3 SPLCLIENT_INFO_3 ('cbSize',UINT), ('dwFlags',DWORD), ('dwFlags',DWORD), ('pMachineName',LPWSTR), ('pUserName',LPWSTR), ('dwBuildNum',DWORD), ('dwMajorVersion',DWORD), ('dwMinorVersion',DWORD), ('wProcessorArchitecture',USHORT), ('hSplPrinter',ULONGLONG), )
('Data', SPLCLIENT_INFO_3), ) # 2.2.1.2.14 SPLCLIENT_CONTAINER ('tag', ULONG), ) 1 : ('pClientInfo1', PSPLCLIENT_INFO_1), 2 : ('pNotUsed1', PSPLCLIENT_INFO_2), 3 : ('pNotUsed2', PSPLCLIENT_INFO_3), }
('Level',DWORD), ('ClientInfo',CLIENT_INFO_UNION), )
# 2.2.1.13.2 RPC_V2_NOTIFY_OPTIONS_TYPE
('Data', USHORT_ARRAY), )
('Type',USHORT), ('Reserved0',USHORT), ('Reserved1',DWORD), ('Reserved2',DWORD), ('Count',DWORD), ('pFields',PUSHORT_ARRAY), )
('Data', RPC_V2_NOTIFY_OPTIONS_TYPE), )
# 2.2.1.13.1 RPC_V2_NOTIFY_OPTIONS ('Version',DWORD), ('Reserved',DWORD), ('Count',DWORD), ('pTypes',PRPC_V2_NOTIFY_OPTIONS_TYPE_ARRAY), )
('Data', RPC_V2_NOTIFY_OPTIONS), )
################################################################################ # RPC CALLS ################################################################################ # 3.1.4.2.1 RpcEnumPrinters (Opnum 0) ('Flags', DWORD), ('Name', STRING_HANDLE), ('Level', DWORD), ('pPrinterEnum', PBYTE_ARRAY), ('cbBuf', DWORD), )
('pPrinterEnum', PBYTE_ARRAY), ('pcbNeeded', DWORD), ('pcReturned', DWORD), ('ErrorCode', ULONG), ) # 3.1.4.2.2 RpcOpenPrinter (Opnum 1) ('pPrinterName', STRING_HANDLE), ('pDatatype', LPWSTR), ('pDevModeContainer', DEVMODE_CONTAINER), ('AccessRequired', DWORD), )
('pHandle', PRINTER_HANDLE), ('ErrorCode', ULONG), )
# 3.1.4.2.9 RpcClosePrinter (Opnum 29) ('phPrinter', PRINTER_HANDLE), )
('phPrinter', PRINTER_HANDLE), ('ErrorCode', ULONG), )
# 3.1.4.10.4 RpcRemoteFindFirstPrinterChangeNotificationEx (Opnum 65) ('hPrinter', PRINTER_HANDLE), ('fdwFlags', DWORD), ('fdwOptions', DWORD), ('pszLocalMachine', LPWSTR), ('dwPrinterLocal', DWORD), ('pOptions', PRPC_V2_NOTIFY_OPTIONS), )
('ErrorCode', ULONG), )
# 3.1.4.2.14 RpcOpenPrinterEx (Opnum 69) ('pPrinterName', STRING_HANDLE), ('pDatatype', LPWSTR), ('pDevModeContainer', DEVMODE_CONTAINER), ('AccessRequired', DWORD), ('pClientInfo', SPLCLIENT_CONTAINER), )
('pHandle', PRINTER_HANDLE), ('ErrorCode', ULONG), )
################################################################################ # OPNUMs and their corresponding structures ################################################################################ 0 : (RpcEnumPrinters, RpcEnumPrintersResponse), 1 : (RpcOpenPrinter, RpcOpenPrinterResponse), 29 : (RpcClosePrinter, RpcClosePrinterResponse), 65 : (RpcRemoteFindFirstPrinterChangeNotificationEx, RpcRemoteFindFirstPrinterChangeNotificationExResponse), 69 : (RpcOpenPrinterEx, RpcOpenPrinterExResponse), }
################################################################################ # HELPER FUNCTIONS ################################################################################ return string
return string + '\x00' else:
""" RpcOpenPrinter retrieves a handle for a printer, port, port monitor, print job, or print server. Full Documentation: https://msdn.microsoft.com/en-us/library/cc244808.aspx
:param DCERPC_v5 dce: a connected DCE instance. :param string printerName: A string for a printer connection, printer object, server object, job object, port object, or port monitor object. This MUST be a Domain Name System (DNS), NetBIOS, Internet Protocol version 4 (IPv4), Internet Protocol version 6 (IPv6), or Universal Naming Convention (UNC) name that remote procedure call (RPC) binds to, and it MUST uniquely identify a print server on the network. :param string pDatatype: A string that specifies the data type to be associated with the printer handle. :param DEVMODE_CONTAINER pDevModeContainer: A DEVMODE_CONTAINER structure. This parameter MUST adhere to the specification in DEVMODE_CONTAINER Parameters (section 3.1.4.1.8.1). :param int accessRequired: The access level that the client requires for interacting with the object to which a handle is being opened.
:return: a RpcOpenPrinterResponse instance, raises DCERPCSessionError on error. """ else: request['pDevModeContainer'] = pDevModeContainer
""" RpcClosePrinter closes a handle to a printer object, server object, job object, or port object. Full Documentation: https://msdn.microsoft.com/en-us/library/cc244768.aspx
:param DCERPC_v5 dce: a connected DCE instance. :param PRINTER_HANDLE phPrinter: A handle to a printer object, server object, job object, or port object.
:return: a RpcClosePrinterResponse instance, raises DCERPCSessionError on error. """
pClientInfo=NULL): """ RpcOpenPrinterEx retrieves a handle for a printer, port, port monitor, print job, or print server Full Documentation: https://msdn.microsoft.com/en-us/library/cc244809.aspx
:param DCERPC_v5 dce: a connected DCE instance. :param string printerName: A string for a printer connection, printer object, server object, job object, port object, or port monitor object. This MUST be a Domain Name System (DNS), NetBIOS, Internet Protocol version 4 (IPv4), Internet Protocol version 6 (IPv6), or Universal Naming Convention (UNC) name that remote procedure call (RPC) binds to, and it MUST uniquely identify a print server on the network. :param string pDatatype: A string that specifies the data type to be associated with the printer handle. :param DEVMODE_CONTAINER pDevModeContainer: A DEVMODE_CONTAINER structure. This parameter MUST adhere to the specification in DEVMODE_CONTAINER Parameters (section 3.1.4.1.8.1). :param int accessRequired: The access level that the client requires for interacting with the object to which a handle is being opened. :param SPLCLIENT_CONTAINER pClientInfo: This parameter MUST adhere to the specification in SPLCLIENT_CONTAINER Parameters.
:return: a RpcOpenPrinterExResponse instance, raises DCERPCSessionError on error. """ else: request['pDevModeContainer'] = pDevModeContainer
raise Exception('pClientInfo cannot be NULL')
dwPrinterLocal=0, pOptions=NULL): """ creates a remote change notification object that monitors changes to printer objects and sends change notifications to a print client using either RpcRouterReplyPrinter (section 3.2.4.1.2) or RpcRouterReplyPrinterEx (section 3.2.4.1.4) Full Documentation: https://msdn.microsoft.com/en-us/library/cc244813.aspx
:param DCERPC_v5 dce: a connected DCE instance. :param PRINTER_HANDLE hPrinter: A handle to a printer or server object. :param int fdwFlags: Flags that specify the conditions that are required for a change notification object to enter a signaled state. :param int fdwOptions: The category of printers for which change notifications are returned. :param string pszLocalMachine: A string that represents the name of the client computer. :param int dwPrinterLocal: An implementation-specific unique value that MUST be sufficient for the client to determine whether a call to RpcReplyOpenPrinter by the server is associated with the hPrinter parameter in this call. :param RPC_V2_NOTIFY_OPTIONS pOptions: An RPC_V2_NOTIFY_OPTIONS structure that specifies printer or job members that the client listens to for notifications.
:return: a RpcRemoteFindFirstPrinterChangeNotificationExResponse instance, raises DCERPCSessionError on error. """
raise Exception('pszLocalMachine cannot be NULL')
""" RpcEnumPrinters enumerates available printers, print servers, domains, or print providers. Full Documentation: https://msdn.microsoft.com/en-us/library/cc244794.aspx
:param DCERPC_v5 dce: a connected DCE instance. :param int flags: The types of print objects that this method enumerates. The value of this parameter is the result of a bitwise OR of one or more of the Printer Enumeration Flags (section 2.2.3.7). :param string name: NULL or a server name parameter as specified in Printer Server Name Parameters (section 3.1.4.1.4). :param level: The level of printer information structure.
:return: a RpcEnumPrintersResponse instance, raises DCERPCSessionError on error. """ raise
|