Get environment variable address with Python
Question: for an university project I have to perform Buffer Overflow with some programs
given by the professor.

I want to setup my shellcode environment variable with python and I do that
with:

    
    
    import os
    os.environ("EGG") = "..."
    os.system('bash')
    

so now python spawns a child bash process. But now how can I print the address
of EGG? I have done this with C:

    
    
    #include <stdlib.h>
    #include <stdio.h>
    
    int main(){
        printf("%x", getenv("EGG"));
        return 0;
    }
    

but I want to do it with Python. Anyone can help?


Answer: You can use id() <https://docs.python.org/2/library/functions.html#id>

    
    
    id(os.environ.get('EGG')
    

in hex:

    
    
    hex(id(os.environ.get('EGG'))
    

