Skip to content

Instantly share code, notes, and snippets.

@juliusgeo
Last active May 16, 2023 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliusgeo/24a154b9cc4505186f6d1009f4da9b2c to your computer and use it in GitHub Desktop.
Save juliusgeo/24a154b9cc4505186f6d1009f4da9b2c to your computer and use it in GitHub Desktop.
Constrict Your Ram With Python
from multiprocessing import Process
import psutil
from time import sleep
def ascii_bomb():
return [
"""
.,-:-,,.
.AMMMHMMHHMII,
.AMM^HMMM^HMMHMMMHHA.
.AM^HMMM^HIM^M^MMHMHHHHHL
.AHHIHHMMHIMMMMMMMH^HHHMHLH:
,LH^I^HHH^IHMHMMMMM^MHH^LHHAIA
;IHHI;H;M;:;HMH^MMMMMHMHIHLIHHIA
.:I;H;I;';'..:.:IHM^MMHH^IH^LIHH.
,I;A;I;:;/. .'.'.::IA^MHMHHIALV^IHA
,A:AVI::.:; . '.:IAVM^HAVLV^IV^HA
.I;:;H;:;/. . ':IAV^MHMAHVHIHHH;
,;:;:;I;:/ . .'.:IAIH^AMAI^HI^HLA
.AIH:AHI/'. .'.:IIAH^MMAHHIHHIH,
.A;I;A;I/.:. .'.VIIHMHMMA^HI^IIA
;;H;:;H/:',_ .,,, _L:IIH^HMMH^HIHIM;
;A;I;H;P%"%&{{; ./{::{{$="`VIHHMHMAHIHI^HM
;IAIV:H|:::,^,,:\ ;:_,,^,_ VIHH^MMH^HHIIHB
;I;I;H;I:;'(*) ';| ..:'(*) ':IHM^HMHH^HI^V
.LHH::HII:::=%=;;:| ..'**%**'`::IIHHHI^MIIHH'
;I;H;H;H|:. ' '.:| .. ' ':H^HMHHMM^IH
;H;H;H;H|::. .::| .. :IHHMM^MM^IV
;H;M;H;H|:::. ..:| .': :HI^M^M^MHV'
;H;H;H;H|::. .::[ __; '.. :IH^MHMMH^P
;H;H;I;IH\::.:.:::;\==// :. .:IHMMM^MHV
H;H;M;H;I'\::.:..:': ; .,:. .:IHMMHMMM'
I;H;I;H;H'H\:::\':;{{%&;;;;;:" .:IHM^MH^V
:;I;H;M;M'HI\::.:\*..,,,,,;; ..:I^HMMMM'
';H;M;H;MH;;\:.::(:._;;;/‘ .::IMHM^M^
;I;M;M;H;M##"\::.::=> ..::':VHHMH:
:IH;M;H;H;M#;#\::<` ..::'.'.':VHV
;HIH;H;I;M;H##%\:> ..:::'.'. .. T,
:IHMM;I;I;M;M##&%<__..::::' . . . ,:.
HHIH;M;M;M;;#M##===;::. .. : . . AHAA.
HMH;M;M;M;H---::::. .. . . . ..:HMMH:
MMM;M;M;';'''::. .. .. . .AOAVA/'-..
"""
for (_) in iter(int, 1)
]
def emoji_bomb():
return ["💣" * (2**32) for (_) in iter(int, 1)]
def while_bomb():
doubloon = "💣"
while 1:
doubloon *= 2
def double_bomb():
doubloon = "💣"
return [doubloon := doubloon*2for (_) in iter(int, 1)]
bombs = (ascii_bomb, emoji_bomb, while_bomb, double_bomb)
if __name__ == "__main__":
for bomb in bombs:
p = Process(target=bomb)
p.start()
sleep(4)
print(
f"{bomb.__name__}: {psutil.Process(p.pid).memory_info().rss/1024/1024/1024:.3f}GB"
)
# ok we got our measurement, kill it
p.terminate()
p.join(0)
@juliusgeo
Copy link
Author

juliusgeo commented May 16, 2023

💥 DANGER
Will use up ALL your ram. Don't call any of the functions themselves without having kill -9 handy.

These are a collection of various ways that you can implement memory bombs in Python, along with some code to test how effective each one is.

ascii_bomb: 0.878GB
emoji_bomb: 2.000GB
while_bomb: 3.532GB
double_bomb: 3.375GB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment