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

最近,在学习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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在VB.NET中,可以通过使用Process类的帮助方法和属性来获取进程句柄,并进而获取模块基址。 首先,我们需要引入System.Diagnostics命名空间,以便能够使用Process类。然后,可以使用Process.GetProcessesByName方法通过进程名或进程ID获取进程对象。接下来,我们可以通过Process.MainModule属性获取模块,并使用Module.BaseAddress属性获取模块基址。 以下是一个简单的示例代码: ``` Imports System.Diagnostics Public Class MainForm Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim processName As String = "YourProcessName" ' 替换为你要获取基址的进程名 Dim processes() As Process = Process.GetProcessesByName(processName) If processes.Length > 0 Then Dim process As Process = processes(0) ' 假设只有一个该进程的实例 Dim moduleBaseAddress As IntPtr = process.MainModule.BaseAddress MessageBox.Show("进程的模块基址为: " & moduleBaseAddress.ToString()) Else MessageBox.Show("未找到指定的进程") End If End Sub End Class ``` 在上述代码中,我们先通过Process.GetProcessesByName方法获取进程对象的数组,然后再获取第一个进程的主模块基址,并将其显示在一个消息框中。请注意,如果指定的进程名不存在,代码会显示一个相应的消息。 需要注意的是,为了能够执行这个操作,程序需要有足够的特权或权限,以便获取目标进程的句柄和模块基址

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值