示例#1
0
    def test_throw_exception_with_share_redir(self):
        ip_addr = SMB2MoveDstIpAddrStructure()
        ip_addr['type'] = IpAddrType.MOVE_DST_IPADDR_V4
        ip_addr.set_ipaddress("192.168.1.100")

        share_redir = SMB2ShareRedirectErrorContext()
        share_redir['ip_addr_move_list'] = [ip_addr]
        share_redir['resource_name'] = "resource".encode('utf-16-le')

        cont_resp = SMB2ErrorContextResponse()
        cont_resp['error_id'] = ErrorContextId.SMB2_ERROR_ID_SHARE_REDIRECT
        cont_resp['error_context_data'] = share_redir

        error_resp = SMB2ErrorResponse()
        error_resp['error_data'] = [cont_resp]
        header = self._get_header(error_resp,
                                  NtStatus.STATUS_BAD_NETWORK_NAME)
        try:
            raise SMBResponseException(header, header['status'].get_value(),
                                       header['message_id'].get_value())
        except SMBResponseException as exc:
            assert len(exc.error_details) == 1
            err1 = exc.error_details[0]
            assert isinstance(err1, SMB2ShareRedirectErrorContext)
            exp_resp = "Received unexpected status from the server: " \
                       "(3221225676) STATUS_BAD_NETWORK_NAME: 0xc00000cc - " \
                       "IP Addresses: '192.168.1.100', Resource Name: resource"
            assert exc.message == exp_resp
            assert str(exc) == exp_resp
            assert exc.status == NtStatus.STATUS_BAD_NETWORK_NAME
示例#2
0
    def test_throw_exception_with_symlink_redir(self):
        symlnk_redir = SMB2SymbolicLinkErrorResponse()
        symlnk_redir.set_name(r"C:\temp\folder", r"\??\C:\temp\folder")

        cont_resp = SMB2ErrorContextResponse()
        cont_resp['error_context_data'] = symlnk_redir

        error_resp = SMB2ErrorResponse()
        error_resp['error_data'] = [cont_resp]
        header = self._get_header(error_resp,
                                  NtStatus.STATUS_STOPPED_ON_SYMLINK)
        try:
            raise SMBResponseException(header, header['status'].get_value(),
                                       header['message_id'].get_value())
        except SMBResponseException as exc:
            assert len(exc.error_details) == 1
            err1 = exc.error_details[0]
            assert isinstance(err1, SMB2SymbolicLinkErrorResponse)
            exp_resp = "Received unexpected status from the server: " \
                       "(2147483693) STATUS_STOPPED_ON_SYMLINK: 0x8000002d " \
                       "- Flag: (0) SYMLINK_FLAG_ABSOLUTE, " \
                       r"Print Name: C:\temp\folder, " \
                       r"Substitute Name: \??\C:\temp\folder"
            assert exc.message == exp_resp
            assert str(exc) == exp_resp
            assert exc.status == NtStatus.STATUS_STOPPED_ON_SYMLINK
示例#3
0
 def test_create_message(self):
     message = SMB2ErrorContextResponse()
     message['error_id'] = ErrorContextId.SMB2_ERROR_ID_SHARE_REDIRECT
     message['error_context_data'] = b"\x01\x02\x03\x04"
     expected = b"\x04\x00\x00\x00" \
                b"\x72\x64\x52\x53" \
                b"\x01\x02\x03\x04"
     actual = message.pack()
     assert len(message) == 12
     assert actual == expected
示例#4
0
    def test_throw_exception_with_multiple_contexts(self):
        error_resp = SMB2ErrorResponse()
        cont_resp1 = SMB2ErrorContextResponse()
        cont_resp1['error_context_data'] = b"\x01\x02\x03\x04"
        cont_resp2 = SMB2ErrorContextResponse()
        cont_resp2['error_context_data'] = b"\x05\x06\x07\x08"
        error_resp['error_data'] = [cont_resp1, cont_resp2]
        header = self._get_header(error_resp)
        try:
            raise SMBResponseException(header)
        except SMBResponseException as exc:
            assert len(exc.error_details) == 2
            assert exc.error_details[0] == b"\x01\x02\x03\x04"
            assert exc.error_details[1] == b"\x05\x06\x07\x08"
            exp_resp = "Received unexpected status from the server: An invalid parameter was passed to a service " \
                       "or function. (3221225485) STATUS_INVALID_PARAMETER: 0xc000000d - Raw: 01020304, Raw: 05060708"
            assert exc.message == exp_resp
            assert str(exc) == exp_resp

            assert exc.status == NtStatus.STATUS_INVALID_PARAMETER
示例#5
0
 def test_parse_message(self):
     actual = SMB2ErrorContextResponse()
     data = b"\x04\x00\x00\x00" \
            b"\x72\x64\x52\x53" \
            b"\x01\x02\x03\x04"
     data = actual.unpack(data)
     assert len(actual) == 12
     assert data == b""
     assert actual['error_data_length'].get_value() == 4
     assert actual['error_id'].get_value() == \
         ErrorContextId.SMB2_ERROR_ID_SHARE_REDIRECT
     assert actual['error_context_data'].get_value() == b"\x01\x02\x03\x04"
示例#6
0
 def test_create_message_with_context(self):
     message = SMB2ErrorResponse()
     error_context = SMB2ErrorContextResponse()
     error_context['error_context_data'] = b"\x01\x02\x03\x04"
     message['error_data'] = [error_context]
     expected = b"\x09\x00" \
                b"\x01" \
                b"\x00" \
                b"\x0c\x00\x00\x00" \
                b"\x04\x00\x00\x00" \
                b"\x00\x00\x00\x00" \
                b"\x01\x02\x03\x04"
     actual = message.pack()
     assert len(message) == 20
     assert actual == expected
示例#7
0
 def test_throw_exception_with_raw_context(self):
     error_resp = SMB2ErrorResponse()
     cont_resp = SMB2ErrorContextResponse()
     cont_resp['error_context_data'] = b"\x01\x02\x03\x04"
     error_resp['error_data'] = [cont_resp]
     header = self._get_header(error_resp)
     try:
         raise SMBResponseException(header, header['status'].get_value())
     except SMBResponseException as exc:
         assert len(exc.error_details) == 1
         assert exc.error_details[0] == b"\x01\x02\x03\x04"
         exp_resp = "Received unexpected status from the server: An invalid parameter was passed to a service " \
                    "or function. (3221225485) STATUS_INVALID_PARAMETER: 0xc000000d - Raw: 01020304"
         assert exc.message == exp_resp
         assert str(exc) == exp_resp
         assert exc.status == NtStatus.STATUS_INVALID_PARAMETER
示例#8
0
    def test_throw_exception_with_symlink_redir(self):
        symlnk_redir = SMB2SymbolicLinkErrorResponse()
        symlnk_redir.set_name(r"C:\temp\folder", r"\??\C:\temp\folder")

        cont_resp = SMB2ErrorContextResponse()
        cont_resp['error_context_data'] = symlnk_redir

        error_resp = SMB2ErrorResponse()
        error_resp['error_data'] = [cont_resp]
        header = self._get_header(error_resp,
                                  NtStatus.STATUS_STOPPED_ON_SYMLINK)
        try:
            raise SMBResponseException(header)
        except SMBResponseException as exc:
            assert len(exc.error_details) == 1
            err1 = exc.error_details[0]
            assert isinstance(err1, SMB2SymbolicLinkErrorResponse)
            exp_resp = "Received unexpected status from the server: The create operation stopped after reaching a " \
                       "symbolic link. (2147483693) STATUS_STOPPED_ON_SYMLINK: 0x8000002d - Flag: (0) " \
                       "SYMLINK_FLAG_ABSOLUTE, Print Name: C:\\temp\\folder, Substitute Name: \\??\\C:\\temp\\folder"
            assert exc.message == exp_resp
            assert str(exc) == exp_resp
            assert exc.status == NtStatus.STATUS_STOPPED_ON_SYMLINK