예제 #1
0
 def test_create_message(self):
     message = SMB2ShareRedirectErrorContext()
     ip1 = SMB2MoveDstIpAddrStructure()
     ip1['type'] = IpAddrType.MOVE_DST_IPADDR_V4
     ip1.set_ipaddress("192.168.1.100")
     ip2 = SMB2MoveDstIpAddrStructure()
     ip2['type'] = IpAddrType.MOVE_DST_IPADDR_V6
     ip2.set_ipaddress("fe80:12ab:0000:0000:0000:0001:0002:0000")
     message['ip_addr_move_list'] = [
         ip1, ip2
     ]
     message['resource_name'] = b"\x01\x02\x03\x04"
     expected = b"\x4c\x00\x00\x00" \
                b"\x03\x00\x00\x00" \
                b"\x48\x00\x00\x00" \
                b"\x04\x00\x00\x00" \
                b"\x00\x00" \
                b"\x00\x00" \
                b"\x02\x00\x00\x00" \
                b"\x01\x00\x00\x00" \
                b"\x00\x00\x00\x00" \
                b"\xc0\xa8\x01\x64" \
                b"\x00\x00\x00\x00\x00\x00\x00\x00" \
                b"\x00\x00\x00\x00" \
                b"\x02\x00\x00\x00" \
                b"\x00\x00\x00\x00" \
                b"\xfe\x80\x12\xab\x00\x00\x00\x00" \
                b"\x00\x00\x00\x01\x00\x02\x00\x00" \
                b"\x01\x02\x03\x04"
     actual = message.pack()
     assert len(message) == 76
     assert actual == expected
예제 #2
0
 def test_fail_invalid_ipv6_address(self):
     message = SMB2MoveDstIpAddrStructure()
     message['type'] = IpAddrType.MOVE_DST_IPADDR_V6
     with pytest.raises(ValueError) as exc:
         message.set_ipaddress("abc")
     assert str(exc.value) == "When setting an IPv6 address, it must be " \
                              "in the full form without concatenation"
예제 #3
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
예제 #4
0
 def test_create_message_v6(self):
     message = SMB2MoveDstIpAddrStructure()
     message['type'] = IpAddrType.MOVE_DST_IPADDR_V6
     message.set_ipaddress("fe80:12ab:0000:0000:0000:0001:0002:0000")
     expected = b"\x02\x00\x00\x00" \
                b"\x00\x00\x00\x00" \
                b"\xfe\x80\x12\xab\x00\x00\x00\x00" \
                b"\x00\x00\x00\x01\x00\x02\x00\x00"
     actual = message.pack()
     assert len(message) == 24
     assert actual == expected
예제 #5
0
 def test_create_message_v4(self):
     message = SMB2MoveDstIpAddrStructure()
     message['type'] = IpAddrType.MOVE_DST_IPADDR_V4
     message.set_ipaddress("192.168.1.100")
     expected = b"\x01\x00\x00\x00" \
                b"\x00\x00\x00\x00" \
                b"\xc0\xa8\x01\x64" \
                b"\x00\x00\x00\x00\x00\x00\x00\x00" \
                b"\x00\x00\x00\x00"
     actual = message.pack()
     assert len(message) == 24
     assert actual == expected
예제 #6
0
 def test_parse_message_v4(self):
     actual = SMB2MoveDstIpAddrStructure()
     data = b"\x01\x00\x00\x00" \
            b"\x00\x00\x00\x00" \
            b"\xc0\xa8\x01\x64" \
            b"\x00\x00\x00\x00\x00\x00\x00\x00" \
            b"\x00\x00\x00\x00"
     data = actual.unpack(data)
     assert len(actual) == 24
     assert data == b""
     assert actual['type'].get_value() == IpAddrType.MOVE_DST_IPADDR_V4
     assert actual['reserved'].get_value() == 0
     assert actual['ip_address'].get_value() == b"\xc0\xa8\x01\x64"
     assert actual['reserved2'].get_value() == b"\x00" * 12
     assert actual.get_ipaddress() == "192.168.1.100"
예제 #7
0
 def test_parse_message_v6(self):
     actual = SMB2MoveDstIpAddrStructure()
     data = b"\x02\x00\x00\x00" \
            b"\x00\x00\x00\x00" \
            b"\xfe\x80\x12\xab\x00\x00\x00\x00" \
            b"\x00\x00\x00\x01\x00\x02\x00\x00"
     data = actual.unpack(data)
     assert len(actual) == 24
     assert data == b""
     assert actual['type'].get_value() == IpAddrType.MOVE_DST_IPADDR_V6
     assert actual['reserved'].get_value() == 0
     assert actual['ip_address'].get_value() == \
         b"\xfe\x80\x12\xab\x00\x00\x00\x00" \
         b"\x00\x00\x00\x01\x00\x02\x00\x00"
     assert actual['reserved2'].get_value() == b""
     assert actual.get_ipaddress() == \
         "fe80:12ab:0000:0000:0000:0001:0002:0000"