linux下获取模块基址,通过DT_DEBUG来获得各个库的基址

本文介绍了如何通过DT_DEBUG在Linux下获取动态链接库的基址,包括解析动态链接表、查找r_debug结构体和link_map链表,从而找到目标库如ld-linux.so的基址。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近,在学习BCTF和0CTF的writeup时,注意到了一种通过DT_DEBUG来获得库的基址的方式:BCTF里的pattern用这一方法来获得ld-linux.so的地址,0CTF里的sandbox用这一方法来获得sandbox.so的基址。之前面对ASLR,我只知道可以通过GOT来获取libc.so的地址,而其他库的地址还不清楚应该怎样取得。于是,我稍微研究了下,在此记录。

首先,通过readelf -d,可以得到.dynamic的信息。而有些二进制文件里的.dynamic里包含DT_DEBUG:

Dynamic section at offset 0x7c8 contains 20 entries:

Tag Type Name/Value

...

0x0000000000000015 (DEBUG) 0x0

...

这里DT_DEBUG的值是0。在实际运行时,DT_DEBUG的值是指向struct r_debug的指针。其定义如下:

/* Rendezvous structure used by the run-time dynamic linker to communicate

details of shared object loading to the debugger. If the executable's

dynamic section has a DT_DEBUG element, the run-time linker sets that

element's value to the address where this structure can be found. */

struct r_debug

{

int r_version; /* Version number for this protocol. */

struct link_map *r_map; /* Head of the chain of loaded objects. */

/* This is the address of a function internal to the run-time linker,

that will always be called when the linker begins to map in a

library or unmap it, and again when the mapping change is complete.

The debugger can set a breakpoint at this address if it wants to

notice shared object mappi

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值