-
-
Save bluss/a3d2ad94d55382f682897ee1efae6d74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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