简体   繁体   English

使用Python获取环境变量地址

[英]Get environment variable address with Python

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: 我想用python设置我的shellcode环境变量,我这样做是:

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

so now python spawns a child bash process. 所以现在python产生了一个子bash进程。 But now how can I print the address of EGG? 但是,现在我该如何打印EGG的地址? I have done this with C: 我已经用C完成了:

#include <stdlib.h>
#include <stdio.h>

int main(){
    printf("%x", getenv("EGG"));
    return 0;
}

but I want to do it with Python. 但是我想用Python做到这一点。 Anyone can help? 有人可以帮忙吗?

You can use id() https://docs.python.org/2/library/functions.html#id 您可以使用id() https://docs.python.org/2/library/functions.html#id

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

in hex: 十六进制:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM