Skip to content
Info disclosure Disclosed report Advanced CVE-2021-22925CVE-2021-22898

CVE-2021-22925: TELNET stack contents disclosure again

The fix for a previous TELNET stack contents disclosure in curl was incomplete: when a NEW_ENV option had a short variable name and a long value, the length counter was updated incorrectly, leaving uninitialised stack memory in a buffer that could be sent to a TELNET server. An attacker controlling a TELNET server could receive that leaked memory.

thoger Follow

Originally disclosed on HackerOne

  • Triaged in 27 hours
  • Fixed in 40 days
  • Paid in 24 days
  • Disclosed after 40 days

Summary:

CVE-2021-22898: TELNET stack contents disclosure (#1176461) issue was recently reported for curl and it was addressed in curl 7.77.0:

https://curl.se/docs/CVE-2021-22898.html https://github.com/curl/curl/commit/39ce47f219b09c380b81f89fe54ac586c8db6bde https://hackerone.com/reports/1176461

However, the fix applied is not correct and does not completely address the issue. It helps in cases when long environment variable name is used ('a'*256 + ',b'), but not when the name is short and only the value is long ('a,' + 'b'*256, which is the example mentioned in the curl project advisory).

Steps To Reproduce:

Follow the steps form #1176461, only use NEW_ENV option with short name and long value, such as:

$ curl telnet://127.0.0.1:23 -t NEW_ENV=`python -c "print('a,' + 'b'*256)"`

Supporting Material/References:

When parsing NEW_ENV option value with short name and long value, sscanf() returns 2, as it writes to both varname and varval, even though the data in varval is truncated. Hence such variable is not skipped and is added to the temp[] buffer. However, the len counter which tracks the amount of data that was already written to temp[] is not updated based on the data written to the buffer in the msnprintf()call, but rather based on the length of the original unparsed data that is stored in tmplen. The relevant code is here:

https://github.com/curl/curl/blob/curl-7_77_0/lib/telnet.c#L926-L929

When value stored in varval is truncated, len is increased too much and a chunk of uninitialized memory is created in temp[]. The len should only be incremented by strlen(varname) + strlen(varval) + 2.

I wonder if the original fix should be preserved or re-worked. In addition to not fixing the info leak problem properly, it also causes certain valid option values to be ignored and not sent to a server any more. Rejected values are of the forms NEW_ENV=a or NEW_ENV=a,. At least the second one seems like an obviously valid way to set variable a to an empty string. RFC 1572 defines that environment variable can be sent with empty value and hence NEW_ENV=a, should remain supported. It also defines that variable can be sent with no value, making NEW_ENV=a a valid option as well. Note that curl prior to 7.77.0 actually did handle NEW_ENV=a that way, but it looks more like an unintended side effect of how len was incremented by tmplen, as the empty value part was written to temp[] and only subsequently overwritten. As the telnet protocol support in curl is not likely to be used widely these days, possibly only to interact with some legacy systems, it seems reasonable to prefer a fix that changes behaviour as little as possible.

Impact

Leak of an uninitialized stack memory.

Report #1176461 and the matching curl advisory provide some estimates on how much data can be leaked. I believe the amount of leaked data is smaller and is less than a half of the temp[] size. The reason for that is in the check_telnet_options() where option arguments are truncated to 255 characters, and at least half of that must part of the defined variable name or value.

https://github.com/curl/curl/blob/curl-7_77_0/lib/telnet.c#L799-L800

The original report as published on HackerOne, by thoger. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The length counter was incremented by the original unparsed data length rather than by the actual number of bytes written to the buffer after truncation, leaving a gap of uninitialised memory.

Impact

An attacker controlling a TELNET server could receive a portion of uninitialised stack memory from the client, potentially disclosing sensitive data; the amount leaked is estimated to be less than half the buffer size.

What the attacker needed

Attacker controls a TELNET server; victim uses curl with TELNET and NEW_ENV

The fix

The length counter should be incremented only by the actual lengths of the parsed variable name and value plus two, and the previous fix should be reworked to avoid rejecting valid empty-value options.

How it was found

  1. Run curl with the TELNET protocol against a server.
  2. Supply a NEW_ENV option with a short variable name and a long value.
  3. The server receives data that includes uninitialised stack memory.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When a program prepares data to send over the network, it sometimes uses a temporary buffer. If the program miscounts how much data it actually put in that buffer, the leftover space may still contain old memory contents. Here, a malformed TELNET option caused that leftover memory to be sent to the server, potentially revealing sensitive information.

What is Info disclosure?

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.