从 shell 代码访问未链接的 libc 全局变量
有没有办法找到 libc 中尚未链接到可执行文件中的全局变量的地址(因此不在 get/plt 中)?我想在 shell 代码中访问 __environ 全局变量。
到目前为止,网络搜索只找到了一种方法,首先从 plt 中的实体查找共享库中的偏移量,然后将偏移量添加到 plt 中的运行时值,以获取所需变量的运行时地址共享库。还有另一种不依赖于共享库版本的方法吗?
谢谢。
Is there any way to find the address of a global variable in libc that hasn't been linked into the executable (therefore not in the got/plt)? I'd like to access the __environ global variable in my shell code.
Web searches have so far only turned up an approach where you first find the offset in the shared library from an entity that is in the plt, and add the offset to the runtime value in the plt to get the runtime address of the desired variable in the shared library. Is there another way that would not depend on the version of the shared library?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不。
__environ
的地址可以通过多种方式轻松找到,除了“首先从 plt 中的实体查找共享库中的偏移量,然后将偏移量添加到 plt 中的运行时值”之外。 plt 获取所需变量的运行时地址”,但该地址将取决于libc.so.6
的确切构建,并且会因版本而异(对于完全相同的 GLIBC 版本)来自发行版分发(例如不同的编译器会产生不同的结果)。那么还有哪些其他方法可以找到这个地址呢?
您需要两件事:
libc.so.6
中变量的地址,由nm
和readelf
打印:libc 的位置.so.6
本身在给定的进程中,可以通过例如/proc/$pid/maps
发现。上面的输出告诉我,
__environ
应该位于进程37
中的0x7f34d2865000+0x0000000000202d00
。量子电子器件。
PS 还有其他方法可以发现 (1) - 您可以直接读取
.dynsym
而不使用nm
,以及 (2) - 您可以使用dladdr( )
在目标进程内。No.
The address of
__environ
can be trivially found via many ways other than "first find the offset in the shared library from an entity that is in the plt, and add the offset to the runtime value in the plt to get the runtime address of the desired variable", but that address will depend on the exact build oflibc.so.6
, and will vary from version to version (and for the exact same GLIBC version) from distribution to distribution (e.g. different compilers will produce different result).So what other methods of finding this address exist?
You need two things:
libc.so.6
, printed bynm
andreadelf
:libc.so.6
itself in a given process, discoverable via e.g./proc/$pid/maps
.Above output tells me that
__environ
should be at0x7f34d2865000+0x0000000000202d00
in process37
.QED.
P.S. There are other ways of discovering (1) -- you could read
.dynsym
directly without usingnm
, and (2) -- you could usedladdr()
within the target process.