Beispiel #1
0
static boolean rdp_recv_tpkt_pdu(rdpRdp* rdp, STREAM* s)
{
	uint16 length;
	uint16 pduType;
	uint16 pduLength;
	uint16 pduSource;
	uint16 channelId;
	uint16 securityFlags;

	if (!rdp_read_header(rdp, s, &length, &channelId))
	{
		printf("Incorrect RDP header.\n");
		return false;
	}

	if (rdp->settings->encryption)
	{
		rdp_read_security_header(s, &securityFlags);
		if (securityFlags & (SEC_ENCRYPT|SEC_REDIRECTION_PKT))
		{
			if (!rdp_decrypt(rdp, s, length - 4, securityFlags))
			{
				printf("rdp_decrypt failed\n");
				return false;
			}
		}
		if (securityFlags & SEC_REDIRECTION_PKT)
		{
			/*
			 * [MS-RDPBCGR] 2.2.13.2.1
			 *  - no share control header, nor the 2 byte pad
			 */
			s->p -= 2;
			rdp_recv_enhanced_security_redirection_packet(rdp, s);
			return true;
		}
	}

	if (channelId != MCS_GLOBAL_CHANNEL_ID)
	{
		freerdp_channel_process(rdp->instance, s, channelId);
	}
	else
	{
		rdp_read_share_control_header(s, &pduLength, &pduType, &pduSource);

		rdp->settings->pdu_source = pduSource;

		switch (pduType)
		{
			case PDU_TYPE_DATA:
				rdp_recv_data_pdu(rdp, s);
				break;

			case PDU_TYPE_DEACTIVATE_ALL:
				if (!rdp_recv_deactivate_all(rdp, s))
					return false;
				break;

			case PDU_TYPE_SERVER_REDIRECTION:
				rdp_recv_enhanced_security_redirection_packet(rdp, s);
				break;

			default:
				printf("incorrect PDU type: 0x%04X\n", pduType);
				break;
		}
	}

	return true;
}
Beispiel #2
0
static int rdp_recv_tpkt_pdu(rdpRdp* rdp, wStream* s)
{
    UINT16 length;
    UINT16 pduType;
    UINT16 pduLength;
    UINT16 pduSource;
    UINT16 channelId = 0;
    UINT16 securityFlags;
    int nextPosition;

    if (!rdp_read_header(rdp, s, &length, &channelId))
    {
        DEBUG_WARN( "Incorrect RDP header.\n");
        return -1;
    }

    if (rdp->settings->DisableEncryption)
    {
        if (!rdp_read_security_header(s, &securityFlags))
            return -1;

        if (securityFlags & (SEC_ENCRYPT | SEC_REDIRECTION_PKT))
        {
            if (!rdp_decrypt(rdp, s, length - 4, securityFlags))
            {
                DEBUG_WARN( "rdp_decrypt failed\n");
                return -1;
            }
        }

        if (securityFlags & SEC_REDIRECTION_PKT)
        {
            /*
             * [MS-RDPBCGR] 2.2.13.2.1
             *  - no share control header, nor the 2 byte pad
             */
            Stream_Rewind(s, 2);

            return rdp_recv_enhanced_security_redirection_packet(rdp, s);
        }
    }

    if (channelId == MCS_GLOBAL_CHANNEL_ID)
    {
        while (Stream_GetRemainingLength(s) > 3)
        {
            nextPosition = Stream_GetPosition(s);

            if (!rdp_read_share_control_header(s, &pduLength, &pduType, &pduSource))
                return -1;

            nextPosition += pduLength;

            rdp->settings->PduSource = pduSource;

            switch (pduType)
            {
            case PDU_TYPE_DATA:
                if (rdp_recv_data_pdu(rdp, s) < 0)
                {
                    DEBUG_WARN( "rdp_recv_data_pdu failed\n");
                    return -1;
                }
                break;

            case PDU_TYPE_DEACTIVATE_ALL:
                if (!rdp_recv_deactivate_all(rdp, s))
                    return -1;
                break;

            case PDU_TYPE_SERVER_REDIRECTION:
                return rdp_recv_enhanced_security_redirection_packet(rdp, s);
                break;

            default:
                DEBUG_WARN( "incorrect PDU type: 0x%04X\n", pduType);
                break;
            }

            Stream_SetPosition(s, nextPosition);
        }
    }
    else if (rdp->mcs->messageChannelId && channelId == rdp->mcs->messageChannelId)
    {
        return rdp_recv_message_channel_pdu(rdp, s);
    }
    else
    {
        if (!freerdp_channel_process(rdp->instance, s, channelId))
            return -1;
    }

    return 0;
}
Beispiel #3
0
static int rdp_recv_tpkt_pdu(rdpRdp* rdp, STREAM* s)
{
	UINT16 length;
	UINT16 pduType;
	UINT16 pduLength;
	UINT16 pduSource;
	UINT16 channelId;
	UINT16 securityFlags;
	BYTE* nextp;

	if (!rdp_read_header(rdp, s, &length, &channelId))
	{
		printf("Incorrect RDP header.\n");
		return -1;
	}

	if (rdp->settings->DisableEncryption)
	{
		if (!rdp_read_security_header(s, &securityFlags))
			return -1;

		if (securityFlags & (SEC_ENCRYPT | SEC_REDIRECTION_PKT))
		{
			if (!rdp_decrypt(rdp, s, length - 4, securityFlags))
			{
				printf("rdp_decrypt failed\n");
				return -1;
			}
		}

		if (securityFlags & SEC_REDIRECTION_PKT)
		{
			/*
			 * [MS-RDPBCGR] 2.2.13.2.1
			 *  - no share control header, nor the 2 byte pad
			 */
			s->p -= 2;
			rdp_recv_enhanced_security_redirection_packet(rdp, s);
			return -1;
		}
	}

	if (channelId != MCS_GLOBAL_CHANNEL_ID)
	{
		if (!freerdp_channel_process(rdp->instance, s, channelId))
			return -1;
	}
	else
	{
		while (stream_get_left(s) > 3)
		{
			stream_get_mark(s, nextp);

			if (!rdp_read_share_control_header(s, &pduLength, &pduType, &pduSource))
				return -1;

			nextp += pduLength;

			rdp->settings->PduSource = pduSource;

			switch (pduType)
			{
				case PDU_TYPE_DATA:
					if (rdp_recv_data_pdu(rdp, s) < 0)
					{
						printf("rdp_recv_data_pdu failed\n");
						return -1;
					}
					break;

				case PDU_TYPE_DEACTIVATE_ALL:
					if (!rdp_recv_deactivate_all(rdp, s))
						return -1;
					break;

				case PDU_TYPE_SERVER_REDIRECTION:
					if (!rdp_recv_enhanced_security_redirection_packet(rdp, s))
						return -1;
					break;

				default:
					printf("incorrect PDU type: 0x%04X\n", pduType);
					break;
			}
			stream_set_mark(s, nextp);
		}
	}

	return 0;
}
Beispiel #4
0
static boolean rdp_recv_tpkt_pdu(rdpRdp* rdp, STREAM* s)
{
	uint16 length;
	uint16 pduType;
	uint16 pduLength;
	uint16 pduSource;
	uint16 channelId;
	uint32 securityHeader;

	if (!rdp_read_header(rdp, s, &length, &channelId))
	{
		printf("Incorrect RDP header.\n");
		return false;
	}

	if (rdp->settings->encryption)
	{
		stream_read_uint32(s, securityHeader);
		if (securityHeader & SEC_SECURE_CHECKSUM)
		{
			printf("Error: TODO\n");
			return false;
		}
		if (securityHeader & SEC_ENCRYPT)
		{
			if (!rdp_decrypt(rdp, s, length - 4))
			{
				printf("rdp_decrypt failed\n");
				return false;
			}
		}
	}

	if (channelId != MCS_GLOBAL_CHANNEL_ID)
	{
		freerdp_channel_process(rdp->instance, s, channelId);
	}
	else
	{
		rdp_read_share_control_header(s, &pduLength, &pduType, &pduSource);

		rdp->settings->pdu_source = pduSource;

		switch (pduType)
		{
			case PDU_TYPE_DATA:
				rdp_recv_data_pdu(rdp, s);
				break;

			case PDU_TYPE_DEACTIVATE_ALL:
				if (!rdp_recv_deactivate_all(rdp, s))
					return false;
				break;

			case PDU_TYPE_SERVER_REDIRECTION:
				rdp_recv_enhanced_security_redirection_packet(rdp, s);
				break;

			default:
				printf("incorrect PDU type: 0x%04X\n", pduType);
				break;
		}
	}

	return true;
}
Beispiel #5
0
static tbool rdp_recv_tpkt_pdu(rdpRdp* rdp, STREAM* s)
{
	uint16 length;
	uint16 pduType;
	uint16 pduLength;
	uint16 pduSource;
	uint16 channelId;
	uint16 securityFlags;
	uint8* nextp;

	LLOGLN(10, ("rdp_recv_tpkt_pdu:"));
	if (!rdp_read_header(rdp, s, &length, &channelId))
	{
		LLOGLN(0, ("Incorrect RDP header."));
		return false;
	}
	LLOGLN(10, ("rdp_recv_tpkt_pdu: length %d", length));
	if (rdp->disconnect)
	{
		LLOGLN(0, ("rdp_recv_tpkt_pdu: disconnect"));
		return false;
	}

	if (rdp->settings->encryption)
	{
		rdp_read_security_header(s, &securityFlags);
		LLOGLN(10, ("rdp_recv_tpkt_pdu: securityFlags 0x%8.8x", securityFlags));
		if (securityFlags & (SEC_ENCRYPT | SEC_REDIRECTION_PKT))
		{
			if (!rdp_decrypt(rdp, s, length - 4, securityFlags))
			{
				LLOGLN(0, ("rdp_decrypt failed"));
				return false;
			}
		}
		if (securityFlags & SEC_REDIRECTION_PKT)
		{
			LLOGLN(0, ("rdp_recv_tpkt_pdu: got SEC_REDIRECTION_PKT securityFlags 0x%8.8x", securityFlags));
			/*
			 * [MS-RDPBCGR] 2.2.13.2.1
			 *  - no share control header, nor the 2 byte pad
			 */
			s->p -= 2;
			rdp_recv_enhanced_security_redirection_packet(rdp, s);
			return true;
		}
	}

	if (channelId != MCS_GLOBAL_CHANNEL_ID)
	{
		freerdp_channel_process(rdp->instance, s, channelId);
	}
	else
	{
		while (stream_get_left(s) > 3)
		{
			stream_get_mark(s, nextp);
			rdp_read_share_control_header(s, &pduLength, &pduType, &pduSource);
			nextp += pduLength;

			rdp->settings->pdu_source = pduSource;

			switch (pduType)
			{
				case PDU_TYPE_DATA:
					if (!rdp_recv_data_pdu(rdp, s))
					{
						LLOGLN(0, ("rdp_recv_data_pdu failed"));
						return false;
					}
					break;

				case PDU_TYPE_DEACTIVATE_ALL:
					if (!rdp_recv_deactivate_all(rdp, s))
						return false;
					break;

				case PDU_TYPE_SERVER_REDIRECTION:
					rdp_recv_enhanced_security_redirection_packet(rdp, s);
					break;

				default:
					LLOGLN(0, ("incorrect PDU type: 0x%04X", pduType));
					break;
			}
			stream_set_mark(s, nextp);
		}
	}

	return true;
}