CUPS Weak Session Cookie Generation

2018.12.13
Credit: Jann Horn
Risk: Medium
Local: Yes
Remote: No
CWE: N/A

CUPS: session cookies are generated with srandom(time(NULL)) and random() on Linux CVE-2018-4700 CUPS generates session cookies as follows in cgi_set_sid(): ============ if ((remote_addr = getenv("REMOTE_ADDR")) == NULL) remote_addr = "REMOTE_ADDR"; if ((server_name = getenv("SERVER_NAME")) == NULL) server_name = "SERVER_NAME"; if ((server_port = getenv("SERVER_PORT")) == NULL) server_port = "SERVER_PORT"; CUPS_SRAND(time(NULL)); snprintf(buffer, sizeof(buffer), "%s:%s:%s:%02X%02X%02X%02X%02X%02X%02X%02X", remote_addr, server_name, server_port, (unsigned)CUPS_RAND() & 255, (unsigned)CUPS_RAND() & 255, (unsigned)CUPS_RAND() & 255, (unsigned)CUPS_RAND() & 255, (unsigned)CUPS_RAND() & 255, (unsigned)CUPS_RAND() & 255, (unsigned)CUPS_RAND() & 255, (unsigned)CUPS_RAND() & 255); cupsHashData("md5", (unsigned char *)buffer, strlen(buffer), sum, sizeof(sum)); cgiSetCookie(CUPS_SID, cupsHashString(sum, sizeof(sum), sid, sizeof(sid)), "/", NULL, 0, 0); ============ Note the CUPS_SRAND(time(NULL)). CUPS_SRAND() and CUPS_RAND() have four possible definitions, depending on the environment: ============ #ifdef HAVE_ARC4RANDOM # define CUPS_RAND() arc4random() # define CUPS_SRAND(v) #elif defined(HAVE_RANDOM) # define CUPS_RAND() random() # define CUPS_SRAND(v) srandom(v) #elif defined(HAVE_LRAND48) # define CUPS_RAND() lrand48() # define CUPS_SRAND(v) srand48(v) #else # define CUPS_RAND() rand() # define CUPS_SRAND(v) srand(v) #endif /* HAVE_ARC4RANDOM */ ============ On a typical Linux system, HAVE_ARC4RANDOM is not defined, but HAVE_RANDOM is defined; so CUPS_RAND() is random(), and CUPS_SRAND() is srandom(). This means that the session cookie is extremely predictable, effectively breaking the CSRF protection of the CUPS web interface. Luckily, this isn't very useful unless the user has already authenticated to CUPS; and because CUPS uses HTTP basic auth for authentication, an attacker can't forcibly sign the user in (e.g. Chrome forbids it completely, Firefox shows a confirmation prompt). This bug is subject to a 90 day disclosure deadline. After 90 days elapse or a patch has been made broadly available (whichever is earlier), the bug report will become visible to the public. Found by: jannh


Vote for this issue:
50%
50%


 

Thanks for you vote!


 

Thanks for you comment!
Your message is in quarantine 48 hours.

Comment it here.


(*) - required fields.  
{{ x.nick }} | Date: {{ x.ux * 1000 | date:'yyyy-MM-dd' }} {{ x.ux * 1000 | date:'HH:mm' }} CET+1
{{ x.comment }}

Copyright 2024, cxsecurity.com

 

Back to Top