Example #1
0
def test_parse_pdu_known():
    message = BindNakPDU()
    message['packed_drep'] = DataRepresentationFormat()
    message['call_id'] = 4
    message['provider_reject_reason'] = BindNakReason.LOCAL_LIMIT_EXCEEDED
    message['p_protocols'] = [5]
    data = message.pack()
    actual = parse_pdu(data)
    assert isinstance(actual, BindNakPDU)
    assert len(actual) == 21
Example #2
0
 def _parse_pdu(self, data, opnum):
     pdu_resp = parse_pdu(data)
     if not isinstance(pdu_resp, ResponsePDU):
         raise PDUException("Expecting ResponsePDU for opnum %d response "
                            "but got: %s" % (opnum, str(pdu_resp)))
     return pdu_resp['stub_data'].get_value()
Example #3
0
    def open(self):
        log.debug("Connecting to SMB Tree %s for SCMR" % self.tree.share_name)
        self.tree.connect()

        log.debug("Opening handle to svcctl pipe")
        self.handle.create(
            ImpersonationLevel.Impersonation,
            FilePipePrinterAccessMask.GENERIC_READ
            | FilePipePrinterAccessMask.GENERIC_WRITE, 0,
            ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE
            | ShareAccess.FILE_SHARE_DELETE, CreateDisposition.FILE_OPEN,
            CreateOptions.FILE_NON_DIRECTORY_FILE)

        # we need to bind svcctl to SCManagerW over DCE/RPC
        bind = BindPDU()
        bind['pfx_flags'].set_flag(PFlags.PFC_FIRST_FRAG)
        bind['pfx_flags'].set_flag(PFlags.PFC_LAST_FRAG)
        bind['packed_drep'] = DataRepresentationFormat()
        bind['call_id'] = self.call_id
        self.call_id += 1

        context_ndr = ContextElement()
        context_ndr['context_id'] = 0
        context_ndr['abstract_syntax'] = SyntaxIdElement()
        context_ndr['abstract_syntax']['uuid'] = \
            uuid.UUID("367ABB81-9844-35F1-AD32-98F038001003")
        context_ndr['abstract_syntax']['version'] = 2

        # https://msdn.microsoft.com/en-us/library/cc243843.aspx
        ndr_syntax = SyntaxIdElement()
        ndr_syntax['uuid'] = uuid.UUID("8a885d04-1ceb-11c9-9fe8-08002b104860")
        ndr_syntax['version'] = 2
        context_ndr['transfer_syntaxes'] = [ndr_syntax]

        context_bind = ContextElement()
        context_bind['context_id'] = 1
        context_bind['abstract_syntax'] = SyntaxIdElement()
        context_bind['abstract_syntax']['uuid'] = \
            uuid.UUID("367ABB81-9844-35F1-AD32-98F038001003")
        context_bind['abstract_syntax']['version'] = 2

        # https://msdn.microsoft.com/en-us/library/cc243715.aspx
        # uuid prefix = 6CB71C2C-9812-4540
        # uuid prefix bytes = b'\x2c\x1c\xb7\x6c\x12\x98\x40\x45'
        # BindTimeFeatureNegotiateBitmask
        # https://msdn.microsoft.com/en-us/library/cc243884.aspx
        # SecurityContextMultiplexingSupported = 0x01
        # KeepConnectionOnOrphanSupported = 0x02
        # version number is 1
        bind_syntax = SyntaxIdElement()
        bind_syntax['uuid'] = b'\x2c\x1c\xb7\x6c\x12\x98\x40\x45' \
                              b'\x03\x00\x00\x00\x00\x00\x00\x00'
        bind_syntax['version'] = 1
        context_bind['transfer_syntaxes'] = [bind_syntax]

        bind['context_elems'] = [context_ndr, context_bind]
        bind_data = bind.pack()

        log.info("Sending bind request to svcctl")
        log.debug(str(bind))
        self.handle.write(bind_data)

        log.info("Receiving bind result for svcctl")
        bind_data = self.handle.read(0, 1024)
        bind_result = parse_pdu(bind_data)
        log.debug(str(bind_result))
        if not isinstance(bind_result, BindAckPDU):
            raise PDUException("Expecting BindAckPDU for initial bind result "
                               "but got: %s" % str(bind_result))
Example #4
0
def test_parse_pdu_unknown():
    data = b"\x00\x00\x99"
    with pytest.raises(PDUException) as exc:
        parse_pdu(data)
    assert str(exc.value) == "Cannot parse PDU of type 153"