Giter Site home page Giter Site logo

sunzip's Introduction

SUNZIP

forthebadge made-with-python


PyPI Wheel Downloads version travis-ci codecov

Introduction

Why are we doing this?

According to Cara Marie, an archive bomb a.k.a. A zip bomb is often employed to disable antivirus software, in order to create an opening for more traditional viruses. In addition, various kinds of pitfalls may occur during decompression.

PyCon Korea-Click Click Boom! Bombs Over Our Minds

What is zip bomb?

It often appeared as a relatively small size zip file. And the unzipped file will be much larger than the zipped one. This would probably cause a problem when your disk volume or memory is relatively small than the unzipped one.

How do we defense zip bomb?

  • Defense Layer 1 - checks perform on the server side.
    1. Check if it's a nested zip file. (i.e. 42.zip)
    2. Check if the compression ratio (Uncompressed Content/Compressed Content)
       is greater than the threshold?
    3. Check if the file format is expected for context.
    4. Upload file size does not exceed the maximum limit.
  • Defense Layer 2 - limit the number of resources available to the process and its children.
    1. Check if CPU time is greater than the threshold.
    2. Check if the extracted part in memory is oversized. (memory usage)
  • Defense Layer 3 - filetype-specific mitigations.

    Filetype: Archives

    1. Restrict output file size and number of extracted files
       to ensure the total doesn't exceed the maximum limit.

How do we set thresholds?

Defense Layer 1:
  Uncompressed content size:  200 MB (vt)
  Compression ratio:          https://youtu.be/IXkX2ojrKZQ?t=553

Defense Layer 2:
  CPU time:                   2 seconds(vt)
  Memoery oversized:

Defense Layer 3:
  Output file size:
  Number of extracted files:

Useful resources

Bomb Codes
https://bomb.codes/

Mitigation Summary
https://youtu.be/IXkX2ojrKZQ?t=1296

Defense layers
https://bomb.codes/mitigations

Install

$ pip3 install sunzip
# for development use "development mode"
# https://packaging.python.org/tutorials/installing-packages/
$ pip3 install -e <directory to project root>

Usage

# for command line usage see the help
$ sunzip-cli -h

You can find the arguments defined at the top of cli.py

import sunzip

f = sunzip.Sunzip("archive.zip")

Customize your resource limit.

Maximum compression ratio threshold

f.threshold = 50

Maximum CPU time (second)

f.cpu = 1

Maximum memory usage (byte)

f.memory = 1024

Maximum file size (byte)

f.filesize = 1024

If there is no setting, the default value will be used.

extract() would perform a series of the above checks before decompression. If all pass, the zip file will be decompressed.

import sunzip

f = sunzip.Sunzip("archive.zip")

f.extract()

sunzip's People

Contributors

krnick avatar marhuang avatar muandrew avatar vamshikr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sunzip's Issues

Tag and publish fix #1

Hello!

I would like to use this package for my side project and I'm currently encountering the divide by zero error fixed in #1 . Could you tag the repository and publish a v0.0.2 so I can pick up the update? Tagging will help others find out which commit the package is built off of.

Thanks!

bug in check_is_nested

the function returns after just checking the first file, instead of checking all the files
PR: #8

Error when using the example code

Hello, i have installed sunzip on my windows computer using "pip install sunzip" and i got an error when using this example code :

import sunzip

f = sunzip.Sunzip("archive.zip")

f.extract()

the error

Traceback (most recent call last):
  File "c:\Users\*****\Desktop\sunzip\sunzip.py", line 1, in <module>
    import sunzip
  File "c:\Users\*****\Desktop\sunzip\sunzip.py", line 3, in <module>
    f = sunzip.Sunzip("archive.zip")
        ^^^^^^^^^^^^^
AttributeError: partially initialized module 'sunzip' has no attribute 'Sunzip' (most likely due to a circular import). Did you mean: 'sunzip'?

Thanks !

Please clarify the license, setup.py contradicts itself

I looked for a LICENSE or COPYING file but wasn't able to find one. I checked setup.py and found two contradictory license statements:

  • license='MIT', in the keyword arguments to setup()
  • "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)" in the classifiers list

Could you please choose one and place the corresponding text in a LICENSE file under the root of the repository?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.