Mercurial > dropbear
comparison common-session.c @ 1715:3974f087d9c0
Disallow leading lines before the ident for server (#102)
Per RFC4253 4.2 clients must be able to process other lines of data
before the version string, server behavior is not defined neither
with MUST/SHOULD nor with MAY.
If server process up to 50 lines too - it may cause too long hanging
session with invalid/evil client that consume host resources and
potentially may lead to DDoS on poor embedded boxes.
Let's require first line from client to be version string and fail
early if it's not - matches both RFC and real OpenSSH behavior.
author | Vladislav Grishenko <themiron@users.noreply.github.com> |
---|---|
date | Mon, 15 Jun 2020 18:22:18 +0500 |
parents | cc0fc5131c5c |
children | 3b9b427925a0 |
comparison
equal
deleted
inserted
replaced
1714:c0f12eaf95c9 | 1715:3974f087d9c0 |
---|---|
368 /* max length of 255 chars */ | 368 /* max length of 255 chars */ |
369 char linebuf[256]; | 369 char linebuf[256]; |
370 int len = 0; | 370 int len = 0; |
371 char done = 0; | 371 char done = 0; |
372 int i; | 372 int i; |
373 /* If they send more than 50 lines, something is wrong */ | 373 |
374 for (i = 0; i < 50; i++) { | 374 /* Servers may send other lines of data before sending the |
375 * version string, client must be able to process such lines. | |
376 * If they send more than 50 lines, something is wrong */ | |
377 for (i = IS_DROPBEAR_CLIENT ? 50 : 1; i > 0; i--) { | |
375 len = ident_readln(ses.sock_in, linebuf, sizeof(linebuf)); | 378 len = ident_readln(ses.sock_in, linebuf, sizeof(linebuf)); |
376 | 379 |
377 if (len < 0 && errno != EINTR) { | 380 if (len < 0 && errno != EINTR) { |
378 /* It failed */ | 381 /* It failed */ |
379 break; | 382 break; |