Python - Setting / Getting Environment Variables and Addrs

I need to set an environment variable in Python and find the address in memory where it is located. Since it's on Linux, I don't mind about using libraries that only work consistently on Linux (if that's the only way). How would you do this?

Edit: The scope of the problem is as follows: I'm trying to hack a program for class, and essentially I'm putting my shellcode into an environment variable and then overwriting one byte on the victim code with the address of my environment variable. I need to find a way to automate this in Python, so my question is two-fold:

  • Is there a way to get the address in memory of an environment variable?

  • Can this only be done in bash/C or can I do it purely in Python?

Answers


The built in function id() returns a unique id for any object, which just happens to be it's memory address.

http://docs.python.org/library/functions.html#id


For accessing and setting environment variables, read up on the os.environ dictionary. You can also use os.putenv to set an environment variable.


Need Your Help

Simplifying an Expression in Python

python string iteration expression

I feel there must be a simpler/cleaner/faster (choose one or more) way to write this expression...

How Do I Create a Sub-Folder via PHP?

php directory new-operator subfolder

I am trying to create a directory that is inside of a folder called upload. Here is my current simple code that I tried to get this done:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.