Summary
An integer overflow in the "v2g_incoming_v2gtp" function in the v2g_server.cpp implementation can allow a remote attacker to overflow the process' heap
Details
In the V2G server implemented in "modules\EvseV2G\v2g_server.cpp" the "v2g_incoming_v2gtp" function appears to contain an integer overflow after reading the V2GTP 4-bytes header:
rv = read_v2gtpHeader(conn->buffer, &conn->payload_len);
if (rv == -1) {
dlog(DLOG_LEVEL_ERROR, "Invalid v2gtp header");
return -1;
}
if (conn->payload_len + V2GTP_HEADER_LENGTH > DEFAULT_BUFFER_SIZE) {
dlog(DLOG_LEVEL_ERROR, "payload too long: have %d, would need %d", DEFAULT_BUFFER_SIZE,
conn->payload_len + V2GTP_HEADER_LENGTH);
/* we have no way to flush/discard remaining unread data from the socket without reading it in chunks,
* but this opens the chance to bind us in a "endless" read loop; so to protect us, simply close the connection
*/
return -1;
}
/* read request */
rv = connection_read(conn, &conn->buffer[V2GTP_HEADER_LENGTH], conn->payload_len);
Providing any value between [0xFFFF FFF8, 0xFFFF FFFF] in these 4 bytes as part of the V2GTP header will cause the check in line 165 to pass.
And since that large length is later passed to "connection_read", the server will accept any number of bytes to the heap buffer "con->buffer",
thereby overflowing the heap.
PoC
This can reproduced when the EvseV2G module is running and sending the following nc
command will trigger the bug (IPv6 address may change of course)
$ python3 -c "import sys; sys.stdout.buffer.write(b'\x01\xFE\x80\x01\xFF\xFF\xFF\xFF' + b'A'*0x3000)" | nc -6 -v fe80::215:5dff:fe2e:ea25%2 61341
Impact
Remote code execution is definitely possible from overwriting the heap in a standard Linux process, exploitation feasibility is still being investigated however an immediate crash can be observed by triggering the vulnerability with the nc
command specified above.
Because of that, "Attack Complexity" is marked as "High" for the CVSS 3.1 score
Patch
This vulnerability has been fixed with f73620c which is included in the releases https://github.com/EVerest/everest-core/releases/tag/2024.3.1 and https://github.com/EVerest/everest-core/releases/tag/2024.6.0 .
Credits
Shaked Delarea of Argus Cyber Security
Summary
An integer overflow in the "v2g_incoming_v2gtp" function in the v2g_server.cpp implementation can allow a remote attacker to overflow the process' heap
Details
In the V2G server implemented in "modules\EvseV2G\v2g_server.cpp" the "v2g_incoming_v2gtp" function appears to contain an integer overflow after reading the V2GTP 4-bytes header:
Providing any value between [0xFFFF FFF8, 0xFFFF FFFF] in these 4 bytes as part of the V2GTP header will cause the check in line 165 to pass.
And since that large length is later passed to "connection_read", the server will accept any number of bytes to the heap buffer "con->buffer",
thereby overflowing the heap.
PoC
This can reproduced when the EvseV2G module is running and sending the following
nc
command will trigger the bug (IPv6 address may change of course)$ python3 -c "import sys; sys.stdout.buffer.write(b'\x01\xFE\x80\x01\xFF\xFF\xFF\xFF' + b'A'*0x3000)" | nc -6 -v fe80::215:5dff:fe2e:ea25%2 61341
Impact
Remote code execution is definitely possible from overwriting the heap in a standard Linux process, exploitation feasibility is still being investigated however an immediate crash can be observed by triggering the vulnerability with the
nc
command specified above.Because of that, "Attack Complexity" is marked as "High" for the CVSS 3.1 score
Patch
This vulnerability has been fixed with f73620c which is included in the releases https://github.com/EVerest/everest-core/releases/tag/2024.3.1 and https://github.com/EVerest/everest-core/releases/tag/2024.6.0 .
Credits
Shaked Delarea of Argus Cyber Security