🇰🇷 한글 설명
urwid 웹 디스플레이 백엔드가 암호학적으로 안전하지 않은 Mersenne Twister PRNG를 사용하여 세션 ID를 생성함으로써 발생합니다. 공격자는 관찰된 세션 ID를 통해 내부 상태를 재구성하여 미래의 세션 ID를 예측하거나, /tmp 디렉토리에 생성된 FIFO 파일을 통해 세션 토큰을 직접 탈취할 수 있습니다. 이를 통해 피해자의 터미널 화면을 읽거나 키 입력을 주입하여 OS 수준의 코드 실행 권한을 획득할 수 있습니다.
💡 쉬운 설명
웹 세션 번호를 만드는 방식이 너무 단순하여 해커가 다음에 나올 번호를 쉽게 맞출 수 있는 보안 결함입니다. 해커가 이 번호를 알아내면 사용자의 화면을 훔쳐보거나 사용자인 척 명령어를 입력해 컴퓨터를 조작할 수 있습니다.
🇺🇸 원문 (English)
The urwid web display backend (urwid/display/web.py) generates web session identifiers (urwid_id) in Screen.start() by concatenating two random.randrange(10**9) calls that use Python's Mersenne Twister PRNG, which is not cryptographically secure. Each call consumes approximately 30 bits of PRNG state, and the Mersenne Twister internal state is approximately 19,937 bits, so an attacker who observes approximately 334 session IDs (for example via the X-Urwid-ID HTTP response header) can fully reconstruct the internal state and predict all past and future session IDs (Path B). The same identifier is also used as the filename of a FIFO created in the world-listable /tmp directory (for example /tmp/urwid375487765176907690.in), so any local user on the host can list /tmp to enumerate active session tokens directly (Path A). With a valid session ID, an attacker can read the victim's terminal screen via the polling endpoint, inject keystrokes into the victim's session (yielding OS-level code execution with the session owner's privileges if the session runs a shell), and inject exit sequences or flood the FIFO to terminate or crash the session. A prior Bandit S311 warning on this usage was suppressed with # noqa: S311 rather than fixed
📍 영향받는 시스템
urwid web display backend (urwid/display/web.py 사용 버전)
⚔️ 공격 벡터
취약한 PRNG를 이용한 세션 ID 예측 또는 /tmp 디렉토리 내 FIFO 파일 목록을 통한 세션 토큰 탈취
🛡️ 대응 방법
Python의 secrets 모듈과 같은 암호학적으로 안전한 난수 생성기를 사용하도록 코드를 수정하고, 세션 ID를 안전한 경로에 저장해야 합니다.
🔧 검증 코드
명령어 결과에 random.randrange가 포함되어 있다면 취약한 난수 생성 방식을 사용 중인 것입니다.
grep -r "random.randrange" /path/to/urwid/display/web.py