Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
0
 def test_create_message_plain(self):
     # This is a plain error response without the error context response
     # data appended
     message = SMB2ErrorResponse()
     expected = b"\x09\x00" \
                b"\x00" \
                b"\x00" \
                b"\x00\x00\x00\x00"
     actual = message.pack()
     assert len(actual) == 8
     assert actual == expected
Exemplo n.º 4
0
 def test_throw_default_exception(self):
     error_resp = SMB2ErrorResponse()
     header = self._get_header(error_resp)
     try:
         raise SMBResponseException(header)
     except SMBResponseException as exc:
         assert exc.error_details == []
         exp_resp = "Received unexpected status from the server: An invalid parameter was passed to a service or " \
                    "function. (3221225485) STATUS_INVALID_PARAMETER: 0xc000000d"
         assert exc.message == exp_resp
         assert str(exc) == exp_resp
         assert exc.status == NtStatus.STATUS_INVALID_PARAMETER
Exemplo n.º 5
0
 def test_throw_default_exception(self):
     error_resp = SMB2ErrorResponse()
     header = self._get_header(error_resp)
     try:
         raise SMBResponseException(header, header['status'].get_value(),
                                    header['message_id'].get_value())
     except SMBResponseException as exc:
         assert exc.error_details == []
         exp_resp = "Received unexpected status from the server: " \
                    "(3221225485) STATUS_INVALID_PARAMETER: 0xc000000d"
         assert exc.message == exp_resp
         assert str(exc) == exp_resp
         assert exc.status == NtStatus.STATUS_INVALID_PARAMETER
Exemplo n.º 6
0
 def test_parse_message_plain(self):
     actual = SMB2ErrorResponse()
     data = b"\x09\x00" \
            b"\x00" \
            b"\x00" \
            b"\x00\x00\x00\x00"
     data = actual.unpack(data)
     assert len(actual) == 8
     assert data == b""
     assert actual['structure_size'].get_value() == 9
     assert actual['error_context_count'].get_value() == 0
     assert actual['reserved'].get_value() == 0
     assert actual['byte_count'].get_value() == 0
     assert actual['error_data'].get_value() == []
Exemplo n.º 7
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
Exemplo n.º 8
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)
     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
Exemplo n.º 9
0
    def test_exception_no_context_but_data(self):
        # Older dialects don't support the Error Context list but still return data in there. This tests those older
        # hosts.
        data = b"\x09\x00" \
               b"\x00" \
               b"\x00" \
               b"\x04\x00\x00\x00" \
               b"\x01\x02\x03\x04"
        error_resp = SMB2ErrorResponse()
        data = error_resp.unpack(data)

        assert data == b""
        assert len(error_resp['error_data'].get_value()) == 1
        error_context = error_resp['error_data'].get_value()[0]
        assert error_context['error_data_length'].get_value() == 4
        assert error_context['error_id'].get_value() == ErrorContextId.SMB2_ERROR_ID_DEFAULT
        assert error_context['error_context_data'].get_value() == b"\x01\x02\x03\x04"
Exemplo n.º 10
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, header['status'].get_value())
        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
Exemplo n.º 11
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
Exemplo n.º 12
0
 def test_parse_message_with_context(self):
     actual = SMB2ErrorResponse()
     data = 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"  # just a fake bytes value for test
     data = actual.unpack(data)
     assert len(actual) == 20
     assert data == b""
     assert actual['structure_size'].get_value() == 9
     assert actual['error_context_count'].get_value() == 1
     assert actual['reserved'].get_value() == 0
     assert actual['byte_count'].get_value() == 12
     assert len(actual['error_data']) == 12
     error_data = actual['error_data'].get_value()
     assert len(error_data) == 1
     assert error_data[0]['error_data_length'].get_value() == 4
     assert error_data[0]['error_id'].get_value() == \
         SymbolicLinkErrorFlags.SYMLINK_FLAG_ABSOLUTE
     assert error_data[0]['error_context_data'].get_value() == \
         b"\x01\x02\x03\x04"