# Impacket - Collection of Python classes for working with network protocols. # # Copyright (C) 2023 Fortra. All rights reserved. # # This software is provided under a slightly modified version # of the Apache Software License. See the accompanying LICENSE file # for more information. # from __future__ import division from __future__ import print_function from struct import unpack import pytest import unittest from tests import RemoteTestCase from impacket.dcerpc.v5 import transport, epm, rpch from impacket.dcerpc.v5.ndr import NULL @pytest.mark.remote class RPCHTest(RemoteTestCase, unittest.TestCase): def setUp(self): super(RPCHTest, self).setUp() self.set_transport_config() def test_1(self): # Direct connection to ncacn_http service, RPC over HTTP v1 # No authentication stringbinding = 'ncacn_http:%s' % self.machine rpctransport = transport.DCERPCTransportFactory(stringbinding) dce = rpctransport.get_dce_rpc() dce.connect() dce.bind(epm.MSRPC_UUID_PORTMAP) request = epm.ept_lookup() request['inquiry_type'] = epm.RPC_C_EP_ALL_ELTS request['object'] = NULL request['Ifid'] = NULL request['vers_option'] = epm.RPC_C_VERS_ALL request['max_ents'] = 10 dce.request(request) dce.disconnect() # Reconnecting dce.connect() dce.bind(epm.MSRPC_UUID_PORTMAP) dce.request(request) dce.disconnect() class RPCHLocalTest(unittest.TestCase): def test_2(self): # CONN/A1 resp = b'\x05\x00\x14\x03\x10\x00\x00\x00\x4c\x00\x00\x00\x00\x00' + \ b'\x00\x00\x00\x00\x04\x00\x06\x00\x00\x00\x01\x00\x00\x00' + \ b'\x03\x00\x00\x00\xb0\xf6\xaf\x3d\x77\x62\x98\x07\x9b\x21' + \ b'\x54\x6e\xec\xf4\x22\x53\x03\x00\x00\x00\x3a\x24\x7a\x37' + \ b'\x6d\xc1\xed\x2c\x68\x5d\x34\x35\x13\x46\x43\x25\x00\x00' + \ b'\x00\x00\x00\x00\x04\x00' packet = rpch.RTSHeader(resp) packet.dump() pduData = packet['pduData'] numberOfCommands = packet['NumberOfCommands'] self.assertEqual(numberOfCommands, 4) self.assertEqual(packet['Flags'], rpch.RTS_FLAG_NONE) self.assertEqual(packet['frag_len'], 76) self.assertEqual(len(pduData), 56) server_cmds = [] while numberOfCommands > 0: numberOfCommands -= 1 cmd_type = unpack(' 0: numberOfCommands -= 1 cmd_type = unpack(' 0: numberOfCommands -= 1 cmd_type = unpack(' 0: numberOfCommands -= 1 cmd_type = unpack(' 0: numberOfCommands -= 1 cmd_type = unpack(' 0: numberOfCommands -= 1 cmd_type = unpack(' 0: numberOfCommands -= 1 cmd_type = unpack('