ssh: fixing unsigned overflow leading to heap overflow
cf GHSL-2020-051
This commit is contained in:
+33
-31
@@ -95,7 +95,7 @@ static void ndpi_int_ssh_add_connection(struct ndpi_detection_module_struct
|
|||||||
|
|
||||||
static u_int16_t concat_hash_string(struct ndpi_packet_struct *packet,
|
static u_int16_t concat_hash_string(struct ndpi_packet_struct *packet,
|
||||||
char *buf, u_int8_t client_hash) {
|
char *buf, u_int8_t client_hash) {
|
||||||
u_int16_t offset = 22, buf_out_len = 0;
|
u_int32_t offset = 22, buf_out_len = 0;
|
||||||
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
u_int32_t len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
u_int32_t len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
||||||
@@ -114,6 +114,8 @@ static u_int16_t concat_hash_string(struct ndpi_packet_struct *packet,
|
|||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
/* ssh.server_host_key_algorithms [None] */
|
/* ssh.server_host_key_algorithms [None] */
|
||||||
len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
||||||
|
if (len > UINT32_MAX - 4 - offset)
|
||||||
|
goto invalid_payload;
|
||||||
offset += 4 + len;
|
offset += 4 + len;
|
||||||
|
|
||||||
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
||||||
@@ -121,106 +123,106 @@ static u_int16_t concat_hash_string(struct ndpi_packet_struct *packet,
|
|||||||
/* ssh.encryption_algorithms_client_to_server [C] */
|
/* ssh.encryption_algorithms_client_to_server [C] */
|
||||||
len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
||||||
|
|
||||||
|
offset += 4;
|
||||||
if(client_hash) {
|
if(client_hash) {
|
||||||
offset += 4;
|
|
||||||
|
|
||||||
if((offset >= packet->payload_packet_len) || (len >= packet->payload_packet_len-offset-1))
|
if((offset >= packet->payload_packet_len) || (len >= packet->payload_packet_len-offset-1))
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
|
|
||||||
strncpy(&buf[buf_out_len], (const char *)&packet->payload[offset], len);
|
strncpy(&buf[buf_out_len], (const char *)&packet->payload[offset], len);
|
||||||
buf_out_len += len;
|
buf_out_len += len;
|
||||||
buf[buf_out_len++] = ';';
|
buf[buf_out_len++] = ';';
|
||||||
offset += len;
|
}
|
||||||
} else
|
if (len > UINT32_MAX - offset)
|
||||||
offset += 4 + len;
|
goto invalid_payload;
|
||||||
|
offset += len;
|
||||||
|
|
||||||
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
/* ssh.encryption_algorithms_server_to_client [S] */
|
/* ssh.encryption_algorithms_server_to_client [S] */
|
||||||
len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
||||||
|
|
||||||
|
offset += 4;
|
||||||
if(!client_hash) {
|
if(!client_hash) {
|
||||||
offset += 4;
|
|
||||||
|
|
||||||
if((offset >= packet->payload_packet_len) || (len >= packet->payload_packet_len-offset-1))
|
if((offset >= packet->payload_packet_len) || (len >= packet->payload_packet_len-offset-1))
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
|
|
||||||
strncpy(&buf[buf_out_len], (const char *)&packet->payload[offset], len);
|
strncpy(&buf[buf_out_len], (const char *)&packet->payload[offset], len);
|
||||||
buf_out_len += len;
|
buf_out_len += len;
|
||||||
buf[buf_out_len++] = ';';
|
buf[buf_out_len++] = ';';
|
||||||
offset += len;
|
}
|
||||||
} else
|
if (len > UINT32_MAX - offset)
|
||||||
offset += 4 + len;
|
goto invalid_payload;
|
||||||
|
offset += len;
|
||||||
|
|
||||||
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
/* ssh.mac_algorithms_client_to_server [C] */
|
/* ssh.mac_algorithms_client_to_server [C] */
|
||||||
len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
||||||
|
|
||||||
|
offset += 4;
|
||||||
if(client_hash) {
|
if(client_hash) {
|
||||||
offset += 4;
|
|
||||||
|
|
||||||
if((offset >= packet->payload_packet_len) || (len >= packet->payload_packet_len-offset-1))
|
if((offset >= packet->payload_packet_len) || (len >= packet->payload_packet_len-offset-1))
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
|
|
||||||
strncpy(&buf[buf_out_len], (const char *)&packet->payload[offset], len);
|
strncpy(&buf[buf_out_len], (const char *)&packet->payload[offset], len);
|
||||||
buf_out_len += len;
|
buf_out_len += len;
|
||||||
buf[buf_out_len++] = ';';
|
buf[buf_out_len++] = ';';
|
||||||
offset += len;
|
}
|
||||||
} else
|
if (len > UINT32_MAX - offset)
|
||||||
offset += 4 + len;
|
goto invalid_payload;
|
||||||
|
offset += len;
|
||||||
|
|
||||||
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
/* ssh.mac_algorithms_server_to_client [S] */
|
/* ssh.mac_algorithms_server_to_client [S] */
|
||||||
len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
||||||
|
|
||||||
|
offset += 4;
|
||||||
if(!client_hash) {
|
if(!client_hash) {
|
||||||
offset += 4;
|
|
||||||
|
|
||||||
if((offset >= packet->payload_packet_len) || (len >= packet->payload_packet_len-offset-1))
|
if((offset >= packet->payload_packet_len) || (len >= packet->payload_packet_len-offset-1))
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
|
|
||||||
strncpy(&buf[buf_out_len], (const char *)&packet->payload[offset], len);
|
strncpy(&buf[buf_out_len], (const char *)&packet->payload[offset], len);
|
||||||
buf_out_len += len;
|
buf_out_len += len;
|
||||||
buf[buf_out_len++] = ';';
|
buf[buf_out_len++] = ';';
|
||||||
offset += len;
|
}
|
||||||
} else
|
if (len > UINT32_MAX - offset)
|
||||||
offset += 4 + len;
|
goto invalid_payload;
|
||||||
|
offset += len;
|
||||||
|
|
||||||
/* ssh.compression_algorithms_client_to_server [C] */
|
/* ssh.compression_algorithms_client_to_server [C] */
|
||||||
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
||||||
|
|
||||||
|
offset += 4;
|
||||||
if(client_hash) {
|
if(client_hash) {
|
||||||
offset += 4;
|
|
||||||
|
|
||||||
if((offset >= packet->payload_packet_len) || (len >= packet->payload_packet_len-offset-1))
|
if((offset >= packet->payload_packet_len) || (len >= packet->payload_packet_len-offset-1))
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
|
|
||||||
strncpy(&buf[buf_out_len], (const char *)&packet->payload[offset], len);
|
strncpy(&buf[buf_out_len], (const char *)&packet->payload[offset], len);
|
||||||
buf_out_len += len;
|
buf_out_len += len;
|
||||||
offset += len;
|
}
|
||||||
} else
|
if (len > UINT32_MAX - offset)
|
||||||
offset += 4 + len;
|
goto invalid_payload;
|
||||||
|
offset += len;
|
||||||
|
|
||||||
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
/* ssh.compression_algorithms_server_to_client [S] */
|
/* ssh.compression_algorithms_server_to_client [S] */
|
||||||
len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
||||||
|
|
||||||
|
offset += 4;
|
||||||
if(!client_hash) {
|
if(!client_hash) {
|
||||||
offset += 4;
|
|
||||||
|
|
||||||
if((offset >= packet->payload_packet_len) || (len >= packet->payload_packet_len-offset-1))
|
if((offset >= packet->payload_packet_len) || (len >= packet->payload_packet_len-offset-1))
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
|
|
||||||
strncpy(&buf[buf_out_len], (const char *)&packet->payload[offset], len);
|
strncpy(&buf[buf_out_len], (const char *)&packet->payload[offset], len);
|
||||||
buf_out_len += len;
|
buf_out_len += len;
|
||||||
offset += len;
|
}
|
||||||
} else
|
if (len > UINT32_MAX - offset)
|
||||||
offset += 4 + len;
|
goto invalid_payload;
|
||||||
|
offset += len;
|
||||||
|
|
||||||
/* ssh.languages_client_to_server [None] */
|
/* ssh.languages_client_to_server [None] */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user