コード例 #1
0
 def test_parse_message(self):
     actual = SMB2NegotiateRequest()
     data = b"\x24\x00" \
            b"\x04\x00" \
            b"\x01\x00" \
            b"\x00\x00" \
            b"\x0a\x00\x00\x00" \
            b"\x33\x33\x33\x33\x33\x33\x33\x33" \
            b"\x33\x33\x33\x33\x33\x33\x33\x33" \
            b"\x00\x00\x00\x00\x00\x00\x00\x00" \
            b"\x02\x02" \
            b"\x10\x02" \
            b"\x00\x03" \
            b"\x02\x03"
     actual.unpack(data)
     assert len(actual) == 44
     assert actual['structure_size'].get_value() == 36
     assert actual['dialect_count'].get_value() == 4
     assert actual['security_mode'].get_value() == \
         SecurityMode.SMB2_NEGOTIATE_SIGNING_ENABLED
     assert actual['reserved'].get_value() == 0
     assert actual['capabilities'].get_value() == 10
     assert actual['client_guid'].get_value() == \
         uuid.UUID(bytes=b"\x33" * 16)
     assert actual['client_start_time'].get_value() == 0
     assert actual['dialects'].get_value() == [
         Dialects.SMB_2_0_2, Dialects.SMB_2_1_0, Dialects.SMB_3_0_0,
         Dialects.SMB_3_0_2
     ]
コード例 #2
0
    def test_broken_message_worker_closed_socket(self, smb_real):
        connection = Connection(uuid.uuid4(), smb_real[2], smb_real[3], True)
        connection.connect()
        try:
            test_msg = SMB2NegotiateRequest()
            test_req = Request(test_msg, type(test_msg), connection)
            connection.outstanding_requests[666] = test_req

            # Close the connection manually
            connection.transport.close()

            with pytest.raises(SMBConnectionClosed):
                connection.receive(test_req)

            with pytest.raises(SMBConnectionClosed):
                connection.send(SMB2NegotiateRequest())
        finally:
            connection.disconnect()
コード例 #3
0
    def test_broken_message_worker(self, smb_real):
        connection = Connection(uuid.uuid4(), smb_real[2], smb_real[3], True)
        connection.connect()
        try:
            test_msg = SMB2NegotiateRequest()
            test_req = Request(test_msg, connection)
            connection.outstanding_requests[666] = test_req

            # Put a bad message in the incoming queue to break the worker in a bad way
            connection.transport._recv_queue.put(b"\x01\x02\x03\x04")
            while connection._t_exc is None:
                pass

            with pytest.raises(Exception):
                connection.send(SMB2NegotiateRequest())

            # Verify that all outstanding request events have been set on a failure
            assert test_req.response_event.is_set()
        finally:
            connection.disconnect()
コード例 #4
0
 def test_create_message(self):
     message = SMB2NegotiateRequest()
     message['security_mode'] = SecurityMode.SMB2_NEGOTIATE_SIGNING_ENABLED
     message['capabilities'] = 10
     message['client_guid'] = uuid.UUID(bytes=b"\x33" * 16)
     message['dialects'] = [
         Dialects.SMB_2_0_2, Dialects.SMB_2_1_0, Dialects.SMB_3_0_0,
         Dialects.SMB_3_0_2
     ]
     expected = b"\x24\x00" \
                b"\x04\x00" \
                b"\x01\x00" \
                b"\x00\x00" \
                b"\x0a\x00\x00\x00" \
                b"\x33\x33\x33\x33\x33\x33\x33\x33" \
                b"\x33\x33\x33\x33\x33\x33\x33\x33" \
                b"\x00\x00\x00\x00\x00\x00\x00\x00" \
                b"\x02\x02" \
                b"\x10\x02" \
                b"\x00\x03" \
                b"\x02\x03"
     actual = message.pack()
     assert len(message) == 44
     assert actual == expected