기본 콘텐츠로 건너뛰기

Linux-BlueBorne-vulnerabilities

Linux BlueBorne vulnerabilities

리눅스 블루투스 스택(BlueZ)에서 두 개의 보안 취약사항이 발견되었다.

이 취약점들은 2017년 9월 12일자로 공개 되어BlueBorne이라는 이름으로 불리고 있으며, 해당 취약점을 보유하고 있는 벤더 사 제품이 존재하여 총 8개의 취약점으로 분류되어졌다.

1) CVE-2017-1000250

이 취약점은 bluetoothd 프로세스에 존재하며, SDP server 요청을 처리하는 과정에서 나타난다. service_search_attr_req (src/sdpd-request.c) 함수에서 sdp 검색 요청 속성을 처리할 때 정보를 유출한다. 이로 인해 희생자 단말 사용자와 상호작용 없이, 어떤 사전의 인증 없이(페어링), 스택의 Service discovery protocol (SDP) server를 엑세스할 수 있다. 이 취약점은 bluetooth 프로세스의 힙으로 부터 정보 유출을 유도할 수 있으며, 여기에는 블루투스 암호 키나 다른 가치있는 데이터가 포함된다.

Simple Service Discovery Protocol
SSDP(Simple Service Discovery Protocol)은 네트워크 서비스나 정보를 찾기 위해서 사용하는 네트워크 프로토콜이다. SSDP를 이용하면, DHCP나 DNS와 같은 네트워크 서버 혹은 정적인 호스트 설정 없이 이런 일들을 수행할 수 있다.
SSDP는 일반 거주지와 소규모 사무 환경에서 UPnP(Universal Plug and Play)를 위한 기본적인 프로토콜로 이미 널리 사용하고 있다. 1999년 MS와 HP가 IETF에 드래프트 했다. IETF제안이 만료된 이후 SSDP는 UPnP 표준에 포함됐다.
이 취약점의 세부사항을 살펴보자.
출처: joinc - SSDP

이 취약점의 세부사항을 살펴보자.
- SDP 서버 검색 속성 핸들러(service_search_attr_req, under src/sdpd-request.c)의 흐름:

...
} else {
/* 연속된 상태 시 캐시에서 가져옴 */
sdp_buf_t *pCache = sdp_get_cached_rsp(cstate);
if (pCache) {
uint16_t sent = MIN(max, pCache->data_size - 
    cstate->cStateValue.maxBytesSent);
pResponse = pCache->data;
memcpy(buf->data,
    pResponse + cstate->cStateValue.maxBytesSent,
    sent);
buf->data_size += sent;
cstate->cStateValue.maxBytesSent += sent;
if (cstate->cStateValue.maxBytesSent == pCache->data_size)
cstate_size = sdp_set_cstate_pdu(buf, NULL);
else
cstate_size = sdp_set_cstate_pdu(buf, cstate);
} else {
status = SDP_INVALID_CSTATE;
SDPDBG("Non-null continuation state, but null cache buffer");
}
}
...

긴 응답이 특정 검색 속성 요청으로 반환되면 추가 fragment를 수신할 수 있도록 연속 상태가 반환되며, 최종 상태를 포함하여 추가 요청이 전송된다. 하지만 추가 요청 fragment를 수신하는 cstate는 범위 검증이 제대로 이루어지지 않았으므로 응답 버퍼 범위(pResponse)의 유효성을 벗어나 읽기를 시도하고 Heap의 정보를 유출될 수 있다.

9월 13일 해당 취약점의 조치가 이루어졌다.

@@ -917,7 +917,7 @@ static int service_search_attr_req(sdp_req_t *req, sdp_buf_t *buf)
    } else {
        /* continuation State exists -> get from cache */
        sdp_buf_t *pCache = sdp_get_cached_rsp(cstate);
-       if (pCache) {
+       if (pCache && cstate->cStateValue.maxBytesSent < pCache->data_size) {
            uint16_t sent = MIN(max, pCache->data_size - cstate->cStateValue.maxBytesSent);
            pResponse = pCache->data;
            memcpy(buf->data, pResponse + cstate->cStateValue.maxBytesSent, sent);

2) CVE-2017-1000251

이 취약점은 블루투스의 L2CAP(net/bluetooth/l2cap_core.c)의 커널 구현에서 RCE 취약점이다.

l2cap_config_rsp 흐름:

...
     case L2CAP_CONF_PENDING:
         set_bit(CONF_REM_CONF_PEND, &chan->conf_state);
         if (test_bit(CONF_LOC_CONF_PEND, &chan->conf_state)) {
             char buf[64];
             len = l2cap_parse_conf_rsp(chan, rsp->data, len,
                            buf, &result);
...

l2cap_parse_conf_rsp 함수는 configuration 응답 요소 (rsp->data)를 해석하고 검증 후 복사하여 출력 버퍼(buf)에 보낸다. 이 함수는 출력 버퍼의 최대 길이를 받지 못할 시 l2cap_config_rsp의 스택에 할당된다. 그래서 configuration 응답 요소에 큰 숫자를 포함하여 configuration 응답을 보내면,(동일한 유형을 여러 번 반복할 수 있다) 출력 버퍼(buf)에서 스택 오버플로우가 야기될 수 있다.
스택 오버플로우 조작 전 case (L2CAP_CONF_PENDING)에 도달하기 위해 EFS element와 stype에 L2CAP_SERV_NOTRAFIC를 설정이 필요하다.

패치된 커널 소스이다.

@@ -58,7 +58,7 @@ static struct sk_buff *l2cap_build_cmd(struct l2cap_conn *conn,
                       u8 code, u8 ident, u16 dlen, void *data);
 static void l2cap_send_cmd(struct l2cap_conn *conn, u8 ident, u8 code, u16 len,
               void *data);
-static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data);
+static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data, size_t data_size);
 static void l2cap_send_disconn_req(struct l2cap_chan *chan, int err);

 static void l2cap_tx(struct l2cap_chan *chan, struct l2cap_ctrl *control,
@@ -1473,7 +1473,7 @@ static void l2cap_conn_start(struct l2cap_conn *conn)

            set_bit(CONF_REQ_SENT, &chan->conf_state);
            l2cap_send_cmd(conn, l2cap_get_ident(conn), L2CAP_CONF_REQ,
-                      l2cap_build_conf_req(chan, buf), buf);
+                      l2cap_build_conf_req(chan, buf, sizeof(buf)), buf);
            chan->num_conf_req++;
        }

@@ -2987,12 +2987,15 @@ static inline int l2cap_get_conf_opt(void **ptr, int *type, int *olen,
    return len;
 }

-static void l2cap_add_conf_opt(void **ptr, u8 type, u8 len, unsigned long val)
+static void l2cap_add_conf_opt(void **ptr, u8 type, u8 len, unsigned long val, size_t size)
 {
    struct l2cap_conf_opt *opt = *ptr;

    BT_DBG("type 0x%2.2x len %u val 0x%lx", type, len, val);

+   if (size < L2CAP_CONF_OPT_SIZE + len)
+       return;
+
    opt->type = type;
    opt->len  = len;

@@ -3017,7 +3020,7 @@ static void l2cap_add_conf_opt(void **ptr, u8 type, u8 len, unsigned long val)
    *ptr += L2CAP_CONF_OPT_SIZE + len;
 }

-static void l2cap_add_opt_efs(void **ptr, struct l2cap_chan *chan)
+static void l2cap_add_opt_efs(void **ptr, struct l2cap_chan *chan, size_t size)
 {
    struct l2cap_conf_efs efs;

@@ -3045,7 +3048,7 @@ static void l2cap_add_opt_efs(void **ptr, struct l2cap_chan *chan)
    }

    l2cap_add_conf_opt(ptr, L2CAP_CONF_EFS, sizeof(efs),
-              (unsigned long) &efs);
+              (unsigned long) &efs, size);
 }

 static void l2cap_ack_timeout(struct work_struct *work)
@@ -3191,11 +3194,12 @@ static inline void l2cap_txwin_setup(struct l2cap_chan *chan)
    chan->ack_win = chan->tx_win;
 }

-static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data)
+static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data, size_t data_size)
 {
    struct l2cap_conf_req *req = data;
    struct l2cap_conf_rfc rfc = { .mode = chan->mode };
    void *ptr = req->data;
+   void *endptr = data + data_size;
    u16 size;

    BT_DBG("chan %p", chan);
@@ -3220,7 +3224,7 @@ static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data)

 done:
    if (chan->imtu != L2CAP_DEFAULT_MTU)
-       l2cap_add_conf_opt(&ptr, L2CAP_CONF_MTU, 2, chan->imtu);
+       l2cap_add_conf_opt(&ptr, L2CAP_CONF_MTU, 2, chan->imtu, endptr - ptr);

    switch (chan->mode) {
    case L2CAP_MODE_BASIC:
@@ -3239,7 +3243,7 @@ done:
        rfc.max_pdu_size    = 0;

        l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC, sizeof(rfc),
-                  (unsigned long) &rfc);
+                  (unsigned long) &rfc, endptr - ptr);
        break;

    case L2CAP_MODE_ERTM:
@@ -3259,21 +3263,21 @@ done:
                       L2CAP_DEFAULT_TX_WINDOW);

        l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC, sizeof(rfc),
-                  (unsigned long) &rfc);
+                  (unsigned long) &rfc, endptr - ptr);

        if (test_bit(FLAG_EFS_ENABLE, &chan->flags))
-           l2cap_add_opt_efs(&ptr, chan);
+           l2cap_add_opt_efs(&ptr, chan, endptr - ptr);

        if (test_bit(FLAG_EXT_CTRL, &chan->flags))
            l2cap_add_conf_opt(&ptr, L2CAP_CONF_EWS, 2,
-                      chan->tx_win);
+                      chan->tx_win, endptr - ptr);

        if (chan->conn->feat_mask & L2CAP_FEAT_FCS)
            if (chan->fcs == L2CAP_FCS_NONE ||
                test_bit(CONF_RECV_NO_FCS, &chan->conf_state)) {
                chan->fcs = L2CAP_FCS_NONE;
                l2cap_add_conf_opt(&ptr, L2CAP_CONF_FCS, 1,
-                          chan->fcs);
+                          chan->fcs, endptr - ptr);
            }
        break;

@@ -3291,17 +3295,17 @@ done:
        rfc.max_pdu_size = cpu_to_le16(size);

        l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC, sizeof(rfc),
-                  (unsigned long) &rfc);
+                  (unsigned long) &rfc, endptr - ptr);

        if (test_bit(FLAG_EFS_ENABLE, &chan->flags))
-           l2cap_add_opt_efs(&ptr, chan);
+           l2cap_add_opt_efs(&ptr, chan, endptr - ptr);

        if (chan->conn->feat_mask & L2CAP_FEAT_FCS)
            if (chan->fcs == L2CAP_FCS_NONE ||
                test_bit(CONF_RECV_NO_FCS, &chan->conf_state)) {
                chan->fcs = L2CAP_FCS_NONE;
                l2cap_add_conf_opt(&ptr, L2CAP_CONF_FCS, 1,
-                          chan->fcs);
+                          chan->fcs, endptr - ptr);
            }
        break;
    }
@@ -3312,10 +3316,11 @@ done:
    return ptr - data;
 }

-static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data)
+static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data, size_t data_size)
 {
    struct l2cap_conf_rsp *rsp = data;
    void *ptr = rsp->data;
+   void *endptr = data + data_size;
    void *req = chan->conf_req;
    int len = chan->conf_len;
    int type, hint, olen;
@@ -3417,7 +3422,7 @@ done:
            return -ECONNREFUSED;

        l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC, sizeof(rfc),
-                  (unsigned long) &rfc);
+                  (unsigned long) &rfc, endptr - ptr);
    }

    if (result == L2CAP_CONF_SUCCESS) {
@@ -3430,7 +3435,7 @@ done:
            chan->omtu = mtu;
            set_bit(CONF_MTU_DONE, &chan->conf_state);
        }
-       l2cap_add_conf_opt(&ptr, L2CAP_CONF_MTU, 2, chan->omtu);
+       l2cap_add_conf_opt(&ptr, L2CAP_CONF_MTU, 2, chan->omtu, endptr - ptr);

        if (remote_efs) {
            if (chan->local_stype != L2CAP_SERV_NOTRAFIC &&
@@ -3444,7 +3449,7 @@ done:

                l2cap_add_conf_opt(&ptr, L2CAP_CONF_EFS,
                           sizeof(efs),
-                          (unsigned long) &efs);
+                          (unsigned long) &efs, endptr - ptr);
            } else {
                /* Send PENDING Conf Rsp */
                result = L2CAP_CONF_PENDING;
@@ -3477,7 +3482,7 @@ done:
            set_bit(CONF_MODE_DONE, &chan->conf_state);

            l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC,
-                      sizeof(rfc), (unsigned long) &rfc);
+                      sizeof(rfc), (unsigned long) &rfc, endptr - ptr);

            if (test_bit(FLAG_EFS_ENABLE, &chan->flags)) {
                chan->remote_id = efs.id;
@@ -3491,7 +3496,7 @@ done:
                    le32_to_cpu(efs.sdu_itime);
                l2cap_add_conf_opt(&ptr, L2CAP_CONF_EFS,
                           sizeof(efs),
-                          (unsigned long) &efs);
+                          (unsigned long) &efs, endptr - ptr);
            }
            break;

@@ -3505,7 +3510,7 @@ done:
            set_bit(CONF_MODE_DONE, &chan->conf_state);

            l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC, sizeof(rfc),
-                      (unsigned long) &rfc);
+                      (unsigned long) &rfc, endptr - ptr);

            break;

@@ -3527,10 +3532,11 @@ done:
 }

 static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
-               void *data, u16 *result)
+               void *data, size_t size, u16 *result)
 {
    struct l2cap_conf_req *req = data;
    void *ptr = req->data;
+   void *endptr = data + size;
    int type, olen;
    unsigned long val;
    struct l2cap_conf_rfc rfc = { .mode = L2CAP_MODE_BASIC };
@@ -3548,13 +3554,13 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
                chan->imtu = L2CAP_DEFAULT_MIN_MTU;
            } else
                chan->imtu = val;
-           l2cap_add_conf_opt(&ptr, L2CAP_CONF_MTU, 2, chan->imtu);
+           l2cap_add_conf_opt(&ptr, L2CAP_CONF_MTU, 2, chan->imtu, endptr - ptr);
            break;

        case L2CAP_CONF_FLUSH_TO:
            chan->flush_to = val;
            l2cap_add_conf_opt(&ptr, L2CAP_CONF_FLUSH_TO,
-                      2, chan->flush_to);
+                      2, chan->flush_to, endptr - ptr);
            break;

        case L2CAP_CONF_RFC:
@@ -3568,13 +3574,13 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
            chan->fcs = 0;

            l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC,
-                      sizeof(rfc), (unsigned long) &rfc);
+                      sizeof(rfc), (unsigned long) &rfc, endptr - ptr);
            break;

        case L2CAP_CONF_EWS:
            chan->ack_win = min_t(u16, val, chan->ack_win);
            l2cap_add_conf_opt(&ptr, L2CAP_CONF_EWS, 2,
-                      chan->tx_win);
+                      chan->tx_win, endptr - ptr);
            break;

        case L2CAP_CONF_EFS:
@@ -3587,7 +3593,7 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
                return -ECONNREFUSED;

            l2cap_add_conf_opt(&ptr, L2CAP_CONF_EFS, sizeof(efs),
-                      (unsigned long) &efs);
+                      (unsigned long) &efs, endptr - ptr);
            break;

        case L2CAP_CONF_FCS:
@@ -3692,7 +3698,7 @@ void __l2cap_connect_rsp_defer(struct l2cap_chan *chan)
        return;

    l2cap_send_cmd(conn, l2cap_get_ident(conn), L2CAP_CONF_REQ,
-              l2cap_build_conf_req(chan, buf), buf);
+              l2cap_build_conf_req(chan, buf, sizeof(buf)), buf);
    chan->num_conf_req++;
 }

@@ -3900,7 +3906,7 @@ sendresp:
        u8 buf[128];
        set_bit(CONF_REQ_SENT, &chan->conf_state);
        l2cap_send_cmd(conn, l2cap_get_ident(conn), L2CAP_CONF_REQ,
-                  l2cap_build_conf_req(chan, buf), buf);
+                  l2cap_build_conf_req(chan, buf, sizeof(buf)), buf);
        chan->num_conf_req++;
    }

@@ -3978,7 +3984,7 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn,
            break;

        l2cap_send_cmd(conn, l2cap_get_ident(conn), L2CAP_CONF_REQ,
-                  l2cap_build_conf_req(chan, req), req);
+                  l2cap_build_conf_req(chan, req, sizeof(req)), req);
        chan->num_conf_req++;
        break;

@@ -4090,7 +4096,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn,
    }

    /* Complete config. */
-   len = l2cap_parse_conf_req(chan, rsp);
+   len = l2cap_parse_conf_req(chan, rsp, sizeof(rsp));
    if (len < 0) {
        l2cap_send_disconn_req(chan, ECONNRESET);
        goto unlock;
@@ -4124,7 +4130,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn,
    if (!test_and_set_bit(CONF_REQ_SENT, &chan->conf_state)) {
        u8 buf[64];
        l2cap_send_cmd(conn, l2cap_get_ident(conn), L2CAP_CONF_REQ,
-                  l2cap_build_conf_req(chan, buf), buf);
+                  l2cap_build_conf_req(chan, buf, sizeof(buf)), buf);
        chan->num_conf_req++;
    }

@@ -4184,7 +4190,7 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn,
            char buf[64];

            len = l2cap_parse_conf_rsp(chan, rsp->data, len,
-                          buf, &result);
+                          buf, sizeof(buf), &result);
            if (len < 0) {
                l2cap_send_disconn_req(chan, ECONNRESET);
                goto done;
@@ -4214,7 +4220,7 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn,
            /* throw out any old stored conf requests */
            result = L2CAP_CONF_SUCCESS;
            len = l2cap_parse_conf_rsp(chan, rsp->data, len,
-                          req, &result);
+                          req, sizeof(req), &result);
            if (len < 0) {
                l2cap_send_disconn_req(chan, ECONNRESET);
                goto done;
@@ -4791,7 +4797,7 @@ static void l2cap_do_create(struct l2cap_chan *chan, int result,
            set_bit(CONF_REQ_SENT, &chan->conf_state);
            l2cap_send_cmd(chan->conn, l2cap_get_ident(chan->conn),
                       L2CAP_CONF_REQ,
-                      l2cap_build_conf_req(chan, buf), buf);
+                      l2cap_build_conf_req(chan, buf, sizeof(buf)), buf);
            chan->num_conf_req++;
        }
    }
@@ -7465,7 +7471,7 @@ static void l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
                set_bit(CONF_REQ_SENT, &chan->conf_state);
                l2cap_send_cmd(conn, l2cap_get_ident(conn),
                           L2CAP_CONF_REQ,
-                          l2cap_build_conf_req(chan, buf),
+                          l2cap_build_conf_req(chan, buf, sizeof(buf)),
                           buf);
                chan->num_conf_req++;
            }

이 블로그의 인기 게시물

데일 카네기 인간관계론 정리

Remove-Server-Header

응답 메시지 내 서버 버전 정보 제거 1. Apache 1) 조치 방법 “/etc/htpd/conf/httpd.conf” 파일 안에서 1. ServerTokens OS → ServerTokens Prod 2. ServerSignature On → ServerSignature Off 로 변경한 후 아파치를 재시작하면 헤더 값의 아파치 버전 정보 및 OS 정보를 제거할 수 있다. 2) 참고 URL http://zetawiki.com/wiki/CentOS_ 아파치_보안권장설정_ServerTokens_Prod,_ServerSignature_Off 2. IIS 1) 조치 방법 IIS 6.0 urlscan_setup 실행. 설치. \windows\system32\inetsrv\urlscan\urlscan.ini 파일을 열어 다음 수정(RemoveServerHeader=0 을 RemoveServerHeader=1 로 변경) 서비스에서 IIS Admin Service 재시작. IIS 7.0 IIS 관리자를 열고 관리하려는 수준으로 이동합니다. 기능 보기에서 HTTP 응답 헤더를 두 번 클릭합니다. HTTP 응답 헤더 페이지에서 제거할 헤더를 선택합니다. 작업 창에서 제거를 클릭하고 예를 클릭합니다. 2) 참고 URL IIS 6.0 : http://gonnie.tistory.com/entry/iis6- 응답헤더-감추기 IIS 7.0 : https://technet.microsoft.com/ko-kr/library/cc733102(v=ws.10).aspx 3. jetty 1) 조치 방법 “jetty.xml” 파일에서 jetty.send.server.version=false 설정 2) 참고 URL http://attenuated-perspicacity.blogspot.kr/2009/09/jetty-61x-hardening.html 4. Nginx ...

CVE-2017-11352

CVE-2017-11352 ImageMagick 에서 발생했던 CVE-2017-9144 취약점의 미흡한 조치로 인하여 동일한 취약점이 다시 발생되었다. 재 발생된 취약점 CVE-2017-11352은 coders/rle.c 에서 RLE 이미지에 대한 부적절한 EOF 처리가 원인이었다. EOF 란? 파일의 끝(End of File, EOF)으로 데이터 소스로부터 더 이상 읽을 수 있는 데이터가 없음을 나타낸다. ImageMagick Github Page 에 들어가보면 해당 이슈를 상세히 확인할 수 있다. 부적절한 EOF 처리 원인은 소스 코드 수정 시 유사한 코드를 복사 붙여넣기 하는 과정에서 검증해야할 변수 명을 고치지 않고 그대로 적용해서 발생했다. operand=ReadBlobByte(image); if (opcode == EOF) ThrowRLEException(CorruptImageError, "UnexpectedEndOfFile" ); 이로 인해서 조치 완료된 줄 알았던 CVE-2017-9144 취약점은 CVE-2017-11352이라는 새로운 취약점 명으로 다시 조치 되었다. case SkipLinesOp: { operand=ReadBlobByte(image); - if (opcode == EOF) + if (operand == EOF) ThrowRLEException(CorruptImageError, "UnexpectedEndOfFile" ); if (opcode & 0x40 ) { operand=ReadBlobLSBSignedShort(image); - if (opcode == EOF) + if (operand == EO...