Skip to content

Instantly share code, notes, and snippets.

@bluss

bluss/mtenv.py Secret

Created June 28, 2023 19:58
Show Gist options
  • Save bluss/a3d2ad94d55382f682897ee1efae6d74 to your computer and use it in GitHub Desktop.
Save bluss/a3d2ad94d55382f682897ee1efae6d74 to your computer and use it in GitHub Desktop.
"""
Original code from http://rachelbythebay.com/w/2017/01/30/env/
"""
import ctypes
import os
import random
import string
import threading
def worker():
"""Loop in thread, for a while"""
while True:
variable = "".join(random.sample(string.ascii_uppercase, 8))
#print(f"{variable}='test'")
os.putenv(variable, "test")
def get_getenv():
libc = ctypes.cdll.LoadLibrary("libc.so.6")
getenv = libc.getenv
getenv.restype = ctypes.c_char_p
getenv.argtypes = [ctypes.c_char_p]
return getenv
def main():
os.putenv("foo", "bar")
thread = threading.Thread(target=worker)
thread.start()
getenv = get_getenv()
while True:
whats_my_foo = getenv(b"foo\x00")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment