Is it possible to print my environment variable memory address ?
With gdb-peda
i have a memory address looking like 0xbffffcd6
with searchmem
and i know it's the right form. (0xbfff????
) but gdb moved the stack with some other environment variable.
I would like with my python script to get this address and then do my trick and include my shellcode.
i tried (with Python):
print hex(id(os.environ["ENVVAR"]))
print memoryview(os.environ["ENVVAR"])
# output :
# 0xb7b205c0L
# <memory at 0xb7b4dd9c>
With Ruby :
puts (ENV['PATH'].object_id << 1).to_s(16)
# output :
# -4836c38c
If anyone have an idea, with python or ruby.
It can be done in these ways:Using id() function. Using addressof() function. Using hex() function.
To print the memory address, we use '%p' format specifier in C. To print the address of a variable, we use "%p" specifier in C programming language. There are two ways to get the address of the variable: By using "address of" (&) operator.
To access the address of a variable to a pointer, we use the unary operator & (ampersand) that returns the address of that variable. For example &x gives us the address of variable x.
In python, the usage of sys. getsizeof() can be done to find the storage size of a particular object that occupies some space in the memory. This function returns the size of the object in bytes.
The cpython built in function id() returns a unique id for any object, which is not exactly it's memory address but is as close as you can get to such.
For example, we have variable x. id(x) does not return the memory address of the variable x, rather it returns the memory address of the object that x points to.
There's a strict separation between 'variables' and 'memory objects'. In the standard implementation, python allocates a set of locals and a stack for the virtual machine to operate on. All local slots are disjoint, so if you load an object from local slot x onto the stack and modify that object, the "location" of the x slot doesn't change.
http://docs.python.org/library/functions.html#id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With