Closed Halcy0nic closed 1 year ago
Hello.
I think Receive
have same bug udpsocket.hpp#L143
` while ((messageLength = recv(udpSocket->sock, tempBuffer, BUFFER_SIZE, 0)) != -1) { tempBuffer[messageLength] = '\0'; // [off-by-one]
... `
About this, you are right: https://github.com/eminfedar/async-sockets-cpp/blob/78641cfde398d2cd71649f6911ee1bf4953498c0/async-sockets/include/udpsocket.hpp#L143
I pushed a commit and increased the buffers' length plus 1: https://github.com/eminfedar/async-sockets-cpp/blob/78641cfde398d2cd71649f6911ee1bf4953498c0/async-sockets/include/tcpsocket.hpp#L99
so this is ok now: tempBuffer[messageLength] = '\0';
Thanks!
(actually you guys can create a PR for these kind of fixes so you can a "contributor" on this repo)
If the issue is solved, you can close this issue, if not, please comment here again so we can fix.
@eminfedar Thanks for the update. I'll make sure to post a PR for any future issues: Commit 78641cfde398d2cd71649f6911ee1bf4953498c0 resolves this issue.
About this, you are right:
I pushed a commit and increased the buffers' length plus 1:
so this is ok now:
tempBuffer[messageLength] = '\0';
Thanks!
(actually you guys can create a PR for these kind of fixes so you can a "contributor" on this repo)
If the issue is solved, you can close this issue, if not, please comment here again so we can fix.
Can i request a CVE for oob write?
@sploitem
This issue was assigned CVE-2023-40296
Hi!
It appears that async-sockets-cpp (through 0.3.1) contains a remote buffer overflow vulnerability in static void ReceiveFrom(UDPSocket* udpSocket) at udpsocket.hpp, around lines 160-167. The buffer overflow affects all corresponding UDP servers. The remote buffer overflow can be triggered by connecting to a UDP socket and sending a large buffer of bytes (similar to it's TCP counterpart ).
https://github.com/eminfedar/async-sockets-cpp/blob/d66588d3bc6fe26f27ab2093f8105191723a983d/async-sockets/include/udpsocket.hpp#L160-L167
To confirm the issue, I first compiled the example UDP server from the async-sockets-cpp/examples folder with debug symbols and address sanitizer:
Makefile
Compilation
Once the server was compiled, I executed the udp-server on port 8888:
I then created a python3 script to connect to the udp-server and send a large packet with around 4096 (or larger) bytes of content:
Executing the above python3 script will result in the server/thread crashing and producing the following detailed output from address sanitizer showing the location of the stack buffer overflow:
ASAN Output
Similar to https://github.com/eminfedar/async-sockets-cpp/issues/31#issue-1812776421, a possible fix could be to check the size of messageLength before copying data to the buffer.
Thanks!